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

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

Plot selected data.

  • Property mode set to 100644
File size: 9.2 KB
Line 
1
2
3import wx
4import wx.lib.newevent
5#from copy import deepcopy
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
9from sas.sasgui.guiframe.events import SlicerParameterEvent, SlicerEvent
10
11
12class SlicerParameterPanel(wx.Dialog):
13    """
14    Panel class to show the slicer parameters
15    """
16    #TODO: show units
17    #TODO: order parameters properly
18
19    def __init__(self, parent, *args, **kwargs):
20        """
21        Dialog window that allow to edit parameters slicer
22        by entering new values
23        """
24        wx.Dialog.__init__(self, parent, *args, **kwargs)
25        self.params = {}
26        self.parent = parent
27        self.type = None
28        self.listeners = []
29        self.parameters = []
30        self.bck = wx.GridBagSizer(5, 5)
31        self.SetSizer(self.bck)
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),
35                     flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15)
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        """
42        Process EVT_SLICER events
43        When the slicer changes, update the panel
44
45        :param event: EVT_SLICER event
46        """
47        event.Skip()
48        if event.obj_class is None:
49            self.set_slicer(None, None)
50        else:
51            self.set_slicer(event.type, event.params)
52
53    def set_slicer(self, type, params):
54        """
55        Rebuild the panel
56        """
57        self.bck.Clear(True)
58        self.bck.Add((5, 5), (0, 0), (1, 1),
59                     wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5)
60        self.type = type
61        if type is None:
62            label = "Right-click on 2D plot for slicer options"
63            title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT)
64            self.bck.Add(title, (1, 0), (1, 2),
65                         flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15)
66        else:
67            title = wx.StaticText(self, -1,
68                                  "Slicer Parameters:", style=wx.ALIGN_LEFT)
69            self.bck.Add(title, (1, 0), (1, 2),
70                         flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15)
71            ix = 0
72            iy = 1
73            self.parameters = []
74            keys = params.keys()
75            keys.sort()
76            for item in keys:
77                iy += 1
78                ix = 0
79                if not item in ["count", "errors"]:
80                    text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT)
81                    self.bck.Add(text, (iy, ix), (1, 1),
82                                 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
83                    ctl = wx.TextCtrl(self, -1, size=(80, 20),
84                                      style=wx.TE_PROCESS_ENTER)
85                    hint_msg = "Modify the value of %s to change" % item
86                    hint_msg += " the 2D slicer"
87                    ctl.SetToolTipString(hint_msg)
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])
92                    self.bck.Add(ctl, (iy, ix), (1, 1),
93                                 wx.EXPAND | wx.ADJUST_MINSIZE, 0)
94                    ix = 3
95                    self.bck.Add((20, 20), (iy, ix), (1, 1),
96                                 wx.EXPAND | wx.ADJUST_MINSIZE, 0)
97                else:
98                    text = wx.StaticText(self, -1, item + " : ",
99                                         style=wx.ALIGN_LEFT)
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)
105                    ix = 1
106                    self.bck.Add(ctl, (iy, ix), (1, 1),
107                                 wx.EXPAND | wx.ADJUST_MINSIZE, 0)
108            ix = 0
109            iy += 1
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),
115                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
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            title_text = "Batch Slicing Options:"
127            title = wx.StaticText(self, -1, title_text, style=wx.ALIGN_LEFT)
128            iy += 1
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)
136            iy += 1
137            id = wx.NewId()
138            main_window = self.parent.parent
139            self.loaded_data = main_window._data_manager.data_name_dict
140            choices = self.loaded_data.keys()
141            self.data_list = wx.CheckListBox(parent=self, id=id,
142                                        choices=choices,
143                                        name="Apply Slicer to Data Sets:")
144            self.bck.Add(self.data_list, (iy, ix), (1, 1),
145                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
146            iy += 1
147            button_label = "Apply Slicer to Selected Files"
148            self.batch_slicer_button = wx.Button(parent=self,
149                                                 label=button_label)
150            self.Bind(wx.EVT_BUTTON, self.onBatchSlice)
151            self.bck.Add(self.batch_slicer_button, (iy, ix), (1, 1),
152                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
153            # TODO: Check box for saving file
154            # TODO: append to file information and file type
155            # TODO: Send to fitting options
156
157            iy += 1
158            self.bck.Add((5, 5), (iy, ix), (1, 1),
159                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5)
160        self.bck.Layout()
161        self.bck.Fit(self)
162        self.parent.GetSizer().Layout()
163
164    def onParamChange(self, evt):
165        """
166        receive an event end reset value text fields
167        inside self.parameters
168        """
169        evt.Skip()
170        if evt.type == "UPDATE":
171            for item in self.parameters:
172                if item[0] in evt.params:
173                    item[1].SetValue("%-5.3g" % evt.params[item[0]])
174                    item[1].Refresh()
175
176    def onTextEnter(self, evt):
177        """
178        Parameters have changed
179        """
180        params = {}
181        has_error = False
182        for item in self.parameters:
183            try:
184                params[item[0]] = float(item[1].GetValue())
185                item[1].SetBackgroundColour(
186                    wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
187                item[1].Refresh()
188            except:
189                has_error = True
190                item[1].SetBackgroundColour("pink")
191                item[1].Refresh()
192
193        if not has_error:
194            # Post parameter event
195            # parent here is plotter2D
196            event = SlicerParameterEvent(type=self.type, params=params)
197            wx.PostEvent(self.parent, event)
198
199    def onBatchSlice(self, evt=None):
200        """
201        Batch slicing button is pushed
202        :param evt: Event triggering hide/show of the batch slicer parameters
203        """
204        # Process each data file individually
205        for item in self.data_list.CheckedStrings:
206            # Get data_id
207            data_dict = self.parent.parent._data_manager.get_by_name([item])
208            data_ids = data_dict.keys()
209            # Plot data
210            self.parent.parent.plot_data(state_id=[], data_id=data_ids, theory_id=[])
211            # TODO: apply slicer
212            # TODO: save file (if desired)
213            # TODO: send to fitting (if desired)
214            plot = None
215            slicer = None
216            f_name = None
217
218    def onChangeSlicer(self, evt):
219        """
220        Change the slicer type when changed in the dropdown
221        :param evt: Event triggering this change
222        """
223        type = self.type_select.GetStringSelection()
224        if self.type != type:
225            if type == "SectorInteractor":
226                self.parent.onSectorQ(None)
227            elif type == "AnnulusInteractor":
228                self.parent.onSectorPhi(None)
229            elif type == "BoxInteractorX":
230                self.parent.onBoxavgX(None)
231            elif type == "BoxInteractorY":
232                self.parent.onBoxavgY(None)
Note: See TracBrowser for help on using the repository browser.