Changeset 7be7136 in sasview
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Corfunc/CorfuncPerspective.py
rff8cb73 r7be7136 1 1 # global 2 import sys3 2 from PyQt4 import QtCore 4 3 from PyQt4 import QtGui 5 from PyQt4 import QtWebKit6 7 from twisted.internet import threads8 from twisted.internet import reactor9 4 10 5 # sas-global 11 from sas.qtgui.Plotting.PlotterData import Data1D12 6 import sas.qtgui.Utilities.GuiUtils as GuiUtils 13 7 from sas.sascalc.corfunc.corfunc_calculator import CorfuncCalculator … … 18 12 from CorfuncUtils import WIDGETS as W 19 13 20 from matplotlib.backends import qt_compat21 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAggas FigureCanvas14 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg \ 15 as FigureCanvas 22 16 from matplotlib.figure import Figure 23 17 … … 25 19 class MyMplCanvas(FigureCanvas): 26 20 """Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.).""" 27 def __init__(self, model, parent=None,width=5, height=4, dpi=100):21 def __init__(self, model, width=5, height=4, dpi=100): 28 22 self.model = model 29 23 self.fig = Figure(figsize=(width, height), dpi=dpi) … … 31 25 32 26 FigureCanvas.__init__(self, self.fig) 33 # self.reparent(parent, QPoint(0, 0))34 35 # FigureCanvas.setSizePolicy(self,36 # QSizePolicy.Expanding,37 # QSizePolicy.Expanding)38 # FigureCanvas.updateGeometry(self)39 27 40 28 self.data = None 41 29 self.extrap = None 42 30 43 def draw QSpace(self):31 def draw_q_space(self): 44 32 self.fig.clf() 45 46 self.qmin = None47 self.qmax1 = None48 self.qmax2 = None49 33 50 34 self.axes = self.fig.add_subplot(111) … … 61 45 self.axes.axvline(qmax1) 62 46 self.axes.axvline(qmax2) 63 self.axes.set_xlim(min(self.data.x), max(self.data.x)*1.5-0.5*min(self.data.x)) 47 self.axes.set_xlim(min(self.data.x), max(self.data.x) * 1.5 - 48 0.5 * min(self.data.x)) 64 49 if self.extrap: 65 50 self.axes.plot(self.extrap.x, self.extrap.y) … … 77 62 self.axes.plot(self.data.x, self.data.y, label="1D Correlation") 78 63 self.axes.plot(self.data3.x, self.data3.y, label="3D Correlation") 79 self.axes.plot(self.data_idf.x, self.data_idf.y, label="Interface Distribution Function") 64 self.axes.plot(self.data_idf.x, self.data_idf.y, 65 label="Interface Distribution Function") 80 66 self.axes.set_xlim(min(self.data.x), max(self.data.x) / 4) 81 67 self.axes.legend() 82 68 83 69 self.draw() 84 85 86 # def sizeHint(self):87 # w, h = self.get_width_height()88 # return QSize(w, h)89 90 # def minimumSizeHint(self):91 # return QSize(10, 10)92 70 93 71 … … 95 73 # The controller which is responsible for managing signal slots connections 96 74 # for the gui and providing an interface to the data model. 97 name = "Corfunc" # For displaying in the combo box98 #def __init__(self, manager=None, parent=None): 75 name = "Corfunc" # For displaying in the combo box 76 99 77 def __init__(self, parent=None): 100 78 super(CorfuncWindow, self).__init__() … … 107 85 self._calculator = CorfuncCalculator() 108 86 109 self._canvas = MyMplCanvas(self.model , self)110 self._realplot = MyMplCanvas(self.model , self)87 self._canvas = MyMplCanvas(self.model) 88 self._realplot = MyMplCanvas(self.model) 111 89 self.verticalLayout_7.insertWidget(0, self._canvas) 112 90 self.verticalLayout_7.insertWidget(1, self._realplot) … … 114 92 # Connect buttons to slots. 115 93 # Needs to be done early so default values propagate properly. 116 self.setup Slots()94 self.setup_slots() 117 95 118 96 # Set up the model. 119 self.setup Model()97 self.setup_model() 120 98 121 99 # Set up the mapper 122 self.setup Mapper()123 124 def setup Slots(self):100 self.setup_mapper() 101 102 def setup_slots(self): 125 103 self.extrapolateBtn.clicked.connect(self.extrapolate) 126 104 self.transformBtn.clicked.connect(self.transform) … … 130 108 self.model.itemChanged.connect(self.modelChanged) 131 109 132 def setup Model(self):110 def setup_model(self): 133 111 self.model.setItem(W.W_QMIN, 134 112 QtGui.QStandardItem("0.01")) … … 158 136 def modelChanged(self, item): 159 137 self.mapper.toFirst() 160 self._canvas.draw QSpace()138 self._canvas.draw_q_space() 161 139 162 140 def _update_calculator(self): … … 165 143 qmax2 = float(self.model.item(W.W_QCUTOFF).text()) 166 144 self._calculator.upperq = (qmax1, qmax2) 167 self._calculator.background = float(self.model.item(W.W_BACKGROUND).text()) 145 self._calculator.background = \ 146 float(self.model.item(W.W_BACKGROUND).text()) 168 147 169 148 def extrapolate(self): 170 149 self._update_calculator() 171 params, extrapolation = self._calculator.compute_extrapolation()150 params, extrapolation, _ = self._calculator.compute_extrapolation() 172 151 173 152 self.model.setItem(W.W_GUINIERA, QtGui.QStandardItem(str(params['A']))) 174 153 self.model.setItem(W.W_GUINIERB, QtGui.QStandardItem(str(params['B']))) 175 154 self.model.setItem(W.W_PORODK, QtGui.QStandardItem(str(params['K']))) 176 self.model.setItem(W.W_PORODSIGMA, QtGui.QStandardItem(str(params['sigma']))) 155 self.model.setItem(W.W_PORODSIGMA, 156 QtGui.QStandardItem(str(params['sigma']))) 177 157 178 158 self._canvas.extrap = extrapolation 179 self._canvas.drawQSpace() 180 159 self._canvas.draw_q_space() 181 160 182 161 def transform(self): … … 188 167 extrap = self._canvas.extrap 189 168 bg = float(self.model.item(W.W_BACKGROUND).text()) 169 190 170 def updatefn(*args, **kwargs): 191 171 pass … … 212 192 213 193 self._update_calculator() 214 self._calculator.compute_transform(extrap, method, bg, completefn, updatefn)215 216 217 def setup Mapper(self):194 self._calculator.compute_transform(extrap, method, bg, 195 completefn, updatefn) 196 197 def setup_mapper(self): 218 198 self.mapper = QtGui.QDataWidgetMapper(self) 219 199 self.mapper.setOrientation(QtCore.Qt.Vertical) … … 269 249 270 250 self._canvas.data = data 271 self._canvas.draw QSpace()251 self._canvas.draw_q_space() 272 252 273 253 # self.model.item(WIDGETS.W_FILENAME).setData(QtCoreQVariant(self._model_item.text())) … … 280 260 281 261 self._allow_close = value 282 283 284 if __name__ == "__main__":285 app = QtGui.QApplication([])286 import qt4reactor287 # qt4reactor.install()288 # DO NOT move the following import to the top!289 # (unless you know what you're doing)290 from twisted.internet import reactor291 dlg = CorfuncWindow(reactor)292 print(dlg)293 dlg.show()294 # print(reactor)295 # reactor.run()296 sys.exit(app.exec_())
Note: See TracChangeset
for help on using the changeset viewer.