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

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 5876f7e 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
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
[9df6a03]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
[d85c194]16from sas.sasgui.guiframe.panel_base import PanelBase
17from sas.sasgui.guiframe.events import StatusEvent
[ed4aef2]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
[2f4b430]25
[ed4aef2]26    :note: For Fit to be performed the user should check at least one parameter
27        on fit Panel window.
[2f4b430]28
[ed4aef2]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
[2f4b430]35
[ed4aef2]36    def __init__(self, parent, manager=None, *args, **kwargs):
37        """
38        """
39        style = ((wx.aui.AUI_NB_WINDOWLIST_BUTTON
[2f4b430]40                 | wx.aui.AUI_NB_DEFAULT_STYLE
41                 | wx.CLIP_CHILDREN)
[ed4aef2]42                 & ~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)
[6f16e25]43        Notebook.__init__(self, parent, wx.ID_ANY, style=style)
[ed4aef2]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'):
[2f4b430]61            best, pop = result.convergence[:, 0], result.convergence[:, 1:]
[9df6a03]62            self._get_view(ConvergenceView).update(best, pop)
63        else:
64            self._del_view(ConvergenceView)
[ed4aef2]65        if hasattr(result, 'uncertainty_state'):
[c915053]66            stats = var_stats(result.uncertainty_state.draw())
67            msg = format_vars(stats)
[9df6a03]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)
[ed4aef2]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"))
[9df6a03]74        else:
75            for view in (CorrelationView, UncertaintyView, TraceView):
76                self._del_view(view)
[ed4aef2]77
78    def get_frame(self):
79        return self.frame
80
[9df6a03]81    def _get_view(self, view_class):
[ed4aef2]82        for idx in range(self.PageCount):
[9df6a03]83            if self.GetPageText(idx) == view_class.title:
[ed4aef2]84                return self.GetPage(idx)
85        else:
[9df6a03]86            panel = view_class(self)
87            self.AddPage(panel, panel.title)
[ed4aef2]88            return panel
[9df6a03]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.