source: sasview/src/sas/sasgui/guiframe/local_perspectives/plotting/parameters_panel_slicer.py @ 39f0bf4

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 39f0bf4 was 39f0bf4, checked in by krzywon, 7 years ago

Modified slicer parameter panel to incorporate batch slicing. Added slicer combobox to slicer panel. Renamed files to be more explicit.

  • Property mode set to 100644
File size: 8.0 KB
RevLine 
[d955bf19]1
[b06ef8c]2
3import wx
4import wx.lib.newevent
[32c0841]5#from copy import deepcopy
[d85c194]6from sas.sasgui.guiframe.events import EVT_SLICER_PARS
7from sas.sasgui.guiframe.utils import format_number
8from sas.sasgui.guiframe.events import EVT_SLICER
[39f0bf4]9from sas.sasgui.guiframe.events import SlicerParameterEvent, SlicerEvent
[32c0841]10
[0d9dae8]11
[ef0c170]12class 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()
[32c0841]48        if event.obj_class == 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)
[39f0bf4]58        self.bck.Add((5, 5), (0, 0), (1, 1),
59                     wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5)
[b40ad40]60        self.type = type
[32c0841]61        if type == None:
62            label = "Right-click on 2D plot for slicer options"
63            title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT)
[39f0bf4]64            self.bck.Add(title, (1, 0), (1, 2),
[b40ad40]65                         flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15)
[b06ef8c]66        else:
[b40ad40]67            title = wx.StaticText(self, -1,
[32c0841]68                                  "Slicer Parameters", style=wx.ALIGN_LEFT)
[39f0bf4]69            self.bck.Add(title, (1, 0), (1, 2),
[b40ad40]70                         flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15)
[ef0c170]71            ix = 0
[39f0bf4]72            iy = 1
[b06ef8c]73            self.parameters = []
74            keys = params.keys()
75            keys.sort()
76            for item in keys:
[ef0c170]77                iy += 1
78                ix = 0
[32c0841]79                if not item in ["count", "errors"]:
[0f6d05f8]80                    text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT)
[b40ad40]81                    self.bck.Add(text, (iy, ix), (1, 1),
82                                 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
[32c0841]83                    ctl = wx.TextCtrl(self, -1, size=(80, 20),
84                                      style=wx.TE_PROCESS_ENTER)
[88989768]85                    hint_msg = "Modify the value of %s to change" % item
86                    hint_msg += " the 2D slicer"
[32c0841]87                    ctl.SetToolTipString(hint_msg)
[0f6d05f8]88                    ix = 1
89                    ctl.SetValue(format_number(str(params[item])))
90                    self.Bind(wx.EVT_TEXT_ENTER, self.onTextEnter)
91                    self.parameters.append([item, ctl])
[b40ad40]92                    self.bck.Add(ctl, (iy, ix), (1, 1),
93                                 wx.EXPAND | wx.ADJUST_MINSIZE, 0)
[32c0841]94                    ix = 3
[b40ad40]95                    self.bck.Add((20, 20), (iy, ix), (1, 1),
96                                 wx.EXPAND | wx.ADJUST_MINSIZE, 0)
[0f6d05f8]97                else:
[b40ad40]98                    text = wx.StaticText(self, -1, item + " : ",
[32c0841]99                                         style=wx.ALIGN_LEFT)
[b40ad40]100                    self.bck.Add(text, (iy, ix), (1, 1),
101                                 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
102                    ctl = wx.StaticText(self, -1,
103                                        format_number(str(params[item])),
104                                        style=wx.ALIGN_LEFT)
[32c0841]105                    ix = 1
[b40ad40]106                    self.bck.Add(ctl, (iy, ix), (1, 1),
107                                 wx.EXPAND | wx.ADJUST_MINSIZE, 0)
[39f0bf4]108            ix = 0
[32c0841]109            iy += 1
[39f0bf4]110
111            # Change slicer within the window
112            txt = "Slicer"
113            text = wx.StaticText(self, -1, txt, style=wx.ALIGN_LEFT)
114            self.bck.Add(text, (iy, ix), (1, 1),
[b40ad40]115                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
[39f0bf4]116            type_list = ["SectorInteractor", "AnnulusInteractor",
117                         "BoxInteractorX", "BoxInteractorY"]
118            self.type_select = wx.ComboBox(parent=self, choices=type_list)
119            self.Bind(wx.EVT_COMBOBOX, self.onChangeSlicer)
120            index = self.type_select.FindString(self.type)
121            self.type_select.SetSelection(index)
122            self.bck.Add(self.type_select, (iy, 1), (1, 1),
123                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
124
125            # batch slicing parameters
126            iy += 1
127            button_label = "Batch Slicing"
128            self.batch_slicer_button = wx.Button(parent=self, label=button_label)
129            self.Bind(wx.EVT_BUTTON, self.onToggleBatchSlicing)
130            self.bck.Add(self.batch_slicer_button, (iy, ix), (1, 1),
131                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
132            self.batch_slice_params = wx.GridBagSizer(5, 5)
133            self.bck.Hide(item=self.batch_slice_params, recursive=True)
134            iy += 1
135            self.bck.Add(self.batch_slice_params, (iy, ix), (1, 1),
136                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
137            iy += 1
138            ix = 1
139            self.bck.Add((5, 5), (iy, ix), (1, 1),
140                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5)
[b06ef8c]141        self.bck.Layout()
142        self.bck.Fit(self)
143        self.parent.GetSizer().Layout()
144
145    def onParamChange(self, evt):
[12aa9b5]146        """
[d955bf19]147        receive an event end reset value text fields
148        inside self.parameters
[12aa9b5]149        """
[b06ef8c]150        evt.Skip()
151        if evt.type == "UPDATE":
[b40ad40]152            for item in self.parameters:
[b06ef8c]153                if item[0] in evt.params:
[32c0841]154                    item[1].SetValue("%-5.3g" % evt.params[item[0]])
[b06ef8c]155                    item[1].Refresh()
[b40ad40]156
157    def onTextEnter(self, evt):
[b06ef8c]158        """
[d955bf19]159        Parameters have changed
[b40ad40]160        """
[b06ef8c]161        params = {}
162        has_error = False
163        for item in self.parameters:
164            try:
165                params[item[0]] = float(item[1].GetValue())
[b40ad40]166                item[1].SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
[b06ef8c]167                item[1].Refresh()
168            except:
169                has_error = True
170                item[1].SetBackgroundColour("pink")
171                item[1].Refresh()
172
[32c0841]173        if has_error == False:
[b06ef8c]174            # Post parameter event
[12aa9b5]175            ##parent hier is plotter2D
[b06ef8c]176            event = SlicerParameterEvent(type=self.type, params=params)
177            wx.PostEvent(self.parent, event)
[39f0bf4]178
179    def onToggleBatchSlicing(self, evt=None):
180        """
181        Batch slicing parameters button is pushed
182        :param evt: Event triggering hide/show of the batch slicer parameters
183        """
184        if self.bck.IsShown(item=self.batch_slice_params):
185            self.bck.Hide(item=self.batch_slice_params, recursive=True)
186        else:
187            self.bck.Show(item=self.batch_slice_params, recursive=True)
188
189    def onChangeSlicer(self, evt):
190        """
191        Change the slicer type when changed in the dropdown
192        :param evt: Event triggering this change
193        """
194        type = self.type_select.GetStringSelection()
195        if self.type != type:
196            if type == "SectorInteractor":
197                self.parent.onSectorQ(None)
198            elif type == "AnnulusInteractor":
199                self.parent.onSectorPhi(None)
200            elif type == "BoxInteractorX":
201                self.parent.onBoxavgX(None)
202            elif type == "BoxInteractorY":
203                self.parent.onBoxavgY(None)
Note: See TracBrowser for help on using the repository browser.