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

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 f6bb24d was f6bb24d, checked in by krzywon, 7 years ago

base prototype of the batch slicing window loads.

  • Property mode set to 100644
File size: 9.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()
[e075203]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)
[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
[e075203]61        if type is None:
[32c0841]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,
[f6bb24d]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
[f6bb24d]126            title_text = "Batch Slicing Options:"
127            title = wx.StaticText(self, -1, title_text, style=wx.ALIGN_LEFT)
[39f0bf4]128            iy += 1
[f6bb24d]129            ln = wx.StaticLine(self, -1, style=wx.LI_VERTICAL)
130            ln.SetSize((60,60))
131            self.bck.Add(ln, (iy, ix), (1, 2),
132                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
133            iy += 1
134            self.bck.Add(title, (iy, ix), (1, 1),
135                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
[39f0bf4]136            iy += 1
[f6bb24d]137            id = wx.NewId()
138            # TODO: Get list of data objects already loaded
139            choices = ("a", "b", "c", "d")
140            self.data_list = wx.CheckListBox(parent=self, id=id,
141                                        choices=choices,
142                                        name="Apply Slicer to Data Sets:")
143            self.bck.Add(self.data_list, (iy, ix), (1, 1),
[39f0bf4]144                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
145            iy += 1
[f6bb24d]146            button_label = "Apply Slicer to Selected Files"
147            self.batch_slicer_button = wx.Button(parent=self,
148                                                 label=button_label)
149            self.Bind(wx.EVT_BUTTON, self.onBatchSlice)
150            self.bck.Add(self.batch_slicer_button, (iy, ix), (1, 1),
151                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
152            # TODO: Check box for saving file
153            # TODO: append to file information and file type
154            # TODO: Send to fitting options
155
156            iy += 1
[39f0bf4]157            self.bck.Add((5, 5), (iy, ix), (1, 1),
158                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5)
[b06ef8c]159        self.bck.Layout()
160        self.bck.Fit(self)
161        self.parent.GetSizer().Layout()
162
163    def onParamChange(self, evt):
[12aa9b5]164        """
[d955bf19]165        receive an event end reset value text fields
166        inside self.parameters
[12aa9b5]167        """
[b06ef8c]168        evt.Skip()
169        if evt.type == "UPDATE":
[b40ad40]170            for item in self.parameters:
[b06ef8c]171                if item[0] in evt.params:
[32c0841]172                    item[1].SetValue("%-5.3g" % evt.params[item[0]])
[b06ef8c]173                    item[1].Refresh()
[b40ad40]174
175    def onTextEnter(self, evt):
[b06ef8c]176        """
[d955bf19]177        Parameters have changed
[b40ad40]178        """
[b06ef8c]179        params = {}
180        has_error = False
181        for item in self.parameters:
182            try:
183                params[item[0]] = float(item[1].GetValue())
[e075203]184                item[1].SetBackgroundColour(
185                    wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
[b06ef8c]186                item[1].Refresh()
187            except:
188                has_error = True
189                item[1].SetBackgroundColour("pink")
190                item[1].Refresh()
191
[e075203]192        if not has_error:
[b06ef8c]193            # Post parameter event
[e075203]194            # parent here is plotter2D
[b06ef8c]195            event = SlicerParameterEvent(type=self.type, params=params)
196            wx.PostEvent(self.parent, event)
[39f0bf4]197
[f6bb24d]198    def onBatchSlice(self, evt=None):
[39f0bf4]199        """
[f6bb24d]200        Batch slicing button is pushed
[39f0bf4]201        :param evt: Event triggering hide/show of the batch slicer parameters
202        """
[f6bb24d]203        for item in self.data_list.Checked:
204            print item
205            # Process each data file
206            # TODO: plot data
207            # TODO: apply slicer
208            # TODO: save file (if desired)
209            # TODO: send to fitting (if desired)
210            plot = None
211            slicer = None
212            f_name = None
[39f0bf4]213
214    def onChangeSlicer(self, evt):
215        """
216        Change the slicer type when changed in the dropdown
217        :param evt: Event triggering this change
218        """
219        type = self.type_select.GetStringSelection()
220        if self.type != type:
221            if type == "SectorInteractor":
222                self.parent.onSectorQ(None)
223            elif type == "AnnulusInteractor":
224                self.parent.onSectorPhi(None)
225            elif type == "BoxInteractorX":
226                self.parent.onBoxavgX(None)
227            elif type == "BoxInteractorY":
228                self.parent.onBoxavgY(None)
Note: See TracBrowser for help on using the repository browser.