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

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 aadf0af1 was aadf0af1, checked in by Piotr Rozyczko <rozyczko@…>, 6 years ago

Plot specific part of the context menu SASVIEW-427

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