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

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

Further work on the main QStandardItemModel

  • 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
272            # Add the plot to the model item
273            # variant_item = QtCore.QVariant(self._plotter)
274            variant_item = QtCore.QVariant(extrapolated_data)
275
276            # This needs to run in the main thread
277            reactor.callFromThread(GuiUtils.updateModelItemWithPlot,
278                    self._model_item, variant_item, title)
279
280        if self._high_extrapolate:
281            # for presentation in InvariantDetails
282            qmax_plot = Q_MAXIMUM_PLOT * max(self._data.x)
283            if qmax_plot > Q_MAXIMUM:
284                qmax_plot = Q_MAXIMUM
285            qstar_high, qstar_high_err = inv.get_qstar_high()
286            power_high = inv.get_extrapolation_power(range='high')
287            high_out_data = inv.get_extra_data_high(q_end=qmax_plot, npts=500)
288
289            # Convert the data into plottable
290            high_out_data = self._manager.createGuiData(high_out_data)
291
292            # find how to add this plot to the existing plot for low_extrapolate
293            # Plot the chart
294            title = "High-Q extrapolation"
295
296            # Add the plot to the model item
297            # variant_item = QtCore.QVariant(self._plotter)
298            variant_item = QtCore.QVariant(high_out_data)
299            # This needs to run in the main thread
300            reactor.callFromThread(GuiUtils.updateModelItemWithPlot,
301                    self._model_item, variant_item, title)
302
303        item = QtGui.QStandardItem(str(float('%.5g'% volume_fraction)))
304        self.model.setItem(WIDGETS.W_VOLUME_FRACTION, item)
305        item = QtGui.QStandardItem(str(float('%.5g'% volume_fraction_error)))
306        self.model.setItem(WIDGETS.W_VOLUME_FRACTION_ERR, item)
307        item = QtGui.QStandardItem(str(float('%.5g'% surface)))
308        self.model.setItem(WIDGETS.W_SPECIFIC_SURFACE, item)
309        item = QtGui.QStandardItem(str(float('%.5g'% surface_error)))
310        self.model.setItem(WIDGETS.W_SPECIFIC_SURFACE_ERR, item)
311        item = QtGui.QStandardItem(str(float('%.5g'% qstar_total)))
312        self.model.setItem(WIDGETS.W_INVARIANT, item)
313        item = QtGui.QStandardItem(str(float('%.5g'% qstar_total_error)))
314        self.model.setItem(WIDGETS.W_INVARIANT_ERR, item)
315
316        #item = QtGui.QStandardItem(str(float('%.5g'% qstar_total)))
317        #self.model.setItem(WIDGETS.D_TOTAL_QSTAR, item)
318        #item = QtGui.QStandardItem(str(float('%.5g'% qstar_total_err)))
319        #self.model.setItem(WIDGETS.D_TOTAL_QSTAR_ERR, item)
320        item = QtGui.QStandardItem(str(float('%.5g'% qstar_low)))
321        self.model.setItem(WIDGETS.D_LOW_QSTAR, item)
322        item = QtGui.QStandardItem(str(float('%.5g'% qstar_low_err)))
323        self.model.setItem(WIDGETS.D_LOW_QSTAR_ERR, item)
324        item = QtGui.QStandardItem(str(float('%.5g'% qstar_high)))
325        self.model.setItem(WIDGETS.D_HIGH_QSTAR, item)
326        item = QtGui.QStandardItem(str(float('%.5g'% qstar_high_err)))
327        self.model.setItem(WIDGETS.D_HIGH_QSTAR_ERR, item)
328
329        self.mapper.toFirst()
330
331        return self.model
332               
333    def title(self):
334        """
335        Perspective name
336        """
337        return "Invariant panel"
338
339    def status(self):
340        """
341        """
342        self.detailsDialog.setModel(self.model)
343        self.detailsDialog.showDialog()
344
345    def help(self):
346        """
347        """
348        _TreeLocation = self._manager.HELP_DIRECTORY_LOCATION + \
349            "/user/sasgui/perspectives/invariant/invariant_help.html"
350        self._helpView.load(QtCore.QUrl(_TreeLocation))
351        self._helpView.show()
352
353    def setupSlots(self):
354        self.pushButton.clicked.connect(self.calculateInvariant)
355        self.pushButton_2.clicked.connect(self.status)
356        self.pushButton_3.clicked.connect(self.help)
357
358        self.radioButton.toggled.connect(self.lowGuinierAndPowerToggle)
359        self.radioButton_8.toggled.connect(self.hiFitAndFixToggle)
360
361        self.radioButton_3.toggled.connect(self.lowFitAndFixToggle)
362
363        # Bug workaround for QDataWidgetMapper() not reacting to checkbox clicks.
364        # https://bugreports.qt.io/browse/QTBUG-1818
365        self.checkBox.clicked.connect(self.setFocus)
366        self.checkBox_2.clicked.connect(self.setFocus)
367
368        self.model.itemChanged.connect(self.modelChanged)
369
370    def modelChanged(self, item):
371        """
372        """
373        if item.row() == WIDGETS.W_ENABLE_LOWQ:
374            toggle = (str(item.text()) == 'true')
375            self._low_extrapolate = toggle
376            self.lowQToggle(toggle)
377        elif item.row() == WIDGETS.W_ENABLE_HIGHQ:
378            toggle = (str(item.text()) == 'true')
379            self._high_extrapolate = toggle
380            self.highQToggle(toggle)
381       
382    def lowGuinierAndPowerToggle(self, toggle):
383        """
384        """
385        self._low_guinier = toggle
386        toggle = not toggle
387        self.lineEdit_11.setEnabled(toggle)
388        self.radioButton_3.setEnabled(toggle)
389        self.radioButton_4.setEnabled(toggle)
390        self.lineEdit_11.setEnabled(toggle and (not self._low_fit))
391
392    def lowFitAndFixToggle(self, toggle):
393        """
394        """
395        self._low_fit = toggle
396        toggle = not toggle
397        self.lineEdit_11.setEnabled(toggle)
398
399    def hiFitAndFixToggle(self, toggle):
400        """
401        """
402        self.lineEdit_13.setEnabled(toggle)
403
404    def highQToggle(self, clicked):
405        """
406        Disable/enable High Q extrapolation
407        """
408        self.radioButton_7.setEnabled(clicked)
409        self.radioButton_8.setEnabled(clicked)
410        self.lineEdit_12.setEnabled(clicked)
411        self.lineEdit_13.setEnabled(clicked)
412
413    def lowQToggle(self, clicked):
414        """
415        Disable/enable Low Q extrapolation
416        """
417        self.radioButton.setEnabled(clicked)
418        self.radioButton_2.setEnabled(clicked)
419        self.lineEdit_11.setEnabled(clicked and not self._low_fit)
420
421        # Enable subelements
422        self.radioButton_3.setEnabled(clicked and not self._low_guinier)
423        self.radioButton_4.setEnabled(clicked and not self._low_guinier)
424        self.lineEdit_10.setEnabled(clicked and not self._low_guinier)
425
426    def setupModel(self):
427
428        # filename
429        item = QtGui.QStandardItem(self._path)
430        self.model.setItem(WIDGETS.W_FILENAME, item)
431
432        # add Q parameters to the model
433        #qmin = min(self._data.x)
434        qmin = 0.0
435        item = QtGui.QStandardItem(str(qmin))
436        self.model.setItem(WIDGETS.W_QMIN, item)
437        qmax = 0.0
438        item = QtGui.QStandardItem(str(qmax))
439        self.model.setItem(WIDGETS.W_QMAX, item)
440
441        # add custom input params
442        item = QtGui.QStandardItem(str(self._background))
443        self.model.setItem(WIDGETS.W_BACKGROUND, item)
444        item = QtGui.QStandardItem(str(self._contrast))
445        self.model.setItem(WIDGETS.W_CONTRAST, item)
446        item = QtGui.QStandardItem(str(self._scale))
447        self.model.setItem(WIDGETS.W_SCALE, item)
448       
449        # Dialog elements
450        itemf = QtGui.QStandardItem("false")
451        self.model.setItem(WIDGETS.W_ENABLE_HIGHQ, itemf)
452        itemf = QtGui.QStandardItem("false")
453        self.model.setItem(WIDGETS.W_ENABLE_LOWQ, itemf)
454
455        item = QtGui.QStandardItem(str(self._npoints_low))
456        self.model.setItem(WIDGETS.W_NPTS_LOWQ, item)
457        item = QtGui.QStandardItem(str(self._npoints_high))
458        self.model.setItem(WIDGETS.W_NPTS_HIGHQ, item)
459
460        itemt = QtGui.QStandardItem("true")
461        self.model.setItem(WIDGETS.W_LOWQ_GUINIER, itemt)
462
463        itemt = QtGui.QStandardItem("true")
464        self.model.setItem(WIDGETS.W_LOWQ_FIT, itemt)
465        item = QtGui.QStandardItem(str(self._power_low))
466        self.model.setItem(WIDGETS.W_LOWQ_POWER_VALUE, item)
467
468        itemt = QtGui.QStandardItem("true")
469        self.model.setItem(WIDGETS.W_HIGHQ_FIT, itemt)
470        item = QtGui.QStandardItem(str(self._power_low))
471        self.model.setItem(WIDGETS.W_HIGHQ_POWER_VALUE, item)
472
473
474    def setupMapper(self):
475        # Set up the mapper.
476        self.mapper = QtGui.QDataWidgetMapper(self)
477        self.mapper.setOrientation(QtCore.Qt.Vertical)
478        self.mapper.setModel(self.model)
479
480        # Set up the view on the model for testing
481        # self.tableView.setModel(self.model)
482
483        # Filename
484        self.mapper.addMapping(self.lineEdit, WIDGETS.W_FILENAME)
485        # Qmin/Qmax
486        self.mapper.addMapping(self.lineEdit_2, WIDGETS.W_QMIN)
487        self.mapper.addMapping(self.lineEdit_3, WIDGETS.W_QMAX)
488
489        # Background
490        self.mapper.addMapping(self.lineEdit_4, WIDGETS.W_BACKGROUND)
491        # Scale
492        self.mapper.addMapping(self.lineEdit_5, WIDGETS.W_SCALE)
493        # Contrast
494        self.mapper.addMapping(self.lineEdit_6, WIDGETS.W_CONTRAST)
495
496        # Lowq/Highq items
497        self.mapper.addMapping(self.checkBox, WIDGETS.W_ENABLE_LOWQ)
498        self.mapper.addMapping(self.checkBox_2, WIDGETS.W_ENABLE_HIGHQ)
499
500        self.mapper.addMapping(self.lineEdit_10, WIDGETS.W_NPTS_LOWQ)
501        self.mapper.addMapping(self.radioButton, WIDGETS.W_LOWQ_GUINIER)
502
503        self.mapper.addMapping(self.radioButton_3, WIDGETS.W_LOWQ_FIT)
504        self.mapper.addMapping(self.lineEdit_11, WIDGETS.W_LOWQ_POWER_VALUE)
505
506        self.mapper.addMapping(self.radioButton_7, WIDGETS.W_HIGHQ_FIT)
507        self.mapper.addMapping(self.lineEdit_13, WIDGETS.W_HIGHQ_POWER_VALUE)
508   
509        # Output
510        self.mapper.addMapping(self.lineEdit_14, WIDGETS.W_VOLUME_FRACTION)
511        self.mapper.addMapping(self.lineEdit_15, WIDGETS.W_VOLUME_FRACTION_ERR)
512        self.mapper.addMapping(self.lineEdit_16, WIDGETS.W_SPECIFIC_SURFACE)
513        self.mapper.addMapping(self.lineEdit_17, WIDGETS.W_SPECIFIC_SURFACE_ERR)
514        self.mapper.addMapping(self.lineEdit_19, WIDGETS.W_INVARIANT)
515        self.mapper.addMapping(self.lineEdit_18, WIDGETS.W_INVARIANT_ERR)
516
517        self.mapper.toFirst()
518
519    def setData(self, data_item):
520        """
521        Obtain a QStandardItem object and dissect it to get Data1D/2D
522        Pass it over to the calculator
523        """
524        if not isinstance(data_item, list):
525            msg = "Incorrect type passed to the Invariant Perspective"
526            raise AttributeError, msg
527
528        if not isinstance(data_item[0], QtGui.QStandardItem):
529            msg = "Incorrect type passed to the Invariant Perspective"
530            raise AttributeError, msg
531
532        self._model_item = data_item[0]
533
534        # Extract data on 1st child - this is the Data1D/2D component
535        data = GuiUtils.dataFromItem(self._model_item)
536        self.model.item(WIDGETS.W_FILENAME).setData(QtCore.QVariant(self._model_item.text()))
537
538        ##### DEBUG ####
539        # set data in the debug tree view window
540        self.treeView.setModel(self.model)
541
542        self.calculate(data_list=[data])
543       
544    def calculate(self, data_list=None):
545        """
546        receive a list of data and compute invariant
547
548        TODO: pass warnings/messages to log
549        """
550        msg = ""
551        data = None
552        if data_list is None:
553            data_list = []
554        if len(data_list) >= 1:
555            if len(data_list) == 1:
556                data = data_list[0]
557            else:
558                data_1d_list = []
559                data_2d_list = []
560                error_msg = ""
561                # separate data into data1d and data2d list
562                for data in data_list:
563                    if data is not None:
564                        if issubclass(data.__class__, Data1D):
565                            data_1d_list.append(data)
566                        else:
567                            error_msg += " %s  type %s \n" % (str(data.name),
568                                                              str(data.__class__.__name__))
569                            data_2d_list.append(data)
570                if len(data_2d_list) > 0:
571                    msg = "Invariant does not support the following data types:\n"
572                    msg += error_msg
573                if len(data_1d_list) == 0:
574                    # remake this as a qt event
575                    #wx.PostEvent(self.parent, StatusEvent(status=msg, info='error'))
576                    return
577
578                # TODO: add msgbox for data choice
579                #msg += "Invariant panel does not allow multiple data!\n"
580                #msg += "Please select one.\n"
581                #if len(data_list) > 1:
582                    #from invariant_widgets import DataDialog
583                    #dlg = DataDialog(data_list=data_1d_list, text=msg)
584                    #if dlg.ShowModal() == wx.ID_OK:
585                    #    data = dlg.get_data()
586                    #else:
587                    #    data = None
588                    #dlg.Destroy()
589
590            if data is None:
591                msg += "invariant receives no data. \n"
592                #wx.PostEvent(self.parent, StatusEvent(status=msg, info='error'))
593                return
594            if not issubclass(data.__class__, Data1D):
595                msg += "invariant cannot be computed for data of "
596                msg += "type %s\n" % (data.__class__.__name__)
597                #wx.PostEvent(self.parent, StatusEvent(status=msg, info='error'))
598                return
599            else:
600                #wx.PostEvent(self.parent, NewPlotEvent(plot=data, title=data.title))
601                try:
602                    self._data = data
603                    self._path = "unique path"
604                    self.calculateInvariant()
605                except:
606                    msg = "Invariant Set_data: " + str(sys.exc_value)
607                    #wx.PostEvent(self.parent, StatusEvent(status=msg, info="error"))
608        else:
609            msg = "invariant cannot be computed for data of "
610            msg += "type %s" % (data.__class__.__name__)
611            #wx.PostEvent(self.parent, StatusEvent(status=msg, info='error'))
612
613    def allowBatch(self):
614        """
615        Tell the caller that we don't accept multiple data instances
616        """
617        return False
618
619if __name__ == "__main__":
620    app = QtGui.QApplication([])
621    import qt4reactor
622    qt4reactor.install()
623    # DO NOT move the following import to the top!
624    # (unless you know what you're doing)
625    from twisted.internet import reactor
626    dlg = InvariantWindow(reactor)
627    dlg.show()
628    reactor.run()
Note: See TracBrowser for help on using the repository browser.