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 | import datetime |
---|
13 | |
---|
14 | from bumps.gui.convergence_view import ConvergenceView |
---|
15 | from bumps.gui.uncertainty_view import UncertaintyView, CorrelationView, TraceView |
---|
16 | from bumps.dream.stats import var_stats, format_vars |
---|
17 | |
---|
18 | from sas.sasgui.guiframe.panel_base import PanelBase |
---|
19 | from sas.sasgui.guiframe.events import StatusEvent |
---|
20 | |
---|
21 | (PlotResultEvent, EVT_PLOT_RESULT) = wx.lib.newevent.NewEvent() |
---|
22 | |
---|
23 | |
---|
24 | class 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 = list(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 | |
---|