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

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 1e81bc8 was d85c194, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago

Remaining modules refactored

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