[6fd89d4] | 1 | # -*- coding: utf-8 -*- |
---|
| 2 | """ |
---|
| 3 | Dialog panel to explore the P(r) inversion results for a range |
---|
| 4 | of D_max value. User picks a number of points and a range of |
---|
| 5 | distances, then can toggle between inversion outputs and see |
---|
| 6 | their distribution as a function of D_max. |
---|
| 7 | """ |
---|
| 8 | |
---|
| 9 | # global |
---|
| 10 | import sys |
---|
| 11 | import os |
---|
| 12 | from PyQt4 import QtCore |
---|
| 13 | from PyQt4 import QtGui |
---|
| 14 | from PyQt4 import QtWebKit |
---|
| 15 | |
---|
| 16 | from twisted.internet import threads |
---|
| 17 | |
---|
| 18 | # sas-global |
---|
| 19 | from sas.qtgui.Plotting.PlotterData import Data1D |
---|
| 20 | from sas.qtgui.Plotting.Plotter import PlotterWidget |
---|
| 21 | import sas.qtgui.Utilities.GuiUtils as GuiUtils |
---|
| 22 | |
---|
| 23 | # local |
---|
| 24 | from UI.dmax import Ui_DmaxExplorer |
---|
| 25 | # from InvariantDetails import DetailsDialog |
---|
| 26 | # from InvariantUtils import WIDGETS |
---|
| 27 | |
---|
[60bf0db] | 28 | def enum(*sequential, **named): |
---|
| 29 | enums = dict(zip(sequential, range(len(sequential))), **named) |
---|
| 30 | return type('Enum', (), enums) |
---|
| 31 | |
---|
| 32 | W = enum( 'NPTS', #0 |
---|
| 33 | 'DMIN', #1 |
---|
| 34 | 'DMAX', #2 |
---|
| 35 | 'VARIABLE', #3 |
---|
| 36 | ) |
---|
[6fd89d4] | 37 | |
---|
| 38 | class 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 | |
---|
[60bf0db] | 43 | def __init__(self, pr_state, nfunc, parent=None): |
---|
[6fd89d4] | 44 | super(DmaxWindow, self).__init__() |
---|
| 45 | self.setupUi(self) |
---|
| 46 | |
---|
| 47 | self.setWindowTitle("Dâââ Explorer") |
---|
| 48 | |
---|
| 49 | self.pr_state = pr_state |
---|
[60bf0db] | 50 | self.nfunc = nfunc |
---|
[6fd89d4] | 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. |
---|
[60bf0db] | 61 | self.setupSlots() |
---|
[6fd89d4] | 62 | |
---|
[60bf0db] | 63 | # Set up the model. |
---|
| 64 | self.setupModel() |
---|
[6fd89d4] | 65 | |
---|
| 66 | # # Set up the mapper |
---|
[60bf0db] | 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 |
---|
[6fd89d4] | 97 | |
---|
| 98 | |
---|
| 99 | if __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 |
---|
[60bf0db] | 106 | from sas.sascalc.pr.invertor import Invertor |
---|
| 107 | pr_state = Invertor() |
---|
| 108 | DLG = DmaxWindow(pr_state, 10, reactor) |
---|
[6fd89d4] | 109 | DLG.show() |
---|
| 110 | reactor.run() |
---|