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

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalcmagnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 3bd677b was a26f67f, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

fixup api doc errors

  • Property mode set to 100644
File size: 22.3 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)
[f6bb24d]253            iy += 1
[39f0bf4]254            self.bck.Add((5, 5), (iy, ix), (1, 1),
255                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5)
[b06ef8c]256        self.bck.Layout()
257        self.bck.Fit(self)
258        self.parent.GetSizer().Layout()
259
[3f75203]260    def on_param_change(self, evt):
[12aa9b5]261        """
[d955bf19]262        receive an event end reset value text fields
263        inside self.parameters
[12aa9b5]264        """
[b06ef8c]265        evt.Skip()
266        if evt.type == "UPDATE":
[b40ad40]267            for item in self.parameters:
[b06ef8c]268                if item[0] in evt.params:
[32c0841]269                    item[1].SetValue("%-5.3g" % evt.params[item[0]])
[b06ef8c]270                    item[1].Refresh()
[b40ad40]271
[3f75203]272    def on_text_enter(self, evt):
[b06ef8c]273        """
[d955bf19]274        Parameters have changed
[b40ad40]275        """
[b06ef8c]276        params = {}
277        has_error = False
278        for item in self.parameters:
279            try:
[edc7852]280                if item[0] == "binning base":
281                    title = self.bin_ctl.GetValue()
282                    params["binning base"] = BINNING_OPTIONS.get(title)
283                    continue
[b06ef8c]284                params[item[0]] = float(item[1].GetValue())
[e075203]285                item[1].SetBackgroundColour(
286                    wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
[b06ef8c]287                item[1].Refresh()
288            except:
289                has_error = True
290                item[1].SetBackgroundColour("pink")
291                item[1].Refresh()
292
[e075203]293        if not has_error:
[b06ef8c]294            # Post parameter event
[e075203]295            # parent here is plotter2D
[3f75203]296            self.update_file_append(params)
297            self.append_name.SetValue(self.default_value)
298            self.append_name.Refresh()
[b06ef8c]299            event = SlicerParameterEvent(type=self.type, params=params)
[cac1828]300            wx.PostEvent(self.parent, event)
[39f0bf4]301
[54557b5]302    def on_batch_slicer(self, evt=None):
[39f0bf4]303        """
[3f75203]304        Event triggered when batch slicing button is pressed
305        :param evt: Event triggering the batch slicing
[39f0bf4]306        """
[a099131]307        apply_to_list = []
308        spp = self.parent.parent
309        params = self.parent.slicer.get_params()
[3f75203]310        slicer_type = self.type_select.GetStringSelection()
[54557b5]311        save = self.auto_save.IsChecked()
312        append = self.append_name.GetValue()
313        path = self.path.GetPath()
[7a80072]314        fit = self.fitting_options.GetValue()
[a099131]315
[b697396b]316        # Find desired 2D data panels
[a099131]317        for key, mgr in spp.plot_panels.iteritems():
[f15da54]318            if mgr.graph.prop['title'] in self.data_list.CheckedStrings:
[a099131]319                apply_to_list.append(mgr)
320
[b697396b]321        # Apply slicer type to selected panels
[a099131]322        for item in apply_to_list:
[3f75203]323            self._apply_slicer_to_plot(item, slicer_type)
[f15da54]324
[b697396b]325        # Post an event to apply appropriate slicer params to each slicer
[3f75203]326        # Pass all variables, including class variables
[cac1828]327        event_params = apply_params(params=params, apply_to_list=apply_to_list,
[3f75203]328                                    auto_save=save, append=append, fit=fit,
329                                    path=path, type=slicer_type)
[cac1828]330        wx.PostEvent(self, event_params)
[39f0bf4]331
[3f75203]332    def on_change_slicer(self, evt):
[39f0bf4]333        """
[df27aa8]334        Event driven slicer change when self.type_select changes
[39f0bf4]335        :param evt: Event triggering this change
336        """
[df27aa8]337        self._apply_slicer_to_plot(self.parent)
338
[3f75203]339    def _apply_slicer_to_plot(self, plot, slicer_type=None):
[df27aa8]340        """
341        Apply a slicer to *any* plot window, not just parent window
[f15da54]342        :param plot: 2D plot panel to apply a slicer to
[3f75203]343        :param slicer_type: The type of slicer to apply to the panel
[df27aa8]344        """
[3f75203]345        # Skip redrawing the current plot if no change in slicer type
346        if self.parent == plot and self.type == slicer_type:
[71b25b2]347            return
[cac1828]348        # Do not draw a slicer on a 1D plot
349        if not isinstance(plot, ModelPanel2D):
350            return
[3f75203]351        if slicer_type is None:
352            slicer_type = self.type_select.GetStringSelection()
353        if slicer_type == self.type_list[0]:
[a099131]354            plot.onSectorQ(None)
[3f75203]355        elif slicer_type == self.type_list[1]:
[a099131]356            plot.onSectorPhi(None)
[3f75203]357        elif slicer_type == self.type_list[2]:
[a099131]358            plot.onBoxavgX(None)
[3f75203]359        elif slicer_type == self.type_list[3]:
[a099131]360            plot.onBoxavgY(None)
[df27aa8]361
[dfa1579]362    def process_list(self):
[b697396b]363        """
364        Populate the check list from the currently plotted 2D data
365        """
[3e5648b]366        # Reinitialize loaded data list on redraw
367        self.loaded_data = []
[b697396b]368        # Iterate over the loaded plots and find all 2D panels
[3f75203]369        for key, value in self.main_window.plot_panels.iteritems():
[f15da54]370            if isinstance(value, ModelPanel2D):
371                self.loaded_data.append(value.data2D.name)
372                if value.data2D.id == self.parent.data2D.id:
[b697396b]373                    # Set current plot panel as uncheckable
[3f75203]374                    self.always_on = self.loaded_data.index(value.data2D.name)
375        self.data_list = wx.CheckListBox(parent=self, id=wx.NewId(),
[dfa1579]376                                         choices=self.loaded_data,
[f15da54]377                                         name="Apply Slicer to 2D Plots:")
[54557b5]378        # Check all items by default
[b697396b]379        for item in range(len(self.data_list.Items)):
380            self.data_list.Check(item)
[54557b5]381        self.data_list.Bind(wx.EVT_CHECKLISTBOX, self.on_check_box_list)
[dfa1579]382
[54557b5]383    def on_check_box_list(self, evt=None):
[f15da54]384        """
[b697396b]385        Prevent a checkbox item from being unchecked
[3f75203]386        :param evt: Event triggered when a checkbox list item is checked
[f15da54]387        """
[54557b5]388        if evt is None:
389            return
390        index = evt.GetSelection()
[3f75203]391        if index == self.always_on:
[dfa1579]392            self.data_list.Check(index)
[f15da54]393
[54557b5]394    def apply_params_list_and_process(self, evt=None):
[b697396b]395        """
396        Event based parameter setting.
[a26f67f]397
[b697396b]398        :param evt: Event triggered to apply parameters to a list of plots
[a26f67f]399           evt should have attrs plot_list and params
400
[b697396b]401        """
[3f75203]402        if evt is None:
403            return
[b697396b]404        # Apply parameter list to each plot as desired
[cac1828]405        for item in evt.apply_to_list:
[71b25b2]406            event = SlicerParameterEvent(type=evt.type, params=evt.params)
407            wx.PostEvent(item, event)
[54557b5]408        # Post an event to save each data set to file
409        if evt.auto_save:
[3f75203]410            event = save_files(append_to_name=evt.append, path=evt.path,
411                               type=evt.type, file_list=evt.apply_to_list,
412                               fit=evt.fit)
[54557b5]413            wx.PostEvent(self, event)
414
415    def save_files(self, evt=None):
416        """
417        Automatically save the sliced data to file.
418        :param evt: Event that triggered the call to the method
419        """
[7a80072]420
[3f75203]421        # Events triggered after this event pass other events to wx that are
422        # necessary before this event is called. If this is the first time
423        # reaching this event, send it to the end of the wx event queue
[47d93073]424        if self.iter < 2:
[377ca62f]425            clone = evt.Clone()
426            wx.PostEvent(self, clone)
427            self.iter += 1
428            return
[54557b5]429        if evt is None:
430            return
[377ca62f]431
432        # Start definitions
[54557b5]433        writer = Reader()
[982577b]434        data_dic = {}
[54557b5]435        append = evt.append_to_name
[71b25b2]436        names = []
[7a80072]437        f_name_list = []
438        f_path_list = []
439
[377ca62f]440        # Get list of 2D data names for saving
[71b25b2]441        for f_name in evt.file_list:
442            names.append(f_name.data2D.label)
[7a80072]443
[377ca62f]444        # Find the correct plots to save
[3f75203]445        for key, plot in self.main_window.plot_panels.iteritems():
[54557b5]446            if not hasattr(plot, "data2D"):
447                for item in plot.plots:
[7a80072]448                    base = item.replace(CONVERT_DICT[evt.type], "")
[71b25b2]449                    if base in names:
450                        data_dic[item] = plot.plots[item]
[7a80072]451
[8e15dce]452        # Save files as Text
[982577b]453        for item, data1d in data_dic.iteritems():
[3f75203]454            base = '.'.join(item.split('.')[:-1])
[8e15dce]455            file_name = base + append + ".txt"
[7a80072]456            save_to = evt.path + "\\" + file_name
[982577b]457            writer.write(save_to, data1d)
[7a80072]458            f_path_list.append(save_to)
459            f_name_list.append(file_name)
460
[377ca62f]461        # Load files into GUI
[7a80072]462        for item in f_path_list:
[3f75203]463            self.main_window.load_data(item)
[7a80072]464
465        # Send to fitting
466        self.send_to_fitting(evt.fit, f_name_list)
467
468    def send_to_fitting(self, fit=FIT_OPTIONS[0], file_list=None):
469        """
470        Send a list of data to the fitting perspective
[a26f67f]471        :param fit: fit type desired
[7a80072]472        :param file_list: list of loaded file names to send to fit
473        """
[8e15dce]474        if fit in FIT_OPTIONS and fit != FIT_OPTIONS[0] and \
475                        file_list is not None:
[7a80072]476            # Set perspective to fitting
[3f75203]477            int = self.data_panel.perspective_cbox.FindString("Fitting")
478            self.data_panel.perspective_cbox.SetSelection(int)
479            self.data_panel._on_perspective_selection(None)
[7a80072]480            # Unselect all loaded data
[3f75203]481            self.data_panel.selection_cbox.SetValue('Unselect all Data')
482            self.data_panel._on_selection_type(None)
[7a80072]483            # Click each sliced data file
484            for f_name in file_list:
485                num = len(f_name)
[3f75203]486                data_list = self.data_panel.list_cb_data
[7a80072]487                for key in data_list:
488                    loaded_key = (key[:num]) if len(key) > num else key
489                    if loaded_key == f_name:
490                        selection = key
491                        data_ctrl = data_list[selection][0]
492                        self.check_item_and_children(data_ctrl=data_ctrl,
493                                                     check_value=True)
[82ce1d0]494            # Switch to batch mode if selected
495            if fit == FIT_OPTIONS[2]:
[3f75203]496                self.data_panel.rb_single_mode.SetValue(False)
497                self.data_panel.rb_batch_mode.SetValue(True)
498                self.data_panel.on_batch_mode(None)
[82ce1d0]499            else:
[3f75203]500                self.data_panel.rb_single_mode.SetValue(True)
501                self.data_panel.rb_batch_mode.SetValue(False)
502                self.data_panel.on_single_mode(None)
[7a80072]503
504            # Post button click event to send data to fitting
505            evt = wx.PyCommandEvent(wx.EVT_BUTTON.typeId,
[3f75203]506                                    self.data_panel.bt_import.GetId())
507            wx.PostEvent(self.data_panel, evt)
[7a80072]508
[54557b5]509    def on_auto_save_checked(self, evt=None):
510        """
511        Enable/Disable auto append when checkbox is checked
512        :param evt: Event
513        """
514        self.append_name.Enable(self.auto_save.IsChecked())
515        self.path.Enable(self.auto_save.IsChecked())
[7a80072]516        self.fitting_options.Enable(self.auto_save.IsChecked())
517
518    def check_item_and_children(self, data_ctrl, check_value=True):
[3f75203]519        self.data_panel.tree_ctrl.CheckItem(data_ctrl, check_value)
[7a80072]520        if data_ctrl.HasChildren():
521            if check_value and not data_ctrl.IsExpanded():
522                return
523            for child_ctrl in data_ctrl.GetChildren():
[3f75203]524                self.data_panel.CheckItem(child_ctrl, check_value)
525
526    def update_file_append(self, params=None):
527        """
528        Update default_value when any parameters are changed
529        :param params: dictionary of parameters
530        """
531        self.default_value = ""
532        if params is None:
533            params = self.params
534        for key in params:
535            self.default_value += "_{0}".format(key).split(" [")[0]
536            self.default_value += "-{:.2f}".format(params[key])
Note: See TracBrowser for help on using the repository browser.