Ignore:
Timestamp:
Mar 4, 2015 1: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/density_panel.py

    r58c125d r49ab5d7  
    88from wx.lib.scrolledpanel import ScrolledPanel 
    99from sas.guiframe.utils import check_float 
    10 from sas.guiframe.events import StatusEvent   
     10from sas.guiframe.events import StatusEvent 
    1111from periodictable import formula as Formula 
    1212from sas.perspectives.calculator import calculator_widgets as widget 
    1313from sas.guiframe.documentation_window import DocumentationWindow 
    14         
    15 AVOGADRO =  6.02214129e23 
     14 
     15AVOGADRO = 6.02214129e23 
    1616_INPUTS = ['Mass Density', 'Molar Volume'] 
    1717_UNITS = ['g/cm^(3)     ', 'cm^(3)/mol '] 
     
    2727    PANEL_SIZE = 460 
    2828    FONT_VARIANT = 1 
    29      
     29 
    3030class DensityPanel(ScrolledPanel, PanelBase): 
    3131    """ 
     
    3838    ## Flag to tell the AUI manager to put this panel in the center pane 
    3939    CENTER_PANE = True 
    40      
     40 
    4141    def __init__(self, parent, base=None, *args, **kwds): 
    4242        """ 
     
    7070        self.SetAutoLayout(True) 
    7171        self.Layout() 
    72         
     72 
    7373    def _do_layout(self): 
    7474        """ 
     
    7878        unit_density = self._unit_list[0] 
    7979        unit_volume = self._unit_list[1] 
    80          
     80 
    8181        # sizers 
    8282        sizer_input = wx.GridBagSizer(5, 5) 
     
    8686        self.sizer2 = wx.BoxSizer(wx.HORIZONTAL) 
    8787        sizer3 = wx.BoxSizer(wx.HORIZONTAL) 
    88         vbox  = wx.BoxSizer(wx.VERTICAL) 
    89          
     88        vbox = wx.BoxSizer(wx.VERTICAL) 
     89 
    9090        # inputs 
    9191        inputbox = wx.StaticBox(self, -1, "Inputs") 
     
    9797        self.compound_eg2 = wx.StaticText(self, -1, 'e.g., D2O') 
    9898        self.input_cb = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    99         wx.EVT_COMBOBOX(self.input_cb, -1, self.on_select_input)  
     99        wx.EVT_COMBOBOX(self.input_cb, -1, self.on_select_input) 
    100100        hint_input_name_txt = 'Mass or volume.' 
    101         self.input_cb.SetToolTipString(hint_input_name_txt)  
     101        self.input_cb.SetToolTipString(hint_input_name_txt) 
    102102        unit_density1 = "     " + unit_density 
    103103        self.input_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
     
    107107        ix = 0 
    108108        sizer_input.Add(compound_txt, (iy, ix), (1, 1), 
    109                              wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     109                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    110110        ix += 1 
    111111        sizer_input.Add(self.compound_ctl, (iy, ix), (1, 1), 
    112                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
     112                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    113113        ix += 1 
    114114        sizer_input.Add(self.compound_eg1, (iy, ix), (1, 1), 
    115                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    116          
     115                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     116 
    117117        ix += 1 
    118118        sizer_input.Add(self.compound_eg2, (iy, ix), (1, 1), 
    119                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
     119                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    120120        self.compound_eg1.Show(False) 
    121121        iy += 1 
    122122        ix = 0 
    123123        sizer_input.Add(self.input_cb, (iy, ix), (1, 1), 
    124                              wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     124                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    125125        ix += 1 
    126126        sizer_input.Add(self.input_ctl, (iy, ix), (1, 1), 
    127                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    128         ix +=1 
    129         sizer_input.Add(self.unit_input_density,(iy, ix), (1, 1), 
    130                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    131         ix +=1 
     127                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     128        ix += 1 
     129        sizer_input.Add(self.unit_input_density, (iy, ix), (1, 1), 
     130                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     131        ix += 1 
    132132        self.unit_input_density.Show(False) 
    133         sizer_input.Add(self.unit_input_volume,(iy, ix), (1, 1), 
    134                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
     133        sizer_input.Add(self.unit_input_volume, (iy, ix), (1, 1), 
     134                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    135135        boxsizer1.Add(sizer_input) 
    136136        self.sizer1.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
    137          
     137 
    138138        # outputs 
    139139        outputbox = wx.StaticBox(self, -1, "Outputs") 
    140140        boxsizer2 = wx.StaticBoxSizer(outputbox, wx.VERTICAL) 
    141141        boxsizer2.SetMinSize((_STATICBOX_WIDTH, -1)) 
    142          
     142 
    143143        molar_mass_txt = wx.StaticText(self, -1, 'Molar Mass ') 
    144144        self.molar_mass_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
     
    147147        self.molar_mass_unit1 = wx.StaticText(self, -1, '     g/mol') 
    148148        self.molar_mass_unit2 = wx.StaticText(self, -1, 'g/mol') 
    149          
     149 
    150150        self.output_cb = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    151         wx.EVT_COMBOBOX(self.output_cb, -1, self.on_select_output)  
     151        wx.EVT_COMBOBOX(self.output_cb, -1, self.on_select_output) 
    152152        hint_output_name_txt = 'Mass or volume.' 
    153         self.output_cb.SetToolTipString(hint_output_name_txt)  
     153        self.output_cb.SetToolTipString(hint_output_name_txt) 
    154154        list = [] 
    155155        for item in self._input_list: 
     
    158158        list.sort() 
    159159        for idx in range(len(list)): 
    160             self.input_cb.Append(list[idx],idx) 
    161             self.output_cb.Append(list[idx],idx) 
    162         self.input_cb.SetStringSelection("Molar Volume")  
    163         self.output_cb.SetStringSelection("Mass Density")  
     160            self.input_cb.Append(list[idx], idx) 
     161            self.output_cb.Append(list[idx], idx) 
     162        self.input_cb.SetStringSelection("Molar Volume") 
     163        self.output_cb.SetStringSelection("Mass Density") 
    164164        unit_volume = "     " + unit_volume 
    165165        self.output_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
     
    171171        ix = 0 
    172172        sizer_output.Add(molar_mass_txt, (iy, ix), (1, 1), 
    173                              wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     173                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    174174        ix += 1 
    175175        sizer_output.Add(self.molar_mass_ctl, (iy, ix), (1, 1), 
    176                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
     176                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    177177        ix += 1 
    178178        sizer_output.Add(self.molar_mass_unit1, (iy, ix), (1, 1), 
    179                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
     179                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    180180        ix += 1 
    181181        sizer_output.Add(self.molar_mass_unit2, (iy, ix), (1, 1), 
    182                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
     182                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    183183        self.molar_mass_unit1.Show(False) 
    184184        iy += 1 
    185185        ix = 0 
    186186        sizer_output.Add(self.output_cb, (iy, ix), (1, 1), 
    187                              wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     187                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    188188        ix += 1 
    189189        sizer_output.Add(self.output_ctl, (iy, ix), (1, 1), 
    190                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    191         ix +=1 
     190                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     191        ix += 1 
    192192        sizer_output.Add(self.unit_output_volume, 
    193                          (iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
     193                         (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    194194        ix += 1 
    195195        sizer_output.Add(self.unit_output_density, 
    196                          (iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    197          
     196                         (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     197 
    198198        self.unit_output_volume.Show(False) 
    199199        boxsizer2.Add(sizer_output) 
    200         self.sizer2.Add(boxsizer2, 0, wx.EXPAND|wx.ALL, 10) 
    201          
     200        self.sizer2.Add(boxsizer2, 0, wx.EXPAND | wx.ALL, 10) 
     201 
    202202        # buttons 
    203203        id = wx.NewId() 
    204204        self.button_calculate = wx.Button(self, id, "Calculate") 
    205205        self.button_calculate.SetToolTipString("Calculate.") 
    206         self.Bind(wx.EVT_BUTTON, self.calculate, id=id)    
    207          
     206        self.Bind(wx.EVT_BUTTON, self.calculate, id=id) 
     207 
    208208        id = wx.NewId() 
    209209        self.button_help = wx.Button(self, id, "HELP") 
    210210        self.button_help.SetToolTipString("Help for density calculator.") 
    211         self.Bind(wx.EVT_BUTTON, self.on_help, id=id)    
    212          
    213         sizer_button.Add((150, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    214         sizer_button.Add(self.button_calculate, 0,  
    215                                         wx.RIGHT|wx.ADJUST_MINSIZE, 20) 
    216         sizer_button.Add(self.button_help, 0,  
    217                                         wx.RIGHT|wx.ADJUST_MINSIZE, 20) 
     211        self.Bind(wx.EVT_BUTTON, self.on_help, id=id) 
     212 
     213        sizer_button.Add((150, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     214        sizer_button.Add(self.button_calculate, 0, 
     215                                        wx.RIGHT | wx.ADJUST_MINSIZE, 20) 
     216        sizer_button.Add(self.button_help, 0, 
     217                                        wx.RIGHT | wx.ADJUST_MINSIZE, 20) 
    218218        sizer3.Add(sizer_button) 
    219          
     219 
    220220        # layout 
    221221        vbox.Add(self.sizer1) 
    222222        vbox.Add(self.sizer2) 
    223223        vbox.Add(sizer3) 
    224         vbox.Fit(self)  
     224        vbox.Fit(self) 
    225225        self.SetSizer(vbox) 
    226      
     226 
    227227    def on_select_input(self, event): 
    228228        """ 
    229         On selection of input combobox,  
     229        On selection of input combobox, 
    230230        update units and output combobox 
    231231        """ 
     
    233233            return 
    234234        event.Skip() 
    235          
     235 
    236236        combo = event.GetEventObject() 
    237237        self._input = combo.GetValue() 
     
    242242 
    243243        self.set_values() 
    244      
     244 
    245245    def on_select_output(self, event): 
    246246        """ 
    247         On selection of output combobox,  
     247        On selection of output combobox, 
    248248        update units and input combobox 
    249249        """ 
     
    251251            return 
    252252        event.Skip() 
    253          
     253 
    254254        combo = event.GetEventObject() 
    255255        self._output = combo.GetValue() 
     
    260260 
    261261        self.set_values() 
    262    
     262 
    263263    def set_values(self): 
    264264        """ 
     
    281281            self.unit_output_volume.Show(True) 
    282282            self.unit_input_volume.Show(False) 
    283             self.unit_output_density.Show(False)  
     283            self.unit_output_density.Show(False) 
    284284        else: 
    285285            self.molar_mass_unit1.Show(False) 
     
    293293        # layout     
    294294        self.clear_outputs() 
    295         self.sizer1.Layout()   
    296         self.sizer2.Layout()     
    297          
     295        self.sizer1.Layout() 
     296        self.sizer2.Layout() 
     297 
    298298    def get_input(self): 
    299299        """ 
     
    301301        """ 
    302302        return self._input, self._output 
    303      
     303 
    304304    def check_inputs(self): 
    305305        """ 
     
    313313            flag = False 
    314314            input_type = str(self.input_cb.GetValue()) 
    315             msg += "Error for %s value :expect float"% input_type 
    316                  
     315            msg += "Error for %s value :expect float" % input_type 
     316 
    317317        self.compound = self.compound_ctl.GetValue().lstrip().rstrip() 
    318318        if self.compound != "": 
     
    332332            msg += "Enter Formula" 
    333333        return flag, msg 
    334          
     334 
    335335 
    336336    def calculate(self, event): 
     
    346346                wx.PostEvent(self.base, StatusEvent(status=msg)) 
    347347            if not flag: 
    348                return  
     348               return 
    349349            #get ready to compute 
    350350            mol_formula = Formula(self.compound) 
     
    355355        except: 
    356356            if self.base is not None: 
    357                 msg = "Density/Volume Calculator: %s"%(sys.exc_value) 
     357                msg = "Density/Volume Calculator: %s" % (sys.exc_value) 
    358358                wx.PostEvent(self.base, StatusEvent(status=msg)) 
    359359        if event is not None: 
    360360            event.Skip() 
    361              
    362     def on_help(self, event):     
     361 
     362    def on_help(self, event): 
    363363        """ 
    364364        Bring up the density/volume calculator Documentation whenever 
    365         the HELP button is clicked.  
    366          
     365        the HELP button is clicked. 
     366 
    367367        Calls DocumentationWindow with the path of the location within the 
    368         documentation tree (after /doc/ ....".  Note that when using old  
    369         versions of Wx (before 2.9) and thus not the release version of  
    370         installers, the help comes up at the top level of the file as  
     368        documentation tree (after /doc/ ....".  Note that when using old 
     369        versions of Wx (before 2.9) and thus not the release version of 
     370        installers, the help comes up at the top level of the file as 
    371371        webbrowser does not pass anything past the # to the browser when it is 
    372372        running "file:///...." 
    373      
     373 
    374374    :param evt: Triggers on clicking the help button 
    375375    """ 
    376                  
     376 
    377377        _TreeLocation = "user/perspectives/calculator/density_calculator_help.html" 
    378378        _doc_viewer = DocumentationWindow(self, -1, \ 
    379              _TreeLocation,"Density/Volume Calculator Help") 
     379             _TreeLocation, "Density/Volume Calculator Help") 
    380380 
    381381    def clear_outputs(self): 
     
    385385        self.molar_mass_ctl.SetValue("") 
    386386        self.output_ctl.SetValue("") 
    387          
     387 
    388388    def _format_number(self, value=None): 
    389389        """ 
    390         Return a float in a standardized, human-readable formatted string  
    391         """ 
    392         try:  
     390        Return a float in a standardized, human-readable formatted string 
     391        """ 
     392        try: 
    393393            value = float(value) 
    394394        except: 
     
    397397 
    398398        output = "%-12.5f" % value 
    399         return output.lstrip().rstrip()   
    400          
     399        return output.lstrip().rstrip() 
     400 
    401401class DensityWindow(widget.CHILD_FRAME): 
    402402    """ 
    403403    """ 
    404404    def __init__(self, parent=None, title="Density/Volume Calculator", 
    405                   base=None, manager=None,  
    406                   size=(PANEL_SIZE*1.05, PANEL_SIZE/1.55), *args, **kwds): 
     405                  base=None, manager=None, 
     406                  size=(PANEL_SIZE * 1.05, PANEL_SIZE / 1.55), *args, **kwds): 
    407407        """ 
    408408        """ 
     
    417417        self.SetPosition((25, 10)) 
    418418        self.Show(True) 
    419      
     419 
    420420    def on_close(self, event): 
    421421        """ 
     
    425425            self.manager.cal_md_frame = None 
    426426        self.Destroy() 
    427          
    428          
     427 
     428 
    429429class ViewApp(wx.App): 
    430430    """ 
     
    434434        """ 
    435435        widget.CHILD_FRAME = wx.Frame 
    436         frame = DensityWindow(None, title="Density/Volume Calculator")     
     436        frame = DensityWindow(None, title="Density/Volume Calculator") 
    437437        frame.Show(True) 
    438438        self.SetTopWindow(frame) 
    439439        return True 
    440          
    441  
    442 if __name__ == "__main__":  
     440 
     441 
     442if __name__ == "__main__": 
    443443    app = ViewApp(0) 
    444     app.MainLoop()      
     444    app.MainLoop() 
Note: See TracChangeset for help on using the changeset viewer.