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