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

magnetic_scattrelease-4.2.2ticket-1009ticket-1249
Last change on this file since 5251ec6 was 5251ec6, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

improved support for py37 in sasgui

  • Property mode set to 100644
File size: 23.2 KB
RevLine 
[d955bf19]1
[b06ef8c]2
[3f75203]3import os
[5251ec6]4
[b06ef8c]5import wx
6import wx.lib.newevent
[5251ec6]7
[54557b5]8from sas.sascalc.dataloader.readers.cansas_reader import Reader
[d85c194]9from sas.sasgui.guiframe.utils import format_number
[47d93073]10from sas.sasgui.guiframe.events import EVT_SLICER_PARS, EVT_SLICER
11from sas.sasgui.guiframe.events import SlicerParameterEvent, StatusEvent
[5251ec6]12
13from .Plotter2D import ModelPanel2D
14
[54557b5]15apply_params, EVT_APPLY_PARAMS = wx.lib.newevent.NewEvent()
[3f75203]16save_files, EVT_AUTO_SAVE = wx.lib.newevent.NewEvent()
[32c0841]17
[88188b4]18FIT_OPTIONS = ["No fitting", "Fitting", "Batch Fitting"]
[3e5648b]19CONVERT_KEYS = ["SectorInteractor", "AnnulusInteractor", "BoxInteractorX",
20                "BoxInteractorY"]
[7a80072]21CONVERT_DICT = {"SectorInteractor": "SectorQ",
22                "AnnulusInteractor": "AnnulusPhi",
23                "BoxInteractorX": "SlabX",
24                "BoxInteractorY": "SlabY"}
[edc7852]25BINNING_OPTIONS = {"Linear" : 0,
26                   "Logarithmic" : 10,}
[0d9dae8]27
[3f75203]28
[ef0c170]29class SlicerParameterPanel(wx.Dialog):
[d955bf19]30    """
[3f75203]31    Panel for dynamically changing slicer parameters and apply the same slicer
32    to multiple 2D plot panels
[d955bf19]33    """
[b40ad40]34
[cd84dca]35    def __init__(self, parent, *args, **kwargs):
[12aa9b5]36        """
[b40ad40]37        Dialog window that allow to edit parameters slicer
[d955bf19]38        by entering new values
[12aa9b5]39        """
[b40ad40]40        wx.Dialog.__init__(self, parent, *args, **kwargs)
[b06ef8c]41        self.params = {}
[377ca62f]42        self.iter = 0
[b06ef8c]43        self.parent = parent
[3f75203]44        self.main_window = parent.parent
45        self.data_panel = self.main_window._data_panel
[b06ef8c]46        self.type = None
47        self.listeners = []
48        self.parameters = []
[32c0841]49        self.bck = wx.GridBagSizer(5, 5)
[b06ef8c]50        self.SetSizer(self.bck)
[54557b5]51        self.auto_save = None
52        self.path = None
[7a80072]53        self.fitting_options = None
[edc7852]54        self.bin_ctl = None
[cac1828]55        self.type_list = []
[3f75203]56        self.loaded_data = []
57        self.always_on = None
[cac1828]58        self.type_select = None
59        self.append_name = None
[54557b5]60        self.data_list = None
[3f75203]61        self.default_value = ""
62        self.batch_slicer_button = None
[32c0841]63        label = "Right-click on 2D plot for slicer options"
64        title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT)
65        self.bck.Add(title, (0, 0), (1, 2),
[b40ad40]66                     flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15)
[b06ef8c]67        # Bindings
[3f75203]68        self.parent.Bind(EVT_SLICER, self.on_evt_slicer)
69        self.Bind(EVT_SLICER_PARS, self.on_param_change)
[54557b5]70        self.Bind(EVT_APPLY_PARAMS, self.apply_params_list_and_process)
71        self.Bind(EVT_AUTO_SAVE, self.save_files)
[b06ef8c]72
[3f75203]73    def on_evt_slicer(self, event):
[b06ef8c]74        """
[d955bf19]75        Process EVT_SLICER events
76        When the slicer changes, update the panel
[b40ad40]77
[d955bf19]78        :param event: EVT_SLICER event
[b06ef8c]79        """
80        event.Skip()
[e075203]81        if event.obj_class is None:
[b06ef8c]82            self.set_slicer(None, None)
83        else:
84            self.set_slicer(event.type, event.params)
[b40ad40]85
[b06ef8c]86    def set_slicer(self, type, params):
87        """
[d955bf19]88        Rebuild the panel
[b06ef8c]89        """
[b40ad40]90        self.bck.Clear(True)
[39f0bf4]91        self.bck.Add((5, 5), (0, 0), (1, 1),
92                     wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5)
[b40ad40]93        self.type = type
[e075203]94        if type is None:
[32c0841]95            label = "Right-click on 2D plot for slicer options"
96            title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT)
[39f0bf4]97            self.bck.Add(title, (1, 0), (1, 2),
[b40ad40]98                         flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15)
[b06ef8c]99        else:
[b40ad40]100            title = wx.StaticText(self, -1,
[f6bb24d]101                                  "Slicer Parameters:", style=wx.ALIGN_LEFT)
[39f0bf4]102            self.bck.Add(title, (1, 0), (1, 2),
[b40ad40]103                         flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15)
[39f0bf4]104            iy = 1
[b06ef8c]105            self.parameters = []
[5251ec6]106            keys = list(sorted(params.keys()))
[b06ef8c]107            for item in keys:
[ef0c170]108                ix = 0
[edc7852]109                iy += 1
110                if item not in ["count", "errors", "binning base"]:
[0f6d05f8]111                    text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT)
[b40ad40]112                    self.bck.Add(text, (iy, ix), (1, 1),
113                                 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
[32c0841]114                    ctl = wx.TextCtrl(self, -1, size=(80, 20),
115                                      style=wx.TE_PROCESS_ENTER)
[88989768]116                    hint_msg = "Modify the value of %s to change" % item
117                    hint_msg += " the 2D slicer"
[32c0841]118                    ctl.SetToolTipString(hint_msg)
[0f6d05f8]119                    ix = 1
120                    ctl.SetValue(format_number(str(params[item])))
[3f75203]121                    self.Bind(wx.EVT_TEXT_ENTER, self.on_text_enter)
[0f6d05f8]122                    self.parameters.append([item, ctl])
[b40ad40]123                    self.bck.Add(ctl, (iy, ix), (1, 1),
124                                 wx.EXPAND | wx.ADJUST_MINSIZE, 0)
[32c0841]125                    ix = 3
[b40ad40]126                    self.bck.Add((20, 20), (iy, ix), (1, 1),
127                                 wx.EXPAND | wx.ADJUST_MINSIZE, 0)
[edc7852]128                elif item == 'binning base':
129                    text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT)
130                    self.bck.Add(text, (iy, ix), (1, 1),
131                                 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
[5251ec6]132                    options = list(BINNING_OPTIONS.keys())
[edc7852]133                    self.bin_ctl = wx.ComboBox(parent=self, choices=options)
134                    hint_msg = "Modify the value of %s to change" % item
135                    hint_msg += " the 2D slicer"
136                    self.bin_ctl.SetToolTipString(hint_msg)
137                    ix = 1
138                    result = ""
139                    value = 0
140                    for name, value in BINNING_OPTIONS.items():
141                        if value == params[item]:
142                            result = name
143                            break
144                    index = self.bin_ctl.FindString(result)
145                    self.bin_ctl.SetSelection(index)
146                    self.parameters.append([item, self.bin_ctl])
147                    self.Bind(wx.EVT_COMBOBOX, self.on_text_enter)
148                    self.bck.Add(self.bin_ctl, (iy, ix), (1, 1),
149                                 wx.EXPAND | wx.ADJUST_MINSIZE, 0)
150                    ix = 3
151                    self.bck.Add((20, 20), (iy, ix), (1, 1),
152                                 wx.EXPAND | wx.ADJUST_MINSIZE, 0)
[0f6d05f8]153                else:
[b40ad40]154                    text = wx.StaticText(self, -1, item + " : ",
[32c0841]155                                         style=wx.ALIGN_LEFT)
[b40ad40]156                    self.bck.Add(text, (iy, ix), (1, 1),
157                                 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
158                    ctl = wx.StaticText(self, -1,
159                                        format_number(str(params[item])),
160                                        style=wx.ALIGN_LEFT)
[32c0841]161                    ix = 1
[b40ad40]162                    self.bck.Add(ctl, (iy, ix), (1, 1),
163                                 wx.EXPAND | wx.ADJUST_MINSIZE, 0)
[39f0bf4]164
165            # Change slicer within the window
[54557b5]166            ix = 0
167            iy += 1
[324e0bf]168            txt = "Slicer type"
[39f0bf4]169            text = wx.StaticText(self, -1, txt, style=wx.ALIGN_LEFT)
170            self.bck.Add(text, (iy, ix), (1, 1),
[b40ad40]171                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
[3e5648b]172            self.type_list = CONVERT_KEYS
[cac1828]173            self.type_select = wx.ComboBox(parent=self, choices=self.type_list)
[3f75203]174            self.type_select.Bind(wx.EVT_COMBOBOX, self.on_change_slicer)
[54557b5]175            index = self.type_select.FindString(type)
[39f0bf4]176            self.type_select.SetSelection(index)
177            self.bck.Add(self.type_select, (iy, 1), (1, 1),
178                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
179
180            # batch slicing parameters
[f6bb24d]181            title_text = "Batch Slicing Options:"
182            title = wx.StaticText(self, -1, title_text, style=wx.ALIGN_LEFT)
[39f0bf4]183            iy += 1
[54557b5]184            line = wx.StaticLine(self, -1, style=wx.LI_VERTICAL)
185            line.SetSize((60, 60))
186            self.bck.Add(line, (iy, ix), (1, 2),
[f6bb24d]187                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
188            iy += 1
189            self.bck.Add(title, (iy, ix), (1, 1),
190                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
[54557b5]191
[b697396b]192            # Create a list box with all of the 2D plots
[54557b5]193            iy += 1
[dfa1579]194            self.process_list()
[f6bb24d]195            self.bck.Add(self.data_list, (iy, ix), (1, 1),
[39f0bf4]196                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
[54557b5]197
[3f75203]198            # Checkbox to enable saving and fitting options
[54557b5]199            iy += 1
200            self.auto_save = wx.CheckBox(parent=self, id=wx.NewId(),
201                                         label="Auto save generated 1D:")
202            self.Bind(wx.EVT_CHECKBOX, self.on_auto_save_checked)
203            self.bck.Add(self.auto_save, (iy, ix), (1, 1),
204                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
205            iy += 1
206            # File browser
207            save_to = "Save files to:"
208            save = wx.StaticText(self, -1, save_to, style=wx.ALIGN_LEFT)
[3f75203]209            path = os.getcwd()
210            self.path = wx.DirPickerCtrl(self, id=wx.NewId(), path=path,
[54557b5]211                                         message=save_to)
212            self.path.Enable(False)
213            self.bck.Add(save, (iy, ix), (1, 1),
214                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
215            self.bck.Add(self.path, (iy, 1), (1, 1),
216                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
217            # Append to file
[39f0bf4]218            iy += 1
[3f75203]219            self.update_file_append(params)
[54557b5]220            append_text = "Append to file name:"
221            append = wx.StaticText(self, -1, append_text, style=wx.ALIGN_LEFT)
[cac1828]222            self.append_name = wx.TextCtrl(parent=self, id=wx.NewId(),
223                                           name="Append to file name:")
[3f75203]224            append_tool_tip = "Files will be saved as <SlicerType><FileName>"
[8e15dce]225            append_tool_tip += "<AppendToText>.txt"
[3f75203]226            self.append_name.SetToolTipString(append_tool_tip)
227            self.append_name.SetValue(self.default_value)
[54557b5]228            self.append_name.Enable(False)
229            self.bck.Add(append, (iy, ix), (1, 1),
230                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
231            self.bck.Add(self.append_name, (iy, 1), (1, 1),
232                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
233
234            # Combobox for selecting fitting options
[7a80072]235            iy += 1
236            fit_text = "Fitting Options:"
[3f75203]237            fit_text_item = wx.StaticText(self, -1, fit_text,
238                                          style=wx.ALIGN_LEFT)
[7a80072]239            self.bck.Add(fit_text_item, (iy, ix), (1, 1),
240                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
241            self.fitting_options = wx.ComboBox(parent=self, choices=FIT_OPTIONS)
242            self.fitting_options.SetSelection(0)
243            self.bck.Add(self.fitting_options, (iy, 1), (1, 1),
244                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
245            self.fitting_options.Enable(False)
246            self.fitting_options.Bind(wx.EVT_COMBOBOX, None)
[54557b5]247
[b697396b]248            # Button to start batch slicing
[54557b5]249            iy += 1
[f15da54]250            button_label = "Apply Slicer to Selected Plots"
[f6bb24d]251            self.batch_slicer_button = wx.Button(parent=self,
252                                                 label=button_label)
[54557b5]253            self.Bind(wx.EVT_BUTTON, self.on_batch_slicer)
[f6bb24d]254            self.bck.Add(self.batch_slicer_button, (iy, ix), (1, 1),
[54557b5]255                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
[a20a255]256            # Help button
257
258            self.bt_help = wx.Button(self, wx.NewId(), "HELP")
259            self.bt_help.SetToolTipString(
260                "Help for the slicer parameters and batch slicing.")
261            self.bck.Add(self.bt_help, (iy, 1), (1, 1),
262                         wx.ALIGN_RIGHT | wx.ADJUST_MINSIZE, 15)
263            wx.EVT_BUTTON(self, self.bt_help.GetId(), self.on_help)
264
[f6bb24d]265            iy += 1
[39f0bf4]266            self.bck.Add((5, 5), (iy, ix), (1, 1),
267                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5)
[a20a255]268
[b06ef8c]269        self.bck.Layout()
270        self.bck.Fit(self)
271        self.parent.GetSizer().Layout()
272
[3f75203]273    def on_param_change(self, evt):
[12aa9b5]274        """
[d955bf19]275        receive an event end reset value text fields
276        inside self.parameters
[12aa9b5]277        """
[b06ef8c]278        evt.Skip()
279        if evt.type == "UPDATE":
[b40ad40]280            for item in self.parameters:
[b06ef8c]281                if item[0] in evt.params:
[32c0841]282                    item[1].SetValue("%-5.3g" % evt.params[item[0]])
[b06ef8c]283                    item[1].Refresh()
[b40ad40]284
[3f75203]285    def on_text_enter(self, evt):
[b06ef8c]286        """
[d955bf19]287        Parameters have changed
[b40ad40]288        """
[b06ef8c]289        params = {}
290        has_error = False
291        for item in self.parameters:
292            try:
[edc7852]293                if item[0] == "binning base":
294                    title = self.bin_ctl.GetValue()
295                    params["binning base"] = BINNING_OPTIONS.get(title)
296                    continue
[b06ef8c]297                params[item[0]] = float(item[1].GetValue())
[e075203]298                item[1].SetBackgroundColour(
299                    wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
[b06ef8c]300                item[1].Refresh()
301            except:
302                has_error = True
303                item[1].SetBackgroundColour("pink")
304                item[1].Refresh()
305
[e075203]306        if not has_error:
[b06ef8c]307            # Post parameter event
[e075203]308            # parent here is plotter2D
[3f75203]309            self.update_file_append(params)
310            self.append_name.SetValue(self.default_value)
311            self.append_name.Refresh()
[b06ef8c]312            event = SlicerParameterEvent(type=self.type, params=params)
[cac1828]313            wx.PostEvent(self.parent, event)
[39f0bf4]314
[54557b5]315    def on_batch_slicer(self, evt=None):
[39f0bf4]316        """
[3f75203]317        Event triggered when batch slicing button is pressed
318        :param evt: Event triggering the batch slicing
[39f0bf4]319        """
[a099131]320        apply_to_list = []
321        spp = self.parent.parent
322        params = self.parent.slicer.get_params()
[3f75203]323        slicer_type = self.type_select.GetStringSelection()
[54557b5]324        save = self.auto_save.IsChecked()
325        append = self.append_name.GetValue()
326        path = self.path.GetPath()
[7a80072]327        fit = self.fitting_options.GetValue()
[a099131]328
[b697396b]329        # Find desired 2D data panels
[5251ec6]330        for key, mgr in spp.plot_panels.items():
[f15da54]331            if mgr.graph.prop['title'] in self.data_list.CheckedStrings:
[a099131]332                apply_to_list.append(mgr)
333
[b697396b]334        # Apply slicer type to selected panels
[a099131]335        for item in apply_to_list:
[3f75203]336            self._apply_slicer_to_plot(item, slicer_type)
[f15da54]337
[b697396b]338        # Post an event to apply appropriate slicer params to each slicer
[3f75203]339        # Pass all variables, including class variables
[cac1828]340        event_params = apply_params(params=params, apply_to_list=apply_to_list,
[3f75203]341                                    auto_save=save, append=append, fit=fit,
342                                    path=path, type=slicer_type)
[cac1828]343        wx.PostEvent(self, event_params)
[39f0bf4]344
[3f75203]345    def on_change_slicer(self, evt):
[39f0bf4]346        """
[df27aa8]347        Event driven slicer change when self.type_select changes
[39f0bf4]348        :param evt: Event triggering this change
349        """
[df27aa8]350        self._apply_slicer_to_plot(self.parent)
351
[3f75203]352    def _apply_slicer_to_plot(self, plot, slicer_type=None):
[df27aa8]353        """
354        Apply a slicer to *any* plot window, not just parent window
[f15da54]355        :param plot: 2D plot panel to apply a slicer to
[3f75203]356        :param slicer_type: The type of slicer to apply to the panel
[df27aa8]357        """
[3f75203]358        # Skip redrawing the current plot if no change in slicer type
359        if self.parent == plot and self.type == slicer_type:
[71b25b2]360            return
[cac1828]361        # Do not draw a slicer on a 1D plot
362        if not isinstance(plot, ModelPanel2D):
363            return
[3f75203]364        if slicer_type is None:
365            slicer_type = self.type_select.GetStringSelection()
366        if slicer_type == self.type_list[0]:
[a099131]367            plot.onSectorQ(None)
[3f75203]368        elif slicer_type == self.type_list[1]:
[a099131]369            plot.onSectorPhi(None)
[3f75203]370        elif slicer_type == self.type_list[2]:
[a099131]371            plot.onBoxavgX(None)
[3f75203]372        elif slicer_type == self.type_list[3]:
[a099131]373            plot.onBoxavgY(None)
[df27aa8]374
[dfa1579]375    def process_list(self):
[b697396b]376        """
377        Populate the check list from the currently plotted 2D data
378        """
[3e5648b]379        # Reinitialize loaded data list on redraw
380        self.loaded_data = []
[b697396b]381        # Iterate over the loaded plots and find all 2D panels
[5251ec6]382        for key, value in self.main_window.plot_panels.items():
[f15da54]383            if isinstance(value, ModelPanel2D):
384                self.loaded_data.append(value.data2D.name)
385                if value.data2D.id == self.parent.data2D.id:
[b697396b]386                    # Set current plot panel as uncheckable
[3f75203]387                    self.always_on = self.loaded_data.index(value.data2D.name)
388        self.data_list = wx.CheckListBox(parent=self, id=wx.NewId(),
[dfa1579]389                                         choices=self.loaded_data,
[f15da54]390                                         name="Apply Slicer to 2D Plots:")
[54557b5]391        # Check all items by default
[b697396b]392        for item in range(len(self.data_list.Items)):
393            self.data_list.Check(item)
[54557b5]394        self.data_list.Bind(wx.EVT_CHECKLISTBOX, self.on_check_box_list)
[dfa1579]395
[54557b5]396    def on_check_box_list(self, evt=None):
[f15da54]397        """
[b697396b]398        Prevent a checkbox item from being unchecked
[3f75203]399        :param evt: Event triggered when a checkbox list item is checked
[f15da54]400        """
[54557b5]401        if evt is None:
402            return
403        index = evt.GetSelection()
[3f75203]404        if index == self.always_on:
[dfa1579]405            self.data_list.Check(index)
[f15da54]406
[54557b5]407    def apply_params_list_and_process(self, evt=None):
[b697396b]408        """
409        Event based parameter setting.
[a26f67f]410
[b697396b]411        :param evt: Event triggered to apply parameters to a list of plots
[a26f67f]412           evt should have attrs plot_list and params
413
[b697396b]414        """
[3f75203]415        if evt is None:
416            return
[b697396b]417        # Apply parameter list to each plot as desired
[cac1828]418        for item in evt.apply_to_list:
[71b25b2]419            event = SlicerParameterEvent(type=evt.type, params=evt.params)
420            wx.PostEvent(item, event)
[54557b5]421        # Post an event to save each data set to file
422        if evt.auto_save:
[3f75203]423            event = save_files(append_to_name=evt.append, path=evt.path,
424                               type=evt.type, file_list=evt.apply_to_list,
425                               fit=evt.fit)
[54557b5]426            wx.PostEvent(self, event)
427
428    def save_files(self, evt=None):
429        """
430        Automatically save the sliced data to file.
431        :param evt: Event that triggered the call to the method
432        """
[7a80072]433
[3f75203]434        # Events triggered after this event pass other events to wx that are
435        # necessary before this event is called. If this is the first time
436        # reaching this event, send it to the end of the wx event queue
[47d93073]437        if self.iter < 2:
[377ca62f]438            clone = evt.Clone()
439            wx.PostEvent(self, clone)
440            self.iter += 1
441            return
[54557b5]442        if evt is None:
443            return
[377ca62f]444
445        # Start definitions
[54557b5]446        writer = Reader()
[982577b]447        data_dic = {}
[54557b5]448        append = evt.append_to_name
[71b25b2]449        names = []
[7a80072]450        f_name_list = []
451        f_path_list = []
452
[377ca62f]453        # Get list of 2D data names for saving
[71b25b2]454        for f_name in evt.file_list:
455            names.append(f_name.data2D.label)
[7a80072]456
[377ca62f]457        # Find the correct plots to save
[5251ec6]458        for key, plot in self.main_window.plot_panels.items():
[54557b5]459            if not hasattr(plot, "data2D"):
460                for item in plot.plots:
[7a80072]461                    base = item.replace(CONVERT_DICT[evt.type], "")
[71b25b2]462                    if base in names:
463                        data_dic[item] = plot.plots[item]
[7a80072]464
[8e15dce]465        # Save files as Text
[5251ec6]466        for item, data1d in data_dic.items():
[3f75203]467            base = '.'.join(item.split('.')[:-1])
[8e15dce]468            file_name = base + append + ".txt"
[7a80072]469            save_to = evt.path + "\\" + file_name
[982577b]470            writer.write(save_to, data1d)
[7a80072]471            f_path_list.append(save_to)
472            f_name_list.append(file_name)
473
[377ca62f]474        # Load files into GUI
[7a80072]475        for item in f_path_list:
[3f75203]476            self.main_window.load_data(item)
[7a80072]477
478        # Send to fitting
479        self.send_to_fitting(evt.fit, f_name_list)
480
481    def send_to_fitting(self, fit=FIT_OPTIONS[0], file_list=None):
482        """
483        Send a list of data to the fitting perspective
[a26f67f]484        :param fit: fit type desired
[7a80072]485        :param file_list: list of loaded file names to send to fit
486        """
[8e15dce]487        if fit in FIT_OPTIONS and fit != FIT_OPTIONS[0] and \
488                        file_list is not None:
[7a80072]489            # Set perspective to fitting
[3f75203]490            int = self.data_panel.perspective_cbox.FindString("Fitting")
491            self.data_panel.perspective_cbox.SetSelection(int)
492            self.data_panel._on_perspective_selection(None)
[7a80072]493            # Unselect all loaded data
[3f75203]494            self.data_panel.selection_cbox.SetValue('Unselect all Data')
495            self.data_panel._on_selection_type(None)
[7a80072]496            # Click each sliced data file
497            for f_name in file_list:
498                num = len(f_name)
[3f75203]499                data_list = self.data_panel.list_cb_data
[7a80072]500                for key in data_list:
501                    loaded_key = (key[:num]) if len(key) > num else key
502                    if loaded_key == f_name:
503                        selection = key
504                        data_ctrl = data_list[selection][0]
505                        self.check_item_and_children(data_ctrl=data_ctrl,
506                                                     check_value=True)
[82ce1d0]507            # Switch to batch mode if selected
508            if fit == FIT_OPTIONS[2]:
[3f75203]509                self.data_panel.rb_single_mode.SetValue(False)
510                self.data_panel.rb_batch_mode.SetValue(True)
511                self.data_panel.on_batch_mode(None)
[82ce1d0]512            else:
[3f75203]513                self.data_panel.rb_single_mode.SetValue(True)
514                self.data_panel.rb_batch_mode.SetValue(False)
515                self.data_panel.on_single_mode(None)
[7a80072]516
517            # Post button click event to send data to fitting
518            evt = wx.PyCommandEvent(wx.EVT_BUTTON.typeId,
[3f75203]519                                    self.data_panel.bt_import.GetId())
520            wx.PostEvent(self.data_panel, evt)
[7a80072]521
[54557b5]522    def on_auto_save_checked(self, evt=None):
523        """
524        Enable/Disable auto append when checkbox is checked
525        :param evt: Event
526        """
527        self.append_name.Enable(self.auto_save.IsChecked())
528        self.path.Enable(self.auto_save.IsChecked())
[7a80072]529        self.fitting_options.Enable(self.auto_save.IsChecked())
530
531    def check_item_and_children(self, data_ctrl, check_value=True):
[3f75203]532        self.data_panel.tree_ctrl.CheckItem(data_ctrl, check_value)
[7a80072]533        if data_ctrl.HasChildren():
534            if check_value and not data_ctrl.IsExpanded():
535                return
536            for child_ctrl in data_ctrl.GetChildren():
[3f75203]537                self.data_panel.CheckItem(child_ctrl, check_value)
538
539    def update_file_append(self, params=None):
540        """
541        Update default_value when any parameters are changed
542        :param params: dictionary of parameters
543        """
544        self.default_value = ""
545        if params is None:
546            params = self.params
547        for key in params:
548            self.default_value += "_{0}".format(key).split(" [")[0]
549            self.default_value += "-{:.2f}".format(params[key])
[a20a255]550
551    def on_help(self, event=None):
552        """
553        Opens a help window for the slicer parameters/batch slicing window
554        :param event:
555        :return:
556        """
557        from sas.sasgui.guiframe.documentation_window import DocumentationWindow
558
559        _TreeLocation = "user/sasgui/guiframe/graph_help.html"
560        _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation,
561                                          "#d-data-averaging",
562                                          "Data Explorer Help")
Note: See TracBrowser for help on using the repository browser.