source: sasview/src/sas/qtgui/Perspectives/Invariant/InvariantPerspective.py @ 02f1d12

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 02f1d12 was 457d961, checked in by Celine Durniak <celine.durniak@…>, 7 years ago

Corrected bugs in display of new GUI (angstrom, size of line edit)

  • Property mode set to 100644
File size: 24.4 KB
Line 
1# global
2import sys
3import os
4from PyQt4 import QtCore
5from PyQt4 import QtGui
6from PyQt4 import QtWebKit
7
8from twisted.internet import threads
9from twisted.internet import reactor
10
11# sas-global
12from sas.sascalc.invariant import invariant
13from sas.qtgui.Plotting.PlotterData import Data1D
14import sas.qtgui.Utilities.GuiUtils as GuiUtils
15
16# local
17from UI.TabbedInvariantUI import Ui_tabbedInvariantUI
18from InvariantDetails import DetailsDialog
19from InvariantUtils import WIDGETS
20
21# The minimum q-value to be used when extrapolating
22Q_MINIMUM = 1e-5
23# The maximum q-value to be used when extrapolating
24Q_MAXIMUM = 10
25# the ratio of maximum q value/(qmax of data) to plot the theory data
26Q_MAXIMUM_PLOT = 3
27
28
29class MyModel(object):
30    def __init__(self):
31        self._model = QtGui.QStandardItemModel(self)
32
33    def addItem(self, item):
34        item = QtGui.QStandardItem(str(item))
35        self._model.appendRow(item)
36
37class InvariantWindow(QtGui.QDialog, Ui_tabbedInvariantUI):
38    # The controller which is responsible for managing signal slots connections
39    # for the gui and providing an interface to the data model.
40    name = "Invariant" # For displaying in the combo box
41    #def __init__(self, manager=None, parent=None):
42    def __init__(self, parent=None):
43        #super(InvariantWindow, self).__init__(parent)
44        super(InvariantWindow, self).__init__()
45        self.setupUi(self)
46
47        self.setWindowTitle("Invariant Perspective")
48
49        # initial input params
50        self._background = 0.0
51        self._scale = 1.0
52        self._contrast = 1.0
53        self._porod = 1.0
54        self._npoints_low = 10
55        self._npoints_high = 10
56        self._power_low = 4
57
58        self._manager = parent
59        #self._manager = manager
60        self._reactor = reactor
61        self._model_item = QtGui.QStandardItem()
62
63        self._helpView = QtWebKit.QWebView()
64        self.detailsDialog = DetailsDialog(self)
65
66        self._low_extrapolate = False
67        self._low_guinier  = True
68        self._low_fit  = True
69        self._high_extrapolate = False
70        self._high_power_value  = False
71
72        # no reason to have this widget resizable
73        self.setFixedSize(self.minimumSizeHint())
74
75        self.communicate = GuiUtils.Communicate()
76
77        self._data = None
78        self._path = ""
79
80        self._allow_close = False
81
82        # Mask file selector
83        ###################################################
84        #self._path = "cyl_400_20.txt"
85        #from sas.sascalc.dataloader.loader import  Loader
86        #loader = Loader()
87        #try:
88        #    self._data = loader.load(self._path)
89        #except:
90        #    raise
91        ###################################################
92
93        self.lineEdit_8.setText(str(Q_MINIMUM))
94        self.lineEdit_9.setText(str(Q_MAXIMUM))
95
96        # Let's choose the Standard Item Model.
97        self.model = QtGui.QStandardItemModel(self)
98
99        # Connect buttons to slots.
100        # Needs to be done early so default values propagate properly.
101        self.setupSlots()
102
103        # Set up the model.
104        self.setupModel()
105
106        # Set up the mapper
107        self.setupMapper()
108
109        new_font = 'font-family: -apple-system, "Helvetica Neue", "Ubuntu";'
110        self.label_2.setStyleSheet(new_font)
111        self.label_24.setStyleSheet(new_font)
112        self.label_27.setStyleSheet(new_font)
113
114    def setClosable(self, value=True):
115        """
116        Allow outsiders close this widget
117        """
118        assert isinstance(value, bool)
119
120        self._allow_close = value
121
122    def closeEvent(self, event):
123        """
124        Overwrite QDialog close method to allow for custom widget close
125        """
126        if self._allow_close:
127            # reset the closability flag
128            self.setClosable(value=False)
129            event.accept()
130        else:
131            event.ignore()
132            # Maybe we should just minimize
133            self.setWindowState(QtCore.Qt.WindowMinimized)
134
135    def communicator(self):
136        """ Getter for the communicator """
137        return self.communicate
138
139    def updateFromModel(self):
140        """
141        update the globals based on the data in the model
142        """
143        self._background = float(self.model.item(WIDGETS.W_BACKGROUND).text())
144        self._contrast   = float(self.model.item(WIDGETS.W_CONTRAST).text())
145        self._scale      = float(self.model.item(WIDGETS.W_SCALE).text())
146
147        # High extrapolate
148        self._low_extrapolate = ( str(self.model.item(WIDGETS.W_ENABLE_LOWQ).text()) == 'true')
149        self._low_points = float(self.model.item(WIDGETS.W_NPTS_LOWQ).text())
150        self._low_guinier  = ( str(self.model.item(WIDGETS.W_LOWQ_GUINIER).text()) == 'true')
151        self._low_fit  = ( str(self.model.item(WIDGETS.W_LOWQ_FIT).text()) == 'true')
152        self._low_power_value  = float(self.model.item(WIDGETS.W_LOWQ_POWER_VALUE).text())
153
154        # High extrapolating
155        self._high_extrapolate = ( str(self.model.item(WIDGETS.W_ENABLE_HIGHQ).text()) == 'true')
156        self._high_points  = float(self.model.item(WIDGETS.W_NPTS_HIGHQ).text())
157        self._high_fit  = ( str(self.model.item(WIDGETS.W_HIGHQ_FIT).text()) == 'true')
158        self._high_power_value  = float(self.model.item(WIDGETS.W_HIGHQ_POWER_VALUE).text())
159
160    def calculateInvariant(self):
161        """
162        Use twisted to thread the calculations away.
163        """
164        # Find out if extrapolation needs to be used.
165        extrapolation = None
166        if self._low_extrapolate  and not self._high_extrapolate:
167            extrapolation = "low"
168        elif not self._low_extrapolate  and self._high_extrapolate:
169            extrapolation = "high"
170        elif self._low_extrapolate and self._high_extrapolate:
171            extrapolation = "both"
172        try:
173            # modify the Calculate button to indicate background process
174            self.pushButton.setText("Calculating...")
175            self.pushButton.setEnabled(False)
176            self.style = self.pushButton.styleSheet()
177            self.pushButton.setStyleSheet("background-color: rgb(255, 255, 0); color: rgb(0, 0, 0)")
178            # Send the calculations to separate thread.
179            d = threads.deferToThread(self.calculateThread, extrapolation)
180            # Add deferred callback for call return
181            d.addCallback(self.plotResult)
182        except Exception as ex:
183            # Set the button back to available
184            self.pushButton.setEnabled(True)
185            self.pushButton.setText("Calculate")
186            self.pushButton.setStyleSheet(self.style)
187
188
189    def plotResult(self, model):
190        """
191        """
192        self.model = model
193        self.mapper.toFirst()
194
195        # Set the button back to available
196        self.pushButton.setEnabled(True)
197        self.pushButton.setText("Calculate")
198        self.pushButton.setStyleSheet(self.style)
199
200        # Send the modified model item to DE for keeping in the model
201        self.communicate.updateModelFromPerspectiveSignal.emit(self._model_item)
202
203
204    def calculateThread(self, extrapolation):
205        """
206        Perform Invariant calculations.
207
208        TODO: Create a dictionary of results to be sent to DE on completion.
209        """
210        self.updateFromModel()
211
212        qstar_low = 0.0
213        qstar_low_err = 0.0
214        qstar_high = 0.0
215        qstar_high_err = 0.0
216        qstar_total = 0.0
217        qstar_total_low_err = 0.0
218
219        # Prepare the invariant object
220        inv = invariant.InvariantCalculator(data=self._data,
221                                            background = self._background,
222                                            scale = self._scale)
223
224        if self._low_extrapolate:
225            function_low = "power_law"
226            if self._low_guinier:
227                function_low = "guinier"
228            if self._low_fit:
229                self._low_power_value = None
230            inv.set_extrapolation(range="low",
231                                  npts=self._low_points,
232                                  function=function_low,
233                                  power=self._low_power_value)
234
235        if self._high_extrapolate:
236            function_low = "power_law"
237            inv.set_extrapolation(range="high",
238                                  npts=self._high_points,
239                                  function=function_low,
240                                  power=self._low_power_value)
241
242        #Compute invariant
243        # TODO: proper exception handling and logic -
244        # display info, update lineedits, don't run extrapolations etc.
245        calculation_failed = False
246        try:
247            qstar_total, qstar_total_error         = inv.get_qstar_with_error()
248        except Exception as ex:
249            calculation_failed = True
250            # Display relevant information
251            item = QtGui.QStandardItem("ERROR")
252            self.model.setItem(WIDGETS.W_INVARIANT, item)
253            item = QtGui.QStandardItem("ERROR")
254            self.model.setItem(WIDGETS.W_INVARIANT_ERR, item)
255        try:
256            volume_fraction, volume_fraction_error = \
257                inv.get_volume_fraction_with_error(self._contrast)
258        except Exception as ex:
259            calculation_failed = True
260            # Display relevant information
261            item = QtGui.QStandardItem("ERROR")
262            self.model.setItem(WIDGETS.W_VOLUME_FRACTION, item)
263            item = QtGui.QStandardItem("ERROR")
264            self.model.setItem(WIDGETS.W_VOLUME_FRACTION_ERR, item)
265        try:
266            surface, surface_error = \
267                inv.get_surface_with_error(self._contrast, self._porod)
268        except Exception as ex:
269            calculation_failed = True
270            # Display relevant information
271            item = QtGui.QStandardItem("ERROR")
272            self.model.setItem(WIDGETS.W_SPECIFIC_SURFACE, item)
273            item = QtGui.QStandardItem("ERROR")
274            self.model.setItem(WIDGETS.W_SPECIFIC_SURFACE_ERR, item)
275
276        if(calculation_failed):
277            # TODO: NOTIFY THE GUI MANAGER!!
278            self.mapper.toFirst()
279            return self.model
280
281        if self._low_extrapolate:
282            # for presentation in InvariantDetails
283            qstar_low, qstar_low_err = inv.get_qstar_low()
284            extrapolated_data = inv.get_extra_data_low(self._low_points)
285            power_low = inv.get_extrapolation_power(range='low')
286
287            #inv.data = extrapolated_data
288            #qstar_total, qstar_total_error = inv.get_qstar_with_error()
289
290            # Plot the chart
291            title = "Low-Q extrapolation"
292
293            # Convert the data into plottable
294            extrapolated_data = self._manager.createGuiData(extrapolated_data)
295            extrapolated_data.name = title
296            extrapolated_data.title = title
297
298            # Add the plot to the model item
299            # variant_item = QtCore.QVariant(self._plotter)
300            variant_item = QtCore.QVariant(extrapolated_data)
301
302            # This needs to run in the main thread
303            reactor.callFromThread(GuiUtils.updateModelItemWithPlot,
304                    self._model_item, variant_item, title)
305
306        if self._high_extrapolate:
307            # for presentation in InvariantDetails
308            qmax_plot = Q_MAXIMUM_PLOT * max(self._data.x)
309            if qmax_plot > Q_MAXIMUM:
310                qmax_plot = Q_MAXIMUM
311            qstar_high, qstar_high_err = inv.get_qstar_high()
312            power_high = inv.get_extrapolation_power(range='high')
313            high_out_data = inv.get_extra_data_high(q_end=qmax_plot, npts=500)
314
315            # Plot the chart
316            title = "High-Q extrapolation"
317
318            # Convert the data into plottable
319            high_out_data = self._manager.createGuiData(high_out_data)
320            high_out_data.name = title
321            high_out_data.title = title
322
323            # Add the plot to the model item
324            # variant_item = QtCore.QVariant(self._plotter)
325            variant_item = QtCore.QVariant(high_out_data)
326            # This needs to run in the main thread
327            reactor.callFromThread(GuiUtils.updateModelItemWithPlot,
328                    self._model_item, variant_item, title)
329
330        item = QtGui.QStandardItem(str(float('%.5g'% volume_fraction)))
331        self.model.setItem(WIDGETS.W_VOLUME_FRACTION, item)
332        item = QtGui.QStandardItem(str(float('%.5g'% volume_fraction_error)))
333        self.model.setItem(WIDGETS.W_VOLUME_FRACTION_ERR, item)
334        item = QtGui.QStandardItem(str(float('%.5g'% surface)))
335        self.model.setItem(WIDGETS.W_SPECIFIC_SURFACE, item)
336        item = QtGui.QStandardItem(str(float('%.5g'% surface_error)))
337        self.model.setItem(WIDGETS.W_SPECIFIC_SURFACE_ERR, item)
338        item = QtGui.QStandardItem(str(float('%.5g'% qstar_total)))
339        self.model.setItem(WIDGETS.W_INVARIANT, item)
340        item = QtGui.QStandardItem(str(float('%.5g'% qstar_total_error)))
341        self.model.setItem(WIDGETS.W_INVARIANT_ERR, item)
342
343        #item = QtGui.QStandardItem(str(float('%.5g'% qstar_total)))
344        #self.model.setItem(WIDGETS.D_TOTAL_QSTAR, item)
345        #item = QtGui.QStandardItem(str(float('%.5g'% qstar_total_err)))
346        #self.model.setItem(WIDGETS.D_TOTAL_QSTAR_ERR, item)
347        item = QtGui.QStandardItem(str(float('%.5g'% qstar_low)))
348        self.model.setItem(WIDGETS.D_LOW_QSTAR, item)
349        item = QtGui.QStandardItem(str(float('%.5g'% qstar_low_err)))
350        self.model.setItem(WIDGETS.D_LOW_QSTAR_ERR, item)
351        item = QtGui.QStandardItem(str(float('%.5g'% qstar_high)))
352        self.model.setItem(WIDGETS.D_HIGH_QSTAR, item)
353        item = QtGui.QStandardItem(str(float('%.5g'% qstar_high_err)))
354        self.model.setItem(WIDGETS.D_HIGH_QSTAR_ERR, item)
355
356        self.mapper.toFirst()
357
358        return self.model
359               
360    def title(self):
361        """
362        Perspective name
363        """
364        return "Invariant panel"
365
366    def status(self):
367        """
368        """
369        self.detailsDialog.setModel(self.model)
370        self.detailsDialog.showDialog()
371
372    def help(self):
373        """
374        """
375        _TreeLocation = GuiUtils.HELP_DIRECTORY_LOCATION + \
376            "/user/sasgui/perspectives/invariant/invariant_help.html"
377        self._helpView.load(QtCore.QUrl(_TreeLocation))
378        self._helpView.show()
379
380    def setupSlots(self):
381        self.pushButton.clicked.connect(self.calculateInvariant)
382        self.pushButton_2.clicked.connect(self.status)
383        self.pushButton_3.clicked.connect(self.help)
384
385        self.radioButton.toggled.connect(self.lowGuinierAndPowerToggle)
386        self.radioButton_8.toggled.connect(self.hiFitAndFixToggle)
387
388        self.radioButton_3.toggled.connect(self.lowFitAndFixToggle)
389
390        # Bug workaround for QDataWidgetMapper() not reacting to checkbox clicks.
391        # https://bugreports.qt.io/browse/QTBUG-1818
392        self.checkBox.clicked.connect(self.setFocus)
393        self.checkBox_2.clicked.connect(self.setFocus)
394
395        self.model.itemChanged.connect(self.modelChanged)
396
397    def modelChanged(self, item):
398        """
399        """
400        if item.row() == WIDGETS.W_ENABLE_LOWQ:
401            toggle = (str(item.text()) == 'true')
402            self._low_extrapolate = toggle
403            self.lowQToggle(toggle)
404        elif item.row() == WIDGETS.W_ENABLE_HIGHQ:
405            toggle = (str(item.text()) == 'true')
406            self._high_extrapolate = toggle
407            self.highQToggle(toggle)
408       
409    def lowGuinierAndPowerToggle(self, toggle):
410        """
411        """
412        self._low_guinier = toggle
413        toggle = not toggle
414        self.lineEdit_11.setEnabled(toggle)
415        self.radioButton_3.setEnabled(toggle)
416        self.radioButton_4.setEnabled(toggle)
417        self.lineEdit_11.setEnabled(toggle and (not self._low_fit))
418
419    def lowFitAndFixToggle(self, toggle):
420        """
421        """
422        self._low_fit = toggle
423        toggle = not toggle
424        self.lineEdit_11.setEnabled(toggle)
425
426    def hiFitAndFixToggle(self, toggle):
427        """
428        """
429        self.lineEdit_13.setEnabled(toggle)
430
431    def highQToggle(self, clicked):
432        """
433        Disable/enable High Q extrapolation
434        """
435        self.radioButton_7.setEnabled(clicked)
436        self.radioButton_8.setEnabled(clicked)
437        self.lineEdit_12.setEnabled(clicked)
438        self.lineEdit_13.setEnabled(clicked)
439
440    def lowQToggle(self, clicked):
441        """
442        Disable/enable Low Q extrapolation
443        """
444        self.radioButton.setEnabled(clicked)
445        self.radioButton_2.setEnabled(clicked)
446        self.lineEdit_11.setEnabled(clicked and not self._low_fit)
447
448        # Enable subelements
449        self.radioButton_3.setEnabled(clicked and not self._low_guinier)
450        self.radioButton_4.setEnabled(clicked and not self._low_guinier)
451        self.lineEdit_10.setEnabled(clicked and not self._low_guinier)
452
453    def setupModel(self):
454
455        # filename
456        item = QtGui.QStandardItem(self._path)
457        self.model.setItem(WIDGETS.W_FILENAME, item)
458
459        # add Q parameters to the model
460        #qmin = min(self._data.x)
461        qmin = 0.0
462        item = QtGui.QStandardItem(str(qmin))
463        self.model.setItem(WIDGETS.W_QMIN, item)
464        qmax = 0.0
465        item = QtGui.QStandardItem(str(qmax))
466        self.model.setItem(WIDGETS.W_QMAX, item)
467
468        # add custom input params
469        item = QtGui.QStandardItem(str(self._background))
470        self.model.setItem(WIDGETS.W_BACKGROUND, item)
471        item = QtGui.QStandardItem(str(self._contrast))
472        self.model.setItem(WIDGETS.W_CONTRAST, item)
473        item = QtGui.QStandardItem(str(self._scale))
474        self.model.setItem(WIDGETS.W_SCALE, item)
475       
476        # Dialog elements
477        itemf = QtGui.QStandardItem("false")
478        self.model.setItem(WIDGETS.W_ENABLE_HIGHQ, itemf)
479        itemf = QtGui.QStandardItem("false")
480        self.model.setItem(WIDGETS.W_ENABLE_LOWQ, itemf)
481
482        item = QtGui.QStandardItem(str(self._npoints_low))
483        self.model.setItem(WIDGETS.W_NPTS_LOWQ, item)
484        item = QtGui.QStandardItem(str(self._npoints_high))
485        self.model.setItem(WIDGETS.W_NPTS_HIGHQ, item)
486
487        itemt = QtGui.QStandardItem("true")
488        self.model.setItem(WIDGETS.W_LOWQ_GUINIER, itemt)
489
490        itemt = QtGui.QStandardItem("true")
491        self.model.setItem(WIDGETS.W_LOWQ_FIT, itemt)
492        item = QtGui.QStandardItem(str(self._power_low))
493        self.model.setItem(WIDGETS.W_LOWQ_POWER_VALUE, item)
494
495        itemt = QtGui.QStandardItem("true")
496        self.model.setItem(WIDGETS.W_HIGHQ_FIT, itemt)
497        item = QtGui.QStandardItem(str(self._power_low))
498        self.model.setItem(WIDGETS.W_HIGHQ_POWER_VALUE, item)
499
500
501    def setupMapper(self):
502        # Set up the mapper.
503        self.mapper = QtGui.QDataWidgetMapper(self)
504        self.mapper.setOrientation(QtCore.Qt.Vertical)
505        self.mapper.setModel(self.model)
506
507        # Set up the view on the model for testing
508        # self.tableView.setModel(self.model)
509
510        # Filename
511        self.mapper.addMapping(self.lineEdit, WIDGETS.W_FILENAME)
512        # Qmin/Qmax
513        self.mapper.addMapping(self.lineEdit_2, WIDGETS.W_QMIN)
514        self.mapper.addMapping(self.lineEdit_3, WIDGETS.W_QMAX)
515
516        # Background
517        self.mapper.addMapping(self.lineEdit_4, WIDGETS.W_BACKGROUND)
518        # Scale
519        self.mapper.addMapping(self.lineEdit_5, WIDGETS.W_SCALE)
520        # Contrast
521        self.mapper.addMapping(self.lineEdit_6, WIDGETS.W_CONTRAST)
522
523        # Lowq/Highq items
524        self.mapper.addMapping(self.checkBox, WIDGETS.W_ENABLE_LOWQ)
525        self.mapper.addMapping(self.checkBox_2, WIDGETS.W_ENABLE_HIGHQ)
526
527        self.mapper.addMapping(self.lineEdit_10, WIDGETS.W_NPTS_LOWQ)
528        self.mapper.addMapping(self.radioButton, WIDGETS.W_LOWQ_GUINIER)
529
530        self.mapper.addMapping(self.radioButton_3, WIDGETS.W_LOWQ_FIT)
531        self.mapper.addMapping(self.lineEdit_11, WIDGETS.W_LOWQ_POWER_VALUE)
532
533        self.mapper.addMapping(self.radioButton_7, WIDGETS.W_HIGHQ_FIT)
534        self.mapper.addMapping(self.lineEdit_13, WIDGETS.W_HIGHQ_POWER_VALUE)
535   
536        # Output
537        self.mapper.addMapping(self.lineEdit_14, WIDGETS.W_VOLUME_FRACTION)
538        self.mapper.addMapping(self.lineEdit_15, WIDGETS.W_VOLUME_FRACTION_ERR)
539        self.mapper.addMapping(self.lineEdit_16, WIDGETS.W_SPECIFIC_SURFACE)
540        self.mapper.addMapping(self.lineEdit_17, WIDGETS.W_SPECIFIC_SURFACE_ERR)
541        self.mapper.addMapping(self.lineEdit_19, WIDGETS.W_INVARIANT)
542        self.mapper.addMapping(self.lineEdit_18, WIDGETS.W_INVARIANT_ERR)
543
544        self.mapper.toFirst()
545
546    def setData(self, data_item, is_batch=False):
547        """
548        Obtain a QStandardItem object and dissect it to get Data1D/2D
549        Pass it over to the calculator
550        """
551        if not isinstance(data_item, list):
552            msg = "Incorrect type passed to the Invariant Perspective"
553            raise AttributeError, msg
554
555        if not isinstance(data_item[0], QtGui.QStandardItem):
556            msg = "Incorrect type passed to the Invariant Perspective"
557            raise AttributeError, msg
558
559        self._model_item = data_item[0]
560
561        # Extract data on 1st child - this is the Data1D/2D component
562        data = GuiUtils.dataFromItem(self._model_item)
563        self.model.item(WIDGETS.W_FILENAME).setData(QtCore.QVariant(self._model_item.text()))
564
565        ##### DEBUG ####
566        # set data in the debug tree view window
567        self.treeView.setModel(self.model)
568
569        self.calculate(data_list=[data])
570       
571    def calculate(self, data_list=None):
572        """
573        receive a list of data and compute invariant
574
575        TODO: pass warnings/messages to log
576        """
577        msg = ""
578        data = None
579        if data_list is None:
580            data_list = []
581        if len(data_list) >= 1:
582            if len(data_list) == 1:
583                data = data_list[0]
584            else:
585                data_1d_list = []
586                data_2d_list = []
587                error_msg = ""
588                # separate data into data1d and data2d list
589                for data in data_list:
590                    if data is not None:
591                        if issubclass(data.__class__, Data1D):
592                            data_1d_list.append(data)
593                        else:
594                            error_msg += " %s  type %s \n" % (str(data.name),
595                                                              str(data.__class__.__name__))
596                            data_2d_list.append(data)
597                if len(data_2d_list) > 0:
598                    msg = "Invariant does not support the following data types:\n"
599                    msg += error_msg
600                if len(data_1d_list) == 0:
601                    # remake this as a qt event
602                    #wx.PostEvent(self.parent, StatusEvent(status=msg, info='error'))
603                    return
604
605                # TODO: add msgbox for data choice
606                #msg += "Invariant panel does not allow multiple data!\n"
607                #msg += "Please select one.\n"
608                #if len(data_list) > 1:
609                    #from invariant_widgets import DataDialog
610                    #dlg = DataDialog(data_list=data_1d_list, text=msg)
611                    #if dlg.ShowModal() == wx.ID_OK:
612                    #    data = dlg.get_data()
613                    #else:
614                    #    data = None
615                    #dlg.Destroy()
616
617            if data is None:
618                msg += "invariant receives no data. \n"
619                #wx.PostEvent(self.parent, StatusEvent(status=msg, info='error'))
620                return
621            if not issubclass(data.__class__, Data1D):
622                msg += "invariant cannot be computed for data of "
623                msg += "type %s\n" % (data.__class__.__name__)
624                #wx.PostEvent(self.parent, StatusEvent(status=msg, info='error'))
625                return
626            else:
627                #wx.PostEvent(self.parent, NewPlotEvent(plot=data, title=data.title))
628                try:
629                    self._data = data
630                    self._path = "unique path"
631                    self.calculateInvariant()
632                except:
633                    msg = "Invariant Set_data: " + str(sys.exc_value)
634                    #wx.PostEvent(self.parent, StatusEvent(status=msg, info="error"))
635        else:
636            msg = "invariant cannot be computed for data of "
637            msg += "type %s" % (data.__class__.__name__)
638            #wx.PostEvent(self.parent, StatusEvent(status=msg, info='error'))
639
640    def allowBatch(self):
641        """
642        Tell the caller that we don't accept multiple data instances
643        """
644        return False
645
646if __name__ == "__main__":
647    app = QtGui.QApplication([])
648    import qt4reactor
649    qt4reactor.install()
650    # DO NOT move the following import to the top!
651    # (unless you know what you're doing)
652    from twisted.internet import reactor
653    dlg = InvariantWindow(reactor)
654    dlg.show()
655    reactor.run()
Note: See TracBrowser for help on using the repository browser.