Changeset f15da54 in sasview


Ignore:
Timestamp:
Apr 4, 2017 11:00:39 AM (8 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:
1661cd5
Parents:
a099131
git-author:
Jeff Krzywon <krzywon@…> (04/04/17 11:00:39)
git-committer:
krzywon <krzywon@…> (04/04/17 11:00:39)
Message:

Apply slicer to plots via events. Look for loaded plots instead of loaded data.

File:
1 edited

Legend:

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

    ra099131 rf15da54  
    1111from Plotter2D import ModelPanel2D 
    1212from sas.sascalc.dataloader.data_info import Data1D, Data2D 
     13ApplyParams, EVT_APPLY_PARAMS = wx.lib.newevent.NewEvent() 
    1314 
    1415 
     
    1718    Panel class to show the slicer parameters 
    1819    """ 
    19     #TODO: show units 
    20     #TODO: order parameters properly 
     20    # TODO: show units 
     21    # TODO: order parameters properly 
    2122 
    2223    def __init__(self, parent, *args, **kwargs): 
     
    4041        self.parent.Bind(EVT_SLICER, self.onEVT_SLICER) 
    4142        self.parent.Bind(EVT_SLICER_PARS, self.onParamChange) 
     43        self.Bind(EVT_APPLY_PARAMS, self.apply_params_list) 
    4244 
    4345    def onEVT_SLICER(self, event): 
     
    141143                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    142144            iy += 1 
    143             button_label = "Apply Slicer to Selected Files" 
     145            button_label = "Apply Slicer to Selected Plots" 
    144146            self.batch_slicer_button = wx.Button(parent=self, 
    145147                                                 label=button_label) 
     
    196198    def onBatchSlice(self, evt=None): 
    197199        """ 
    198         Batch slicing button is pushed 
     200        Method invoked with batch slicing button is pressed 
    199201        :param evt: Event triggering hide/show of the batch slicer parameters 
    200202        """ 
    201         self.parent.parent._data_panel._uncheck_all() 
    202203        apply_to_list = [] 
    203         plot_list = [] 
    204204        spp = self.parent.parent 
    205         data_panel = spp._data_panel 
    206         data_list = data_panel.list_cb_data 
    207205        params = self.parent.slicer.get_params() 
    208206        type = self.type_select.GetStringSelection() 
    209207 
    210         # Process each data file individually 
    211         for item in self.data_list.CheckedStrings: 
    212             # Get data_id 
    213             num = len(item) 
    214             for key in data_list: 
    215                 loaded_key = (key[:num]) if len(key) > num else key 
    216                 if loaded_key == item: 
    217                     selection = key 
    218                     break 
    219  
    220             # Check the data checkbox 
    221             data_ctrl = data_list[selection][0] 
    222             self.check_item_and_children(data_ctrl=data_ctrl, check_value=True) 
    223             plot_list.append(item) 
    224  
    225         # Plot all checked data 
    226         data_panel.on_plot() 
    227         time.sleep(1.0) 
    228  
    229208        # Find loaded 2D data panels 
    230209        for key, mgr in spp.plot_panels.iteritems(): 
    231             if mgr.graph.prop['title'] in plot_list: 
     210            if mgr.graph.prop['title'] in self.data_list.CheckedStrings: 
    232211                apply_to_list.append(mgr) 
    233212 
     
    235214        for item in apply_to_list: 
    236215            self._apply_slicer_to_plot(item, type) 
    237             item.slicer.set_params(params) 
    238             item.slicer.base.update() 
     216 
     217        event = ApplyParams(params=params, plot_list=apply_to_list) 
     218        wx.PostEvent(self, event) 
    239219 
    240220        # TODO: save file (if desired) 
     
    251231        """ 
    252232        Apply a slicer to *any* plot window, not just parent window 
    253         :param plot: 
    254         :return: 
     233        :param plot: 2D plot panel to apply a slicer to 
     234        :param type: The type of slicer to apply to the panel 
     235        :return: Return the plot with the slicer applied 
    255236        """ 
    256237        if type is None: 
     
    265246            plot.onBoxavgY(None) 
    266247 
    267     def check_item_and_children(self, data_ctrl, check_value=True): 
    268         self.parent.parent._data_panel.tree_ctrl.CheckItem(data_ctrl, 
    269                                                            check_value) 
    270         if data_ctrl.HasChildren(): 
    271             if check_value and not data_ctrl.IsExpanded(): 
    272                 # Only select children if control is expanded 
    273                 # Always deselect children, regardless (see ticket #259) 
    274                 return 
    275             for child_ctrl in data_ctrl.GetChildren(): 
    276                 self.tree_ctrl.CheckItem(child_ctrl, check_value) 
    277  
    278248    def process_list(self): 
     249        self.checkme = None 
    279250        main_window = self.parent.parent 
    280251        self.loaded_data = [] 
    281252        id = wx.NewId() 
    282         for key, value in main_window._data_manager.stored_data.iteritems(): 
    283             if isinstance(value.data, Data2D): 
    284                 self.loaded_data.append(value.data.name) 
    285             if key == self.parent.data2D.id: 
    286                 self.checkme = self.loaded_data.index(value.data.name) 
     253        for key, value in main_window.plot_panels.iteritems(): 
     254            if isinstance(value, ModelPanel2D): 
     255                self.loaded_data.append(value.data2D.name) 
     256                if value.data2D.id == self.parent.data2D.id: 
     257                    self.checkme = self.loaded_data.index(value.data2D.name) 
    287258        self.data_list = wx.CheckListBox(parent=self, id=id, 
    288259                                         choices=self.loaded_data, 
    289                                          name="Apply Slicer to Data Sets:") 
    290         self.data_list.Check(self.checkme) 
     260                                         name="Apply Slicer to 2D Plots:") 
     261        if self.checkme is not None: 
     262            self.data_list.Check(self.checkme) 
    291263        self.data_list.Bind(wx.EVT_CHECKLISTBOX, self.onCheckBoxList) 
    292264 
    293265    def onCheckBoxList(self, e): 
     266        """ 
     267        Do not allow a checkbox to be unchecked 
     268        :param e: Event triggered when a checkbox list item is checked 
     269        """ 
    294270        index = e.GetSelection() 
    295271        if index == self.checkme: 
    296272            self.data_list.Check(index) 
     273 
     274    def apply_params_list(self, evt=None): 
     275        for item in evt.plot_list: 
     276            item.slicer.set_params(evt.params) 
     277            item.slicer.base.update() 
     278        self.Destroy() 
Note: See TracChangeset for help on using the changeset viewer.