source: sasview/src/sas/qtgui/Perspectives/PrInversion/dmax.py @ 60bf0db

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 60bf0db was 60bf0db, checked in by Adam Washington <adam.washington@…>, 6 years ago

Added Model and Mapper boilerplate

  • Property mode set to 100644
File size: 3.3 KB
Line 
1# -*- coding: utf-8 -*-
2"""
3Dialog panel to explore the P(r) inversion results for a range
4of D_max value. User picks a number of points and a range of
5distances, then can toggle between inversion outputs and see
6their distribution as a function of D_max.
7"""
8
9# global
10import sys
11import os
12from PyQt4 import QtCore
13from PyQt4 import QtGui
14from PyQt4 import QtWebKit
15
16from twisted.internet import threads
17
18# sas-global
19from sas.qtgui.Plotting.PlotterData import Data1D
20from sas.qtgui.Plotting.Plotter import PlotterWidget
21import sas.qtgui.Utilities.GuiUtils as GuiUtils
22
23# local
24from UI.dmax import Ui_DmaxExplorer
25# from InvariantDetails import DetailsDialog
26# from InvariantUtils import WIDGETS
27
28def enum(*sequential, **named):
29    enums = dict(zip(sequential, range(len(sequential))), **named)
30    return type('Enum', (), enums)
31
32W = enum( 'NPTS',           #0
33          'DMIN',               #1
34          'DMAX',               #2
35          'VARIABLE',         #3
36)
37
38class DmaxWindow(QtGui.QDialog, Ui_DmaxExplorer):
39    # The controller which is responsible for managing signal slots connections
40    # for the gui and providing an interface to the data model.
41    name = "Dmax Explorer"  # For displaying in the combo box
42
43    def __init__(self, pr_state, nfunc, parent=None):
44        super(DmaxWindow, self).__init__()
45        self.setupUi(self)
46
47        self.setWindowTitle("Dₘₐₓ Explorer")
48
49        self.pr_state = pr_state
50        self.nfunc = nfunc
51        self.communicator = GuiUtils.Communicate()
52
53        self.plot = PlotterWidget(self, self)
54        self.verticalLayout.insertWidget(0, self.plot)
55
56        # Let's choose the Standard Item Model.
57        self.model = QtGui.QStandardItemModel(self)
58
59        # # Connect buttons to slots.
60        # # Needs to be done early so default values propagate properly.
61        self.setupSlots()
62
63        # Set up the model.
64        self.setupModel()
65
66        # # Set up the mapper
67        self.setupMapper()
68
69    def setupSlots(self):
70        self.closeButton.clicked.connect(self.close)
71
72        self.model.itemChanged.connect(self.modelChanged)
73
74    def setupModel(self):
75        self.model.setItem(W.NPTS, QtGui.QStandardItem(str(self.nfunc)))
76        self.model.setItem(W.DMIN,
77                           QtGui.QStandardItem(
78                               str(0.9*self.pr_state.d_max)))
79        self.model.setItem(W.DMAX,
80                           QtGui.QStandardItem(
81                               str(1.1*self.pr_state.d_max)))
82
83    def setupMapper(self):
84        self.mapper = QtGui.QDataWidgetMapper(self)
85        self.mapper.setOrientation(QtCore.Qt.Vertical)
86        self.mapper.setModel(self.model)
87
88        self.mapper.addMapping(self.Npts, W.NPTS)
89        self.mapper.addMapping(self.minDist, W.DMIN)
90        self.mapper.addMapping(self.maxDist, W.DMAX)
91        self.mapper.addMapping(self.dependentVariable, W.VARIABLE)
92
93        self.mapper.toFirst()
94
95    def modelChanged(self, item):
96        pass
97
98
99if __name__ == "__main__":
100    APP = QtGui.QApplication([])
101    import qt4reactor
102    qt4reactor.install()
103    # DO NOT move the following import to the top!
104    # (unless you know what you're doing)
105    from twisted.internet import reactor
106    from sas.sascalc.pr.invertor import Invertor
107    pr_state = Invertor()
108    DLG = DmaxWindow(pr_state, 10, reactor)
109    DLG.show()
110    reactor.run()
Note: See TracBrowser for help on using the repository browser.