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

magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249unittest-saveload
Last change on this file since a20a255 was a20a255, checked in by krzywon, 6 years ago

Add a help button to the slicer parameters panel.

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