Changeset af6b53c in sasview


Ignore:
Timestamp:
Mar 4, 2015 1:50:03 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:
76aed53
Parents:
7cd87c2
Message:

pylint fixes

File:
1 edited

Legend:

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

    r18d58a6e raf6b53c  
     1# pylint: disable=attribute-defined-outside-init 
    12""" 
    23This software was developed by the University of Tennessee as part of the 
    34Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    4 project funded by the US National Science Foundation.  
     5project funded by the US National Science Foundation. 
    56 
    67See the license text in license.txt 
     
    1314import matplotlib 
    1415import math 
     16import logging 
    1517#Use the WxAgg back end. The Wx one takes too long to render 
    1618matplotlib.use('WXAgg') 
     
    2325from matplotlib.figure import Figure 
    2426 
    25 #from sas.guicomm.events import StatusEvent   
    26 from sas.calculator.resolution_calculator import ResolutionCalculator  
    27 from sas.guiframe.events import StatusEvent   
     27#from sas.guicomm.events import StatusEvent 
     28from sas.calculator.resolution_calculator import ResolutionCalculator 
     29from sas.guiframe.events import StatusEvent 
    2830from sas.perspectives.calculator.calculator_widgets import OutputTextCtrl 
    2931from sas.perspectives.calculator.calculator_widgets import InputTextCtrl 
    3032from wx.lib.scrolledpanel import ScrolledPanel 
    3133from math import fabs 
    32 from sas.perspectives.calculator import calculator_widgets as widget    
     34from sas.perspectives.calculator import calculator_widgets as widget 
    3335from sas.guiframe.documentation_window import DocumentationWindow 
    3436 
    3537_BOX_WIDTH = 100 
    3638_Q_DEFAULT = 0.0 
    37 #Slit length panel size  
     39#Slit length panel size 
    3840if sys.platform.count("win32") > 0: 
    3941    PANEL_WIDTH = 525 
     
    4951_SOURCE_MASS = {'Alpha':6.64465620E-24, 
    5052                'Deuteron':3.34358320E-24, 
    51                 'Neutron':1.67492729E-24,  
     53                'Neutron':1.67492729E-24, 
    5254                'Photon': 0.0, 
    5355                'Proton':1.67262137E-24, 
     
    6466    ## Flag to tell the AUI manager to put this panel in the center pane 
    6567    CENTER_PANE = True 
    66      
    67     def __init__(self, parent,  *args, **kwds): 
     68 
     69    def __init__(self, parent, *args, **kwds): 
    6870        kwds["size"] = (PANEL_WIDTH * 2, PANEL_HEIGHT) 
    6971        kwds["style"] = wx.FULL_REPAINT_ON_RESIZE 
     
    7173        self.SetupScrolling() 
    7274        self.parent = parent 
    73          
     75 
    7476        # input defaults 
    7577        self.qx = [] 
     
    8789        # results of sigmas 
    8890        self.sigma_strings = ' ' 
    89         #Font size  
     91        #Font size 
    9092        self.SetWindowVariant(variant=FONT_VARIANT) 
    9193        # Object that receive status event 
     
    110112        self.vertical_r_sizer = wx.StaticBoxSizer(self.vertical_r_frame, 
    111113                                                  wx.VERTICAL) 
    112         self.box_source = wx.StaticBox(self, -1, 
    113                                 str(self.window_caption)) 
    114         self.boxsizer_source = wx.StaticBoxSizer(self.box_source, 
    115                                                     wx.VERTICAL) 
     114        self.box_source = wx.StaticBox(self, -1, str(self.window_caption)) 
     115        self.boxsizer_source = wx.StaticBoxSizer(self.box_source, wx.VERTICAL) 
    116116        self.mass_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    117117        self.intensity_sizer = wx.BoxSizer(wx.HORIZONTAL) 
     
    125125        self.detector_size_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    126126        self.detector_pix_size_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    127         #self.detector_offset_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    128127        self.input_sizer = wx.BoxSizer(wx.VERTICAL) 
    129128        self.output_sizer = wx.BoxSizer(wx.VERTICAL) 
    130129        self.hint_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    131130        self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    132          
     131 
    133132    def _layout_mass(self): 
    134133        """ 
     
    137136        # get the mass 
    138137        mass_value = str(self.resolution.mass) 
    139         self.mass_txt = wx.StaticText(self, -1,  
    140                                 'Source: ') 
    141         self.mass_hint = "Mass of Neutrons m = %s [g]"\ 
    142                                  % str(self.resolution.mass) 
     138        self.mass_txt = wx.StaticText(self, -1, 'Source: ') 
     139        self.mass_hint = "Mass of Neutrons m = %s [g]" % str(self.resolution.mass) 
    143140        self.source_cb = wx.ComboBox(self, -1, 
    144                                 style=wx.CB_READONLY, 
    145                                 name = '%s'%mass_value) 
     141                                     style=wx.CB_READONLY, 
     142                                     name='%s' % mass_value) 
    146143        # Sort source name because wx2.9 on Mac does not support CB_SORT 
    147144        # Custom sorting 
    148145        source_list = [] 
    149         for key, value in self.source_mass.iteritems(): 
     146        for key, _ in self.source_mass.iteritems(): 
    150147            name_source = str(key) 
    151148            source_list.append(name_source) 
     
    153150        for idx in range(len(source_list)): 
    154151            self.source_cb.Append(source_list[idx], idx) 
    155         self.source_cb.SetStringSelection("Neutron")  
    156         wx.EVT_COMBOBOX(self.source_cb, -1, self._on_source_selection)  
    157          
     152        self.source_cb.SetStringSelection("Neutron") 
     153        wx.EVT_COMBOBOX(self.source_cb, -1, self._on_source_selection) 
     154 
    158155        # combo box for color 
    159         self.wave_color_cb =  wx.ComboBox(self, -1, 
    160                                 style=wx.CB_READONLY, 
    161                                 name = 'color') 
     156        self.wave_color_cb = wx.ComboBox(self, -1, 
     157                                         style=wx.CB_READONLY, 
     158                                         name='color') 
    162159        # two choices 
    163160        self.wave_color_cb.Append('Monochromatic') 
    164161        self.wave_color_cb.Append('TOF') 
    165         self.wave_color_cb.SetStringSelection("Monochromatic")  
    166         wx.EVT_COMBOBOX(self.wave_color_cb, -1, self._on_source_color)  
    167          
     162        self.wave_color_cb.SetStringSelection("Monochromatic") 
     163        wx.EVT_COMBOBOX(self.wave_color_cb, -1, self._on_source_color) 
     164 
    168165        source_hint = "Source Selection: Affect on" 
    169166        source_hint += " the gravitational contribution.\n" 
     
    172169        self.mass_txt.SetToolTipString(source_hint) 
    173170        self.mass_sizer.AddMany([(self.mass_txt, 0, wx.LEFT, 15), 
    174                                     (self.source_cb, 0, wx.LEFT, 15), 
    175                                     (self.wave_color_cb, 0, wx.LEFT, 15)])    
    176          
     171                                 (self.source_cb, 0, wx.LEFT, 15), 
     172                                 (self.wave_color_cb, 0, wx.LEFT, 15)]) 
     173 
    177174    def _layout_intensity(self): 
    178175        """ 
     
    182179        intensity_value = str(self.resolution.intensity) 
    183180        intensity_unit_txt = wx.StaticText(self, -1, '[counts/s]') 
    184         intensity_txt = wx.StaticText(self, -1,  
    185                                 'Intensity: ') 
    186         self.intensity_tcl = InputTextCtrl(self, -1,  
    187                                         size=(_BOX_WIDTH,-1)) 
     181        intensity_txt = wx.StaticText(self, -1, 'Intensity: ') 
     182        self.intensity_tcl = InputTextCtrl(self, -1, 
     183                                           size=(_BOX_WIDTH, -1)) 
    188184        intensity_hint = "Intensity of Neutrons" 
    189185        self.intensity_tcl.SetValue(intensity_value) 
    190186        self.intensity_tcl.SetToolTipString(intensity_hint) 
    191187        self.intensity_sizer.AddMany([(intensity_txt, 0, wx.LEFT, 15), 
    192                                     (self.intensity_tcl, 0, wx.LEFT, 15), 
    193                                     (intensity_unit_txt,0, wx.LEFT, 10)])    
    194  
    195          
     188                                      (self.intensity_tcl, 0, wx.LEFT, 15), 
     189                                      (intensity_unit_txt, 0, wx.LEFT, 10)]) 
     190 
     191 
    196192    def _layout_wavelength(self): 
    197193        """ 
     
    201197        wavelength_value = str(self.resolution.get_wavelength()) 
    202198        wavelength_unit_txt = wx.StaticText(self, -1, '[A]') 
    203         wavelength_txt = wx.StaticText(self, -1,  
    204                                 'Wavelength: ') 
    205         self.wavelength_tcl = InputTextCtrl(self, -1,  
    206                                          size=(_BOX_WIDTH,-1)) 
     199        wavelength_txt = wx.StaticText(self, -1, 'Wavelength: ') 
     200        self.wavelength_tcl = InputTextCtrl(self, -1, 
     201                                            size=(_BOX_WIDTH, -1)) 
    207202        wavelength_hint = "Wavelength of Neutrons" 
    208203        self.wavelength_tcl.SetValue(wavelength_value) 
     
    213208        self.spectrum_dic['Add new'] = '' 
    214209        self.spectrum_dic['Flat'] = spectrum_value 
    215          
    216         self.spectrum_txt = wx.StaticText(self, -1,  
    217                                 'Spectrum: ') 
     210 
     211        self.spectrum_txt = wx.StaticText(self, -1, 'Spectrum: ') 
    218212        self.spectrum_cb = wx.ComboBox(self, -1, 
    219                                 style=wx.CB_READONLY, 
    220                                 size=(_BOX_WIDTH,-1), 
    221                                 name = 'spectrum') 
     213                                       style=wx.CB_READONLY, 
     214                                       size=(_BOX_WIDTH, -1), 
     215                                       name='spectrum') 
    222216        self.spectrum_cb.Append('Add new') 
    223217        self.spectrum_cb.Append('Flat') 
    224         wx.EVT_COMBOBOX(self.spectrum_cb, -1, self._on_spectrum_cb)  
     218        wx.EVT_COMBOBOX(self.spectrum_cb, -1, self._on_spectrum_cb) 
    225219        spectrum_hint = "Wavelength Spectrum: Intensity vs. wavelength" 
    226         #self.spectrum_cb.SetValue(spectrum_value) 
    227         self.spectrum_cb.SetStringSelection('Flat')  
     220        self.spectrum_cb.SetStringSelection('Flat') 
    228221        self.spectrum_cb.SetToolTipString(spectrum_hint) 
    229222        self.wavelength_sizer.AddMany([(wavelength_txt, 0, wx.LEFT, 15), 
    230                                     (self.wavelength_tcl, 0, wx.LEFT, 5), 
    231                                     (wavelength_unit_txt,0, wx.LEFT, 5), 
    232                                     (self.spectrum_txt, 0, wx.LEFT, 20), 
    233                                     (self.spectrum_cb, 0, wx.LEFT, 5)])    
     223                                       (self.wavelength_tcl, 0, wx.LEFT, 5), 
     224                                       (wavelength_unit_txt, 0, wx.LEFT, 5), 
     225                                       (self.spectrum_txt, 0, wx.LEFT, 20), 
     226                                       (self.spectrum_cb, 0, wx.LEFT, 5)]) 
    234227        self.spectrum_txt.Show(False) 
    235228        self.spectrum_cb.Show(False) 
    236          
     229 
    237230    def _layout_wavelength_spread(self): 
    238231        """ 
     
    242235        wavelength_spread_value = str(self.resolution.get_wavelength_spread()) 
    243236        wavelength_spread_unit_txt = wx.StaticText(self, -1, '') 
    244         wavelength_spread_txt = wx.StaticText(self, -1,  
    245                                 'Wavelength Spread: ') 
    246         self.wavelength_spread_tcl = InputTextCtrl(self, -1,  
    247                                          size=(_BOX_WIDTH,-1)) 
     237        wavelength_spread_txt = wx.StaticText(self, -1, 'Wavelength Spread: ') 
     238        self.wavelength_spread_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
    248239        wavelength_spread_hint = "Wavelength  Spread of Neutrons" 
    249240        self.wavelength_spread_tcl.SetValue(wavelength_spread_value) 
    250241        self.wavelength_spread_tcl.SetToolTipString(wavelength_spread_hint) 
    251         self.wavelength_spread_sizer.AddMany([(wavelength_spread_txt, 0,  
     242        self.wavelength_spread_sizer.AddMany([(wavelength_spread_txt, 0, 
    252243                                               wx.LEFT, 15), 
    253                                 (self.wavelength_spread_tcl, 0, wx.LEFT, 15), 
    254                                 (wavelength_spread_unit_txt,0, wx.LEFT, 10)])       
    255           
    256          
     244                                              (self.wavelength_spread_tcl, 0, wx.LEFT, 15), 
     245                                              (wavelength_spread_unit_txt, 0, wx.LEFT, 10)]) 
     246 
     247 
    257248    def _layout_source_aperture(self): 
    258249        """ 
     
    261252        # get the wavelength 
    262253        source_aperture_value = str(self.resolution.source_aperture_size[0]) 
    263         if len(self.resolution.source_aperture_size)>1: 
     254        if len(self.resolution.source_aperture_size) > 1: 
    264255            source_aperture_value += ", " 
    265             source_aperture_value += str(\ 
    266                                     self.resolution.source_aperture_size[1]) 
     256            source_aperture_value += str(self.resolution.source_aperture_size[1]) 
    267257        source_aperture_unit_txt = wx.StaticText(self, -1, '[cm]') 
    268         source_aperture_txt = wx.StaticText(self, -1,  
    269                                 'Source Aperture Size: ') 
    270         self.source_aperture_tcl = InputTextCtrl(self, -1,  
    271                                          size=(_BOX_WIDTH,-1)) 
     258        source_aperture_txt = wx.StaticText(self, -1, 'Source Aperture Size: ') 
     259        self.source_aperture_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
    272260        source_aperture_hint = "Source Aperture Size" 
    273261        self.source_aperture_tcl.SetValue(source_aperture_value) 
    274262        self.source_aperture_tcl.SetToolTipString(source_aperture_hint) 
    275         self.source_aperture_sizer.AddMany([(source_aperture_txt, 0,  
    276                                                wx.LEFT, 15), 
    277                                 (self.source_aperture_tcl, 0, wx.LEFT, 15), 
    278                                 (source_aperture_unit_txt, 0, wx.LEFT, 10)])   
    279  
    280          
     263        self.source_aperture_sizer.AddMany([(source_aperture_txt, 0, wx.LEFT, 15), 
     264                                            (self.source_aperture_tcl, 0, wx.LEFT, 15), 
     265                                            (source_aperture_unit_txt, 0, wx.LEFT, 10)]) 
     266 
    281267    def _layout_sample_aperture(self): 
    282268        """ 
     
    285271        # get the wavelength 
    286272        sample_aperture_value = str(self.resolution.sample_aperture_size[0]) 
    287         if len(self.resolution.sample_aperture_size)>1: 
     273        if len(self.resolution.sample_aperture_size) > 1: 
    288274            sample_aperture_value += ", " 
    289             sample_aperture_value += str(\ 
    290                                     self.resolution.sample_aperture_size[1]) 
     275            sample_aperture_value += str(self.resolution.sample_aperture_size[1]) 
    291276        sample_aperture_unit_txt = wx.StaticText(self, -1, '[cm]') 
    292         sample_aperture_txt = wx.StaticText(self, -1,  
    293                                 'Sample Aperture Size: ') 
    294         self.sample_aperture_tcl = InputTextCtrl(self, -1,  
    295                                          size=(_BOX_WIDTH,-1)) 
     277        sample_aperture_txt = wx.StaticText(self, -1, 'Sample Aperture Size: ') 
     278        self.sample_aperture_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
    296279        sample_aperture_hint = "Sample Aperture Size" 
    297280        self.sample_aperture_tcl.SetValue(sample_aperture_value) 
    298281        self.sample_aperture_tcl.SetToolTipString(sample_aperture_hint) 
    299         self.sample_aperture_sizer.AddMany([(sample_aperture_txt, 0,  
    300                                                wx.LEFT, 15), 
    301                                 (self.sample_aperture_tcl, 0, wx.LEFT, 15), 
    302                                 (sample_aperture_unit_txt, 0, wx.LEFT, 10)])   
    303  
     282        self.sample_aperture_sizer.AddMany([(sample_aperture_txt, 0, wx.LEFT, 15), 
     283                                            (self.sample_aperture_tcl, 0, wx.LEFT, 15), 
     284                                            (sample_aperture_unit_txt, 0, wx.LEFT, 10)]) 
    304285 
    305286    def _layout_source2sample_distance(self): 
     
    308289        """ 
    309290        # get the wavelength 
    310         source2sample_distance_value = str(\ 
    311                                     self.resolution.source2sample_distance[0]) 
     291        source2sample_distance_value = str(self.resolution.source2sample_distance[0]) 
    312292 
    313293        source2sample_distance_unit_txt = wx.StaticText(self, -1, '[cm]') 
    314         source2sample_distance_txt = wx.StaticText(self, -1,  
    315                                 'Source to Sample Aperture Distance: ') 
    316         self.source2sample_distance_tcl = InputTextCtrl(self, -1,  
    317                                          size=(_BOX_WIDTH,-1)) 
     294        source2sample_distance_txt = wx.StaticText(self, -1, 
     295                                                   'Source to Sample Aperture Distance: ') 
     296        self.source2sample_distance_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
    318297        source2sample_distance_hint = "Source to Sample Aperture Distance" 
    319298        self.source2sample_distance_tcl.SetValue(source2sample_distance_value) 
    320         self.source2sample_distance_tcl.SetToolTipString(\ 
    321                                                 source2sample_distance_hint) 
    322         self.source2sample_distance_sizer.AddMany([(source2sample_distance_txt,  
    323                                                0, wx.LEFT, 15), 
    324                             (self.source2sample_distance_tcl, 0, wx.LEFT, 15), 
    325                             (source2sample_distance_unit_txt,0, wx.LEFT, 10)])   
     299        self.source2sample_distance_tcl.SetToolTipString(source2sample_distance_hint) 
     300        self.source2sample_distance_sizer.AddMany([(source2sample_distance_txt, 0, wx.LEFT, 15), 
     301                                                   (self.source2sample_distance_tcl, 0, wx.LEFT, 15), 
     302                                                   (source2sample_distance_unit_txt, 0, wx.LEFT, 10)]) 
    326303 
    327304    def _layout_sample2sample_distance(self): 
     
    330307        """ 
    331308        # get the distance 
    332         sample2sample_distance_value = str(\ 
    333                                     self.resolution.sample2sample_distance[0]) 
     309        sample2sample_distance_value = str(self.resolution.sample2sample_distance[0]) 
    334310 
    335311        sample2sample_distance_unit_txt = wx.StaticText(self, -1, '[cm]') 
    336         sample2sample_distance_txt = wx.StaticText(self, -1,  
    337                                 'Sample Offset: ') 
    338         self.sample2sample_distance_tcl = InputTextCtrl(self, -1,  
    339                                          size=(_BOX_WIDTH,-1)) 
     312        sample2sample_distance_txt = wx.StaticText(self, -1, 'Sample Offset: ') 
     313        self.sample2sample_distance_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
    340314        sample2sample_distance_hint = "Sample Aperture to Sample Distance" 
    341315        self.sample2sample_distance_tcl.SetValue(sample2sample_distance_value) 
    342         self.sample2sample_distance_tcl.SetToolTipString(\ 
    343                                                 sample2sample_distance_hint) 
    344         self.sample2sample_distance_sizer.AddMany([(sample2sample_distance_txt,  
    345                                                0, wx.LEFT, 15), 
    346                             (self.sample2sample_distance_tcl, 0, wx.LEFT, 15), 
    347                             (sample2sample_distance_unit_txt,0, wx.LEFT, 10)])   
    348  
    349  
     316        self.sample2sample_distance_tcl.SetToolTipString(sample2sample_distance_hint) 
     317        self.sample2sample_distance_sizer.AddMany([(sample2sample_distance_txt, 0, wx.LEFT, 15), 
     318                                                   (self.sample2sample_distance_tcl, 0, wx.LEFT, 15), 
     319                                                   (sample2sample_distance_unit_txt, 0, wx.LEFT, 10)]) 
    350320 
    351321    def _layout_sample2detector_distance(self): 
     
    354324        """ 
    355325        # get the wavelength 
    356         sample2detector_distance_value = str(\ 
    357                                     self.resolution.sample2detector_distance[0]) 
     326        sample2detector_distance_value = str(self.resolution.sample2detector_distance[0]) 
    358327 
    359328        sample2detector_distance_unit_txt = wx.StaticText(self, -1, '[cm]') 
    360         sample2detector_distance_txt = wx.StaticText(self, -1,  
    361                                 'Sample Aperture to Detector Distance: ') 
    362         self.sample2detector_distance_tcl = InputTextCtrl(self, -1,  
    363                                          size=(_BOX_WIDTH,-1)) 
    364         sample2detector_distance_hint = \ 
    365                                 "Sample Aperture to Detector Distance" 
    366         self.sample2detector_distance_tcl.SetValue(\ 
    367                                                 sample2detector_distance_value) 
    368         self.sample2detector_distance_tcl.SetToolTipString(\ 
    369                                                 sample2detector_distance_hint) 
     329        sample2detector_distance_txt = wx.StaticText(self, -1, 
     330                                                     'Sample Aperture to Detector Distance: ') 
     331        self.sample2detector_distance_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
     332        sample2detector_distance_hint = "Sample Aperture to Detector Distance" 
     333        self.sample2detector_distance_tcl.SetValue(sample2detector_distance_value) 
     334        self.sample2detector_distance_tcl.SetToolTipString(sample2detector_distance_hint) 
    370335        self.sample2detector_distance_sizer.AddMany([\ 
    371                         (sample2detector_distance_txt, 0, wx.LEFT, 15),         
     336                        (sample2detector_distance_txt, 0, wx.LEFT, 15), 
    372337                        (self.sample2detector_distance_tcl, 0, wx.LEFT, 15), 
    373                         (sample2detector_distance_unit_txt,0, wx.LEFT, 10)])   
    374          
     338                        (sample2detector_distance_unit_txt, 0, wx.LEFT, 10)]) 
     339 
    375340    def _layout_detector_size(self): 
    376341        """ 
     
    379344        # get the wavelength 
    380345        detector_size_value = str(self.resolution.detector_size[0]) 
    381         if len(self.resolution.detector_size)>1: 
     346        if len(self.resolution.detector_size) > 1: 
    382347            detector_size_value += ", " 
    383348            detector_size_value += str(self.resolution.detector_size[1]) 
    384349        detector_size_unit_txt = wx.StaticText(self, -1, '') 
    385         detector_size_txt = wx.StaticText(self, -1,  
    386                                 'Number of Pixels on Detector: ') 
    387         self.detector_size_tcl = InputTextCtrl(self, -1,  
    388                                          size=(_BOX_WIDTH,-1)) 
     350        detector_size_txt = wx.StaticText(self, -1, 'Number of Pixels on Detector: ') 
     351        self.detector_size_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
    389352        detector_size_hint = "Number of Pixels on Detector" 
    390353        self.detector_size_tcl.SetValue(detector_size_value) 
    391354        self.detector_size_tcl.SetToolTipString(detector_size_hint) 
    392         self.detector_size_sizer.AddMany([(detector_size_txt, 0,  
    393                                                wx.LEFT, 15), 
    394                                 (self.detector_size_tcl, 0, wx.LEFT, 15), 
    395                                     (detector_size_unit_txt,0, wx.LEFT, 10)])   
    396  
    397          
     355        self.detector_size_sizer.AddMany([(detector_size_txt, 0, wx.LEFT, 15), 
     356                                          (self.detector_size_tcl, 0, wx.LEFT, 15), 
     357                                          (detector_size_unit_txt, 0, wx.LEFT, 10)]) 
     358 
    398359    def _layout_detector_pix_size(self): 
    399360        """ 
     
    402363        # get the detector_pix_size 
    403364        detector_pix_size_value = str(self.resolution.detector_pix_size[0]) 
    404         if len(self.resolution.detector_pix_size)>1: 
     365        if len(self.resolution.detector_pix_size) > 1: 
    405366            detector_pix_size_value += ", " 
    406367            detector_pix_size_value += str(self.resolution.detector_pix_size[1]) 
    407368        detector_pix_size_unit_txt = wx.StaticText(self, -1, '[cm]') 
    408         detector_pix_size_txt = wx.StaticText(self, -1,  
    409                                 'Detector Pixel Size: ') 
    410         self.detector_pix_size_tcl = InputTextCtrl(self, -1,  
    411                                          size=(_BOX_WIDTH,-1)) 
     369        detector_pix_size_txt = wx.StaticText(self, -1, 'Detector Pixel Size: ') 
     370        self.detector_pix_size_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
    412371        detector_pix_size_hint = "Detector Pixel Size" 
    413372        self.detector_pix_size_tcl.SetValue(detector_pix_size_value) 
    414373        self.detector_pix_size_tcl.SetToolTipString(detector_pix_size_hint) 
    415         self.detector_pix_size_sizer.AddMany([(detector_pix_size_txt, 0,  
    416                                                wx.LEFT, 15), 
    417                                 (self.detector_pix_size_tcl, 0, wx.LEFT, 15), 
    418                                 (detector_pix_size_unit_txt,0, wx.LEFT, 10)]) 
    419          
     374        self.detector_pix_size_sizer.AddMany([(detector_pix_size_txt, 0, wx.LEFT, 15), 
     375                                              (self.detector_pix_size_tcl, 0, wx.LEFT, 15), 
     376                                              (detector_pix_size_unit_txt, 0, wx.LEFT, 10)]) 
     377 
    420378    def _layout_input(self): 
    421379        """ 
    422380        Fill the sizer containing inputs; qx, qy 
    423381        """ 
    424          
    425         q_title = wx.StaticText(self, -1,  
    426                             "[Q Location of the Estimation]:") 
     382 
     383        q_title = wx.StaticText(self, -1, "[Q Location of the Estimation]:") 
    427384        # sizers for inputs 
    428385        inputQx_sizer = wx.BoxSizer(wx.HORIZONTAL) 
     
    433390        qx_unit_txt = wx.StaticText(self, -1, '[1/A]  ') 
    434391        qy_unit_txt = wx.StaticText(self, -1, '[1/A]  ') 
    435         qx_name_txt = wx.StaticText(self, -1,  
    436                                 'Qx: ') 
    437         qy_name_txt = wx.StaticText(self, -1,  
    438                                 'Qy: ') 
    439         self.qx_tcl = InputTextCtrl(self, -1,  
    440                                          size=(_BOX_WIDTH*3,-1)) 
    441         self.qy_tcl = InputTextCtrl(self, -1,  
    442                                          size=(_BOX_WIDTH*3,-1)) 
     392        qx_name_txt = wx.StaticText(self, -1, 'Qx: ') 
     393        qy_name_txt = wx.StaticText(self, -1, 'Qy: ') 
     394        self.qx_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH * 3, -1)) 
     395        self.qy_tcl = InputTextCtrl(self, -1, size=(_BOX_WIDTH * 3, -1)) 
    443396        qx_hint = "Type the Qx value." 
    444397        qy_hint = "Type the Qy value." 
     
    448401        self.qy_tcl.SetToolTipString(qy_hint) 
    449402        inputQx_sizer.AddMany([(qx_name_txt, 0, wx.LEFT, 15), 
    450                                     (self.qx_tcl, 0, wx.LEFT, 15), 
    451                                     (qx_unit_txt, 0, wx.LEFT, 15)]) 
     403                               (self.qx_tcl, 0, wx.LEFT, 15), 
     404                               (qx_unit_txt, 0, wx.LEFT, 15)]) 
    452405        inputQy_sizer.AddMany([(qy_name_txt, 0, wx.LEFT, 15), 
    453                                     (self.qy_tcl, 0, wx.LEFT, 15), 
    454                                     (qy_unit_txt, 0, wx.LEFT, 15)]) 
    455         self.input_sizer.AddMany([(q_title, 0, wx.LEFT, 15),  
    456                                     (inputQx_sizer, 0, 
    457                                      wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 
    458                                     (inputQy_sizer, 0,  
    459                                      wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) 
    460                                 #(self.compute_button, 0, wx.LEFT, 30)]) 
    461          
     406                               (self.qy_tcl, 0, wx.LEFT, 15), 
     407                               (qy_unit_txt, 0, wx.LEFT, 15)]) 
     408        self.input_sizer.AddMany([(q_title, 0, wx.LEFT, 15), 
     409                                  (inputQx_sizer, 0, 
     410                                   wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 
     411                                  (inputQy_sizer, 0, 
     412                                   wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) 
     413 
    462414    def _layout_output(self): 
    463415        """ 
    464416        Fill the sizer containing dQ|| and dQ+ 
    465417        """ 
    466         sigma_title = wx.StaticText(self, -1,  
    467                         "[Standard Deviation of the Resolution Distribution]:") 
    468          # sizers for inputs 
     418        sigma_title = wx.StaticText(self, -1, 
     419                                    "[Standard Deviation of the Resolution Distribution]:") 
     420        # sizers for inputs 
    469421        outputQxy_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    470422        outputQ_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    471         sigma_unit = '['+'1/A' +']' 
    472         self.sigma_r_txt = wx.StaticText(self, -1,  
    473                                            'Sigma_x:   ') 
    474         self.sigma_r_tcl = OutputTextCtrl(self, -1,  
    475                                                  size=(_BOX_WIDTH*0.8,-1)) 
    476         self.sigma_phi_txt = wx.StaticText(self, -1,  
    477                                            'Sigma_y:') 
    478         self.sigma_phi_tcl = OutputTextCtrl(self, -1,  
    479                                                  size=(_BOX_WIDTH*0.8,-1)) 
    480         self.sigma_lamd_txt = wx.StaticText(self, -1,  
    481                                            'Sigma_lamd:') 
    482         self.sigma_lamd_tcl = OutputTextCtrl(self, -1,  
    483                                                  size=(_BOX_WIDTH*0.7,-1)) 
     423        sigma_unit = '[' + '1/A' + ']' 
     424        self.sigma_r_txt = wx.StaticText(self, -1, 'Sigma_x:   ') 
     425        self.sigma_r_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH * 0.8, -1)) 
     426        self.sigma_phi_txt = wx.StaticText(self, -1, 'Sigma_y:') 
     427        self.sigma_phi_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH * 0.8, -1)) 
     428        self.sigma_lamd_txt = wx.StaticText(self, -1, 'Sigma_lamd:') 
     429        self.sigma_lamd_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH * 0.7, -1)) 
    484430        sigma_1d_txt = wx.StaticText(self, -1, '( 1D:   Sigma:') 
    485         self.sigma_1d_tcl = OutputTextCtrl(self, -1,  
    486                                                  size=(_BOX_WIDTH*0.7,-1)) 
     431        self.sigma_1d_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH * 0.7, -1)) 
    487432        sigmax_hint = " The x component of the geometric resolution," 
    488         sigmax_hint +=  " excluding sigma_lamda." 
     433        sigmax_hint += " excluding sigma_lamda." 
    489434        sigmay_hint = " The y component of the geometric resolution," 
    490         sigmay_hint +=  " excluding sigma_lamda." 
     435        sigmay_hint += " excluding sigma_lamda." 
    491436        sigma_hint_lamd = " The wavelength contribution in the radial direction" 
    492437        sigma_hint_lamd += ".\n Note: The phi component is always zero." 
     
    499444        sigma_phi_unit_txt = wx.StaticText(self, -1, sigma_unit) 
    500445        sigma_lamd_unit_txt = wx.StaticText(self, -1, sigma_unit) 
    501         sigma_1d_unit_txt = wx.StaticText(self, -1, sigma_unit+' )') 
     446        sigma_1d_unit_txt = wx.StaticText(self, -1, sigma_unit + ' )') 
    502447        outputQxy_sizer.AddMany([(self.sigma_r_txt, 0, wx.LEFT, 15), 
    503                                     (self.sigma_r_tcl, 0, wx.LEFT, 15), 
    504                                     (sigma_r_unit_txt, 0, wx.LEFT, 15), 
    505                                     (self.sigma_phi_txt, 0, wx.LEFT, 15), 
    506                                     (self.sigma_phi_tcl, 0, wx.LEFT, 15), 
    507                                     (sigma_phi_unit_txt, 0, wx.LEFT, 15)]) 
     448                                 (self.sigma_r_tcl, 0, wx.LEFT, 15), 
     449                                 (sigma_r_unit_txt, 0, wx.LEFT, 15), 
     450                                 (self.sigma_phi_txt, 0, wx.LEFT, 15), 
     451                                 (self.sigma_phi_tcl, 0, wx.LEFT, 15), 
     452                                 (sigma_phi_unit_txt, 0, wx.LEFT, 15)]) 
    508453        outputQ_sizer.AddMany([(self.sigma_lamd_txt, 0, wx.LEFT, 15), 
    509                                     (self.sigma_lamd_tcl, 0, wx.LEFT, 15), 
    510                                     (sigma_lamd_unit_txt, 0, wx.LEFT, 15), 
    511                                     (sigma_1d_txt, 0, wx.LEFT, 15), 
    512                                     (self.sigma_1d_tcl, 0, wx.LEFT, 15), 
    513                                     (sigma_1d_unit_txt, 0, wx.LEFT, 15)]) 
    514         self.output_sizer.AddMany([(sigma_title, 0, wx.LEFT, 15),  
    515                                     (outputQxy_sizer, 0, 
    516                                      wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 
    517                                     (outputQ_sizer, 0,  
    518                                      wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) 
    519          
    520      
     454                               (self.sigma_lamd_tcl, 0, wx.LEFT, 15), 
     455                               (sigma_lamd_unit_txt, 0, wx.LEFT, 15), 
     456                               (sigma_1d_txt, 0, wx.LEFT, 15), 
     457                               (self.sigma_1d_tcl, 0, wx.LEFT, 15), 
     458                               (sigma_1d_unit_txt, 0, wx.LEFT, 15)]) 
     459        self.output_sizer.AddMany([(sigma_title, 0, wx.LEFT, 15), 
     460                                   (outputQxy_sizer, 0, 
     461                                    wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 
     462                                   (outputQ_sizer, 0, 
     463                                    wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) 
     464 
    521465    def _layout_hint(self): 
    522466        """ 
    523         Fill the sizer containing hint  
     467        Fill the sizer containing hint 
    524468        """ 
    525469        hint_msg = "" 
     
    529473        self.hint_txt = wx.StaticText(self, -1, hint_msg) 
    530474        self.hint_sizer.AddMany([(self.hint_txt, 0, wx.LEFT, 15)]) 
    531      
    532     def _layout_button(self):   
     475 
     476    def _layout_button(self): 
    533477        """ 
    534478        Do the layout for the button widgets 
    535         """  
    536  
    537         id = wx.NewId() 
    538         self.reset_button = wx.Button(self, id, "Reset") 
     479        """ 
     480 
     481        wx_id = wx.NewId() 
     482        self.reset_button = wx.Button(self, wx_id, "Reset") 
    539483        hint_on_reset = "..." 
    540484        self.reset_button.SetToolTipString(hint_on_reset) 
    541         self.Bind(wx.EVT_BUTTON, self.on_reset, id=id) 
     485        self.Bind(wx.EVT_BUTTON, self.on_reset, id=wx_id) 
    542486        #compute button 
    543         id = wx.NewId() 
    544         self.compute_button = wx.Button(self, id, "Compute") 
     487        wx_id = wx.NewId() 
     488        self.compute_button = wx.Button(self, wx_id, "Compute") 
    545489        hint_on_compute = "Compute... Please wait until finished." 
    546490        self.compute_button.SetToolTipString(hint_on_compute) 
    547         self.Bind(wx.EVT_BUTTON, self.on_compute, id=id) 
     491        self.Bind(wx.EVT_BUTTON, self.on_compute, id=wx_id) 
    548492        #help button 
    549         id = wx.NewId() 
    550         self.help_button = wx.Button(self, id, "HELP") 
     493        wx_id = wx.NewId() 
     494        self.help_button = wx.Button(self, wx_id, "HELP") 
    551495        hint_on_help = "Help on using the Resolution Calculator" 
    552496        self.help_button.SetToolTipString(hint_on_help) 
    553         self.Bind(wx.EVT_BUTTON, self.on_help, id=id) 
     497        self.Bind(wx.EVT_BUTTON, self.on_help, id=wx_id) 
    554498        # close button 
    555         self.bt_close = wx.Button(self, wx.ID_CANCEL,'Close') 
     499        self.bt_close = wx.Button(self, wx.ID_CANCEL, 'Close') 
    556500        self.bt_close.Bind(wx.EVT_BUTTON, self.on_close) 
    557501        self.bt_close.SetToolTipString("Close this window.") 
     
    563507                                   (self.bt_close, 0, wx.LEFT, 15)]) 
    564508        self.compute_button.SetFocus() 
    565          
     509 
    566510    def _layout_image(self): 
    567511        """ 
    568512        Layout for image plot 
    569513        """ 
    570         color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BACKGROUND) 
    571  
    572514        # Contribution by James C. 
    573515        # Instantiate a figure object that will contain our plots. 
    574516        # Make the fig a little smaller than the default 
    575         self.figure = Figure(figsize=(6.5, 6), facecolor = 'white') 
    576          
     517        self.figure = Figure(figsize=(6.5, 6), facecolor='white') 
     518 
    577519        # Initialize the figure canvas, mapping the figure object to the plot 
    578520        # engine backend. 
     
    588530        self.fm = FigureManagerBase(self.canvas, 1) 
    589531        _pylab_helpers.Gcf.set_active(self.fm) 
    590          
     532 
    591533        # Instantiate the matplotlib navigation toolbar and explicitly show it. 
    592534        mpl_toolbar = Toolbar(self.canvas) 
     
    599541        # Compute before adding the canvas to the sizer 
    600542        self.on_compute() 
    601          
     543 
    602544        # Fill up the sizer 
    603545        if IS_WIN: 
     
    605547        else: 
    606548            gap = 13 
    607         self.vertical_r_sizer.Add(self.canvas, 0,  
    608                                        wx.ALL|wx.EXPAND, 2)  
    609         self.vertical_r_spacer.Add((0, gap))  
    610         self.vertical_r_spacer.Add(self.vertical_r_sizer, 0,  
    611                                        wx.ALL|wx.EXPAND, 2) 
    612         self.vertical_r_spacer.Add((0, gap))  
    613         self.vertical_r_spacer.Add(wx.StaticLine(self), 0,  
    614                                        wx.ALL|wx.EXPAND, 2) 
    615         self.vertical_r_spacer.Add(mpl_toolbar, 0,  wx.ALL|wx.EXPAND, 2) 
    616  
    617          
     549        self.vertical_r_sizer.Add(self.canvas, 0, wx.ALL | wx.EXPAND, 2) 
     550        self.vertical_r_spacer.Add((0, gap)) 
     551        self.vertical_r_spacer.Add(self.vertical_r_sizer, 0, wx.ALL | wx.EXPAND, 2) 
     552        self.vertical_r_spacer.Add((0, gap)) 
     553        self.vertical_r_spacer.Add(wx.StaticLine(self), 0, wx.ALL | wx.EXPAND, 2) 
     554        self.vertical_r_spacer.Add(mpl_toolbar, 0, wx.ALL | wx.EXPAND, 2) 
     555 
    618556    def _do_layout(self): 
    619557        """ 
     
    621559        """ 
    622560        #  Title of parameters 
    623         instrument_txt = wx.StaticText(self, -1,  
    624                                 '[Instrumental Parameters]:') 
     561        instrument_txt = wx.StaticText(self, -1, '[Instrumental Parameters]:') 
    625562        # Build individual layouts 
    626563        self._define_structure() 
    627564        self._layout_mass() 
    628         #self._layout_intensity() 
    629565        self._layout_wavelength() 
    630566        self._layout_wavelength_spread() 
     
    642578        # Fill the sizers 
    643579        self.boxsizer_source.AddMany([(instrument_txt, 0, 
    644                                        wx.EXPAND|wx.LEFT, 15), 
     580                                       wx.EXPAND | wx.LEFT, 15), 
    645581                                      (self.mass_sizer, 0, 
    646                                       wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 
    647                                       #(self.intensity_sizer, 0, 
    648                                       #wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 
     582                                       wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 
    649583                                      (self.wavelength_sizer, 0, 
    650                                       wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 
     584                                       wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 
    651585                                      (self.wavelength_spread_sizer, 0, 
    652                                       wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 
     586                                       wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 
    653587                                      (self.source_aperture_sizer, 0, 
    654                                       wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 
     588                                       wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 
    655589                                      (self.sample_aperture_sizer, 0, 
    656                                       wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 
     590                                       wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 
    657591                                      (self.source2sample_distance_sizer, 0, 
    658                                       wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 
     592                                       wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 
    659593                                      (self.sample2detector_distance_sizer, 0, 
    660                                       wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 
     594                                       wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 
    661595                                      (self.sample2sample_distance_sizer, 0, 
    662                                       wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 
     596                                       wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 
    663597                                      (self.detector_size_sizer, 0, 
    664                                       wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 
     598                                       wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 
    665599                                      (self.detector_pix_size_sizer, 0, 
    666                                       wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 
    667                                       (wx.StaticLine(self), 0,  
    668                                        wx.ALL|wx.EXPAND, 5), 
     600                                       wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 
     601                                      (wx.StaticLine(self), 0, 
     602                                       wx.ALL | wx.EXPAND, 5), 
    669603                                      (self.input_sizer, 0, 
    670                                       wx.EXPAND|wx.TOP|wx.BOTTOM, 5), 
    671                                       (wx.StaticLine(self), 0,  
    672                                        wx.ALL|wx.EXPAND, 5), 
     604                                       wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 
     605                                      (wx.StaticLine(self), 0, 
     606                                       wx.ALL | wx.EXPAND, 5), 
    673607                                      (self.output_sizer, 0, 
    674                                       wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) 
     608                                       wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) 
    675609        self.vertical_l_sizer.AddMany([(self.boxsizer_source, 0, wx.ALL, 10), 
    676                                        (wx.StaticLine(self), 0,  
    677                                        wx.ALL|wx.EXPAND, 5), 
    678                                   (self.button_sizer, 0, 
    679                                     wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) 
     610                                       (wx.StaticLine(self), 0, 
     611                                        wx.ALL | wx.EXPAND, 5), 
     612                                       (self.button_sizer, 0, 
     613                                        wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) 
    680614        self.main_sizer.Add(self.vertical_l_sizer, 0, wx.ALL, 10) 
    681          
    682         # Build image plot layout                      
     615 
     616        # Build image plot layout 
    683617        self._layout_image() 
    684618        # Add a vertical static line 
    685         self.main_sizer.Add( wx.StaticLine(self, -1, (2, 2),  
    686                             (2,PANEL_HEIGHT * 0.94), style = wx.LI_VERTICAL)) 
     619        self.main_sizer.Add(wx.StaticLine(self, -1, (2, 2), 
     620                                          (2, PANEL_HEIGHT * 0.94), style=wx.LI_VERTICAL)) 
    687621        # Add the plot to main sizer 
    688622        self.main_sizer.Add(self.vertical_r_spacer, 0, wx.ALL, 10) 
    689623        self.SetSizer(self.main_sizer) 
    690624        self.SetAutoLayout(True) 
    691          
    692  
    693     def on_help(self, event):     
     625 
     626    def on_help(self, event): 
    694627        """ 
    695628        Bring up the Resolution calculator Documentation whenever 
    696         the HELP button is clicked.  
    697          
     629        the HELP button is clicked. 
     630 
    698631        Calls DocumentationWindow with the path of the location within the 
    699         documentation tree (after /doc/ ....".  Note that when using old  
    700         versions of Wx (before 2.9) and thus not the release version of  
    701         installers, the help comes up at the top level of the file as  
     632        documentation tree (after /doc/ ....".  Note that when using old 
     633        versions of Wx (before 2.9) and thus not the release version of 
     634        installers, the help comes up at the top level of the file as 
    702635        webbrowser does not pass anything past the # to the browser when it is 
    703636        running "file:///...." 
    704      
     637 
    705638    :param evt: Triggers on clicking the help button 
    706639    """ 
    707                  
     640 
    708641        _TreeLocation = "user/perspectives/calculator/resolution_calculator_help.html" 
    709         _doc_viewer = DocumentationWindow(self, -1, \ 
    710              _TreeLocation,"Resolution Calculator Help") 
     642        _doc_viewer = DocumentationWindow(self, -1, 
     643                                          _TreeLocation, "Resolution Calculator Help") 
    711644 
    712645    def on_close(self, event): 
     
    724657        # Close panel 
    725658        self.parent.OnClose(None) 
    726          
    727      
    728     def on_compute(self, event = None):   
     659 
     660    def on_compute(self, event=None): 
    729661        """ 
    730662        Execute the computation of resolution 
    731663        """ 
    732664        wx.CallAfter(self.on_compute_call, event) 
    733          
     665 
    734666    def on_compute_call(self, event=None): 
    735667        """ 
     
    743675 
    744676        # message 
    745         status_type = 'progress'  
     677        status_type = 'progress' 
    746678        msg = 'Calculating...' 
    747679        self._status_info(msg, status_type) 
    748680 
    749         status_type = 'stop'            
     681        status_type = 'stop' 
    750682        # Q min max list default 
    751         qx_min = []    
    752         qx_max = []  
    753         qy_min = []  
    754         qy_max = []  
     683        qx_min = [] 
     684        qx_max = [] 
     685        qy_min = [] 
     686        qy_max = [] 
    755687        # possible max qrange 
    756688        self.resolution.qxmin_limit = 0 
     
    773705            if wave_input != None: 
    774706                wavelength, wavelength_spread = wave_input 
    775      
    776             #self.resolution.set_wave(float(wavelength)) 
     707 
    777708            self.resolution.set_wave(wavelength) 
    778             #self.resolution.set_wave_spread(float(wavelength_spread)) 
    779709            self.resolution.set_wave_spread(wavelength_spread) 
    780710            source_aperture_size = self.source_aperture_tcl.GetValue() 
     
    804734            self.qx = self._string2inputlist(self.qx_tcl.GetValue()) 
    805735            self.qy = self._string2inputlist(self.qy_tcl.GetValue()) 
    806              
    807              
     736 
    808737            # Find min max of qs 
    809738            xmin = min(self.qx) 
     
    825754        if q_input != None: 
    826755            self.qx, self.qy = q_input 
    827          
     756 
    828757        # Make list of q min max for mapping 
    829         for length in range(len(self.qx)): 
     758        for i in range(len(self.qx)): 
    830759            qx_min.append(xmin) 
    831760            qx_max.append(xmax) 
    832         for length in range(len(self.qy)): 
     761        for i in range(len(self.qy)): 
    833762            qy_min.append(ymin) 
    834763            qy_max.append(ymax) 
    835          
     764 
    836765        # Compute the resolution 
    837766        if self.image != None: 
     
    845774        # Compute and get the image plot 
    846775        try: 
    847             from sas.perspectives.calculator.resolcal_thread \ 
    848                                                 import CalcRes as thread 
     776            from sas.perspectives.calculator.resolcal_thread import CalcRes as thread 
    849777            self.sigma_strings = '\nResolution: Computation is finished. \n' 
    850             cal_res = thread(func = self._map_func, 
    851                          qx = self.qx, 
    852                          qy = self.qy, 
    853                          qx_min = qx_min, 
    854                          qx_max = qx_max, 
    855                          qy_min = qy_min, 
    856                          qy_max = qy_max, 
    857                          image = self.image, 
    858                          completefn = self.complete) 
    859             #self.image = map(self._map_func, self.qx, self.qy,  
    860             #                 qx_min, qx_max, qy_min, qy_max)[0] 
     778            cal_res = thread(func=self._map_func, 
     779                             qx=self.qx, 
     780                             qy=self.qy, 
     781                             qx_min=qx_min, 
     782                             qx_max=qx_max, 
     783                             qy_min=qy_min, 
     784                             qy_max=qy_max, 
     785                             image=self.image, 
     786                             completefn=self.complete) 
    861787            cal_res.queue() 
    862788            msg = "Computation is in progress..." 
    863             #msg = "Finished the resolution computation..." 
    864789            status_type = 'progress' 
    865790            self._status_info(msg, status_type) 
    866791        except: 
    867792            raise 
    868              
     793 
    869794    def complete(self, image, elapsed=None): 
    870795        """ 
    871796        Callafter complete: wx call after needed for stable output 
    872797        """ 
    873         wx.CallAfter(self.complete_cal, image, elapsed)    
    874          
     798        wx.CallAfter(self.complete_cal, image, elapsed) 
     799 
    875800    def complete_cal(self, image, elapsed=None): 
    876801        """ 
     
    881806        wave_list, _ = self.resolution.get_wave_list() 
    882807        if len(wave_list) > 1 and wave_list[-1] == max(wave_list): 
    883             # draw a green rectangle(limit for the longest wavelength  
     808            # draw a green rectangle(limit for the longest wavelength 
    884809            # to be involved) for tof inputs 
    885810            self._draw_lines(self.image, color='g') 
     
    887812        # Draw image 
    888813        self.image.draw() 
    889         #self.vertical_r_sizer.Layout() 
    890          
    891         # Get and format the sigmas  
     814 
     815        # Get and format the sigmas 
    892816        sigma_r = self.format_number(self.resolution.sigma_1) 
    893817        sigma_phi = self.format_number(self.resolution.sigma_2) 
    894818        sigma_lamd = self.format_number(self.resolution.sigma_lamd) 
    895         sigma_1d =  self.format_number(self.resolution.sigma_1d) 
    896  
    897         # Set output values  
     819        sigma_1d = self.format_number(self.resolution.sigma_1d) 
     820 
     821        # Set output values 
    898822        self.sigma_r_tcl.SetValue(str(sigma_r)) 
    899823        self.sigma_phi_tcl.SetValue(str(sigma_phi)) 
     
    904828        status_type = 'stop' 
    905829        self._status_info(msg, status_type) 
    906          
     830 
    907831    def _draw_lines(self, image=None, color='r'): 
    908832        """ 
     
    935859        # Draw zero axis lines 
    936860        if qy_min < 0 and qy_max >= 0: 
    937             image.axhline(linewidth = 1) 
     861            image.axhline(linewidth=1) 
    938862        if qx_min < 0 and qx_max >= 0: 
    939             image.axvline(linewidth = 1) 
    940              
     863            image.axvline(linewidth=1) 
     864 
    941865        # Find x and y ratio values to draw the detector outline 
    942866        x_min = fabs(detector_qx_min - qx_min) / (qx_max - qx_min) 
     
    947871        # Draw Detector outline 
    948872        if detector_qy_min >= qy_min: 
    949             image.axhline(y = detector_qy_min + 0.0002, 
    950                                xmin = x_min, 
    951                                xmax = x_max,  
    952                                linewidth = 2, color=color) 
     873            image.axhline(y=detector_qy_min + 0.0002, 
     874                          xmin=x_min, xmax=x_max, 
     875                          linewidth=2, color=color) 
    953876        if detector_qy_max <= qy_max: 
    954             image.axhline(y = detector_qy_max - 0.0002,  
    955                                xmin = x_min,  
    956                                xmax = x_max,  
    957                                linewidth = 2, color=color) 
     877            image.axhline(y=detector_qy_max - 0.0002, 
     878                          xmin=x_min, xmax=x_max, 
     879                          linewidth=2, color=color) 
    958880        if detector_qx_min >= qx_min: 
    959             image.axvline(x = detector_qx_min + 0.0002,  
    960                                ymin = y_min,  
    961                                ymax = y_max,  
    962                                linewidth = 2, color=color) 
     881            image.axvline(x=detector_qx_min + 0.0002, 
     882                          ymin=y_min, ymax=y_max, 
     883                          linewidth=2, color=color) 
    963884        if detector_qx_max <= qx_max: 
    964             image.axvline(x = detector_qx_max - 0.0002,  
    965                                ymin = y_min,  
    966                                ymax = y_max,  
    967                                linewidth = 2, color=color) 
     885            image.axvline(x=detector_qx_max - 0.0002, 
     886                          ymin=y_min, ymax=y_max, 
     887                          linewidth=2, color=color) 
    968888        xmin = min(self.qx) 
    969889        xmax = max(self.qx) 
     
    974894                        ymin < detector_qy_min or ymax > detector_qy_max: 
    975895                # message 
    976                 status_type = 'stop'  
     896                status_type = 'stop' 
    977897                msg = 'At least one q value located out side of\n' 
    978898                msg += " the detector range (%s < qx < %s, %s < qy < %s),\n" % \ 
    979                         (self.format_number(detector_qx_min),  
     899                        (self.format_number(detector_qx_min), 
    980900                         self.format_number(detector_qx_max), 
    981                          self.format_number(detector_qy_min),  
     901                         self.format_number(detector_qy_min), 
    982902                         self.format_number(detector_qy_max)) 
    983903                msg += " is ignored in computation.\n" 
    984                  
     904 
    985905                self._status_info(msg, status_type) 
    986906                wx.MessageBox(msg, 'Warning') 
    987          
    988     def _map_func(self, qx, qy, qx_min, qx_max, qy_min, qy_max):     
     907 
     908    def _map_func(self, qx, qy, qx_min, qx_max, qy_min, qy_max): 
    989909        """ 
    990910        Prepare the Mapping for the computation 
    991911        : params qx, qy, qx_min, qx_max, qy_min, qy_max: 
    992          
     912 
    993913        : return: image (pylab) 
    994914        """ 
     
    999919            raise 
    1000920        # calculate 2D resolution distribution image 
    1001         image = self.resolution.compute_and_plot(qx_value, qy_value,  
    1002                                  qx_min, qx_max, qy_min, qy_max,  
    1003                                  self.det_coordinate) 
     921        image = self.resolution.compute_and_plot(qx_value, qy_value, 
     922                                                 qx_min, qx_max, qy_min, qy_max, 
     923                                                 self.det_coordinate) 
    1004924        # record sigmas 
    1005         self.sigma_strings += " At Qx = %s, Qy = %s; \n"% (qx_value, qy_value) 
     925        self.sigma_strings += " At Qx = %s, Qy = %s; \n" % (qx_value, qy_value) 
    1006926        self._sigma_strings() 
    1007927        return image 
     928 
    1008929    def _sigma_strings(self): 
    1009930        """ 
     
    1013934        sigma_phi = self.format_number(self.resolution.sigma_2) 
    1014935        sigma_lamd = self.format_number(self.resolution.sigma_lamd) 
    1015         sigma_1d =  self.format_number(self.resolution.sigma_1d) 
    1016         # Set output values  
    1017         self.sigma_strings += "   sigma_x = %s\n"% sigma_r 
    1018         self.sigma_strings += "   sigma_y = %s\n"% sigma_phi 
    1019         self.sigma_strings += "   sigma_lamd = %s\n"% sigma_lamd 
    1020         self.sigma_strings += "   sigma_1D = %s\n"% sigma_1d 
    1021      
    1022     def _validate_q_input(self, qx, qy):     
     936        sigma_1d = self.format_number(self.resolution.sigma_1d) 
     937        # Set output values 
     938        self.sigma_strings += "   sigma_x = %s\n" % sigma_r 
     939        self.sigma_strings += "   sigma_y = %s\n" % sigma_phi 
     940        self.sigma_strings += "   sigma_lamd = %s\n" % sigma_lamd 
     941        self.sigma_strings += "   sigma_1D = %s\n" % sigma_1d 
     942 
     943    def _validate_q_input(self, qx, qy): 
    1023944        """ 
    1024945        Check if q inputs are valid 
    1025946        : params qx:  qx as a list 
    1026947        : params qy:  qy as a list 
    1027          
     948 
    1028949        : return: True/False 
    1029950        """ 
     
    1031952        if qx.__class__.__name__ != 'list': 
    1032953            return None 
    1033         if qy.__class__.__name__ != 'list' : 
     954        if qy.__class__.__name__ != 'list': 
    1034955            return None 
    1035956        if len(qx) < 1: 
     
    1049970        if qx == None or qy == None: 
    1050971            return None 
    1051         return qx, qy  
    1052       
     972        return qx, qy 
     973 
    1053974    def on_reset(self, event): 
    1054975        """ 
     
    1057978        # skip for another event 
    1058979        if event != None: 
    1059             event.Skip()   
     980            event.Skip() 
    1060981        # init resolution_calculator 
    1061982        self.resolution = ResolutionCalculator() 
     
    1073994        self.spectrum_cb.Show(False) 
    1074995        source_aperture_value = str(self.resolution.source_aperture_size[0]) 
    1075         if len(self.resolution.source_aperture_size)>1: 
     996        if len(self.resolution.source_aperture_size) > 1: 
    1076997            source_aperture_value += ", " 
    1077998            source_aperture_value += \ 
     
    10791000        self.source_aperture_tcl.SetValue(str(source_aperture_value)) 
    10801001        sample_aperture_value = str(self.resolution.sample_aperture_size[0]) 
    1081         if len(self.resolution.sample_aperture_size)>1: 
     1002        if len(self.resolution.sample_aperture_size) > 1: 
    10821003            sample_aperture_value += ", " 
    10831004            sample_aperture_value += \ 
     
    10951016                                            sample2detector_distance_value) 
    10961017        detector_size_value = str(self.resolution.detector_size[0]) 
    1097         if len(self.resolution.detector_size)>1: 
     1018        if len(self.resolution.detector_size) > 1: 
    10981019            detector_size_value += ", " 
    10991020            detector_size_value += str(self.resolution.detector_size[1]) 
    11001021        self.detector_size_tcl.SetValue(detector_size_value) 
    11011022        detector_pix_size_value = str(self.resolution.detector_pix_size[0]) 
    1102         if len(self.resolution.detector_pix_size)>1: 
     1023        if len(self.resolution.detector_pix_size) > 1: 
    11031024            detector_pix_size_value += ", " 
    11041025            detector_pix_size_value += str(self.resolution.detector_pix_size[1]) 
     
    11201041        msg = " Finished the resetting..." 
    11211042        self._status_info(msg, 'stop') 
    1122          
     1043 
    11231044    def format_number(self, value=None): 
    11241045        """ 
    1125         Return a float in a standardized, human-readable formatted string  
    1126         """ 
    1127         try:  
     1046        Return a float in a standardized, human-readable formatted string 
     1047        """ 
     1048        try: 
    11281049            value = float(value) 
    11291050        except: 
     
    11321053 
    11331054        output = "%-7.4g" % value 
    1134         return output.lstrip().rstrip()   
    1135       
     1055        return output.lstrip().rstrip() 
     1056 
    11361057    def _string2list(self, string): 
    11371058        """ 
     
    11391060        """ 
    11401061        new_string = [] 
    1141         # check the number of floats  
     1062        # check the number of floats 
    11421063        try: 
    11431064            strg = float(string) 
    11441065            new_string.append(strg) 
    1145             #new_string.append(0) 
    11461066        except: 
    11471067            string_split = string.split(',') 
     
    11601080 
    11611081        return new_string 
    1162      
     1082 
    11631083    def _string2inputlist(self, string): 
    11641084        """ 
    11651085        Change NNN, NNN,... to list,ie. [NNN, NNN,...] where NNN is a number 
    1166          
     1086 
    11671087        : return new_string: string like list 
    11681088        """ 
     
    11751095                new_string.append(value) 
    11761096            except: 
    1177                 pass 
    1178          
     1097                logging.error(sys.exc_value) 
     1098 
    11791099        return new_string 
    1180      
     1100 
    11811101    def _str2longlist(self, string): 
    11821102        """ 
    11831103        Change NNN, NNN,... to list, NNN - NNN ; NNN to list, or float to list 
    1184          
     1104 
    11851105        : return new_string: string like list 
    11861106        """ 
    1187         #new_string = [] 
    11881107        msg = "Wrong format of intputs." 
    11891108        try: 
     
    11961115            else: 
    11971116                try: 
    1198                     # has a '-'  
     1117                    # has a '-' 
    11991118                    if string.count('-') > 0: 
    12001119                        value = string.split('-') 
     
    12021121                            # has a ';' 
    12031122                            last_list = value[1].split(';') 
    1204                             num =  math.ceil(float(last_list[1])) 
    1205                             max = float(last_list[0]) 
     1123                            num = math.ceil(float(last_list[1])) 
     1124                            max_value = float(last_list[0]) 
    12061125                            self.num_wave = num 
    12071126                        else: 
    12081127                            # default num 
    12091128                            num = self.num_wave 
    1210                             max = float(value[1]) 
    1211                         min = float(value[0]) 
     1129                            max_value = float(value[1]) 
     1130                        min_value = float(value[0]) 
    12121131                        # make a list 
    1213                         bin_size = math.fabs(max - min) / (num - 1) 
    1214                         out = [min + bin_size * bnum for bnum in range(num)] 
     1132                        bin_size = math.fabs(max_value - min_value) / (num - 1) 
     1133                        out = [min_value + bin_size * bnum for bnum in range(num)] 
    12151134                        return out 
    12161135                    if string.count(',') > 0: 
     
    12181137                        return out 
    12191138                except: 
    1220                     pass 
    1221                 #    wx.MessageBox(msg, 'Warning') 
     1139                    logging.error(sys.exc_value) 
    12221140 
    12231141    def _on_xy_coordinate(self, event=None): 
     
    12261144        """ 
    12271145        if event != None: 
    1228             event.Skip()         
    1229         # Set the coordinate in Cartesian        
     1146            event.Skip() 
     1147        # Set the coordinate in Cartesian 
    12301148        self.det_coordinate = 'cartesian' 
    12311149        self.sigma_r_txt.SetLabel('Sigma_x:') 
    12321150        self.sigma_phi_txt.SetLabel('Sigma_y:') 
    12331151        self._onparamEnter() 
    1234          
     1152 
    12351153    def _on_rp_coordinate(self, event=None): 
    12361154        """ 
     
    12381156        """ 
    12391157        if event != None: 
    1240             event.Skip()         
    1241         # Set the coordinate in polar             
     1158            event.Skip() 
     1159        # Set the coordinate in polar 
    12421160        self.det_coordinate = 'polar' 
    12431161        self.sigma_r_txt.SetLabel('Sigma_r:   ') 
    12441162        self.sigma_phi_txt.SetLabel('Sigma_phi:') 
    12451163        self._onparamEnter() 
    1246          
    1247     def _status_info(self, msg = '', type = "update"): 
     1164 
     1165    def _status_info(self, msg='', type="update"): 
    12481166        """ 
    12491167        Status msg 
     
    12521170            label = "Compute" 
    12531171            able = True 
    1254         else:    
     1172        else: 
    12551173            label = "Wait..." 
    12561174            able = False 
     
    12591177        self.compute_button.SetToolTipString(label) 
    12601178        if self.parent.parent != None: 
    1261             wx.PostEvent(self.parent.parent,  
    1262                              StatusEvent(status = msg, type = type )) 
    1263  
    1264  
    1265     def _onparamEnter(self, event = None): 
     1179            wx.PostEvent(self.parent.parent, 
     1180                         StatusEvent(status=msg, type=type)) 
     1181 
     1182 
     1183    def _onparamEnter(self, event=None): 
    12661184        """ 
    12671185        On Text_enter_callback, perform compute 
    12681186        """ 
    12691187        self.on_compute() 
    1270          
    1271     def _on_source_selection(self, event = None): 
     1188 
     1189    def _on_source_selection(self, event=None): 
    12721190        """ 
    12731191        On source combobox selection 
     
    12801198        selection = combo.GetValue() 
    12811199        mass = self.source_mass[selection] 
    1282         self.resolution.set_neutron_mass(mass)    
     1200        self.resolution.set_neutron_mass(mass) 
    12831201        source_hint = "Source Selection: Affect on" 
    12841202        source_hint += " the gravitational contribution.\n" 
     
    12871205        #source_tip.SetTip(source_hint) 
    12881206        self.mass_txt.ToolTip.SetTip(source_hint) 
    1289          
    1290     def _on_source_color(self, event = None): 
     1207 
     1208    def _on_source_color(self, event=None): 
    12911209        """ 
    12921210        On source color combobox selection 
     
    13141232            self.spectrum_txt.Show(True) 
    13151233            self.spectrum_cb.Show(True) 
    1316            
     1234 
    13171235        else: 
    13181236            wavelength = self.resolution.get_wavelength() 
     
    13231241            self.spectrum_txt.Show(False) 
    13241242            self.spectrum_cb.Show(False) 
    1325         self.wavelength_sizer.Layout()  
     1243        self.wavelength_sizer.Layout() 
    13261244        self.Layout() 
    1327          
     1245 
    13281246    def _on_spectrum_cb(self, event=None): 
    13291247        """ 
     
    13451263                return 
    13461264            try: 
    1347                 basename  = os.path.basename(path) 
     1265                basename = os.path.basename(path) 
    13481266                if basename not in self.spectrum_dic.keys(): 
    13491267                    self.spectrum_cb.Append(basename) 
     
    13541272            except: 
    13551273                raise 
    1356          
     1274 
    13571275        self.resolution.set_spectrum(self.spectrum_dic[selection]) 
    1358                               
     1276 
    13591277    def _selectDlg(self): 
    13601278        """ 
    13611279        open a dialog file to select a customized spectrum 
    13621280        """ 
    1363         dlg = wx.FileDialog(self,  
    1364                 "Choose a wavelength spectrum file: Intensity vs. wavelength", 
    1365                 self.parent.parent.get_save_location() , "",  
    1366                 "*.*", wx.OPEN) 
     1281        dlg = wx.FileDialog(self, 
     1282                            "Choose a wavelength spectrum file: Intensity vs. wavelength", 
     1283                            self.parent.parent.get_save_location() , "", "*.*", wx.OPEN) 
    13671284        path = None 
    13681285        if dlg.ShowModal() == wx.ID_OK: 
     
    13701287        dlg.Destroy() 
    13711288        return path 
    1372          
     1289 
    13731290    def _read_file(self, path): 
    13741291        """ 
    13751292        Read two columns file as tuples of numpy array 
    1376          
     1293 
    13771294        :param path: the path to the file to read 
    1378          
     1295 
    13791296        """ 
    13801297        try: 
    13811298            if path == None: 
    13821299                wx.PostEvent(self.parent.parent, StatusEvent(status=\ 
    1383                             " Selected Distribution was not loaded: %s"%path)) 
     1300                            " Selected Distribution was not loaded: %s" % path)) 
    13841301                return None, None 
    13851302            input_f = open(path, 'r') 
    13861303            buff = input_f.read() 
    13871304            lines = buff.split('\n') 
    1388              
     1305 
    13891306            wavelength = [] 
    13901307            intensity = [] 
     
    13981315                except: 
    13991316                    # Skip non-data lines 
    1400                     pass 
    1401                  
     1317                    logging.error(sys.exc_value) 
     1318 
    14021319            return [wavelength, intensity] 
    14031320        except: 
    1404             raise  
    1405          
     1321            raise 
     1322 
    14061323class ResolutionWindow(widget.CHILD_FRAME): 
    14071324    """ 
    14081325    Resolution Window 
    14091326    """ 
    1410     def __init__(self, parent = None, manager=None,  
    1411                  title = "SAS Resolution Estimator", 
     1327    def __init__(self, parent=None, manager=None, 
     1328                 title="SAS Resolution Estimator", 
    14121329                 size=(PANEL_WIDTH * 2, PANEL_HEIGHT), *args, **kwds): 
    14131330        kwds['title'] = title 
     
    14201337        self.SetPosition((25, 10)) 
    14211338        self.Show(True) 
    1422      
    1423     def OnClose(self, event):   
     1339 
     1340    def OnClose(self, event): 
    14241341        """ 
    14251342        On close event 
     
    14281345        if self.manager != None: 
    14291346            self.manager.cal_res_frame = None 
    1430         self.Destroy()  
    1431  
    1432          
    1433 if __name__ == "__main__":  
     1347        self.Destroy() 
     1348 
     1349 
     1350if __name__ == "__main__": 
    14341351    app = wx.PySimpleApp() 
    14351352    widget.CHILD_FRAME = wx.Frame 
    1436     frame = ResolutionWindow()     
     1353    frame = ResolutionWindow() 
    14371354    frame.Show(True) 
    1438     app.MainLoop()      
     1355    app.MainLoop() 
Note: See TracChangeset for help on using the changeset viewer.