[ed4aef2] | 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. |
---|
[2f4b430] | 6 | |
---|
[ed4aef2] | 7 | """ |
---|
| 8 | import wx |
---|
| 9 | import wx.lib.newevent |
---|
| 10 | from wx.aui import AuiNotebook as Notebook |
---|
| 11 | |
---|
[9df6a03] | 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 | |
---|
[79492222] | 16 | from sas.guiframe.panel_base import PanelBase |
---|
| 17 | from sas.guiframe.events import StatusEvent |
---|
[ed4aef2] | 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 |
---|
[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) |
---|
[2f4b430] | 43 | Notebook.__init__(self, parent, -1, 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 | |
---|