[d955bf19] | 1 | |
---|
[b06ef8c] | 2 | |
---|
| 3 | import wx |
---|
| 4 | import wx.lib.newevent |
---|
[32c0841] | 5 | #from copy import deepcopy |
---|
[d85c194] | 6 | from sas.sasgui.guiframe.events import EVT_SLICER_PARS |
---|
| 7 | from sas.sasgui.guiframe.utils import format_number |
---|
| 8 | from sas.sasgui.guiframe.events import EVT_SLICER |
---|
| 9 | from sas.sasgui.guiframe.events import SlicerParameterEvent |
---|
[32c0841] | 10 | |
---|
[0d9dae8] | 11 | |
---|
[ef0c170] | 12 | class SlicerParameterPanel(wx.Dialog): |
---|
[d955bf19] | 13 | """ |
---|
[b40ad40] | 14 | Panel class to show the slicer parameters |
---|
[d955bf19] | 15 | """ |
---|
[b06ef8c] | 16 | #TODO: show units |
---|
| 17 | #TODO: order parameters properly |
---|
[b40ad40] | 18 | |
---|
[cd84dca] | 19 | def __init__(self, parent, *args, **kwargs): |
---|
[12aa9b5] | 20 | """ |
---|
[b40ad40] | 21 | Dialog window that allow to edit parameters slicer |
---|
[d955bf19] | 22 | by entering new values |
---|
[12aa9b5] | 23 | """ |
---|
[b40ad40] | 24 | wx.Dialog.__init__(self, parent, *args, **kwargs) |
---|
[b06ef8c] | 25 | self.params = {} |
---|
| 26 | self.parent = parent |
---|
| 27 | self.type = None |
---|
| 28 | self.listeners = [] |
---|
| 29 | self.parameters = [] |
---|
[32c0841] | 30 | self.bck = wx.GridBagSizer(5, 5) |
---|
[b06ef8c] | 31 | self.SetSizer(self.bck) |
---|
[32c0841] | 32 | label = "Right-click on 2D plot for slicer options" |
---|
| 33 | title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) |
---|
| 34 | self.bck.Add(title, (0, 0), (1, 2), |
---|
[b40ad40] | 35 | flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) |
---|
[b06ef8c] | 36 | # Bindings |
---|
| 37 | self.parent.Bind(EVT_SLICER, self.onEVT_SLICER) |
---|
| 38 | self.parent.Bind(EVT_SLICER_PARS, self.onParamChange) |
---|
| 39 | |
---|
| 40 | def onEVT_SLICER(self, event): |
---|
| 41 | """ |
---|
[d955bf19] | 42 | Process EVT_SLICER events |
---|
| 43 | When the slicer changes, update the panel |
---|
[b40ad40] | 44 | |
---|
[d955bf19] | 45 | :param event: EVT_SLICER event |
---|
[b06ef8c] | 46 | """ |
---|
| 47 | event.Skip() |
---|
[235f514] | 48 | if event.obj_class is None: |
---|
[b06ef8c] | 49 | self.set_slicer(None, None) |
---|
| 50 | else: |
---|
| 51 | self.set_slicer(event.type, event.params) |
---|
[b40ad40] | 52 | |
---|
[b06ef8c] | 53 | def set_slicer(self, type, params): |
---|
| 54 | """ |
---|
[d955bf19] | 55 | Rebuild the panel |
---|
[b06ef8c] | 56 | """ |
---|
[b40ad40] | 57 | self.bck.Clear(True) |
---|
| 58 | self.type = type |
---|
[235f514] | 59 | if type is None: |
---|
[32c0841] | 60 | label = "Right-click on 2D plot for slicer options" |
---|
| 61 | title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) |
---|
[b40ad40] | 62 | self.bck.Add(title, (0, 0), (1, 2), |
---|
| 63 | flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) |
---|
[b06ef8c] | 64 | else: |
---|
[b40ad40] | 65 | title = wx.StaticText(self, -1, |
---|
[32c0841] | 66 | "Slicer Parameters", style=wx.ALIGN_LEFT) |
---|
| 67 | self.bck.Add(title, (0, 0), (1, 2), |
---|
[b40ad40] | 68 | flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) |
---|
[ef0c170] | 69 | ix = 0 |
---|
| 70 | iy = 0 |
---|
[b06ef8c] | 71 | self.parameters = [] |
---|
| 72 | keys = params.keys() |
---|
| 73 | keys.sort() |
---|
| 74 | for item in keys: |
---|
[ef0c170] | 75 | iy += 1 |
---|
| 76 | ix = 0 |
---|
[32c0841] | 77 | if not item in ["count", "errors"]: |
---|
[0f6d05f8] | 78 | text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT) |
---|
[b40ad40] | 79 | self.bck.Add(text, (iy, ix), (1, 1), |
---|
| 80 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
[32c0841] | 81 | ctl = wx.TextCtrl(self, -1, size=(80, 20), |
---|
| 82 | style=wx.TE_PROCESS_ENTER) |
---|
[88989768] | 83 | hint_msg = "Modify the value of %s to change" % item |
---|
| 84 | hint_msg += " the 2D slicer" |
---|
[32c0841] | 85 | ctl.SetToolTipString(hint_msg) |
---|
[0f6d05f8] | 86 | ix = 1 |
---|
| 87 | ctl.SetValue(format_number(str(params[item]))) |
---|
| 88 | self.Bind(wx.EVT_TEXT_ENTER, self.onTextEnter) |
---|
| 89 | self.parameters.append([item, ctl]) |
---|
[b40ad40] | 90 | self.bck.Add(ctl, (iy, ix), (1, 1), |
---|
| 91 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[32c0841] | 92 | ix = 3 |
---|
[b40ad40] | 93 | self.bck.Add((20, 20), (iy, ix), (1, 1), |
---|
| 94 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[0f6d05f8] | 95 | else: |
---|
[b40ad40] | 96 | text = wx.StaticText(self, -1, item + " : ", |
---|
[32c0841] | 97 | style=wx.ALIGN_LEFT) |
---|
[b40ad40] | 98 | self.bck.Add(text, (iy, ix), (1, 1), |
---|
| 99 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
| 100 | ctl = wx.StaticText(self, -1, |
---|
| 101 | format_number(str(params[item])), |
---|
| 102 | style=wx.ALIGN_LEFT) |
---|
[32c0841] | 103 | ix = 1 |
---|
[b40ad40] | 104 | self.bck.Add(ctl, (iy, ix), (1, 1), |
---|
| 105 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[32c0841] | 106 | iy += 1 |
---|
[ef0c170] | 107 | ix = 1 |
---|
[b40ad40] | 108 | self.bck.Add((20, 20), (iy, ix), (1, 1), |
---|
| 109 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
[b06ef8c] | 110 | self.bck.Layout() |
---|
| 111 | self.bck.Fit(self) |
---|
| 112 | self.parent.GetSizer().Layout() |
---|
| 113 | |
---|
| 114 | def onParamChange(self, evt): |
---|
[12aa9b5] | 115 | """ |
---|
[d955bf19] | 116 | receive an event end reset value text fields |
---|
| 117 | inside self.parameters |
---|
[12aa9b5] | 118 | """ |
---|
[b06ef8c] | 119 | evt.Skip() |
---|
| 120 | if evt.type == "UPDATE": |
---|
[b40ad40] | 121 | for item in self.parameters: |
---|
[b06ef8c] | 122 | if item[0] in evt.params: |
---|
[32c0841] | 123 | item[1].SetValue("%-5.3g" % evt.params[item[0]]) |
---|
[b06ef8c] | 124 | item[1].Refresh() |
---|
[b40ad40] | 125 | |
---|
| 126 | def onTextEnter(self, evt): |
---|
[b06ef8c] | 127 | """ |
---|
[d955bf19] | 128 | Parameters have changed |
---|
[b40ad40] | 129 | """ |
---|
[b06ef8c] | 130 | params = {} |
---|
| 131 | has_error = False |
---|
| 132 | for item in self.parameters: |
---|
| 133 | try: |
---|
| 134 | params[item[0]] = float(item[1].GetValue()) |
---|
[b40ad40] | 135 | item[1].SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW)) |
---|
[b06ef8c] | 136 | item[1].Refresh() |
---|
| 137 | except: |
---|
| 138 | has_error = True |
---|
| 139 | item[1].SetBackgroundColour("pink") |
---|
| 140 | item[1].Refresh() |
---|
| 141 | |
---|
[32c0841] | 142 | if has_error == False: |
---|
[b06ef8c] | 143 | # Post parameter event |
---|
[12aa9b5] | 144 | ##parent hier is plotter2D |
---|
[b06ef8c] | 145 | event = SlicerParameterEvent(type=self.type, params=params) |
---|
| 146 | wx.PostEvent(self.parent, event) |
---|