1 | """ |
---|
2 | FitPanel 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 | """ |
---|
8 | import wx |
---|
9 | import wx.lib.newevent |
---|
10 | from wx.aui import AuiNotebook as Notebook |
---|
11 | |
---|
12 | from bumps.gui.convergence_view import ConvergenceView |
---|
13 | from bumps.gui.uncertainty_view import UncertaintyView, CorrelationView, TraceView |
---|
14 | from bumps.dream.stats import var_stats, format_vars |
---|
15 | |
---|
16 | from sas.sasgui.guiframe.panel_base import PanelBase |
---|
17 | from sas.sasgui.guiframe.events import StatusEvent |
---|
18 | |
---|
19 | (PlotResultEvent, EVT_PLOT_RESULT) = wx.lib.newevent.NewEvent() |
---|
20 | |
---|
21 | |
---|
22 | class 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 | |
---|