Changeset e767897 in sasview for src


Ignore:
Timestamp:
Aug 16, 2016 4:11:39 AM (8 years ago)
Author:
lewis
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.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
a674d0b
Parents:
fa1cbee
Message:

Select/deselct children datasets when select/deselect all is clicked (fixes #259)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/guiframe/data_panel.py

    rb5c44f0 re767897  
    22#This software was developed by the University of Tennessee as part of the 
    33#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    4 #project funded by the US National Science Foundation.  
     4#project funded by the US National Science Foundation. 
    55# 
    66#See the license text in license.txt 
     
    4141        as QucikPlotDialog 
    4242import sas.sasgui.guiframe.config as config 
    43   
     43 
    4444extension_list = [] 
    4545if config.APPLICATION_STATE_EXTENSION is not None: 
    4646    extension_list.append(config.APPLICATION_STATE_EXTENSION) 
    47 EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS + extension_list    
     47EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS + extension_list 
    4848PLUGINS_WLIST = config.PLUGINS_WLIST 
    4949APPLICATION_WLIST = config.APPLICATION_WLIST 
    5050 
    51 #Control panel width  
     51#Control panel width 
    5252if sys.platform.count("win32") > 0: 
    5353    PANEL_WIDTH = 235 
     
    6767STYLE_FLAG = wx.RAISED_BORDER|CT.TR_HAS_BUTTONS| CT.TR_HIDE_ROOT|\ 
    6868                    wx.WANTS_CHARS|CT.TR_HAS_VARIABLE_ROW_HEIGHT 
    69                      
    70                      
     69 
     70 
    7171class DataTreeCtrl(CT.CustomTreeCtrl): 
    7272    """ 
     
    9797                    CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds) 
    9898        self.root = self.AddRoot("Available Data") 
    99                     
     99 
    100100    def OnCompareItems(self, item1, item2): 
    101         """  
    102         Overrides OnCompareItems in wx.TreeCtrl.  
    103         Used by the SortChildren method.  
     101        """ 
     102        Overrides OnCompareItems in wx.TreeCtrl. 
     103        Used by the SortChildren method. 
    104104        """ 
    105105        # Get the item data 
     
    113113        else: 
    114114            return 0 
    115          
     115 
    116116class DataPanel(ScrolledPanel, PanelBase): 
    117117    """ 
    118     This panel displays data available in the application and widgets to  
     118    This panel displays data available in the application and widgets to 
    119119    interact with data. 
    120120    """ 
     
    123123    ## Title to appear on top of the window 
    124124    window_caption = "Data Explorer" 
    125     #type of window  
     125    #type of window 
    126126    window_type = "Data Panel" 
    127127    ## Flag to tell the GUI manager that this panel is not 
    128128    #  tied to any perspective 
    129129    #ALWAYS_ON = True 
    130     def __init__(self, parent,  
     130    def __init__(self, parent, 
    131131                 list=None, 
    132132                 size=(PANEL_WIDTH, PANEL_HEIGHT), 
     
    138138        PanelBase.__init__(self, parent) 
    139139        self.SetupScrolling() 
    140         #Set window's font size  
     140        #Set window's font size 
    141141        self.SetWindowVariant(variant=FONT_VARIANT) 
    142         self.loader = Loader()   
     142        self.loader = Loader() 
    143143        #Default location 
    144         self._default_save_location = None   
     144        self._default_save_location = None 
    145145        self.all_data1d = True 
    146146        self.parent = parent.parent 
     
    188188        if self.parent is not None: 
    189189            self.parent.Bind(EVT_DELETE_PLOTPANEL, self._on_delete_plot_panel) 
    190       
     190 
    191191    def do_layout(self): 
    192192        """ 
     
    198198        self.layout_batch() 
    199199        self.layout_button() 
    200          
     200 
    201201    def disable_app_combo(self, enable): 
    202202        """ 
     
    204204        """ 
    205205        self.perspective_cbox.Enable(enable) 
    206          
     206 
    207207    def define_panel_structure(self): 
    208208        """ 
     
    213213        self.sizer1 = wx.BoxSizer(wx.VERTICAL) 
    214214        self.sizer1.SetMinSize(wx.Size(w/13, h*2/5)) 
    215        
     215 
    216216        self.sizer2 = wx.BoxSizer(wx.VERTICAL) 
    217217        self.sizer3 = wx.FlexGridSizer(9, 2, 4, 1) 
    218218        self.sizer4 = wx.BoxSizer(wx.VERTICAL) 
    219219        self.sizer5 = wx.BoxSizer(wx.VERTICAL) 
    220         
     220 
    221221        self.vbox.Add(self.sizer5, 0, wx.EXPAND|wx.ALL, 1) 
    222222        self.vbox.Add(self.sizer1, 1, wx.EXPAND|wx.ALL, 0) 
     
    224224        self.vbox.Add(self.sizer3, 0, wx.EXPAND|wx.ALL, 10) 
    225225        #self.vbox.Add(self.sizer4, 0, wx.EXPAND|wx.ALL,5) 
    226          
     226 
    227227        self.SetSizer(self.vbox) 
    228          
     228 
    229229    def layout_selection(self): 
    230230        """ 
     
    244244        self.selection_cbox.SetValue('Select all Data') 
    245245        wx.EVT_COMBOBOX(self.selection_cbox, -1, self._on_selection_type) 
    246         self.sizer5.AddMany([(select_txt, 0, wx.ALL, 5),  
     246        self.sizer5.AddMany([(select_txt, 0, wx.ALL, 5), 
    247247                            (self.selection_cbox, 0, wx.ALL,5)]) 
    248248        self.enable_selection() 
    249          
    250      
     249 
     250 
    251251    def _on_selection_type(self, event): 
    252252        """ 
     
    254254            :param event: UI event 
    255255        """ 
     256        def check_item_and_children(control, check_value=True): 
     257            self.tree_ctrl.CheckItem(data_ctrl, check_value) 
     258            if data_ctrl.HasChildren(): 
     259                if check_value == True and not control.IsExpanded(): 
     260                    # Only select children if control is expanded 
     261                    # Always deselect children, regardless (see ticket #259) 
     262                    return 
     263                for child_ctrl in data_ctrl.GetChildren(): 
     264                    self.tree_ctrl.CheckItem(child_ctrl, check_value) 
     265 
    256266        option = self.selection_cbox.GetValue() 
    257          
     267 
    258268        pos = self.selection_cbox.GetSelection() 
    259269        if pos == wx.NOT_FOUND: 
    260             return  
     270            return 
    261271        option = self.selection_cbox.GetString(pos) 
    262272        for item in self.list_cb_data.values(): 
    263273            data_ctrl, _, _, _, _, _, _, _ = item 
    264             _, data_class, _ = self.tree_ctrl.GetItemPyData(data_ctrl)  
     274            _, data_class, _ = self.tree_ctrl.GetItemPyData(data_ctrl) 
    265275            if option == 'Select all Data': 
    266                 self.tree_ctrl.CheckItem(data_ctrl, True)  
     276                check_item_and_children(data_ctrl, check_value=True) 
    267277            elif option == 'Unselect all Data': 
    268                 self.tree_ctrl.CheckItem(data_ctrl, False) 
     278                check_item_and_children(data_ctrl, check_value=False) 
    269279            elif option == 'Select all Data 1D': 
    270280                if data_class == 'Data1D': 
    271                     self.tree_ctrl.CheckItem(data_ctrl, True)  
     281                    check_item_and_children(data_ctrl, check_value=True) 
    272282            elif option == 'Unselect all Data 1D': 
    273283                if data_class == 'Data1D': 
    274                     self.tree_ctrl.CheckItem(data_ctrl, False)  
    275             elif option == 'Select all Data 1D': 
    276                 if data_class == 'Data1D': 
    277                     self.tree_ctrl.CheckItem(data_ctrl, True)  
     284                    check_item_and_children(data_ctrl, check_value=False) 
    278285            elif option == 'Select all Data 2D': 
    279286                if data_class == 'Data2D': 
    280                     self.tree_ctrl.CheckItem(data_ctrl, True)  
     287                    check_item_and_children(data_ctrl, check_value=True) 
    281288            elif option == 'Unselect all Data 2D': 
    282289                if data_class == 'Data2D': 
    283                     self.tree_ctrl.CheckItem(data_ctrl, False)  
     290                    check_item_and_children(data_ctrl, check_value=False) 
    284291        self.enable_append() 
    285292        self.enable_freeze() 
     
    287294        self.enable_import() 
    288295        self.enable_remove() 
    289                 
     296 
    290297    def layout_button(self): 
    291298        """ 
     
    293300        """ 
    294301        #Load Data Button 
    295         self.bt_add = wx.Button(self, wx.NewId(), "Load Data",  
     302        self.bt_add = wx.Button(self, wx.NewId(), "Load Data", 
    296303                                size=(BUTTON_WIDTH, -1)) 
    297304        self.bt_add.SetToolTipString("Load data files") 
    298305        wx.EVT_BUTTON(self, self.bt_add.GetId(), self._load_data) 
    299          
     306 
    300307        #Delete Data Button 
    301308        self.bt_remove = wx.Button(self, wx.NewId(), "Delete Data", 
     
    303310        self.bt_remove.SetToolTipString("Delete data from the application") 
    304311        wx.EVT_BUTTON(self, self.bt_remove.GetId(), self.on_remove) 
    305          
     312 
    306313        #Send data to perspective button 
    307314        self.bt_import = wx.Button(self, wx.NewId(), "Send To", 
     
    309316        self.bt_import.SetToolTipString("Send Data set to active perspective") 
    310317        wx.EVT_BUTTON(self, self.bt_import.GetId(), self.on_import) 
    311          
     318 
    312319        #Choose perspective to be send data to combo box 
    313320        self.perspective_cbox = wx.ComboBox(self, -1, 
     
    315322        if not IS_MAC: 
    316323            self.perspective_cbox.SetMinSize((BUTTON_WIDTH*1.6, -1)) 
    317         wx.EVT_COMBOBOX(self.perspective_cbox, -1,  
     324        wx.EVT_COMBOBOX(self.perspective_cbox, -1, 
    318325                        self._on_perspective_selection) 
    319      
     326 
    320327        #Append data to current Graph Button 
    321328        self.bt_append_plot = wx.Button(self, wx.NewId(), "Append Plot To", 
     
    324331                                "Plot the selected data in the active panel") 
    325332        wx.EVT_BUTTON(self, self.bt_append_plot.GetId(), self.on_append_plot) 
    326          
     333 
    327334        #Create a new graph and send data to that new graph button 
    328         self.bt_plot = wx.Button(self, wx.NewId(), "New Plot",  
     335        self.bt_plot = wx.Button(self, wx.NewId(), "New Plot", 
    329336                                 size=(BUTTON_WIDTH, -1)) 
    330337        self.bt_plot.SetToolTipString("To trigger plotting") 
    331338        wx.EVT_BUTTON(self, self.bt_plot.GetId(), self.on_plot) 
    332          
     339 
    333340        #Freeze current theory button - becomes a data set and stays on graph 
    334         self.bt_freeze = wx.Button(self, wx.NewId(), "Freeze Theory",  
     341        self.bt_freeze = wx.Button(self, wx.NewId(), "Freeze Theory", 
    335342                                   size=(BUTTON_WIDTH, -1)) 
    336343        freeze_tip = "To trigger freeze a theory: making a copy\n" 
     
    339346        self.bt_freeze.SetToolTipString(freeze_tip) 
    340347        wx.EVT_BUTTON(self, self.bt_freeze.GetId(), self.on_freeze) 
    341         
     348 
    342349        #select plot to send to combo box (blank if no data) 
    343350        if sys.platform == 'darwin': 
    344             self.cb_plotpanel = wx.ComboBox(self, -1,  
     351            self.cb_plotpanel = wx.ComboBox(self, -1, 
    345352                                            style=wx.CB_READONLY) 
    346353        else: 
    347             self.cb_plotpanel = wx.ComboBox(self, -1,  
     354            self.cb_plotpanel = wx.ComboBox(self, -1, 
    348355                                            style=wx.CB_READONLY|wx.CB_SORT) 
    349356        wx.EVT_COMBOBOX(self.cb_plotpanel, -1, self._on_plot_selection) 
    350357        self.cb_plotpanel.Disable() 
    351          
     358 
    352359        #Help button 
    353360        self.bt_help = wx.Button(self, wx.NewId(), "HELP", 
     
    365372                             ((10, 10)), 
    366373                             (self.bt_append_plot), 
    367                              (self.cb_plotpanel,  
     374                             (self.cb_plotpanel, 
    368375                              wx.EXPAND|wx.ADJUST_MINSIZE, 5), 
    369376                             ((5, 5)), 
    370377                             ((5, 5)), 
    371378                             (self.bt_import, 0, wx.EXPAND|wx.RIGHT, 5), 
    372                              (self.perspective_cbox,  
     379                             (self.perspective_cbox, 
    373380                              wx.EXPAND|wx.ADJUST_MINSIZE, 5), 
    374381                             ((10, 10)), 
     
    385392        self.enable_freeze() 
    386393        self.enable_remove_plot() 
    387          
     394 
    388395    def layout_batch(self): 
    389396        """ 
     
    397404        self.Bind(wx.EVT_RADIOBUTTON, self.on_batch_mode, 
    398405                   id=self.rb_batch_mode.GetId()) 
    399          
     406 
    400407        self.rb_single_mode.SetValue(not self.parent.batch_on) 
    401408        self.rb_batch_mode.SetValue(self.parent.batch_on) 
    402409        self.sizer4.AddMany([(self.rb_single_mode, 0, wx.ALL, 4), 
    403410                             (self.rb_batch_mode, 0, wx.ALL, 4)]) 
    404          
     411 
    405412    def on_single_mode(self, event): 
    406413        """ 
     
    410417        if self.parent is not None: 
    411418            wx.PostEvent(self.parent, NewBatchEvent(enable=False)) 
    412         
     419 
    413420    def on_batch_mode(self, event): 
    414421        """ 
     
    417424        """ 
    418425        if self.parent is not None: 
    419             wx.PostEvent(self.parent,  
     426            wx.PostEvent(self.parent, 
    420427                         NewBatchEvent(enable=True)) 
    421      
    422     def _get_data_selection(self, event):   
     428 
     429    def _get_data_selection(self, event): 
    423430        """ 
    424431            Get data selection from the right click 
     
    435442            data = theory_list.values()[0][0] 
    436443        return data 
    437      
     444 
    438445    def on_edit_data(self, event): 
    439446        """ 
     
    443450        from sas.sasgui.guiframe.local_perspectives.plotting.masking \ 
    444451            import MaskPanel as MaskDialog 
    445          
    446         panel = MaskDialog(parent=self.parent, base=self,  
     452 
     453        panel = MaskDialog(parent=self.parent, base=self, 
    447454                           data=data, id=wx.NewId()) 
    448455        panel.ShowModal() 
    449      
     456 
    450457    def on_plot_3d(self, event): 
    451458        """ 
     
    455462        from sas.sasgui.guiframe.local_perspectives.plotting.masking \ 
    456463        import FloatPanel as Float3dDialog 
    457          
    458         panel = Float3dDialog(base=self, data=data,  
     464 
     465        panel = Float3dDialog(base=self, data=data, 
    459466                              dimension=3, id=wx.NewId()) 
    460         panel.ShowModal()    
    461      
     467        panel.ShowModal() 
     468 
    462469    def on_quick_plot(self, event): 
    463470        """ 
     
    468475            dimension = 2 
    469476        else: 
    470             dimension = 1  
    471         #panel = QucikPlotDialog(base=self, data=data,  
     477            dimension = 1 
     478        #panel = QucikPlotDialog(base=self, data=data, 
    472479        #                        dimension=dimension, id=wx.NewId()) 
    473480        frame = QucikPlotDialog(self, -1, "Plot " + data.name, 'log_{10}') 
     
    477484        frame.Show(True) 
    478485        frame.SetFocus() 
    479         #panel.ShowModal()     
    480      
     486        #panel.ShowModal() 
     487 
    481488    def on_data_info(self, event): 
    482489        """ 
     
    488495        else: 
    489496            self.parent.show_data1d(data, data.name) 
    490          
     497 
    491498    def on_save_as(self, event): 
    492499        """ 
     
    506513            else: 
    507514                print "unable to save this type of data" 
    508          
     515 
    509516    def layout_data_list(self): 
    510517        """ 
     
    523530        self.data_menu.Append(id, name, msg) 
    524531        wx.EVT_MENU(self, id, self.on_data_info) 
    525          
     532 
    526533        id = wx.NewId() 
    527534        name = "Save As" 
     
    529536        self.data_menu.Append(id, name, msg) 
    530537        wx.EVT_MENU(self, id, self.on_save_as) 
    531      
     538 
    532539        quickplot_id = wx.NewId() 
    533540        name = "Quick Plot" 
     
    535542        self.data_menu.Append(quickplot_id, name, msg) 
    536543        wx.EVT_MENU(self, quickplot_id, self.on_quick_plot) 
    537          
     544 
    538545        self.plot3d_id = wx.NewId() 
    539546        name = "Quick 3DPlot (Slow)" 
     
    541548        self.data_menu.Append(self.plot3d_id, name, msg) 
    542549        wx.EVT_MENU(self, self.plot3d_id, self.on_plot_3d) 
    543              
     550 
    544551        self.editmask_id = wx.NewId() 
    545552        name = "Edit Mask" 
     
    547554        self.data_menu.Append(self.editmask_id, name, msg) 
    548555        wx.EVT_MENU(self, self.editmask_id, self.on_edit_data) 
    549          
     556 
    550557        tree_ctrl_theory_label = wx.StaticText(self, -1, "Theory") 
    551558        tree_ctrl_theory_label.SetForegroundColour('blue') 
    552         self.tree_ctrl_theory = DataTreeCtrl(parent=self,  
     559        self.tree_ctrl_theory = DataTreeCtrl(parent=self, 
    553560                                                    style=wx.SUNKEN_BORDER) 
    554         self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_CHECKING,  
     561        self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_CHECKING, 
    555562                                                    self.on_check_item) 
    556         self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_MENU,  
     563        self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_MENU, 
    557564                                   self.on_right_click_theory) 
    558565        self.sizer1.Add(tree_ctrl_label, 0, wx.LEFT, 10) 
     
    560567        self.sizer1.Add(tree_ctrl_theory_label, 0,  wx.LEFT, 10) 
    561568        self.sizer1.Add(self.tree_ctrl_theory, 1, wx.EXPAND|wx.ALL, 10) 
    562             
     569 
    563570    def on_right_click_theory(self, event): 
    564571        """ 
     
    575582            self.data_menu.Enable(self.editmask_id, False) 
    576583            self.data_menu.Enable(self.plot3d_id, menu_enable) 
    577             self.PopupMenu(self.data_menu)  
    578                     
     584            self.PopupMenu(self.data_menu) 
     585 
    579586    def on_right_click_data(self, event): 
    580587        """ 
     
    596603            self.data_menu.Enable(self.editmask_id, maskmenu_enable) 
    597604            self.data_menu.Enable(self.plot3d_id, menu_enable) 
    598             self.PopupMenu(self.data_menu)  
    599          
    600     def onContextMenu(self, event):  
     605            self.PopupMenu(self.data_menu) 
     606 
     607    def onContextMenu(self, event): 
    601608        """ 
    602609        Retrieve the state selected state 
     
    606613        pos = event.GetPosition() 
    607614        pos = self.ScreenToClient(pos) 
    608         self.PopupMenu(self.popUpMenu, pos)  
    609        
    610    
     615        self.PopupMenu(self.popUpMenu, pos) 
     616 
     617 
    611618    def on_check_item(self, event): 
    612619        """ 
     
    614621        """ 
    615622        item = event.GetItem() 
    616         item.Check(not item.IsChecked())  
     623        item.Check(not item.IsChecked()) 
    617624        self.enable_append() 
    618625        self.enable_freeze() 
     
    621628        self.enable_remove() 
    622629        event.Skip() 
    623          
     630 
    624631    def fill_cbox_analysis(self, plugin): 
    625632        """ 
     
    635642                if plug.get_perspective(): 
    636643                    self.perspective_cbox.Append(plug.sub_menu, plug) 
    637              
     644 
    638645            curr_pers = self.parent.get_current_perspective() 
    639646            if curr_pers: 
    640647                self.perspective_cbox.SetStringSelection(curr_pers.sub_menu) 
    641648                self.enable_import() 
    642                          
     649 
    643650    def load_data_list(self, list): 
    644651        """ 
     
    654661                    data_run = str(data.run) 
    655662                    data_class = data.__class__.__name__ 
    656                     path = dstate.get_path()  
     663                    path = dstate.get_path() 
    657664                    process_list = data.process 
    658665                    data_id = data.id 
     
    661668                        #new state 
    662669                        data_c = self.tree_ctrl.InsertItem(self.tree_ctrl.root, 
    663                                         0, data_name, ct_type=1,  
     670                                        0, data_name, ct_type=1, 
    664671                                        data=(data_id, data_class, state_id)) 
    665672                        data_c.Check(True) 
    666673                        d_i_c = self.tree_ctrl.AppendItem(data_c, 'Info') 
    667                         d_t_c = self.tree_ctrl.AppendItem(d_i_c,  
     674                        d_t_c = self.tree_ctrl.AppendItem(d_i_c, 
    668675                                                      'Title: %s' % data_title) 
    669                         r_n_c = self.tree_ctrl.AppendItem(d_i_c,  
     676                        r_n_c = self.tree_ctrl.AppendItem(d_i_c, 
    670677                                                      'Run: %s' % data_run) 
    671                         i_c_c = self.tree_ctrl.AppendItem(d_i_c,  
     678                        i_c_c = self.tree_ctrl.AppendItem(d_i_c, 
    672679                                                      'Type: %s' % data_class) 
    673680                        p_c_c = self.tree_ctrl.AppendItem(d_i_c, 
    674681                                                      "Path: '%s'" % s_path) 
    675682                        d_p_c = self.tree_ctrl.AppendItem(d_i_c, 'Process') 
    676                          
     683 
    677684                        for process in process_list: 
    678685                            process_str = str(process).replace('\n',' ') 
     
    680687                                process_str = process_str[:20]+' [...]' 
    681688                            self.tree_ctrl.AppendItem(d_p_c, process_str) 
    682                         theory_child = self.tree_ctrl.AppendItem(data_c,  
     689                        theory_child = self.tree_ctrl.AppendItem(data_c, 
    683690                                                                 "THEORIES") 
    684                         self.list_cb_data[state_id] = [data_c,  
     691                        self.list_cb_data[state_id] = [data_c, 
    685692                                                       d_i_c, 
    686693                                                       d_t_c, 
     
    695702                        data_c, d_i_c, d_t_c, r_n_c,  i_c_c, p_c_c, d_p_c, _ \ 
    696703                                = data_ctrl_list 
    697                         self.tree_ctrl.SetItemText(data_c, data_name)  
     704                        self.tree_ctrl.SetItemText(data_c, data_name) 
    698705                        temp = (data_id, data_class, state_id) 
    699                         self.tree_ctrl.SetItemPyData(data_c, temp)  
    700                         self.tree_ctrl.SetItemText(i_c_c,  
     706                        self.tree_ctrl.SetItemPyData(data_c, temp) 
     707                        self.tree_ctrl.SetItemText(i_c_c, 
    701708                                                   'Type: %s' % data_class) 
    702                         self.tree_ctrl.SetItemText(p_c_c,  
    703                                                    'Path: %s' % s_path)  
    704                         self.tree_ctrl.DeleteChildren(d_p_c)  
     709                        self.tree_ctrl.SetItemText(p_c_c, 
     710                                                   'Path: %s' % s_path) 
     711                        self.tree_ctrl.DeleteChildren(d_p_c) 
    705712                        for process in process_list: 
    706713                            if not process.is_empty(): 
     
    710717            # Sort by data name 
    711718            if self.tree_ctrl.root: 
    712                 self.tree_ctrl.SortChildren(self.tree_ctrl.root)     
     719                self.tree_ctrl.SortChildren(self.tree_ctrl.root) 
    713720        self.enable_remove() 
    714721        self.enable_import() 
     
    716723        self.enable_freeze() 
    717724        self.enable_selection() 
    718          
     725 
    719726    def _uncheck_all(self): 
    720727        """ 
     
    723730        for item in self.list_cb_data.values(): 
    724731            data_ctrl, _, _, _, _, _, _, _ = item 
    725             self.tree_ctrl.CheckItem(data_ctrl, False)  
     732            self.tree_ctrl.CheckItem(data_ctrl, False) 
    726733        self.enable_append() 
    727734        self.enable_freeze() 
     
    729736        self.enable_import() 
    730737        self.enable_remove() 
    731     
     738 
    732739    def append_theory(self, state_id, theory_list): 
    733740        """ 
     
    736743        """ 
    737744        if not theory_list: 
    738             return  
     745            return 
    739746        if state_id not in self.list_cb_data.keys(): 
    740747            root = self.tree_ctrl_theory.root 
     
    746753            tree = self.tree_ctrl 
    747754        if root is not None: 
    748             wx.CallAfter(self.append_theory_helper, tree=tree, root=root,  
    749                                        state_id=state_id,  
     755            wx.CallAfter(self.append_theory_helper, tree=tree, root=root, 
     756                                       state_id=state_id, 
    750757                                       theory_list=theory_list) 
    751        
    752        
     758 
     759 
    753760    def append_theory_helper(self, tree, root, state_id, theory_list): 
    754761        """ 
     
    778785                                                    name, ct_type=1, data=temp) 
    779786                    t_i_c = tree.AppendItem(t_child, 'Info') 
    780                     i_c_c = tree.AppendItem(t_i_c,  
     787                    i_c_c = tree.AppendItem(t_i_c, 
    781788                                                  'Type: %s' % theory_class) 
    782789                    t_p_c = tree.AppendItem(t_i_c, 'Process') 
    783                      
     790 
    784791                    for process in theory_data.process: 
    785792                        tree.AppendItem(t_p_c, process.__str__()) 
    786                     theory_list_ctrl[theory_id] = [t_child,  
    787                                                    i_c_c,  
     793                    theory_list_ctrl[theory_id] = [t_child, 
     794                                                   i_c_c, 
    788795                                                   t_p_c] 
    789796                else: 
    790797                    #replace theory 
    791798                    t_child, i_c_c, t_p_c = theory_list_ctrl[theory_id] 
    792                     tree.SetItemText(t_child, name)  
    793                     tree.SetItemPyData(t_child, temp)  
    794                     tree.SetItemText(i_c_c, 'Type: %s' % theory_class)  
    795                     tree.DeleteChildren(t_p_c)  
     799                    tree.SetItemText(t_child, name) 
     800                    tree.SetItemPyData(t_child, temp) 
     801                    tree.SetItemText(i_c_c, 'Type: %s' % theory_class) 
     802                    tree.DeleteChildren(t_p_c) 
    796803                    for process in theory_data.process: 
    797804                        tree.AppendItem(t_p_c, process.__str__()) 
    798                
     805 
    799806        else: 
    800807            #data didn't have a theory associated it before 
     
    807814                    theory_id = theory_data.id 
    808815                    #if theory_state is not None: 
    809                     #    name = theory_state.model.name  
     816                    #    name = theory_state.model.name 
    810817                    temp = (theory_id, theory_class, state_id) 
    811818                    t_child = tree.AppendItem(root, 
    812                             name, ct_type=1,  
     819                            name, ct_type=1, 
    813820                            data=(theory_data.id, theory_class, state_id)) 
    814821                    t_i_c = tree.AppendItem(t_child, 'Info') 
    815                     i_c_c = tree.AppendItem(t_i_c,  
     822                    i_c_c = tree.AppendItem(t_i_c, 
    816823                                                  'Type: %s' % theory_class) 
    817824                    t_p_c = tree.AppendItem(t_i_c, 'Process') 
    818                      
     825 
    819826                    for process in theory_data.process: 
    820827                        tree.AppendItem(t_p_c, process.__str__()) 
    821              
     828 
    822829                    theory_list_ctrl[theory_id] = [t_child, i_c_c, t_p_c] 
    823830                #self.list_cb_theory[data_id] = theory_list_ctrl 
    824831                self.list_cb_theory[state_id] = theory_list_ctrl 
    825          
    826              
    827     
     832 
     833 
     834 
    828835    def set_data_helper(self): 
    829836        """ 
     
    840847                if state_id not in state_to_plot: 
    841848                    state_to_plot.append(state_id) 
    842             
     849 
    843850        for theory_dict in self.list_cb_theory.values(): 
    844851            for _, value in theory_dict.iteritems(): 
     
    850857                        state_to_plot.append(state_id) 
    851858        return data_to_plot, theory_to_plot, state_to_plot 
    852      
     859 
    853860    def remove_by_id(self, id): 
    854861        """ 
     
    857864        for item in self.list_cb_data.values(): 
    858865            data_c, _, _, _, _, _,  _, _ = item 
    859             data_id, _, state_id = self.tree_ctrl.GetItemPyData(data_c)  
     866            data_id, _, state_id = self.tree_ctrl.GetItemPyData(data_c) 
    860867            if id == data_id: 
    861868                self.tree_ctrl.Delete(data_c) 
    862869                del self.list_cb_data[state_id] 
    863870                del self.list_cb_theory[data_id] 
    864                
     871 
    865872    def load_error(self, error=None): 
    866873        """ 
    867874        Pop up an error message. 
    868          
     875 
    869876        :param error: details error message to be displayed 
    870877        """ 
    871878        if error is not None or str(error).strip() != "": 
    872             dial = wx.MessageDialog(self.parent, str(error),  
     879            dial = wx.MessageDialog(self.parent, str(error), 
    873880                                    'Error Loading File', 
    874881                                    wx.OK | wx.ICON_EXCLAMATION) 
    875             dial.ShowModal()   
    876          
     882            dial.ShowModal() 
     883 
    877884    def _load_data(self, event): 
    878885        """ 
     
    881888        if self.parent is not None: 
    882889            wx.PostEvent(self.parent, NewLoadDataEvent()) 
    883              
     890 
    884891 
    885892    def on_remove(self, event): 
    886893        """ 
    887894        Get a list of item checked and remove them from the treectrl 
    888         Ask the parent to remove reference to this item  
     895        Ask the parent to remove reference to this item 
    889896        """ 
    890897        msg = "This operation will delete the data sets checked " 
     
    893900        if msg_box.ShowModal() != wx.ID_OK: 
    894901            return 
    895          
     902 
    896903        data_to_remove, theory_to_remove, _ = self.set_data_helper() 
    897904        data_key = [] 
     
    906913                    theory_list_ctrl = self.list_cb_theory[d_key] 
    907914                    theory_to_remove += theory_list_ctrl.keys() 
    908         # Remove theory from treectrl        
     915        # Remove theory from treectrl 
    909916        for _, theory_dict in self.list_cb_theory.iteritems(): 
    910917            for  key, value in theory_dict.iteritems(): 
     
    916923                        pass 
    917924                    theory_key.append(key) 
    918                      
     925 
    919926        #Remove data and related theory references 
    920927        for key in data_key: 
     
    934941                                pass 
    935942                    del theory_dict[key] 
    936                      
    937              
     943 
     944 
    938945        self.parent.remove_data(data_id=data_to_remove, 
    939946                                  theory_id=theory_to_remove) 
     
    941948        self.enable_freeze() 
    942949        self.enable_remove_plot() 
    943          
     950 
    944951    def on_import(self, event=None): 
    945952        """ 
     
    951958        temp = data_id + state_id 
    952959        self.parent.set_data(data_id=temp, theory_id=theory_id) 
    953          
     960 
    954961    def on_append_plot(self, event=None): 
    955962        """ 
     
    958965        self._on_plot_selection() 
    959966        data_id, theory_id, state_id = self.set_data_helper() 
    960         self.parent.plot_data(data_id=data_id,   
     967        self.parent.plot_data(data_id=data_id, 
    961968                              state_id=state_id, 
    962969                              theory_id=theory_id, 
    963970                              append=True) 
    964     
     971 
    965972    def on_plot(self, event=None): 
    966973        """ 
     
    968975        """ 
    969976        data_id, theory_id, state_id = self.set_data_helper() 
    970         self.parent.plot_data(data_id=data_id,   
     977        self.parent.plot_data(data_id=data_id, 
    971978                              state_id=state_id, 
    972979                              theory_id=theory_id, 
    973980                              append=False) 
    974981        self.enable_remove_plot() 
    975           
     982 
    976983    def on_close_page(self, event=None): 
    977984        """ 
     
    982989        # send parent to update menu with no show nor hide action 
    983990        self.parent.show_data_panel(action=False) 
    984      
     991 
    985992    def on_freeze(self, event): 
    986993        """ 
     
    9951002            msg = "Freeze Theory: Requires at least one theory checked." 
    9961003        wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    997              
     1004 
    9981005    def set_active_perspective(self, name): 
    9991006        """ 
     
    10021009        self.perspective_cbox.SetStringSelection(name) 
    10031010        self.enable_import() 
    1004          
     1011 
    10051012    def _on_delete_plot_panel(self, event): 
    10061013        """ 
    1007         get an event with attribute name and caption to delete existing name  
     1014        get an event with attribute name and caption to delete existing name 
    10081015        from the combobox of the current panel 
    10091016        """ 
     
    10111018        caption = event.caption 
    10121019        if self.cb_plotpanel is not None: 
    1013             pos = self.cb_plotpanel.FindString(str(caption))  
     1020            pos = self.cb_plotpanel.FindString(str(caption)) 
    10141021            if pos != wx.NOT_FOUND: 
    10151022                self.cb_plotpanel.Delete(pos) 
    10161023        self.enable_append() 
    1017          
     1024 
    10181025    def set_panel_on_focus(self, name=None): 
    10191026        """ 
     
    10311038        self.enable_append() 
    10321039        self.enable_remove_plot() 
    1033      
     1040 
    10341041    def set_plot_unfocus(self): 
    10351042        """ 
     
    10371044        """ 
    10381045        return 
    1039      
     1046 
    10401047    def _on_perspective_selection(self, event=None): 
    10411048        """ 
     
    10471054            perspective.on_perspective(event=None) 
    10481055            self.parent.check_multimode(perspective=perspective) 
    1049                  
     1056 
    10501057    def _on_plot_selection(self, event=None): 
    10511058        """ 
     
    10611068        if combo.GetValue() != 'None': 
    10621069            panel = combo.GetClientData(selection) 
    1063             self.parent.on_set_plot_focus(panel)    
    1064              
     1070            self.parent.on_set_plot_focus(panel) 
     1071 
    10651072    def on_close_plot(self, event): 
    10661073        """ 
    10671074        clseo the panel on focus 
    1068         """  
     1075        """ 
    10691076        self.enable_append() 
    10701077        selection = self.cb_plotpanel.GetSelection() 
     
    10721079            panel = self.cb_plotpanel.GetClientData(selection) 
    10731080            if self.parent is not None and panel is not None: 
    1074                 wx.PostEvent(self.parent,  
     1081                wx.PostEvent(self.parent, 
    10751082                             NewPlotEvent(group_id=panel.group_id, 
    10761083                                          action="delete")) 
    10771084        self.enable_remove_plot() 
    1078      
     1085 
    10791086    def set_frame(self, frame): 
    10801087        """ 
    10811088        """ 
    10821089        self.frame = frame 
    1083      
     1090 
    10841091    def get_frame(self): 
    10851092        """ 
    10861093        """ 
    1087         return self.frame  
    1088      
     1094        return self.frame 
     1095 
    10891096    def on_help(self, event): 
    10901097        """ 
     
    11151122        """ 
    11161123        self.parent.show_data_panel(event) 
    1117                          
     1124 
    11181125    def set_schedule_full_draw(self, panel=None, func='del'): 
    11191126        """ 
     
    11211128        """ 
    11221129        self.parent.set_schedule_full_draw(panel, func) 
    1123          
     1130 
    11241131    def enable_remove_plot(self): 
    11251132        """ 
     
    11311138        #else: 
    11321139        #    self.bt_close_plot.Enable() 
    1133              
     1140 
    11341141    def enable_remove(self): 
    11351142        """ 
     
    11421149        else: 
    11431150            self.bt_remove.Enable() 
    1144              
     1151 
    11451152    def enable_import(self): 
    11461153        """ 
     
    11601167        else: 
    11611168            self.perspective_cbox.Enable() 
    1162              
     1169 
    11631170    def enable_plot(self): 
    11641171        """ 
    11651172        enable or disable plot button 
    11661173        """ 
    1167         n_t = 0  
     1174        n_t = 0 
    11681175        n_t_t = 0 
    11691176        if self.tree_ctrl != None: 
     
    11761183            self.bt_plot.Enable() 
    11771184        self.enable_append() 
    1178         
     1185 
    11791186    def enable_append(self): 
    11801187        """ 
    11811188        enable or disable append button 
    11821189        """ 
    1183         n_t = 0  
     1190        n_t = 0 
    11841191        n_t_t = 0 
    11851192        if self.tree_ctrl != None: 
     
    11871194        if self.tree_ctrl_theory != None: 
    11881195            n_t_t = self.tree_ctrl_theory.GetCount() 
    1189         if n_t + n_t_t <= 0:  
     1196        if n_t + n_t_t <= 0: 
    11901197            self.bt_append_plot.Disable() 
    11911198            self.cb_plotpanel.Disable() 
     
    11961203            self.bt_append_plot.Enable() 
    11971204            self.cb_plotpanel.Enable() 
    1198              
     1205 
    11991206    def check_theory_to_freeze(self): 
    12001207        """ 
     
    12141221        else: 
    12151222            self.bt_freeze.Disable() 
    1216          
     1223 
    12171224    def enable_selection(self): 
    12181225        """ 
     
    12291236        else: 
    12301237            self.selection_cbox.Disable() 
    1231              
     1238 
    12321239    def show_data_button(self): 
    12331240        """ 
    1234         show load data and remove data button if  
     1241        show load data and remove data button if 
    12351242        dataloader on else hide them 
    12361243        """ 
     
    12381245            gui_style = self.parent.get_style() 
    12391246            style = gui_style & GUIFRAME.DATALOADER_ON 
    1240             if style == GUIFRAME.DATALOADER_ON:  
     1247            if style == GUIFRAME.DATALOADER_ON: 
    12411248                #self.bt_remove.Show(True) 
    1242                 self.bt_add.Show(True)  
     1249                self.bt_add.Show(True) 
    12431250            else: 
    12441251                #self.bt_remove.Hide() 
    12451252                self.bt_add.Hide() 
    1246         except:  
     1253        except: 
    12471254            #self.bt_remove.Hide() 
    1248             self.bt_add.Hide()  
    1249      
     1255            self.bt_add.Hide() 
     1256 
    12501257 
    12511258 
     
    12641271        self.list_of_ctrl = [] 
    12651272        if not data_list: 
    1266             return  
     1273            return 
    12671274        self._sizer_main = wx.BoxSizer(wx.VERTICAL) 
    12681275        self._sizer_txt = wx.BoxSizer(wx.VERTICAL) 
     
    12731280        self._panel.SetupScrolling() 
    12741281        self.__do_layout(data_list, text=text) 
    1275          
     1282 
    12761283    def __do_layout(self, data_list, text=''): 
    12771284        """ 
     
    12791286        """ 
    12801287        if not data_list or len(data_list) <= 1: 
    1281             return  
     1288            return 
    12821289        #add text 
    1283          
     1290 
    12841291        text = "Deleting these file reset some panels.\n" 
    12851292        text += "Do you want to proceed?\n" 
     
    13151322                                wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
    13161323        static_line = wx.StaticLine(self, -1) 
    1317          
     1324 
    13181325        self._sizer_txt.Add(self._panel, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 5) 
    13191326        self._sizer_main.Add(self._sizer_txt, 1, wx.EXPAND|wx.ALL, 10) 
    1320         #self._sizer_main.Add(self._data_text_ctrl, 0,  
     1327        #self._sizer_main.Add(self._data_text_ctrl, 0, 
    13211328        #                     wx.EXPAND|wx.LEFT|wx.RIGHT, 10) 
    13221329        self._sizer_main.Add(static_line, 0, wx.EXPAND, 0) 
     
    13241331        self.SetSizer(self._sizer_main) 
    13251332        self.Layout() 
    1326          
     1333 
    13271334    def get_data(self): 
    13281335        """ 
     
    13351342                temp.append(data) 
    13361343        return temp 
    1337                 
     1344 
    13381345class DataFrame(wx.Frame): 
    13391346    """ 
     
    13471354    #  tied to any perspective 
    13481355    ALWAYS_ON = True 
    1349      
     1356 
    13501357    def __init__(self, parent=None, owner=None, manager=None, size=(300, 800), 
    13511358                         list_of_perspective=[], list=[], *args, **kwds): 
     
    13571364        self.owner = owner 
    13581365        self._manager = manager 
    1359         self.panel = DataPanel(parent=self,  
     1366        self.panel = DataPanel(parent=self, 
    13601367                               manager=manager, 
    13611368                               list_of_perspective=list_of_perspective) 
    1362       
     1369 
    13631370    def load_data_list(self, list=[]): 
    13641371        """ 
     
    13661373        """ 
    13671374        self.panel.load_data_list(list=list) 
    1368          
    1369     
    1370      
     1375 
     1376 
     1377 
    13711378from sas.sasgui.guiframe.dataFitting import Theory1D 
    13721379from sas.sasgui.guiframe.data_state import DataState 
     
    13831390        self.msg += "name  value\n" 
    13841391        return self.msg 
    1385      
     1392 
    13861393def set_data_state(data=None, path=None, theory=None, state=None): 
    13871394    """ 
     
    13911398    dstate.set_path(path=path) 
    13921399    dstate.set_theory(theory, state) 
    1393    
     1400 
    13941401    return dstate 
    1395      
     1402 
    13961403if __name__ == "__main__": 
    1397      
     1404 
    13981405    app = wx.App() 
    13991406    try: 
     
    14771484        #raise 
    14781485        print "error", sys.exc_value 
    1479          
    1480     app.MainLoop()   
    1481      
    1482      
     1486 
     1487    app.MainLoop() 
Note: See TracChangeset for help on using the changeset viewer.