Changeset 7a80072 in sasview for src/sas/sasgui/guiframe


Ignore:
Timestamp:
Apr 8, 2017 8:54:39 AM (7 years ago)
Author:
krzywon
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
ac0578c
Parents:
377ca62f
git-author:
Jeff Krzywon <krzywon@…> (04/08/17 08:54:39)
git-committer:
krzywon <krzywon@…> (04/08/17 08:54:39)
Message:

Fitting partially works. Problem creating new pages.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/guiframe/local_perspectives/plotting/parameters_panel_slicer.py

    r377ca62f r7a80072  
    1212auto_save, EVT_AUTO_SAVE = wx.lib.newevent.NewEvent() 
    1313 
     14FIT_OPTIONS = ["No fitting", "Fitting"] 
     15CONVERT_DICT = {"SectorInteractor": "SectorQ", 
     16                "AnnulusInteractor": "AnnulusPhi", 
     17                "BoxInteractorX": "SlabX", 
     18                "BoxInteractorY": "SlabY"} 
    1419 
    1520class SlicerParameterPanel(wx.Dialog): 
     
    3641        self.auto_save = None 
    3742        self.path = None 
     43        self.fitting_options = None 
    3844        self.type_list = [] 
    3945        self.type_select = None 
     
    128134                              "BoxInteractorX", "BoxInteractorY"] 
    129135            self.type_select = wx.ComboBox(parent=self, choices=self.type_list) 
    130             self.Bind(wx.EVT_COMBOBOX, self.onChangeSlicer) 
     136            self.type_select.Bind(wx.EVT_COMBOBOX, self.onChangeSlicer) 
    131137            index = self.type_select.FindString(type) 
    132138            self.type_select.SetSelection(index) 
     
    187193                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    188194 
    189             # TODO: Fix fitting options combobox/radiobox 
    190195            # Combobox for selecting fitting options 
    191             # iy += 1 
    192             # self.fitting_radio = wx.RadioBox(parent=self, id=wx.NewId(), 
    193             #                                  size=(4,1)) 
    194             # self.fitting_radio.SetString(0, "No fitting") 
    195             # self.fitting_radio.SetString(1, "Batch Fitting") 
    196             # self.fitting_radio.SetString(2, "Fitting") 
    197             # self.fitting_radio.SetString(3, "Simultaneous and Constrained Fit") 
    198             # self.fitting_radio.SetValue(0) 
    199             # self.bck.Add(self.fitting_radio, (iy, ix), (1, 1), 
    200             #              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     196            iy += 1 
     197            fit_text = "Fitting Options:" 
     198            fit_text_item = wx.StaticText(self, -1, fit_text, style=wx.ALIGN_LEFT) 
     199            self.bck.Add(fit_text_item, (iy, ix), (1, 1), 
     200                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     201            self.fitting_options = wx.ComboBox(parent=self, choices=FIT_OPTIONS) 
     202            self.fitting_options.SetSelection(0) 
     203            self.bck.Add(self.fitting_options, (iy, 1), (1, 1), 
     204                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     205            self.fitting_options.Enable(False) 
     206            self.fitting_options.Bind(wx.EVT_COMBOBOX, None) 
    201207 
    202208            # Button to start batch slicing 
     
    262268        append = self.append_name.GetValue() 
    263269        path = self.path.GetPath() 
     270        fit = self.fitting_options.GetValue() 
    264271 
    265272        # Find desired 2D data panels 
     
    274281        # Post an event to apply appropriate slicer params to each slicer 
    275282        event_params = apply_params(params=params, apply_to_list=apply_to_list, 
    276                              auto_save=save, append=append, 
     283                             auto_save=save, append=append, fit=fit, 
    277284                             path=path, type=type) 
    278285        wx.PostEvent(self, event_params) 
     
    354361        # Post an event to save each data set to file 
    355362        if evt.auto_save: 
    356             event = auto_save(append_to_name=evt.append, 
    357                               file_list=evt.apply_to_list, 
    358                               path=evt.path, type=evt.type) 
     363            event = auto_save(append_to_name=evt.append, path=evt.path, 
     364                              type=evt.type, file_list=evt.apply_to_list, 
     365                              fit=evt.fit) 
    359366            wx.PostEvent(self, event) 
    360367 
     
    364371        :param evt: Event that triggered the call to the method 
    365372        """ 
     373 
     374        # Send the event to the end of the wx event queue 
    366375        if self.iter == 0: 
    367             # Forces the event to be processed after dynamically generated evts 
    368376            clone = evt.Clone() 
    369377            wx.PostEvent(self, clone) 
     
    379387        append = evt.append_to_name 
    380388        names = [] 
    381         file_list = [] 
    382         convert_dict = {"SectorInteractor": "SectorQ", 
    383                         "AnnulusInteractor": "AnnulusPhi", 
    384                         "BoxInteractorX": "SlabX", 
    385                         "BoxInteractorY": "SlabY"} 
     389        f_name_list = [] 
     390        f_path_list = [] 
     391 
    386392        # Get list of 2D data names for saving 
    387393        for f_name in evt.file_list: 
    388394            names.append(f_name.data2D.label) 
     395 
    389396        # Find the correct plots to save 
    390397        for key, plot in main_window.plot_panels.iteritems(): 
    391398            if not hasattr(plot, "data2D"): 
    392399                for item in plot.plots: 
    393                     base = item.replace(convert_dict[evt.type], "") 
     400                    base = item.replace(CONVERT_DICT[evt.type], "") 
    394401                    if base in names: 
    395402                        data_dic[item] = plot.plots[item] 
     403 
    396404        # Save files as XML 
    397405        for item, data1d in data_dic.iteritems(): 
    398406            base = ('.').join(item.split('.')[:-1]) 
    399             save_to = evt.path + "\\" + base + append + ".xml" 
     407            file_name = base + append + ".xml" 
     408            save_to = evt.path + "\\" + file_name 
    400409            writer.write(save_to, data1d) 
    401             file_list.append(save_to) 
     410            f_path_list.append(save_to) 
     411            f_name_list.append(file_name) 
     412 
    402413        # Load files into GUI 
    403         for item in file_list: 
    404             self.parent.parent.load_data(item) 
     414        for item in f_path_list: 
     415            main_window.load_data(item) 
     416 
     417        # Send to fitting 
     418        self.send_to_fitting(evt.fit, f_name_list) 
     419 
     420    def send_to_fitting(self, fit=FIT_OPTIONS[0], file_list=None): 
     421        """ 
     422        Send a list of data to the fitting perspective 
     423        :param fit: fit type desired  
     424        :param file_list: list of loaded file names to send to fit 
     425        """ 
     426        if fit != FIT_OPTIONS[0] and file_list is not None: 
     427            # Method variable definitions 
     428            main_window = self.parent.parent 
     429            datapanel = main_window._data_panel 
     430            # Set perspective to fitting 
     431            int = datapanel.perspective_cbox.FindString("Fitting") 
     432            datapanel.perspective_cbox.SetSelection(int) 
     433            datapanel._on_perspective_selection(None) 
     434            # Unselect all loaded data 
     435            datapanel.selection_cbox.SetValue('Unselect all Data') 
     436            datapanel._on_selection_type(None) 
     437            # Click each sliced data file 
     438            for f_name in file_list: 
     439                num = len(f_name) 
     440                data_list = datapanel.list_cb_data 
     441                for key in data_list: 
     442                    loaded_key = (key[:num]) if len(key) > num else key 
     443                    if loaded_key == f_name: 
     444                        selection = key 
     445                        data_ctrl = data_list[selection][0] 
     446                        self.check_item_and_children(data_ctrl=data_ctrl, 
     447                                                     check_value=True) 
     448            # TODO: Batch fitting 
     449            # # Switch to batch mode if selected 
     450            # if fit == FIT_OPTIONS[2]: 
     451            #     datapanel.rb_single_mode.SetValue(False) 
     452            #     datapanel.rb_batch_mode.SetValue(True) 
     453            #     evt = wx.PyCommandEvent(wx.EVT_RADIOBUTTON.typeId, 
     454            #                             datapanel.rb_batch_mode.GetId()) 
     455            #     wx.PostEvent(datapanel, evt) 
     456            # else: 
     457            #     datapanel.rb_single_mode.SetValue(True) 
     458            #     datapanel.rb_batch_mode.SetValue(False) 
     459            #     evt = wx.PyCommandEvent(wx.EVT_RADIOBUTTON.typeId, 
     460            #                             datapanel.rb_single_mode.GetId()) 
     461            #     wx.PostEvent(datapanel, evt) 
     462 
     463            # Post button click event to send data to fitting 
     464            evt = wx.PyCommandEvent(wx.EVT_BUTTON.typeId, 
     465                                    datapanel.bt_import.GetId()) 
     466            wx.PostEvent(datapanel, evt) 
     467 
     468            # TODO: Simultaneous/Constrained fitting 
     469            # # Create event to open simfitpage if selected 
     470            # if fit == FIT_OPTIONS[3]: 
     471            #     fit_pers = main_window._current_perspective 
     472            #     evt = wx.PyCommandEvent(wx.EVT_MENU.typeId, 
     473            #                         fit_pers.id_simfit) 
     474            #     wx.PostEvent(datapanel, evt) 
    405475 
    406476    def on_auto_save_checked(self, evt=None): 
     
    411481        self.append_name.Enable(self.auto_save.IsChecked()) 
    412482        self.path.Enable(self.auto_save.IsChecked()) 
     483        self.fitting_options.Enable(self.auto_save.IsChecked()) 
     484 
     485    def check_item_and_children(self, data_ctrl, check_value=True): 
     486        self.parent.parent._data_panel.tree_ctrl.CheckItem(data_ctrl, 
     487                                                           check_value) 
     488        if data_ctrl.HasChildren(): 
     489            if check_value and not data_ctrl.IsExpanded(): 
     490                # Only select children if control is expanded 
     491                # Always deselect children, regardless (see ticket #259) 
     492                return 
     493            for child_ctrl in data_ctrl.GetChildren(): 
     494                self.tree_ctrl.CheckItem(child_ctrl, check_value) 
Note: See TracChangeset for help on using the changeset viewer.