Ignore:
Timestamp:
Oct 27, 2010 4:41:30 PM (14 years ago)
Author:
Gervaise Alina <gervyh@…>
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:
6cda91f
Parents:
c4d6900
Message:

working with pylint

File:
1 edited

Legend:

Unmodified
Added
Removed
  • calculatorview/perspectives/calculator/data_editor.py

    rc5dca87 rb0ab6cb  
    66 
    77from DataLoader.loader import Loader 
    8 from DataLoader.data_info import DataInfo, Detector, Collimation, Data2D 
     8#from DataLoader.data_info import DataInfo 
     9#from DataLoader.data_info import  Detector 
     10#from DataLoader.data_info import Collimation 
     11from DataLoader.data_info import Data2D 
    912from detector_editor import DetectorDialog 
    1013from collimation_editor import CollimationDialog 
    1114from console import ConsoleDialog 
    1215 
    13 from sans.guiframe.utils import check_float 
     16#from sans.guiframe.utils import check_float 
    1417from sans.guicomm.events import StatusEvent 
    1518 
     
    1922_NPTS_DEFAULT = 50 
    2023#Control panel width  
    21 if sys.platform.count("darwin")==0: 
     24if sys.platform.count("darwin") == 0: 
    2225    PANEL_WIDTH = 500 
    2326    PANEL_HEIGTH = 350 
     
    4346     
    4447    if error is not None: 
    45         message += "When contacting the DANSE team, mention the following:\n%s" % str(error) 
    46      
    47     dial = wx.MessageDialog(None, message, 'Error Loading File', wx.OK | wx.ICON_EXCLAMATION) 
     48        message += "When contacting the DANSE team," 
     49        message += " mention the following:\n%s" % str(error) 
     50     
     51    dial = wx.MessageDialog(None, message,  
     52                            'Error Loading File', wx.OK | wx.ICON_EXCLAMATION) 
    4853    dial.ShowModal()  
    4954     
     
    5156class DataEditorPanel(wx.ScrolledWindow): 
    5257    """ 
    53         @param data: when not empty the class can same information into a dat object 
     58    :param data: when not empty the class can  
     59                same information into a dat object 
    5460        and post event containing the changed data object to some other frame 
    5561    """ 
    5662    def __init__(self, parent, data=[], *args, **kwds): 
    57          kwds['name'] = "Data Editor" 
    58          kwds["size"]= (PANEL_WIDTH, PANEL_HEIGTH) 
    59          wx.ScrolledWindow.__init__(self, parent, *args, **kwds) 
    60          self.parent = parent 
    61          self._data = data 
    62          self._reset_data = deepcopy(data) 
    63          self.reader = None 
    64          self._notes = "" 
    65          self_description = "Edit Data" 
    66          self._default_save_location = os.getcwd() 
    67          self._do_layout() 
    68          self.reset_panel() 
    69          self.bt_apply.Disable() 
    70          if data: 
    71              self.complete_loading(data=data) 
    72              self.bt_apply.Enable() 
     63        kwds['name'] = "Data Editor" 
     64        kwds["size"] = (PANEL_WIDTH, PANEL_HEIGTH) 
     65        wx.ScrolledWindow.__init__(self, parent, *args, **kwds) 
     66        self.parent = parent 
     67        self._data = data 
     68        self._reset_data = deepcopy(data) 
     69        self.reader = None 
     70        self._notes = "" 
     71        self._description = "Edit Data" 
     72        self._default_save_location = os.getcwd() 
     73        self._do_layout() 
     74        self.reset_panel() 
     75        self.bt_apply.Disable() 
     76        if data: 
     77            self.complete_loading(data=data) 
     78            self.bt_apply.Enable() 
    7379              
    7480    def _define_structure(self): 
    7581        """ 
    76             define initial sizer  
     82        define initial sizer  
    7783        """ 
    7884        self.main_sizer = wx.BoxSizer(wx.VERTICAL) 
     
    9197    def _layout_name(self): 
    9298        """ 
    93             Do the layout for data name related widgets 
     99        Do the layout for data name related widgets 
    94100        """ 
    95101        #data name [string] 
     
    110116    def _layout_title(self): 
    111117        """ 
    112             Do the layout for data title related widgets 
     118        Do the layout for data title related widgets 
    113119        """ 
    114120        #title name [string] 
     
    123129    def _layout_run(self): 
    124130        """ 
    125             Do the layout for data run related widgets 
     131        Do the layout for data run related widgets 
    126132        """ 
    127133        data_run_txt = wx.StaticText(self, -1, 'Run : ')  
    128134        data_run_txt.SetToolTipString('')  
    129         self.data_run_tcl = wx.TextCtrl(self, -1, size=(PANEL_WIDTH*3/5, -1), style=wx.TE_MULTILINE) 
     135        self.data_run_tcl = wx.TextCtrl(self, -1, size=(PANEL_WIDTH*3/5, -1), 
     136                                         style=wx.TE_MULTILINE) 
    130137        hint_run = "Data's run." 
    131138        self.data_run_tcl.SetToolTipString(hint_run) 
     
    135142    def _layout_instrument(self): 
    136143        """ 
    137             Do the layout for instrument related widgets 
     144        Do the layout for instrument related widgets 
    138145        """ 
    139146        instrument_txt = wx.StaticText(self, -1, 'Instrument : ')  
     
    148155    def _layout_editor(self): 
    149156        """ 
    150             Do the layout for sample related widgets 
     157        Do the layout for sample related widgets 
    151158        """ 
    152159        self.detector_rb = wx.RadioButton(self, -1, "Detector", 
     
    186193            Layout widgets related to data's summary 
    187194        """ 
    188         self.data_summary = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE|wx.HSCROLL, 
     195        self.data_summary = wx.TextCtrl(self, -1, 
     196                                         style=wx.TE_MULTILINE|wx.HSCROLL, 
    189197                                        size=(-1, 200)) 
    190198        summary = 'No data info available...' 
     
    196204            Do the layout for the button widgets 
    197205        """  
    198         self.bt_summary = wx.Button(self, -1, "View", size=(_BOX_WIDTH,-1)) 
     206        self.bt_summary = wx.Button(self, -1, "View", size=(_BOX_WIDTH, -1)) 
    199207        self.bt_summary.SetToolTipString("View final changes on data.") 
    200208        self.bt_summary.Bind(wx.EVT_BUTTON, self.on_click_view) 
    201209         
    202         self.bt_save = wx.Button(self, -1, "Save As", size=(_BOX_WIDTH,-1)) 
     210        self.bt_save = wx.Button(self, -1, "Save As", size=(_BOX_WIDTH, -1)) 
    203211        self.bt_save.SetToolTipString("Save changes in a file.") 
    204212        self.bt_save.Bind(wx.EVT_BUTTON, self.on_click_save) 
    205213         
    206         self.bt_apply = wx.Button(self, -1, "Apply", size=(_BOX_WIDTH,-1)) 
     214        self.bt_apply = wx.Button(self, -1, "Apply", size=(_BOX_WIDTH, -1)) 
    207215        self.bt_apply.SetToolTipString("Save changes into the imported data.") 
    208216        self.bt_apply.Bind(wx.EVT_BUTTON, self.on_click_apply) 
    209217       
    210         self.bt_reset = wx.Button(self, -1,'Reset', size=(_BOX_WIDTH,-1)) 
     218        self.bt_reset = wx.Button(self, -1, 'Reset', size=(_BOX_WIDTH, -1)) 
    211219        self.bt_reset.Bind(wx.EVT_BUTTON, self.on_click_reset) 
    212220        self.bt_reset.SetToolTipString("Reset data to its initial state.") 
    213221         
    214         self.bt_close = wx.Button(self, -1,'Close', size=(_BOX_WIDTH,-1)) 
     222        self.bt_close = wx.Button(self, -1, 'Close', size=(_BOX_WIDTH, -1)) 
    215223        self.bt_close.Bind(wx.EVT_BUTTON, self.on_close) 
    216224        self.bt_close.SetToolTipString("Close this panel.") 
     
    222230                                   (self.bt_close, 0, wx.RIGHT, 10)]) 
    223231         
    224     def _do_layout(self, data=None): 
    225         """ 
    226             Draw the current panel 
     232    def _do_layout(self): 
     233        """ 
     234        Draw the current panel 
    227235        """ 
    228236        self._define_structure() 
     
    244252                                          wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) 
    245253        self.SetSizer(self.main_sizer) 
    246         self.SetScrollbars(20,20,25,65) 
     254        self.SetScrollbars(20, 20, 25, 65) 
    247255        self.SetAutoLayout(True) 
    248256         
    249257    def fill_data_combox(self): 
    250258        """ 
    251             fill the current combobox with the available data 
     259        fill the current combobox with the available data 
    252260        """ 
    253261        if not self._data: 
     
    275283        """ 
    276284        """ 
    277         data, data_name, position = self.get_current_data() 
     285        data, _, _ = self.get_current_data() 
    278286        self.reset_panel() 
    279287        if data is None: 
     
    322330    def set_sample(self, sample, notes=None): 
    323331        """ 
    324             set sample for data 
    325         """ 
    326         data, data_name, position = self.get_current_data() 
     332        set sample for data 
     333        """ 
     334        data, _, _ = self.get_current_data() 
    327335        if data is None: 
    328336            return  
     
    333341    def set_source(self, source, notes=None): 
    334342        """ 
    335             set source for data 
     343        set source for data 
    336344        """ 
    337345        data, data_name, position = self.get_current_data() 
     
    344352    def set_detector(self, detector, notes=None): 
    345353        """ 
    346             set detector for data 
     354        set detector for data 
    347355        """ 
    348356        data, data_name, position = self.get_current_data() 
     
    355363    def set_collimation(self, collimation, notes=None): 
    356364        """ 
    357             set collimation for data 
     365        set collimation for data 
    358366        """ 
    359367        data, data_name, position = self.get_current_data() 
     
    366374    def edit_collimation(self): 
    367375        """ 
    368             Edit the selected collimation 
     376        Edit the selected collimation 
    369377        """ 
    370378        data, data_name, position = self.get_current_data() 
     
    377385    def edit_detector(self): 
    378386        """ 
    379             Edit the selected detector 
     387        Edit the selected detector 
    380388        """ 
    381389        data, data_name, position = self.get_current_data() 
     
    388396    def edit_sample(self): 
    389397        """ 
    390             Open the dialog to edit the sample of the current data 
    391         """ 
    392         data, data_name, position = self.get_current_data() 
     398        Open the dialog to edit the sample of the current data 
     399        """ 
     400        data, _, _ = self.get_current_data() 
    393401        if data is None: 
    394402            return 
     
    400408    def edit_source(self): 
    401409        """ 
    402             Open the dialog to edit the saource of the current data 
     410        Open the dialog to edit the saource of the current data 
    403411        """ 
    404412        data, data_name, position = self.get_current_data() 
     
    412420    def choose_data_file(self, location=None): 
    413421        """ 
    414             Open a file dialog to allow loading a file 
     422        Open a file dialog to allow loading a file 
    415423        """ 
    416424        path = None 
     
    432440    def complete_loading(self, data=None, filename=''): 
    433441        """ 
    434             Complete the loading and compute the slit size 
     442        Complete the loading and compute the slit size 
    435443        """ 
    436444        self.done = True 
     
    438446        if data is None: 
    439447            msg = "Couldn't load data" 
    440             wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="warning",type='stop')) 
     448            wx.PostEvent(self.parent.parent, StatusEvent(status=msg, 
     449                                             info="warning",type='stop')) 
    441450            return  
    442451        if not  data.__class__.__name__ == "list": 
     
    450459            return  
    451460        msg = "Load Complete" 
    452         wx.PostEvent(self.parent.parent, StatusEvent(status=msg,info="info",type='stop')) 
     461        wx.PostEvent(self.parent.parent, StatusEvent(status=msg, 
     462                                                info="info",type='stop')) 
    453463   
    454464    def set_values(self): 
    455465        """ 
    456             take the aperture values of the current data and display them 
    457             through the panel 
     466        take the aperture values of the current data and display them 
     467        through the panel 
    458468        """ 
    459469        if self._data: 
     
    463473    def get_data(self): 
    464474        """ 
    465             return the current data 
     475        return the current data 
    466476        """ 
    467477        return self._data 
     
    469479    def get_notes(self): 
    470480        """ 
    471             return notes 
     481        return notes 
    472482        """ 
    473483        return self._notes 
     
    475485    def on_change_run(self, event=None): 
    476486        """ 
    477             Change run 
     487        Change run 
    478488        """ 
    479489        run = [] 
    480         data, data_name, position = self.get_current_data() 
     490        data, _, _ = self.get_current_data() 
    481491        for i in range(self.data_run_tcl.GetNumberOfLines()): 
    482492            text = self.data_run_tcl.GetLineText(i).lstrip().rstrip() 
     
    485495        if data.run != run: 
    486496            self._notes += "Change data 's " 
    487             self._notes += "run from %s to %s \n"%(data.run, str(run)) 
     497            self._notes += "run from %s to %s \n" % (data.run, str(run)) 
    488498            data.run = run 
    489              
     499        if event is not None: 
     500            event.Skip() 
     501                  
    490502    def on_change_title(self, event=None): 
    491503        """ 
    492             Change title 
    493         """ 
    494         data, data_name, position = self.get_current_data() 
     504        Change title 
     505        """ 
     506        data, _, _ = self.get_current_data() 
    495507        #Change data's name 
    496508        title = self.data_title_tcl.GetValue().lstrip().rstrip() 
     
    498510        if data.title != title: 
    499511            self._notes += "Change data 's " 
    500             self._notes += "title from %s to %s \n"%(data.title, str(title)) 
     512            self._notes += "title from %s to %s \n" % (data.title, str(title)) 
    501513            data.title = title 
    502             
     514        if event is not None: 
     515            event.Skip() 
     516             
    503517    def on_click_browse(self, event): 
    504518        """ 
    505             Open a file dialog to allow the user to select a given file. 
    506             Display the loaded data if available. 
     519        Open a file dialog to allow the user to select a given file. 
     520        Display the loaded data if available. 
    507521        """ 
    508522        path = self.choose_data_file(location=self._default_save_location) 
     
    510524            return  
    511525        if self.parent.parent is not None: 
    512             wx.PostEvent(self.parent.parent, StatusEvent(status="Loading...",info="info", 
    513                                 type="progress")) 
     526            wx.PostEvent(self.parent.parent, StatusEvent(status="Loading...", 
     527                                        info="info", type="progress")) 
    514528         
    515529        self.done = False 
     
    526540            self.reader.queue() 
    527541        except: 
    528             msg = "Data Editor: %s"%(sys.exc_value) 
     542            msg = "Data Editor: %s" % (sys.exc_value) 
    529543            load_error(msg) 
    530544            return  
     545        event.Skip() 
    531546          
    532547    def on_edit(self, event): 
     
    541556        if self.collimation_rb.GetValue(): 
    542557            self.edit_collimation() 
     558        event.Skip() 
    543559             
    544560    def on_click_apply(self, event): 
    545561        """    
    546             changes are saved in data object imported to edit 
    547         """ 
    548         data, data_name, position = self.get_current_data() 
     562        changes are saved in data object imported to edit 
     563        """ 
     564        data, _, _ = self.get_current_data() 
    549565        if data is None: 
    550566            return 
     
    552568        self.on_change_title(event=None) 
    553569        #must post event here 
     570        event.Skip() 
    554571         
    555572    def on_click_save(self, event): 
    556573        """ 
    557             Save change into a file 
     574        Save change into a file 
    558575        """ 
    559576        if not self._data: 
     
    579596                    loader = Loader()  
    580597                    format = ".xml" 
    581                     if os.path.splitext(mypath)[1].lower() ==format: 
     598                    if os.path.splitext(mypath)[1].lower() == format: 
    582599                        loader.save( path, data, format) 
    583600                    try: 
     
    586603                        pass     
    587604                    dlg.Destroy() 
     605        event.Skip() 
    588606         
    589607    def on_click_view(self, event): 
    590608        """ 
    591             Display data info  
     609        Display data info  
    592610        """ 
    593611        data, data_name, position = self.get_current_data() 
     
    598616        dlg = ConsoleDialog(data=data) 
    599617        dlg.ShowModal() 
     618        event.Skip() 
    600619     
    601620    def on_click_reset(self, event): 
     
    605624        if data is None: 
    606625            return 
    607         self._data[position]= deepcopy(self._reset_data[position]) 
     626        self._data[position] = deepcopy(self._reset_data[position]) 
    608627        self.set_values() 
     628        event.Skip() 
    609629         
    610630    def on_close(self, event): 
    611631        """ 
    612             leave data as it is and close 
     632        leave data as it is and close 
    613633        """ 
    614634        self.parent.Close() 
     635        event.Skip() 
    615636         
    616637class DataEditorWindow(wx.Frame): 
    617638    def __init__(self, parent, data=None, *args, **kwds): 
    618         kwds["size"]= (PANEL_WIDTH, PANEL_HEIGTH) 
     639        kwds["size"] = (PANEL_WIDTH, PANEL_HEIGTH) 
    619640        wx.Frame.__init__(self, parent, *args, **kwds) 
    620641        self.parent = parent 
     
    628649        return self.panel.get_data() 
    629650     
    630 if __name__ =="__main__": 
     651if __name__ == "__main__": 
    631652    
    632653    app  = wx.App() 
Note: See TracChangeset for help on using the changeset viewer.