Ignore:
Timestamp:
Mar 4, 2015 3:28:39 PM (9 years ago)
Author:
Doucet, Mathieu <doucetm@…>
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:
2f732b0
Parents:
76aed53
Message:

Take care of white spaces (pylint)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/perspectives/calculator/model_editor.py

    r79492222 r49ab5d7  
    2828_BOX_WIDTH = 55 
    2929 
    30      
     30 
    3131def _compileFile(path): 
    3232    """ 
     
    4040        _, value, _ = sys.exc_info() 
    4141        return value 
    42      
     42 
    4343def _deleteFile(path): 
    4444    """ 
     
    5050        raise 
    5151 
    52   
     52 
    5353class TextDialog(wx.Dialog): 
    5454    """ 
    55     Dialog for easy custom sum models   
     55    Dialog for easy custom sum models 
    5656    """ 
    57     def __init__(self, parent=None, base=None, id=None, title='',  
     57    def __init__(self, parent=None, base=None, id=None, title='', 
    5858                 model_list=[], plugin_dir=None): 
    5959        """ 
    60         Dialog window popup when selecting 'Easy Custom Sum/Multiply'  
     60        Dialog window popup when selecting 'Easy Custom Sum/Multiply' 
    6161        on the menu 
    6262        """ 
    63         wx.Dialog.__init__(self, parent=parent, id=id,  
     63        wx.Dialog.__init__(self, parent=parent, id=id, 
    6464                           title=title, size=(PNL_WIDTH, PNL_HITE)) 
    6565        self.parent = base 
     
    102102        self.good_name = True 
    103103        self.fill_oprator_combox() 
    104          
     104 
    105105    def _layout_name(self): 
    106106        """ 
     
    110110        self.name_hsizer = wx.BoxSizer(wx.HORIZONTAL) 
    111111        #title name [string] 
    112         name_txt = wx.StaticText(self, -1, 'Function Name : ')   
    113         self.name_tcl = wx.TextCtrl(self, -1, size=(PANEL_WIDTH*3/5, -1))  
     112        name_txt = wx.StaticText(self, -1, 'Function Name : ') 
     113        self.name_tcl = wx.TextCtrl(self, -1, size=(PANEL_WIDTH * 3 / 5, -1)) 
    114114        self.name_tcl.Bind(wx.EVT_TEXT_ENTER, self.on_change_name) 
    115115        self.name_tcl.SetValue('') 
     
    117117        hint_name = "Unique Sum/Multiply Model Function Name." 
    118118        self.name_tcl.SetToolTipString(hint_name) 
    119         self.name_hsizer.AddMany([(name_txt, 0, wx.LEFT|wx.TOP, 10), 
    120                             (self.name_tcl, -1,  
    121                              wx.EXPAND|wx.RIGHT|wx.TOP|wx.BOTTOM, 10)]) 
    122         self.name_sizer.AddMany([(self.name_hsizer, -1,  
    123                                         wx.LEFT|wx.TOP, 10)]) 
    124          
    125          
     119        self.name_hsizer.AddMany([(name_txt, 0, wx.LEFT | wx.TOP, 10), 
     120                            (self.name_tcl, -1, 
     121                             wx.EXPAND | wx.RIGHT | wx.TOP | wx.BOTTOM, 10)]) 
     122        self.name_sizer.AddMany([(self.name_hsizer, -1, 
     123                                        wx.LEFT | wx.TOP, 10)]) 
     124 
     125 
    126126    def _layout_description(self): 
    127127        """ 
     
    130130        self.desc_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    131131        #title name [string] 
    132         desc_txt = wx.StaticText(self, -1, 'Description (optional) : ')   
    133         self.desc_tcl = wx.TextCtrl(self, -1, size=(PANEL_WIDTH*3/5, -1))  
     132        desc_txt = wx.StaticText(self, -1, 'Description (optional) : ') 
     133        self.desc_tcl = wx.TextCtrl(self, -1, size=(PANEL_WIDTH * 3 / 5, -1)) 
    134134        self.desc_tcl.SetValue('') 
    135135        #self.name_tcl.SetFont(self.font) 
    136136        hint_desc = "Write a short description of this model function." 
    137137        self.desc_tcl.SetToolTipString(hint_desc) 
    138         self.desc_sizer.AddMany([(desc_txt, 0, wx.LEFT|wx.TOP, 10), 
    139                                 (self.desc_tcl, -1,  
    140                                 wx.EXPAND|wx.RIGHT|wx.TOP|wx.BOTTOM, 10)])      
    141    
     138        self.desc_sizer.AddMany([(desc_txt, 0, wx.LEFT | wx.TOP, 10), 
     139                                (self.desc_tcl, -1, 
     140                                wx.EXPAND | wx.RIGHT | wx.TOP | wx.BOTTOM, 10)]) 
     141 
    142142    def _build_sizer(self): 
    143143        """ 
     
    145145        """ 
    146146        box_width = 195 # combobox width 
    147         vbox  = wx.BoxSizer(wx.VERTICAL) 
     147        vbox = wx.BoxSizer(wx.VERTICAL) 
    148148        self.sizer = wx.GridBagSizer(1, 3) 
    149149        self._layout_name() 
    150150        self._layout_description() 
    151          
    152          
    153         sum_description = wx.StaticBox(self, -1, 'Select',  
    154                                        size=(PNL_WIDTH-30, 70)) 
     151 
     152 
     153        sum_description = wx.StaticBox(self, -1, 'Select', 
     154                                       size=(PNL_WIDTH - 30, 70)) 
    155155        sum_box = wx.StaticBoxSizer(sum_description, wx.VERTICAL) 
    156156        model1_box = wx.BoxSizer(wx.HORIZONTAL) 
    157157        model2_box = wx.BoxSizer(wx.HORIZONTAL) 
    158158        model_vbox = wx.BoxSizer(wx.VERTICAL) 
    159         self.model1 =  wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     159        self.model1 = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    160160        wx.EVT_COMBOBOX(self.model1, -1, self.on_model1) 
    161         self.model1.SetMinSize((box_width*5/6, -1)) 
     161        self.model1.SetMinSize((box_width * 5 / 6, -1)) 
    162162        self.model1.SetToolTipString("model1") 
    163          
    164         self.operator_cbox = wx.ComboBox(self, -1, size=(50, -1),  
     163 
     164        self.operator_cbox = wx.ComboBox(self, -1, size=(50, -1), 
    165165                                         style=wx.CB_READONLY) 
    166166        wx.EVT_COMBOBOX(self.operator_cbox, -1, self.on_select_operator) 
    167167        operation_tip = "Add: +, Multiply: * " 
    168168        self.operator_cbox.SetToolTipString(operation_tip) 
    169          
    170         self.model2 =  wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     169 
     170        self.model2 = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    171171        wx.EVT_COMBOBOX(self.model2, -1, self.on_model2) 
    172         self.model2.SetMinSize((box_width*5/6, -1)) 
     172        self.model2.SetMinSize((box_width * 5 / 6, -1)) 
    173173        self.model2.SetToolTipString("model2") 
    174174        self._set_model_list() 
    175          
     175 
    176176         # Buttons on the bottom 
    177177        self.static_line_1 = wx.StaticLine(self, -1) 
    178         self.okButton = wx.Button(self,wx.ID_OK, 'Apply', size=(box_width/2, 25)) 
     178        self.okButton = wx.Button(self, wx.ID_OK, 'Apply', size=(box_width / 2, 25)) 
    179179        self.okButton.Bind(wx.EVT_BUTTON, self.check_name) 
    180         self.closeButton = wx.Button(self,wx.ID_CANCEL, 'Close',  
    181                                      size=(box_width/2, 25)) 
     180        self.closeButton = wx.Button(self, wx.ID_CANCEL, 'Close', 
     181                                     size=(box_width / 2, 25)) 
    182182        # Intro 
    183         self.explanation  = "  custom model = %s %s "% (self.factor, '*') 
    184         self.explanation  += "(model1 %s model2)\n"% self.operator 
     183        self.explanation = "  custom model = %s %s " % (self.factor, '*') 
     184        self.explanation += "(model1 %s model2)\n" % self.operator 
    185185        #explanation  += "  Note: This will overwrite the previous sum model.\n" 
    186186        model_string = " Model%s (p%s):" 
     
    196196        self.explanationctr = wx.StaticText(self, -1, self.explanation) 
    197197        self.sizer.Add(self.explanationctr , (iy, ix), 
    198                  (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    199         model1_box.Add(wx.StaticText(self, -1, model_string% (1, 1)), -1, 0) 
    200         model1_box.Add((box_width-15, 10)) 
    201         model1_box.Add(wx.StaticText(self, -1, model_string% (2, 2)), -1, 0) 
     198                 (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     199        model1_box.Add(wx.StaticText(self, -1, model_string % (1, 1)), -1, 0) 
     200        model1_box.Add((box_width - 15, 10)) 
     201        model1_box.Add(wx.StaticText(self, -1, model_string % (2, 2)), -1, 0) 
    202202        model2_box.Add(self.model1, -1, 0) 
    203203        model2_box.Add((15, 10)) 
     
    211211        ix = 0 
    212212        self.sizer.Add(sum_box, (iy, ix), 
    213                   (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     213                  (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    214214        vbox.Add((10, 10)) 
    215215        vbox.Add(self.static_line_1, 0, wx.EXPAND, 10) 
    216         vbox.Add(self.msg_sizer, 0,  
    217                  wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE|wx.BOTTOM, 10) 
     216        vbox.Add(self.msg_sizer, 0, 
     217                 wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE | wx.BOTTOM, 10) 
    218218        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    219         sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    220         sizer_button.Add(self.okButton, 0,  
    221                          wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 0) 
     219        sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     220        sizer_button.Add(self.okButton, 0, 
     221                         wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 0) 
    222222        sizer_button.Add(self.closeButton, 0, 
    223                           wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)         
    224         vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 
    225           
     223                          wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 
     224        vbox.Add(sizer_button, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 10) 
     225 
    226226        self.SetSizer(vbox) 
    227227        self.Centre() 
    228          
     228 
    229229    def on_change_name(self, event=None): 
    230230        """ 
     
    235235        self.name_tcl.SetBackgroundColour('white') 
    236236        self.Refresh() 
    237      
     237 
    238238    def check_name(self, event=None): 
    239239        """ 
     
    264264                info = 'Error' 
    265265                msg = "Name exists already." 
    266                 wx.MessageBox(msg, info)   
     266                wx.MessageBox(msg, info) 
    267267                self._notes = msg 
    268268                color = 'red' 
     
    278278        self.on_apply(self.fname) 
    279279        return self.good_name 
    280      
     280 
    281281    def on_apply(self, path): 
    282282        """ 
     
    295295            color = 'blue' 
    296296        except: 
    297             msg= "Easy Custom Sum/Multipy: Error occurred..." 
     297            msg = "Easy Custom Sum/Multipy: Error occurred..." 
    298298            info = 'Error' 
    299299            color = 'red' 
     
    301301        self._msg_box.SetForegroundColour(color) 
    302302        if self.parent.parent != None: 
    303             from sas.guiframe.events import StatusEvent  
    304             wx.PostEvent(self.parent.parent, StatusEvent(status = msg,  
     303            from sas.guiframe.events import StatusEvent 
     304            wx.PostEvent(self.parent.parent, StatusEvent(status=msg, 
    305305                                                      info=info)) 
    306306        else: 
    307307            raise 
    308                    
     308 
    309309    def _set_model_list(self): 
    310310        """ 
     
    328328            list.sort() 
    329329        for idx in range(len(list)): 
    330             self.model1.Append(str(list[idx]), idx)  
     330            self.model1.Append(str(list[idx]), idx) 
    331331            self.model2.Append(str(list[idx]), idx) 
    332332        self.model1.SetStringSelection(self.model1_string) 
    333333        self.model2.SetStringSelection(self.model2_string) 
    334      
     334 
    335335    def update_cm_list(self): 
    336336        """ 
     
    344344                name = str(c_name.split('.')[0]) 
    345345                cm_list.append(name) 
    346         self.cm_list = cm_list  
    347                
     346        self.cm_list = cm_list 
     347 
    348348    def on_model1(self, event): 
    349349        """ 
     
    358358        else: 
    359359            self.is_p1_custom = False 
    360              
     360 
    361361    def on_model2(self, event): 
    362362        """ 
     
    371371        else: 
    372372            self.is_p2_custom = False 
    373          
     373 
    374374    def on_select_operator(self, event=None): 
    375375        """ 
     
    379379        if event != None: 
    380380            event.Skip() 
    381         name = ''     
     381        name = '' 
    382382        item = event.GetEventObject() 
    383383        text = item.GetValue() 
     
    393393        self.factor = factor 
    394394        self.operator = text 
    395         self.explanation = "  Custom Model = %s %s (model1 %s model2)\n"% \ 
     395        self.explanation = "  Custom Model = %s %s (model1 %s model2)\n" % \ 
    396396                    (self.factor, f_oper, self.operator) 
    397397        self.explanationctr.SetLabel(self.explanation) 
    398         self.name = name + M_NAME  
     398        self.name = name + M_NAME 
    399399        self.sizer.Layout() 
    400               
     400 
    401401    def fill_oprator_combox(self): 
    402402        """ 
    403403        fill the current combobox with the operator 
    404         """    
     404        """ 
    405405        operator_list = [' +', ' *'] 
    406406        for oper in operator_list: 
     
    408408            self.operator_cbox.SetClientData(pos, str(oper.strip())) 
    409409        self.operator_cbox.SetSelection(0) 
    410              
     410 
    411411    def getText(self): 
    412412        """ 
     
    414414        """ 
    415415        return [self.model1_name, self.model2_name] 
    416      
     416 
    417417    def write_string(self, fname, name1, name2): 
    418418        """ 
    419419        Write and Save file 
    420420        """ 
    421         self.fname = fname   
     421        self.fname = fname 
    422422        description = self.desc_tcl.GetValue().lstrip().rstrip() 
    423423        if description == '': 
     
    435435        path = self.fname 
    436436        try: 
    437             out_f =  open(path,'w') 
     437            out_f = open(path, 'w') 
    438438        except : 
    439439            raise 
     
    488488        #else: 
    489489        #    msg = "Name exists already." 
    490          
     490 
    491491    def compile_file(self, path): 
    492492        """ 
     
    495495        path = self.fname 
    496496        _compileFile(path) 
    497          
     497 
    498498    def delete_file(self, path): 
    499499        """ 
     
    535535        #self.bt_apply.Disable() 
    536536 
    537               
     537 
    538538    def _define_structure(self): 
    539539        """ 
    540         define initial sizer  
     540        define initial sizer 
    541541        """ 
    542542        #w, h = self.parent.GetSize() 
     
    550550        self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    551551        self.msg_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    552          
     552 
    553553    def _layout_name(self): 
    554554        """ 
     
    556556        """ 
    557557        #title name [string] 
    558         name_txt = wx.StaticText(self, -1, 'Function Name : ')   
     558        name_txt = wx.StaticText(self, -1, 'Function Name : ') 
    559559        overwrite_cb = wx.CheckBox(self, -1, "Overwrite?", (10, 10)) 
    560560        overwrite_cb.SetValue(False) 
     
    562562        wx.EVT_CHECKBOX(self, overwrite_cb.GetId(), self.on_over_cb) 
    563563        #overwrite_cb.Show(False) 
    564         self.name_tcl = wx.TextCtrl(self, -1, size=(PANEL_WIDTH*3/5, -1))  
     564        self.name_tcl = wx.TextCtrl(self, -1, size=(PANEL_WIDTH * 3 / 5, -1)) 
    565565        self.name_tcl.Bind(wx.EVT_TEXT_ENTER, self.on_change_name) 
    566566        self.name_tcl.SetValue('MyFunction') 
     
    568568        hint_name = "Unique Model Function Name." 
    569569        self.name_tcl.SetToolTipString(hint_name) 
    570         self.name_hsizer.AddMany([(self.name_tcl, 0, wx.LEFT|wx.TOP, 0), 
     570        self.name_hsizer.AddMany([(self.name_tcl, 0, wx.LEFT | wx.TOP, 0), 
    571571                                       (overwrite_cb, 0, wx.LEFT, 20)]) 
    572         self.name_sizer.AddMany([(name_txt, 0, wx.LEFT|wx.TOP, 10), 
    573                                        (self.name_hsizer, 0,  
    574                                         wx.LEFT|wx.TOP|wx.BOTTOM, 10)]) 
    575          
    576          
     572        self.name_sizer.AddMany([(name_txt, 0, wx.LEFT | wx.TOP, 10), 
     573                                       (self.name_hsizer, 0, 
     574                                        wx.LEFT | wx.TOP | wx.BOTTOM, 10)]) 
     575 
     576 
    577577    def _layout_description(self): 
    578578        """ 
     
    580580        """ 
    581581        #title name [string] 
    582         desc_txt = wx.StaticText(self, -1, 'Description (optional) : ')   
    583         self.desc_tcl = wx.TextCtrl(self, -1, size=(PANEL_WIDTH*3/5, -1))  
     582        desc_txt = wx.StaticText(self, -1, 'Description (optional) : ') 
     583        self.desc_tcl = wx.TextCtrl(self, -1, size=(PANEL_WIDTH * 3 / 5, -1)) 
    584584        self.desc_tcl.SetValue('') 
    585585        #self.name_tcl.SetFont(self.font) 
    586586        hint_desc = "Write a short description of the model function." 
    587587        self.desc_tcl.SetToolTipString(hint_desc) 
    588         self.desc_sizer.AddMany([(desc_txt, 0, wx.LEFT|wx.TOP, 10), 
    589                                        (self.desc_tcl, 0,  
    590                                         wx.LEFT|wx.TOP|wx.BOTTOM, 10)])      
     588        self.desc_sizer.AddMany([(desc_txt, 0, wx.LEFT | wx.TOP, 10), 
     589                                       (self.desc_tcl, 0, 
     590                                        wx.LEFT | wx.TOP | wx.BOTTOM, 10)]) 
    591591    def _layout_param(self): 
    592592        """ 
    593593        Do the layout for parameter related widgets 
    594594        """ 
    595         param_txt = wx.StaticText(self, -1, 'Fit Parameters (if any): ')  
    596          
     595        param_txt = wx.StaticText(self, -1, 'Fit Parameters (if any): ') 
     596 
    597597        param_tip = "#Set the parameters and initial values.\n" 
    598598        param_tip += "#Example:\n" 
    599599        param_tip += "A = 1\nB = 1" 
    600600        #param_txt.SetToolTipString(param_tip) 
    601         id  = wx.NewId()  
    602         self.param_tcl = EditWindow(self, id, wx.DefaultPosition,  
    603                             wx.DefaultSize, wx.CLIP_CHILDREN|wx.SUNKEN_BORDER) 
     601        id = wx.NewId() 
     602        self.param_tcl = EditWindow(self, id, wx.DefaultPosition, 
     603                            wx.DefaultSize, wx.CLIP_CHILDREN | wx.SUNKEN_BORDER) 
    604604        self.param_tcl.setDisplayLineNumbers(True) 
    605605        self.param_tcl.SetToolTipString(param_tip) 
    606606 
    607607        self.param_sizer.AddMany([(param_txt, 0, wx.LEFT, 10), 
    608                         (self.param_tcl, 1, wx.EXPAND|wx.ALL, 10)]) 
    609                  
     608                        (self.param_tcl, 1, wx.EXPAND | wx.ALL, 10)]) 
     609 
    610610    def _layout_function(self): 
    611611        """ 
    612612        Do the layout for function related widgets 
    613613        """ 
    614         function_txt = wx.StaticText(self, -1, 'Function(x) : ')  
     614        function_txt = wx.StaticText(self, -1, 'Function(x) : ') 
    615615        hint_function = "#Example:\n" 
    616616        hint_function += "if x <= 0:\n" 
     
    621621        math_txt = wx.StaticText(self, -1, '*Useful math functions: ') 
    622622        math_combo = self._fill_math_combo() 
    623          
    624         id  = wx.NewId()  
    625         self.function_tcl = EditWindow(self, id, wx.DefaultPosition,  
    626                             wx.DefaultSize, wx.CLIP_CHILDREN|wx.SUNKEN_BORDER) 
     623 
     624        id = wx.NewId() 
     625        self.function_tcl = EditWindow(self, id, wx.DefaultPosition, 
     626                            wx.DefaultSize, wx.CLIP_CHILDREN | wx.SUNKEN_BORDER) 
    627627        self.function_tcl.setDisplayLineNumbers(True) 
    628628        self.function_tcl.SetToolTipString(hint_function) 
    629          
     629 
    630630        self.func_horizon_sizer.Add(function_txt) 
    631631        self.func_horizon_sizer.Add(math_txt, 0, wx.LEFT, 250) 
     
    633633 
    634634        self.function_sizer.Add(self.func_horizon_sizer, 0, wx.LEFT, 10) 
    635         self.function_sizer.Add( self.function_tcl, 1, wx.EXPAND|wx.ALL, 10) 
    636          
     635        self.function_sizer.Add(self.function_tcl, 1, wx.EXPAND | wx.ALL, 10) 
     636 
    637637    def _layout_msg(self): 
    638638        """ 
    639639        Layout msg 
    640640        """ 
    641         self._msg_box = wx.StaticText(self, -1, self._notes,  
     641        self._msg_box = wx.StaticText(self, -1, self._notes, 
    642642                                      size=(PANEL_WIDTH, -1)) 
    643         self.msg_sizer.Add(self._msg_box, 0, wx.LEFT, 10)   
    644                      
    645     def _layout_button(self):   
     643        self.msg_sizer.Add(self._msg_box, 0, wx.LEFT, 10) 
     644 
     645    def _layout_button(self): 
    646646        """ 
    647647        Do the layout for the button widgets 
    648         """          
     648        """ 
    649649        self.bt_apply = wx.Button(self, -1, "Apply", size=(_BOX_WIDTH, -1)) 
    650650        self.bt_apply.SetToolTipString("Save changes into the imported data.") 
    651651        self.bt_apply.Bind(wx.EVT_BUTTON, self.on_click_apply) 
    652          
     652 
    653653        self.bt_close = wx.Button(self, -1, 'Close', size=(_BOX_WIDTH, -1)) 
    654654        self.bt_close.Bind(wx.EVT_BUTTON, self.on_close) 
    655655        self.bt_close.SetToolTipString("Close this panel.") 
    656          
    657         self.button_sizer.AddMany([(self.bt_apply, 0,  
     656 
     657        self.button_sizer.AddMany([(self.bt_apply, 0, 
    658658                                    wx.LEFT, EDITOR_WIDTH * 0.8), 
    659                                    (self.bt_close, 0,  
    660                                     wx.LEFT|wx.BOTTOM, 15)]) 
    661            
     659                                   (self.bt_close, 0, 
     660                                    wx.LEFT | wx.BOTTOM, 15)]) 
     661 
    662662    def _do_layout(self): 
    663663        """ 
     
    671671        self._layout_msg() 
    672672        self._layout_button() 
    673         self.main_sizer.AddMany([(self.name_sizer, 0,   
    674                                         wx.EXPAND|wx.ALL, 5), 
    675                                  (wx.StaticLine(self), 0,  
    676                                        wx.ALL|wx.EXPAND, 5), 
    677                                  (self.desc_sizer, 0,   
    678                                         wx.EXPAND|wx.ALL, 5), 
    679                                  (wx.StaticLine(self), 0,  
    680                                        wx.ALL|wx.EXPAND, 5), 
     673        self.main_sizer.AddMany([(self.name_sizer, 0, 
     674                                        wx.EXPAND | wx.ALL, 5), 
     675                                 (wx.StaticLine(self), 0, 
     676                                       wx.ALL | wx.EXPAND, 5), 
     677                                 (self.desc_sizer, 0, 
     678                                        wx.EXPAND | wx.ALL, 5), 
     679                                 (wx.StaticLine(self), 0, 
     680                                       wx.ALL | wx.EXPAND, 5), 
    681681                                (self.param_sizer, 1, 
    682                                          wx.EXPAND|wx.ALL, 5), 
    683                                  (wx.StaticLine(self), 0,  
    684                                        wx.ALL|wx.EXPAND, 5), 
     682                                         wx.EXPAND | wx.ALL, 5), 
     683                                 (wx.StaticLine(self), 0, 
     684                                       wx.ALL | wx.EXPAND, 5), 
    685685                                (self.function_sizer, 2, 
    686                                          wx.EXPAND|wx.ALL, 5), 
    687                                  (wx.StaticLine(self), 0,  
    688                                        wx.ALL|wx.EXPAND, 5), 
    689                                  (self.msg_sizer, 0,  
    690                                         wx.EXPAND|wx.ALL, 5), 
     686                                         wx.EXPAND | wx.ALL, 5), 
     687                                 (wx.StaticLine(self), 0, 
     688                                       wx.ALL | wx.EXPAND, 5), 
     689                                 (self.msg_sizer, 0, 
     690                                        wx.EXPAND | wx.ALL, 5), 
    691691                                (self.button_sizer, 0, 
    692                                          wx.EXPAND|wx.ALL, 5)]) 
     692                                         wx.EXPAND | wx.ALL, 5)]) 
    693693        self.SetSizer(self.main_sizer) 
    694694        self.SetAutoLayout(True) 
     
    698698        Fill up the math combo box 
    699699        """ 
    700         self.math_combo = wx.ComboBox(self, -1, size=(100, -1),  
    701                                       style=wx.CB_READONLY)  
     700        self.math_combo = wx.ComboBox(self, -1, size=(100, -1), 
     701                                      style=wx.CB_READONLY) 
    702702        for item in dir(math): 
    703703            if item.count("_") < 1: 
    704704                try: 
    705                     exec "float(math.%s)"% item 
     705                    exec "float(math.%s)" % item 
    706706                    self.math_combo.Append(str(item)) 
    707707                except: 
    708                     self.math_combo.Append(str(item) + "()" ) 
     708                    self.math_combo.Append(str(item) + "()") 
    709709        self.math_combo.Bind(wx.EVT_COMBOBOX, self._on_math_select) 
    710710        self.math_combo.SetSelection(0) 
    711711        return self.math_combo 
    712          
     712 
    713713    def _on_math_select(self, event): 
    714714        """ 
     
    716716        """ 
    717717        event.Skip() 
    718         label = self.math_combo.GetLabel()  
     718        label = self.math_combo.GetLabel() 
    719719        self.function_tcl.SetFocus() 
    720720        # Put the text at the cursor position 
    721721        pos = self.function_tcl.GetCurrentPos() 
    722         self.function_tcl.InsertText(pos, label)   
     722        self.function_tcl.InsertText(pos, label) 
    723723        # Put the cursor at appropriate postion 
    724724        length = len(label) 
     
    726726            length -= 1 
    727727        f_pos = pos + length 
    728         self.function_tcl.GotoPos(f_pos)    
     728        self.function_tcl.GotoPos(f_pos) 
    729729 
    730730    def get_notes(self): 
     
    733733        """ 
    734734        return self._notes 
    735                   
     735 
    736736    def on_change_name(self, event=None): 
    737737        """ 
     
    742742        self.name_tcl.SetBackgroundColour('white') 
    743743        self.Refresh() 
    744      
     744 
    745745    def check_name(self): 
    746746        """ 
     
    766766        self._notes += "to %s. \n" % str(s_title) 
    767767        return True 
    768      
     768 
    769769    def on_over_cb(self, event): 
    770770        """ 
     
    775775        cb = event.GetEventObject() 
    776776        self.overwrite_name = cb.GetValue() 
    777          
     777 
    778778    def on_click_apply(self, event): 
    779         """    
     779        """ 
    780780        Changes are saved in data object imported to edit 
    781781        """ 
     
    791791            func_str = self.function_tcl.GetText() 
    792792            # No input for the model function 
    793             if func_str.lstrip().rstrip():      
     793            if func_str.lstrip().rstrip(): 
    794794                if func_str.count('return') > 0: 
    795                     self.write_file(self.fname, description, param_str,  
     795                    self.write_file(self.fname, description, param_str, 
    796796                                                                    func_str) 
    797797                    tr_msg = _compileFile(self.fname) 
     
    800800                    if msg: 
    801801                        msg.replace("  ", "\n") 
    802                         msg +=  "\nCompiling Failed" 
     802                        msg += "\nCompiling Failed" 
    803803                else: 
    804804                    msg = "Error: The func(x) must 'return' a value at least.\n" 
     
    811811        if self.base != None and not msg: 
    812812            self.base.update_custom_combo() 
    813             Model  = None 
    814             exec "from %s import Model"% name  
     813            Model = None 
     814            exec "from %s import Model" % name 
    815815            try: 
    816                 Model().run(0.01)  
     816                Model().run(0.01) 
    817817            except: 
    818818                msg = "Error " 
    819819                _, value, _ = sys.exc_info() 
    820                 msg += "in %s:\n%s\n" % (name,  value) 
     820                msg += "in %s:\n%s\n" % (name, value) 
    821821        if msg: 
    822822            info = 'Error' 
    823             color = 'red'  
     823            color = 'red' 
    824824            try: 
    825825                # try to remove pyc file if exists 
     
    843843        # Send msg to the top window   
    844844        if self.base != None: 
    845                 from sas.guiframe.events import StatusEvent  
    846                 wx.PostEvent(self.base.parent, StatusEvent(status = msg,  
     845                from sas.guiframe.events import StatusEvent 
     846                wx.PostEvent(self.base.parent, StatusEvent(status=msg, 
    847847                                                      info=info)) 
    848848        self.warning = msg 
    849849 
    850                  
    851     def write_file(self, fname, desc_str, param_str, func_str):   
     850 
     851    def write_file(self, fname, desc_str, param_str, func_str): 
    852852        """ 
    853853        Write content in file 
    854          
     854 
    855855        :param fname: full file path 
    856856        :param desc_str: content of the description strings 
    857         :param param_str: content of params; Strings   
     857        :param param_str: content of params; Strings 
    858858        :param func_str: content of func; Strings 
    859         """  
     859        """ 
    860860        try: 
    861             out_f =  open(fname,'w') 
     861            out_f = open(fname, 'w') 
    862862        except : 
    863863            raise 
     
    890890                des0 = self.name + "\\n" 
    891891                desc = str(desc_str.lstrip().rstrip().replace('\"', '')) 
    892                 out_f.write(line% (des0 + desc) + "\n") 
     892                out_f.write(line % (des0 + desc) + "\n") 
    893893            elif line.count("def function(self, x=0.0%s):"): 
    894894                if self.is_2d: 
    895895                    y_str = ', y=0.0' 
    896                     out_f.write(line% y_str + "\n") 
     896                    out_f.write(line % y_str + "\n") 
    897897                else: 
    898                     out_f.write(line% '' + "\n") 
     898                    out_f.write(line % '' + "\n") 
    899899            elif line.count("#function here"): 
    900900                for func_line in func_str.split('\n'): 
     
    906906                    if self.is_2d: 
    907907                        dep_var = 'z' 
    908                     out_f.write(spaces + 'return %s'% dep_var + "\n") 
     908                    out_f.write(spaces + 'return %s' % dep_var + "\n") 
    909909            elif line.count("#import scipy?"): 
    910910                if has_scipy: 
     
    921921        for line in line_test: 
    922922            out_f.write(line + "\n") 
    923     
    924         out_f.close()  
    925      
    926     def set_param_helper(self, line):    
     923 
     924        out_f.close() 
     925 
     926    def set_param_helper(self, line): 
    927927        """ 
    928928        Get string in line to define the params dictionary 
    929          
     929 
    930930        :param line: one line of string got from the param_str 
    931931        """ 
     
    941941            except: 
    942942                value = 1.0 # default 
    943             params_str += spaces + "self.params['%s'] = %s\n"% (name, value) 
    944              
     943            params_str += spaces + "self.params['%s'] = %s\n" % (name, value) 
     944 
    945945        return params_str 
    946946 
    947     def set_function_helper(self, line):    
     947    def set_function_helper(self, line): 
    948948        """ 
    949949        Get string in line to define the local params 
    950          
     950 
    951951        :param line: one line of string got from the param_str 
    952952        """ 
     
    957957        for item in items: 
    958958            name = item.split("=")[0].lstrip().rstrip() 
    959             params_str += spaces + "%s = self.params['%s']\n"% (name, name) 
     959            params_str += spaces + "%s = self.params['%s']\n" % (name, name) 
    960960        return params_str 
    961      
     961 
    962962    def get_warning(self): 
    963963        """ 
    964         Get the warning msg  
     964        Get the warning msg 
    965965        """ 
    966966        return self.warning 
    967          
     967 
    968968    def on_close(self, event): 
    969969        """ 
     
    972972        self.parent.Show(False)#Close() 
    973973        event.Skip() 
    974          
     974 
    975975class EditorWindow(wx.Frame): 
    976976    """ 
    977977    Editor Window 
    978978    """ 
    979     def __init__(self, parent, base, path, title,  
     979    def __init__(self, parent, base, path, title, 
    980980                 size=(EDITOR_WIDTH, EDITOR_HEIGTH), *args, **kwds): 
    981981        """ 
     
    986986        wx.Frame.__init__(self, parent=None, *args, **kwds) 
    987987        self.parent = parent 
    988         self.panel = EditorPanel(parent=self, base=parent,  
     988        self.panel = EditorPanel(parent=self, base=parent, 
    989989                                 path=path, title=title) 
    990990        self.Show(True) 
    991991        wx.EVT_CLOSE(self, self.OnClose) 
    992      
    993     def OnClose(self, event):   
     992 
     993    def OnClose(self, event): 
    994994        """ 
    995995        On close event 
     
    10091009#import scipy? 
    10101010class Model(Model1DPlugin): 
    1011     name = ""                              
     1011    name = "" 
    10121012    def __init__(self): 
    1013         Model1DPlugin.__init__(self, name=self.name)   
    1014         #set name same as file name  
    1015         self.name = self.get_fname()                                                    
     1013        Model1DPlugin.__init__(self, name=self.name) 
     1014        #set name same as file name 
     1015        self.name = self.get_fname() 
    10161016        #self.params here 
    10171017        self.description = "%s" 
     
    10641064        return name 
    10651065###################################################################### 
    1066 ## THIS IS FOR TEST. DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!!        
    1067 if __name__ == "__main__":  
    1068     m= Model()  
     1066## THIS IS FOR TEST. DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!! 
     1067if __name__ == "__main__": 
     1068    m= Model() 
    10691069    out1 = m.runXY(0.0) 
    10701070    out2 = m.runXY(0.01) 
     
    10851085from sas.models.pluginmodel import Model1DPlugin 
    10861086# User can change the name of the model (only with single functional model) 
    1087 #P1_model:  
     1087#P1_model: 
    10881088#from sas.models.%s import %s as P1 
    1089 #from %s import Model as P1  
    1090  
    1091 #P2_model:  
     1089#from %s import Model as P1 
     1090 
     1091#P2_model: 
    10921092#from sas.models.%s import %s as P2 
    1093 #from %s import Model as P2  
     1093#from %s import Model as P2 
    10941094import os 
    10951095import sys 
     
    11191119        self.magnetic_params = [] 
    11201120        # non-fittable parameters 
    1121         self.non_fittable = p_model1.non_fittable   
    1122         self.non_fittable += p_model2.non_fittable   
    1123              
    1124         ##models  
     1121        self.non_fittable = p_model1.non_fittable 
     1122        self.non_fittable += p_model2.non_fittable 
     1123 
     1124        ##models 
    11251125        self.p_model1= p_model1 
    11261126        self.p_model2= p_model2 
    1127          
    1128         
     1127 
     1128 
    11291129        ## dispersion 
    11301130        self._set_dispersion() 
     
    11331133        ## New parameter:scaling_factor 
    11341134        self.params['scale_factor'] = %s 
    1135          
     1135 
    11361136        ## Parameter details [units, min, max] 
    11371137        self._set_details() 
    11381138        self.details['scale_factor'] = ['', None, None] 
    11391139 
    1140          
     1140 
    11411141        #list of parameter that can be fitted 
    1142         self._set_fixed_params()   
     1142        self._set_fixed_params() 
    11431143        ## parameters with orientation 
    11441144        for item in self.p_model1.orientation_params: 
     
    11461146            if not new_item in self.orientation_params: 
    11471147                self.orientation_params.append(new_item) 
    1148              
     1148 
    11491149        for item in self.p_model2.orientation_params: 
    11501150            new_item = "p2_" + item 
     
    11561156            if not new_item in self.magnetic_params: 
    11571157                self.magnetic_params.append(new_item) 
    1158              
     1158 
    11591159        for item in self.p_model2.magnetic_params: 
    11601160            new_item = "p2_" + item 
     
    11721172            multiplicity2 = 1 
    11731173        ## functional multiplicity of the model 
    1174         self.multiplicity1 = multiplicity1   
    1175         self.multiplicity2 = multiplicity2     
    1176         self.multiplicity_info = []    
    1177          
     1174        self.multiplicity1 = multiplicity1 
     1175        self.multiplicity2 = multiplicity2 
     1176        self.multiplicity_info = [] 
     1177 
    11781178    def _clone(self, obj): 
    11791179        obj.params     = copy.deepcopy(self.params) 
     
    11851185        #obj = copy.deepcopy(self) 
    11861186        return obj 
    1187      
     1187 
    11881188    def _get_name(self, name1, name2): 
    11891189        p1_name = self._get_upper_name(name1) 
     
    11971197        name += p2_name 
    11981198        return name 
    1199      
     1199 
    12001200    def _get_upper_name(self, name=None): 
    12011201        if name == None: 
     
    12071207                upper_name += str_name[index] 
    12081208        return upper_name 
    1209          
     1209 
    12101210    def _set_dispersion(self): 
    1211         ##set dispersion only from p_model  
     1211        ##set dispersion only from p_model 
    12121212        for name , value in self.p_model1.dispersion.iteritems(): 
    12131213            #if name.lower() not in self.p_model1.orientation_params: 
    12141214            new_name = "p1_" + name 
    1215             self.dispersion[new_name]= value  
     1215            self.dispersion[new_name]= value 
    12161216        for name , value in self.p_model2.dispersion.iteritems(): 
    12171217            #if name.lower() not in self.p_model2.orientation_params: 
    12181218            new_name = "p2_" + name 
    1219             self.dispersion[new_name]= value  
    1220              
    1221     def function(self, x=0.0):  
     1219            self.dispersion[new_name]= value 
     1220 
     1221    def function(self, x=0.0): 
    12221222        return 0 
    1223                                 
     1223 
    12241224    def getProfile(self): 
    12251225        try: 
     
    12281228            x = None 
    12291229            y = None 
    1230              
     1230 
    12311231        return x, y 
    1232      
     1232 
    12331233    def _set_params(self): 
    12341234        for name , value in self.p_model1.params.iteritems(): 
     
    12371237            new_name = "p1_" + name 
    12381238            self.params[new_name]= value 
    1239              
     1239 
    12401240        for name , value in self.p_model2.params.iteritems(): 
    12411241            # No 2D-supported 
     
    12431243            new_name = "p2_" + name 
    12441244            self.params[new_name]= value 
    1245                  
     1245 
    12461246        # Set "scale" as initializing 
    12471247        self._set_scale_factor() 
    1248        
    1249              
     1248 
     1249 
    12501250    def _set_details(self): 
    12511251        for name ,detail in self.p_model1.details.iteritems(): 
     
    12531253            #if new_name not in self.orientation_params: 
    12541254            self.details[new_name]= detail 
    1255              
     1255 
    12561256        for name ,detail in self.p_model2.details.iteritems(): 
    12571257            new_name = "p2_" + name 
    12581258            #if new_name not in self.orientation_params: 
    12591259            self.details[new_name]= detail 
    1260      
     1260 
    12611261    def _set_scale_factor(self): 
    12621262        pass 
    1263          
    1264                  
     1263 
     1264 
    12651265    def setParam(self, name, value): 
    12661266        # set param to this (p1, p2) model 
    12671267        self._setParamHelper(name, value) 
    1268          
    1269         ## setParam to p model  
     1268 
     1269        ## setParam to p model 
    12701270        model_pre = '' 
    12711271        new_name = '' 
     
    12841284        else: 
    12851285            raise ValueError, "Model does not contain parameter %s" % name 
    1286              
     1286 
    12871287    def getParam(self, name): 
    12881288        # Look for dispersion parameters 
     
    13001300                if item.lower()==name.lower(): 
    13011301                    return self.params[item] 
    1302         return   
     1302        return 
    13031303        #raise ValueError, "Model does not contain parameter %s" % name 
    1304         
     1304 
    13051305    def _setParamHelper(self, name, value): 
    13061306        # Look for dispersion parameters 
     
    13191319                    self.params[item] = value 
    13201320                    return 
    1321              
     1321 
    13221322        raise ValueError, "Model does not contain parameter %s" % name 
    1323               
    1324     
     1323 
     1324 
    13251325    def _set_fixed_params(self): 
    13261326        for item in self.p_model1.fixed: 
     
    13321332 
    13331333        self.fixed.sort() 
    1334                  
    1335                      
     1334 
     1335 
    13361336    def run(self, x = 0.0): 
    13371337        self._set_scale_factor() 
    13381338        return self.params['scale_factor'] %s \ 
    13391339(self.p_model1.run(x) %s self.p_model2.run(x)) 
    1340      
     1340 
    13411341    def runXY(self, x = 0.0): 
    13421342        self._set_scale_factor() 
    13431343        return self.params['scale_factor'] %s \ 
    13441344(self.p_model1.runXY(x) %s self.p_model2.runXY(x)) 
    1345      
    1346     ## Now (May27,10) directly uses the model eval function  
     1345 
     1346    ## Now (May27,10) directly uses the model eval function 
    13471347    ## instead of the for-loop in Base Component. 
    13481348    def evalDistribution(self, x = []): 
     
    13661366            return value 
    13671367        except: 
    1368             raise  
     1368            raise 
    13691369 
    13701370    def fill_description(self, p_model1, p_model2): 
     
    13731373        description += "%s and %s. "% ( p_model1.name, p_model2.name ) 
    13741374        self.description += description 
    1375            
     1375 
    13761376    def get_fname(self): 
    13771377        path = sys._getframe().f_code.co_filename 
    13781378        basename  = os.path.basename(path) 
    13791379        name, _ = os.path.splitext(basename) 
    1380         return name      
    1381             
    1382 if __name__ == "__main__":  
    1383     m1= Model()  
    1384     #m1.setParam("p1_scale", 25)   
     1380        return name 
     1381 
     1382if __name__ == "__main__": 
     1383    m1= Model() 
     1384    #m1.setParam("p1_scale", 25) 
    13851385    #m1.setParam("p1_length", 1000) 
    1386     #m1.setParam("p2_scale", 100)  
    1387     #m1.setParam("p2_rg", 100)  
     1386    #m1.setParam("p2_scale", 100) 
     1387    #m1.setParam("p2_rg", 100) 
    13881388    out1 = m1.runXY(0.01) 
    13891389 
    13901390    m2= Model() 
    1391     #m2.p_model1.setParam("scale", 25)  
    1392     #m2.p_model1.setParam("length", 1000)  
     1391    #m2.p_model1.setParam("scale", 25) 
     1392    #m2.p_model1.setParam("length", 1000) 
    13931393    #m2.p_model2.setParam("scale", 100) 
    13941394    #m2.p_model2.setParam("rg", 100) 
     
    14011401        print "===> Simple Test: Failed!" 
    14021402""" 
    1403        
     1403 
    14041404#if __name__ == "__main__":  
    14051405#    app = wx.PySimpleApp() 
     
    14111411    from sas.perspectives.fitting import models 
    14121412    dir_path = models.find_plugins_dir() 
    1413     app  = wx.App() 
     1413    app = wx.App() 
    14141414    window = EditorWindow(parent=None, base=None, path=dir_path, title="Editor") 
    1415     app.MainLoop()          
     1415    app.MainLoop() 
Note: See TracChangeset for help on using the changeset viewer.