source: sasview/src/sas/qtgui/Utilities/ResultPanel.py @ 6216eb75

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 6216eb75 was 6216eb75, checked in by piotr, 5 years ago

Remove not just widgets but also tabs between fits. SASVIEW-275

  • Property mode set to 100644
File size: 3.5 KB
Line 
1"""
2FitPanel class contains fields allowing to fit  models and  data
3
4"""
5import sys
6import datetime
7
8from PyQt5 import QtCore
9from PyQt5 import QtGui
10from PyQt5 import QtWidgets
11
12from bumps.dream.stats import var_stats, format_vars
13
14
15class ResultPanel(QtWidgets.QTabWidget):
16    """
17    FitPanel class contains fields allowing to fit  models and  data
18
19    :note: For Fit to be performed the user should check at least one parameter
20        on fit Panel window.
21
22    """
23    ## Internal name for the AUI manager
24    window_name = "Result panel"
25    windowClosedSignal = QtCore.pyqtSignal()
26
27    def __init__(self, parent, manager=None, *args, **kwargs):
28        """
29        """
30        super(ResultPanel, self).__init__(parent)
31        self.manager = manager
32        self.communicator = self.manager.communicator()
33        self.setMinimumSize(400, 400)
34
35        self.updateBumps() # patch bumps ## TEMPORARY ##
36
37        # the following two imports will move to the top once
38        # the monkeypatching is gone
39        from bumps.gui.convergence_view import ConvergenceView
40        from bumps.gui.uncertainty_view import UncertaintyView, CorrelationView, TraceView
41
42
43        self.convergenceView = ConvergenceView()
44        self.uncertaintyView = UncertaintyView()
45        self.correlationView = CorrelationView()
46        self.traceView = TraceView()
47        self.show()
48
49    def updateBumps(self):
50        """
51        Monkeypatching bumps plot viewer to allow Qt
52        """
53        from . import PlotView
54        import bumps.gui
55        sys.modules['bumps.gui.plot_view'] = PlotView
56
57    def onPlotResults(self, results):
58        # Clear up previous results
59        for view in (self.convergenceView, self.correlationView,
60                     self.uncertaintyView, self.traceView):
61            view.close()
62        # close all tabs. REMEMBER TO USE REVERSED RANGE!!!
63        for index in reversed(range(self.count())):
64            self.removeTab(index)
65
66        result = results[0][0]
67        filename = result.data.sas_data.filename
68        current_time = datetime.datetime.now().strftime("%I:%M%p, %B %d, %Y")
69        self.setWindowTitle(self.window_name + " - " + filename + " - " + current_time)
70        if hasattr(result, 'convergence'):
71            best, pop = result.convergence[:, 0], result.convergence[:, 1:]
72            self.convergenceView.update(best, pop)
73            self.addTab(self.convergenceView, "Convergence")
74            self.convergenceView.show()
75        else:
76            self.convergenceView.close()
77        if hasattr(result, 'uncertainty_state'):
78            stats = var_stats(result.uncertainty_state.draw())
79            msg = format_vars(stats)
80            self.correlationView.update(result.uncertainty_state)
81            self.correlationView.show()
82            self.addTab(self.correlationView, "Correlation")
83
84            self.uncertaintyView.update((result.uncertainty_state, stats))
85            self.uncertaintyView.show()
86            self.addTab(self.uncertaintyView, "Uncertainty")
87
88            self.traceView.update(result.uncertainty_state)
89            self.traceView.show()
90            self.addTab(self.traceView, "Parameter Trace")
91        else:
92            for view in (self.correlationView, self.uncertaintyView, self.traceView):
93                view.close()
94
95    def closeEvent(self, event):
96        """
97        Overwrite QDialog close method to allow for custom widget close
98        """
99        # notify the parent so it hides this window
100        self.windowClosedSignal.emit()
101        event.ignore()
102
Note: See TracBrowser for help on using the repository browser.