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

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 c31dcdb1 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
RevLine 
[ed4aef2]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.
[2f4b430]6
[ed4aef2]7"""
8import wx
9import wx.lib.newevent
10from wx.aui import AuiNotebook as Notebook
11
[0c2c324]12import datetime
13
[9df6a03]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
[d85c194]18from sas.sasgui.guiframe.panel_base import PanelBase
19from sas.sasgui.guiframe.events import StatusEvent
[ed4aef2]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
[2f4b430]27
[ed4aef2]28    :note: For Fit to be performed the user should check at least one parameter
29        on fit Panel window.
[2f4b430]30
[ed4aef2]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
[2f4b430]37
[ed4aef2]38    def __init__(self, parent, manager=None, *args, **kwargs):
39        """
40        """
41        style = ((wx.aui.AUI_NB_WINDOWLIST_BUTTON
[2f4b430]42                 | wx.aui.AUI_NB_DEFAULT_STYLE
43                 | wx.CLIP_CHILDREN)
[ed4aef2]44                 & ~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)
[6f16e25]45        Notebook.__init__(self, parent, wx.ID_ANY, style=style)
[ed4aef2]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):
[0c2c324]60        self.frame.Show(True)
[ed4aef2]61        result = event.result[0][0]
[0c2c324]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)
[ed4aef2]65        if hasattr(result, 'convergence'):
[2f4b430]66            best, pop = result.convergence[:, 0], result.convergence[:, 1:]
[9df6a03]67            self._get_view(ConvergenceView).update(best, pop)
68        else:
69            self._del_view(ConvergenceView)
[ed4aef2]70        if hasattr(result, 'uncertainty_state'):
[c915053]71            stats = var_stats(result.uncertainty_state.draw())
72            msg = format_vars(stats)
[9df6a03]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)
[ed4aef2]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"))
[9df6a03]79        else:
80            for view in (CorrelationView, UncertaintyView, TraceView):
81                self._del_view(view)
[ed4aef2]82
83    def get_frame(self):
84        return self.frame
85
[9df6a03]86    def _get_view(self, view_class):
[ed4aef2]87        for idx in range(self.PageCount):
[9df6a03]88            if self.GetPageText(idx) == view_class.title:
[ed4aef2]89                return self.GetPage(idx)
90        else:
[9df6a03]91            panel = view_class(self)
92            self.AddPage(panel, panel.title)
[ed4aef2]93            return panel
[9df6a03]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.