source: sasview/src/sas/sasgui/perspectives/fitting/resultpanel.py @ 628acad

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 628acad was 0c2c324, checked in by krzywon, 9 years ago

Resolve #456 - The filename (or first file in a constrained/simultaneous fit) and the time and date when the fit completed are now shown in the title bar of the results panel.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1"""
2FitPanel class contains fields allowing to fit  models and  data
3
4:note: For Fit to be performed the user should check at least one parameter
5    on fit Panel window.
6
7"""
8import wx
9import wx.lib.newevent
10from wx.aui import AuiNotebook as Notebook
11
12import datetime
13
14from bumps.gui.convergence_view import ConvergenceView
15from bumps.gui.uncertainty_view import UncertaintyView, CorrelationView, TraceView
16from bumps.dream.stats import var_stats, format_vars
17
18from sas.sasgui.guiframe.panel_base import PanelBase
19from sas.sasgui.guiframe.events import StatusEvent
20
21(PlotResultEvent, EVT_PLOT_RESULT) = wx.lib.newevent.NewEvent()
22
23
24class ResultPanel(Notebook, PanelBase):
25    """
26    FitPanel class contains fields allowing to fit  models and  data
27
28    :note: For Fit to be performed the user should check at least one parameter
29        on fit Panel window.
30
31    """
32    ## Internal name for the AUI manager
33    window_name = "Result panel"
34    ## Title to appear on top of the window
35    window_caption = "Result Panel"
36    CENTER_PANE = True
37
38    def __init__(self, parent, manager=None, *args, **kwargs):
39        """
40        """
41        style = ((wx.aui.AUI_NB_WINDOWLIST_BUTTON
42                 | wx.aui.AUI_NB_DEFAULT_STYLE
43                 | wx.CLIP_CHILDREN)
44                 & ~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)
45        Notebook.__init__(self, parent, wx.ID_ANY, style=style)
46        PanelBase.__init__(self, parent)
47        self.frame = parent
48        self.Bind(EVT_PLOT_RESULT, self.on_plot_results)
49        self.frame.Bind(wx.EVT_CLOSE, self.on_close)
50        self._manager = None
51
52    def on_close(self, event):
53        if event.CanVeto():
54            self.frame.Hide()
55            event.Veto()
56        else:
57            event.Skip()
58
59    def on_plot_results(self, event):
60        self.frame.Show(True)
61        result = event.result[0][0]
62        filename = result.data.sas_data.filename
63        current_time = datetime.datetime.now().strftime("%I:%M%p, %B %d, %Y")
64        self.parent.SetTitle(self.window_name + " - " + filename + " - " + current_time)
65        if hasattr(result, 'convergence'):
66            best, pop = result.convergence[:, 0], result.convergence[:, 1:]
67            self._get_view(ConvergenceView).update(best, pop)
68        else:
69            self._del_view(ConvergenceView)
70        if hasattr(result, 'uncertainty_state'):
71            stats = var_stats(result.uncertainty_state.draw())
72            msg = format_vars(stats)
73            self._get_view(CorrelationView).update(result.uncertainty_state)
74            self._get_view(UncertaintyView).update((result.uncertainty_state, stats))
75            self._get_view(TraceView).update(result.uncertainty_state)
76            # TODO: stats should be stored in result rather than computed in bumps UncertaintyView
77            wx.PostEvent(self.frame.parent,
78                         StatusEvent(status=msg, info="info"))
79        else:
80            for view in (CorrelationView, UncertaintyView, TraceView):
81                self._del_view(view)
82
83    def get_frame(self):
84        return self.frame
85
86    def _get_view(self, view_class):
87        for idx in range(self.PageCount):
88            if self.GetPageText(idx) == view_class.title:
89                return self.GetPage(idx)
90        else:
91            panel = view_class(self)
92            self.AddPage(panel, panel.title)
93            return panel
94
95    def _del_view(self, view_class):
96        for idx in range(self.PageCount):
97            if self.GetPageText(idx) == view_class.title:
98                self.DeletePage(idx)
99
Note: See TracBrowser for help on using the repository browser.