Changeset 8b21fa7 in sasview


Ignore:
Timestamp:
Mar 6, 2015 12:05:50 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:
b1e609c
Parents:
c1c14ba
Message:

pylint fixes

Location:
src/sas/perspectives/pr
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/sas/perspectives/pr/explore_dialog.py

    r79492222 r8b21fa7  
    33#This software was developed by the University of Tennessee as part of the 
    44#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    5 #project funded by the US National Science Foundation.  
     5#project funded by the US National Science Foundation. 
    66# 
    77#See the license text in license.txt 
     
    1616their distribution as a function of D_max. 
    1717""" 
    18      
     18 
    1919 
    2020import wx 
    2121import numpy 
    22 import math 
    2322import logging 
    2423import sys 
    2524 
    26 # Avoid Matplotlib complaining about the lack of legend on the plot  
     25# Avoid Matplotlib complaining about the lack of legend on the plot 
    2726import warnings 
    2827warnings.simplefilter("ignore") 
     
    4645    of D_max 
    4746    """ 
    48     def __init__(self, d_min, d_max, parent, id = -1, color = None,\ 
    49         dpi = None, style = wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): 
     47    def __init__(self, d_min, d_max, parent, id= -1, color=None, \ 
     48                 dpi=None, style=wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): 
    5049        """ 
    5150        Initialization. The parameters added to PlotPanel are: 
    52          
     51 
    5352        :param d_min: Minimum value of D_max to explore 
    5453        :param d_max: Maximum value of D_max to explore 
    55          
    56         """ 
    57         PlotPanel.__init__(self, parent, id = id, style = style, **kwargs) 
     54 
     55        """ 
     56        PlotPanel.__init__(self, parent, id=id, style=style, **kwargs) 
    5857 
    5958        self.parent = parent 
     
    6261        self.npts = DEFAULT_NPTS 
    6362 
    64         step = (self.max-self.min)/(self.npts-1) 
    65         self.x = numpy.arange(self.min, self.max+step*0.01, step) 
     63        step = (self.max - self.min) / (self.npts - 1) 
     64        self.x = numpy.arange(self.min, self.max + step * 0.01, step) 
    6665        dx = numpy.zeros(len(self.x)) 
    6766        y = numpy.ones(len(self.x)) 
    6867        dy = numpy.zeros(len(self.x)) 
    69   
     68 
    7069        # Plot area 
    7170        self.plot = Model1D(self.x, y=y, dy=dy) 
     
    7675        self.graph = Graph() 
    7776        self.graph.xaxis("\\rm{D_{max}}", 'A') 
    78         self.graph.yaxis("\\rm{%s}" % DEFAULT_OUTPUT,"") 
     77        self.graph.yaxis("\\rm{%s}" % DEFAULT_OUTPUT, "") 
    7978        self.graph.add(self.plot) 
    8079        self.graph.render(self) 
    81          
     80 
    8281        self.toolbar.DeleteToolByPos(0) 
    8382        self.toolbar.DeleteToolByPos(8) 
     
    8786        """ 
    8887        Default context menu for the plot panel 
    89          
     88 
    9089        :TODO: Would be nice to add printing and log/linear scales. 
    91             The current verison of plottools no longer plays well with  
    92             plots outside of guiframe. Guiframe team needs to fix this.  
     90            The current verison of plottools no longer plays well with 
     91            plots outside of guiframe. Guiframe team needs to fix this. 
    9392        """ 
    9493        # Slicer plot popup menu 
    95         id = wx.NewId() 
     94        wx_id = wx.NewId() 
    9695        slicerpop = wx.Menu() 
    97         slicerpop.Append(id, '&Save image', 'Save image as PNG') 
    98         wx.EVT_MENU(self, id, self.onSaveImage) 
    99          
    100         id = wx.NewId() 
     96        slicerpop.Append(wx_id, '&Save image', 'Save image as PNG') 
     97        wx.EVT_MENU(self, wx_id, self.onSaveImage) 
     98 
     99        wx_id = wx.NewId() 
    101100        slicerpop.AppendSeparator() 
    102         slicerpop.Append(id, '&Reset Graph') 
    103         wx.EVT_MENU(self, id, self.onResetGraph) 
    104         
     101        slicerpop.Append(wx_id, '&Reset Graph') 
     102        wx.EVT_MENU(self, wx_id, self.onResetGraph) 
     103 
    105104        pos = event.GetPosition() 
    106105        pos = self.ScreenToClient(pos) 
    107106        self.PopupMenu(slicerpop, pos) 
    108107 
    109 class Results: 
     108class Results(object): 
    110109    """ 
    111110    Class to hold the inversion output parameters 
     
    126125        self.bck = [] 
    127126        self.d_max = [] 
    128          
     127 
    129128        # Dictionary of outputs 
    130129        self.outputs = {} 
    131         self.outputs['Chi2/dof'] = ["\chi^2/dof", "a.u.", self.chi2]     
    132         self.outputs['Oscillation parameter'] = ["Osc", "a.u.", self.osc]     
    133         self.outputs['Positive fraction'] = ["P^+", "a.u.", self.pos]     
    134         self.outputs['1-sigma positive fraction'] = ["P^+_{1\ \sigma}",  
    135                                                      "a.u.", self.pos_err]     
    136         self.outputs['Rg'] = ["R_g", "A", self.rg]     
    137         self.outputs['I(q=0)'] = ["I(q=0)", "1/A", self.iq0]     
    138         self.outputs['Background'] = ["Bck", "1/A", self.bck]  
    139          
     130        self.outputs['Chi2/dof'] = ["\chi^2/dof", "a.u.", self.chi2] 
     131        self.outputs['Oscillation parameter'] = ["Osc", "a.u.", self.osc] 
     132        self.outputs['Positive fraction'] = ["P^+", "a.u.", self.pos] 
     133        self.outputs['1-sigma positive fraction'] = ["P^+_{1\ \sigma}", 
     134                                                     "a.u.", self.pos_err] 
     135        self.outputs['Rg'] = ["R_g", "A", self.rg] 
     136        self.outputs['I(q=0)'] = ["I(q=0)", "1/A", self.iq0] 
     137        self.outputs['Background'] = ["Bck", "1/A", self.bck] 
     138 
    140139class ExploreDialog(wx.Dialog): 
    141140    """ 
     
    143142    invoked by the InversionControl class. 
    144143    """ 
    145      
     144 
    146145    def __init__(self, pr_state, nfunc, *args, **kwds): 
    147146        """ 
    148147        Initialization. The parameters added to Dialog are: 
    149          
     148 
    150149        :param pr_state: sas.pr.invertor.Invertor object 
    151150        :param nfunc: Number of terms in the expansion 
    152          
    153         """ 
    154         kwds["style"] = wx.RESIZE_BORDER|wx.DEFAULT_DIALOG_STYLE 
     151 
     152        """ 
     153        kwds["style"] = wx.RESIZE_BORDER | wx.DEFAULT_DIALOG_STYLE 
    155154        wx.Dialog.__init__(self, *args, **kwds) 
    156          
     155 
    157156        # Initialize Results object 
    158157        self.results = Results() 
    159          
    160         self.pr_state  = pr_state 
    161         self._default_min = 0.9*self.pr_state.d_max 
    162         self._default_max = 1.1*self.pr_state.d_max 
    163         self.nfunc     = nfunc 
    164          
     158 
     159        self.pr_state = pr_state 
     160        self._default_min = 0.9 * self.pr_state.d_max 
     161        self._default_max = 1.1 * self.pr_state.d_max 
     162        self.nfunc = nfunc 
     163 
    165164        # Control for number of points 
    166165        self.npts_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 
    167                                    size=(60,20)) 
     166                                   size=(60, 20)) 
    168167        # Control for the minimum value of D_max 
    169168        self.dmin_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 
    170                                    size=(60,20)) 
     169                                   size=(60, 20)) 
    171170        # Control for the maximum value of D_max 
    172171        self.dmax_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 
    173                                    size=(60,20)) 
     172                                   size=(60, 20)) 
    174173 
    175174        # Output selection box for the y axis 
     
    179178        self.plotpanel = OutputPlot(self._default_min, self._default_max, 
    180179                                    self, -1, style=wx.RAISED_BORDER) 
    181          
     180 
    182181        # Create the layout of the dialog 
    183182        self.__do_layout() 
    184183        self.Fit() 
    185          
     184 
    186185        # Calculate exploration results 
    187186        self._recalc() 
    188187        # Graph the default output curve 
    189188        self._plot_output() 
    190          
    191     class Event: 
     189 
     190    class Event(object): 
    192191        """ 
    193192        Class that holds the content of the form 
    194193        """ 
    195194        ## Number of points to be plotted 
    196         npts   = 0 
     195        npts = 0 
    197196        ## Minimum value of D_max 
    198         dmin   = 0 
     197        dmin = 0 
    199198        ## Maximum value of D_max 
    200         dmax   = 0 
    201                  
     199        dmax = 0 
     200 
    202201    def _get_values(self, event=None): 
    203202        """ 
    204203        Invoked when the user changes a value of the form. 
    205204        Check that the values are of the right type. 
    206          
    207         :return: ExploreDialog.Event object if the content is good,  
     205 
     206        :return: ExploreDialog.Event object if the content is good, 
    208207            None otherwise 
    209208        """ 
    210209        # Flag to make sure that all values are good 
    211210        flag = True 
    212          
     211 
    213212        # Empty ExploreDialog.Event content 
    214213        content_event = self.Event() 
    215          
     214 
    216215        # Read each text control and make sure the type is valid 
    217216        # Let the user know if a type is invalid by changing the 
     
    225224            self.npts_ctl.SetBackgroundColour("pink") 
    226225            self.npts_ctl.Refresh() 
    227              
     226 
    228227        try: 
    229228            content_event.dmin = float(self.dmin_ctl.GetValue()) 
     
    234233            self.dmin_ctl.SetBackgroundColour("pink") 
    235234            self.dmin_ctl.Refresh() 
    236          
     235 
    237236        try: 
    238237            content_event.dmax = float(self.dmax_ctl.GetValue()) 
     
    243242            self.dmax_ctl.SetBackgroundColour("pink") 
    244243            self.dmax_ctl.Refresh() 
    245          
     244 
    246245        # If the content of the form is valid, return the content, 
    247246        # otherwise return None 
     
    252251        else: 
    253252            return None 
    254      
     253 
    255254    def _plot_output(self, event=None): 
    256255        """ 
    257         Invoked when a new output type is selected for plotting,  
     256        Invoked when a new output type is selected for plotting, 
    258257        or when a new computation is finished. 
    259258        """ 
    260259        # Get the output type selection 
    261260        output_type = self.output_box.GetString(self.output_box.GetSelection()) 
    262          
     261 
    263262        # If the selected output type is part of the results ojbect, 
    264         # display the results.  
     263        # display the results. 
    265264        # Note: by design, the output type should always be part of the 
    266265        #       results object. 
    267         if self.results.outputs.has_key(output_type):  
     266        if self.results.outputs.has_key(output_type): 
    268267            self.plotpanel.plot.x = self.results.d_max 
    269268            self.plotpanel.plot.y = self.results.outputs[output_type][2] 
     
    272271            self.plotpanel.graph.yaxis(y_label, 
    273272                                       self.results.outputs[output_type][1]) 
    274              
     273 
    275274            # Redraw 
    276275            self.plotpanel.graph.render(self.plotpanel) 
    277276            self.plotpanel.subplot.figure.canvas.draw_idle() 
    278277        else: 
    279             msg =  "ExploreDialog: the Results object's dictionary " 
     278            msg = "ExploreDialog: the Results object's dictionary " 
    280279            msg += "does not contain " 
    281280            msg += "the [%s] output type. This must be indicative of " 
     
    283282            msg += "ExploreDialog code." 
    284283            logging.error(msg) 
    285          
     284 
    286285    def __do_layout(self): 
    287286        """ 
     
    291290        self.SetTitle("D_max Explorer") 
    292291        self.SetSize((600, 595)) 
    293          
     292 
    294293        sizer_main = wx.BoxSizer(wx.VERTICAL) 
    295294        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
     
    298297        iy = 0 
    299298        ix = 0 
    300         label_npts  = wx.StaticText(self, -1, "Npts") 
    301         sizer_params.Add(label_npts, (iy, ix), (1, 1),  
    302                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     299        label_npts = wx.StaticText(self, -1, "Npts") 
     300        sizer_params.Add(label_npts, (iy, ix), (1, 1), 
     301                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    303302        ix += 1 
    304         sizer_params.Add(self.npts_ctl,   (iy, ix), (1, 1),  
    305                          wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     303        sizer_params.Add(self.npts_ctl, (iy, ix), (1, 1), 
     304                         wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    306305        self.npts_ctl.SetValue("%g" % DEFAULT_NPTS) 
    307306        self.npts_ctl.Bind(wx.EVT_KILL_FOCUS, self._recalc) 
    308          
     307 
    309308        ix += 1 
    310         label_dmin   = wx.StaticText(self, -1, "Min Distance [A]") 
     309        label_dmin = wx.StaticText(self, -1, "Min Distance [A]") 
    311310        sizer_params.Add(label_dmin, (iy, ix), (1, 1), 
    312                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     311                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    313312        ix += 1 
    314313        sizer_params.Add(self.dmin_ctl, (iy, ix), (1, 1), 
    315                          wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     314                         wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    316315        self.dmin_ctl.SetValue(str(self._default_min)) 
    317316        self.dmin_ctl.Bind(wx.EVT_KILL_FOCUS, self._recalc) 
    318          
     317 
    319318        ix += 1 
    320319        label_dmax = wx.StaticText(self, -1, "Max Distance [A]") 
    321320        sizer_params.Add(label_dmax, (iy, ix), (1, 1), 
    322                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     321                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    323322        ix += 1 
    324         sizer_params.Add(self.dmax_ctl,   (iy, ix), (1, 1), 
    325                          wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     323        sizer_params.Add(self.dmax_ctl, (iy, ix), (1, 1), 
     324                         wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    326325        self.dmax_ctl.SetValue(str(self._default_max)) 
    327326        self.dmax_ctl.Bind(wx.EVT_KILL_FOCUS, self._recalc) 
     
    334333            self.output_box.Append(item, "") 
    335334        self.output_box.SetStringSelection(DEFAULT_OUTPUT) 
    336          
     335 
    337336        output_sizer = wx.GridBagSizer(5, 5) 
    338337        output_sizer.Add(selection_msg, (0, 0), (1, 1), 
    339                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) 
     338                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 
    340339        output_sizer.Add(self.output_box, (0, 1), (1, 2), 
    341                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) 
    342          
    343         wx.EVT_COMBOBOX(self.output_box, -1, self._plot_output)  
     340                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 
     341 
     342        wx.EVT_COMBOBOX(self.output_box, -1, self._plot_output) 
    344343        sizer_main.Add(output_sizer, 0, wx.EXPAND | wx.ALL, 10) 
    345          
     344 
    346345        sizer_main.Add(self.plotpanel, 0, wx.EXPAND | wx.ALL, 10) 
    347346        sizer_main.SetItemMinSize(self.plotpanel, 400, 400) 
    348          
    349         sizer_main.Add(sizer_params, 0, wx.EXPAND|wx.ALL, 10) 
     347 
     348        sizer_main.Add(sizer_params, 0, wx.EXPAND | wx.ALL, 10) 
    350349        static_line_3 = wx.StaticLine(self, -1) 
    351350        sizer_main.Add(static_line_3, 0, wx.EXPAND, 0) 
    352          
     351 
    353352        # Bottom area with the close button 
    354         sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     353        sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    355354        button_OK = wx.Button(self, wx.ID_OK, "Close") 
    356         sizer_button.Add(button_OK, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
    357          
    358         sizer_main.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 
     355        sizer_button.Add(button_OK, 0, wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 
     356 
     357        sizer_main.Add(sizer_button, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 10) 
    359358        self.SetAutoLayout(True) 
    360359        self.SetSizer(sizer_main) 
    361360        self.Layout() 
    362361        self.Centre() 
    363          
     362 
    364363        # Bind the Enter key to recalculation 
    365364        self.Bind(wx.EVT_TEXT_ENTER, self._recalc) 
     
    370369        """ 
    371370        pass 
    372      
     371 
    373372    def _recalc(self, event=None): 
    374373        """ 
     
    381380        if content is None: 
    382381            return 
    383          
     382 
    384383        # Results object to store the computation outputs. 
    385384        results = Results() 
    386          
     385 
    387386        # Loop over d_max values 
    388         for i in range(content.npts):  
    389             temp = (content.dmax - content.dmin)/(content.npts - 1.0)    
     387        for i in range(content.npts): 
     388            temp = (content.dmax - content.dmin) / (content.npts - 1.0) 
    390389            d = content.dmin + i * temp 
    391                  
     390 
    392391            self.pr_state.d_max = d 
    393392            try: 
    394                 out, cov = self.pr_state.invert(self.nfunc)    
    395              
     393                out, cov = self.pr_state.invert(self.nfunc) 
     394 
    396395                # Store results 
    397396                iq0 = self.pr_state.iq0(out) 
     
    400399                pos_err = self.pr_state.get_pos_err(out, cov) 
    401400                osc = self.pr_state.oscillations(out) 
    402              
     401 
    403402                results.d_max.append(self.pr_state.d_max) 
    404403                results.bck.append(self.pr_state.background) 
     
    408407                results.pos.append(pos) 
    409408                results.pos_err.append(pos_err) 
    410                 results.osc.append(osc)            
     409                results.osc.append(osc) 
    411410            except: 
    412411                # This inversion failed, skip this D_max value 
     
    414413                msg += "for D_max=%s\n%s" % (str(d), sys.exc_value) 
    415414                logging.error(msg) 
    416              
    417         self.results = results             
    418           
     415 
     416        self.results = results 
     417 
    419418        # Plot the selected output 
    420         self._plot_output()    
    421              
    422 ##### testing code ############################################################ 
    423 """ 
    424 Example: :: 
    425  
    426 class MyApp(wx.App): 
    427      
    428     #Test application used to invoke the ExploreDialog for testing 
    429     
    430     def OnInit(self): 
    431         from inversion_state import Reader 
    432         from sas.pr.invertor import Invertor 
    433         wx.InitAllImageHandlers() 
    434          
    435         def call_back(state, datainfo=None): 
    436              
    437             #Dummy call-back method used by the P(r)  
    438             #file reader. 
    439              
    440             print state 
    441              
    442         # Load test data 
    443         # This would normally be loaded by the application  
    444         # of the P(r) plug-in. 
    445         r = Reader(call_back) 
    446         data = r.read("test_pr_data.prv") 
    447         pr_state = data.meta_data['prstate'] 
    448          
    449         # Create Invertor object for the data 
    450         # This would normally be assembled by the P(r) plug-in 
    451         pr = Invertor() 
    452         pr.d_max = pr_state.d_max 
    453         pr.alpha = pr_state.alpha 
    454         pr.q_min = pr_state.qmin 
    455         pr.q_max = pr_state.qmax 
    456         pr.x = data.x 
    457         pr.y = data.y 
    458         pr.err = data.y*0.1 
    459         pr.has_bck = False 
    460         pr.slit_height = pr_state.height 
    461         pr.slit_width = pr_state.width 
    462          
    463         # Create the dialog 
    464         dialog = ExploreDialog(pr, 10, None, -1, "") 
    465         self.SetTopWindow(dialog) 
    466         dialog.ShowModal() 
    467         dialog.Destroy() 
    468  
    469         return 1 
    470  
    471 if __name__ == "__main__": 
    472     app = MyApp(0) 
    473     app.MainLoop() 
    474      
    475 """  
     419        self._plot_output() 
  • src/sas/perspectives/pr/inversion_panel.py

    r79492222 r8b21fa7  
    1010import logging 
    1111from wx.lib.scrolledpanel import ScrolledPanel 
    12 from sas.guiframe.events import StatusEvent    
    13 from sas.guiframe.panel_base import PanelBase  
     12from sas.guiframe.events import StatusEvent 
     13from sas.guiframe.panel_base import PanelBase 
    1414from inversion_state import InversionState 
    1515from pr_widgets import PrTextCtrl 
     
    2828    window_caption = "P(r) control panel" 
    2929    CENTER_PANE = True 
    30      
     30 
    3131    # Figure of merit parameters [default] 
    32      
     32 
    3333    ## Oscillation parameters (sin function = 1.1) 
    3434    oscillation_max = 1.5 
    35      
    36     def __init__(self, parent, id=-1, plots=None,  
    37                  standalone=False, **kwargs): 
     35 
     36    def __init__(self, parent, id=-1, plots=None, standalone=False, **kwargs): 
    3837        """ 
    3938        """ 
     
    4140        PanelBase.__init__(self, parent) 
    4241        self.SetupScrolling() 
    43         #Set window's font size  
     42        #Set window's font size 
    4443        self.SetWindowVariant(variant=FONT_VARIANT) 
    45          
     44 
    4645        self.plots = plots 
    4746        self.radio_buttons = {} 
    4847        self.parent = parent.parent 
    49          
     48 
    5049        ## Data file TextCtrl 
    51         self.data_file  = None 
    52         self.plot_data  = None 
    53         self.nfunc_ctl  = None 
    54         self.alpha_ctl  = None 
    55         self.dmax_ctl   = None 
    56         self.time_ctl   = None 
    57         self.chi2_ctl   = None 
    58         self.osc_ctl    = None 
     50        self.data_file = None 
     51        self.plot_data = None 
     52        self.nfunc_ctl = None 
     53        self.alpha_ctl = None 
     54        self.dmax_ctl = None 
     55        self.time_ctl = None 
     56        self.chi2_ctl = None 
     57        self.osc_ctl = None 
    5958        self.file_radio = None 
    6059        self.plot_radio = None 
    6160        self.label_sugg = None 
    62         self.qmin_ctl   = None 
    63         self.qmax_ctl   = None 
     61        self.qmin_ctl = None 
     62        self.qmax_ctl = None 
    6463        self.swidth_ctl = None 
    6564        self.sheight_ctl = None 
    66          
    67         self.rg_ctl     = None 
    68         self.iq0_ctl    = None 
    69         self.bck_chk    = None 
    70         self.bck_ctl    = None 
    71          
     65 
     66        self.rg_ctl = None 
     67        self.iq0_ctl = None 
     68        self.bck_chk = None 
     69        self.bck_ctl = None 
     70 
    7271        # TextCtrl for fraction of positive P(r) 
    7372        self.pos_ctl = None 
    74          
     73 
    7574        # TextCtrl for fraction of 1 sigma positive P(r) 
    76         self.pos_err_ctl = None  
    77          
     75        self.pos_err_ctl = None 
     76 
    7877        ## Estimates 
    7978        self.alpha_estimate_ctl = None 
     
    8281        self.distance_explorator_ctl = None 
    8382        ## Data manager 
    84         self._manager   = None 
     83        self._manager = None 
    8584        ## Standalone flage 
    8685        self.standalone = standalone 
     
    8887        self._default_save_location = os.getcwd() 
    8988        if self.parent is not None: 
    90             self._default_save_location =\ 
     89            self._default_save_location = \ 
    9190                        self.parent._default_save_location 
    92          
     91 
    9392        # Default width 
    9493        self._default_width = 350 
    9594        self._do_layout() 
    96          
     95 
    9796    def __setattr__(self, name, value): 
    9897        """ 
     
    115114        elif name == 'elapsed': 
    116115            self.time_ctl.SetValue("%-5.2g" % value) 
    117         elif name =='rg': 
     116        elif name == 'rg': 
    118117            self.rg_ctl.SetValue("%-5.2g" % value) 
    119118        elif name == 'iq0': 
     
    147146        else: 
    148147            wx.Panel.__setattr__(self, name, value) 
    149          
     148 
    150149    def __getattr__(self, name): 
    151150        """ 
     
    182181            except: 
    183182                return 0.0 
    184         elif name=='q_max': 
     183        elif name == 'q_max': 
    185184            try: 
    186185                return float(self.qmax_ctl.GetValue()) 
     
    197196            except: 
    198197                return None 
    199         elif name=='iq0': 
     198        elif name == 'iq0': 
    200199            try: 
    201200                return float(self.iq0_ctl.GetValue()) 
     
    212211            except: 
    213212                return None 
    214         elif name=='slit_height': 
     213        elif name == 'slit_height': 
    215214            try: 
    216215                return float(self.sheight_ctl.GetValue()) 
     
    243242        else: 
    244243            return wx.Panel.__getattribute__(self, name) 
    245          
     244 
    246245    def save_project(self, doc=None): 
    247246        """ 
     
    260259                else: 
    261260                    doc = new_doc 
    262         return doc    
    263      
     261        return doc 
     262 
    264263    def on_save(self, evt=None): 
    265264        """ 
    266265        Method used to create a memento of the current state 
    267              
    268         :return: state object  
     266 
     267        :return: state object 
    269268        """ 
    270269        # Ask the user the location of the file to write to. 
    271270        path = None 
    272271        if self.parent != None: 
    273             self._default_save_location =\ 
    274              self.parent._default_save_location 
     272            self._default_save_location = self.parent._default_save_location 
    275273        dlg = wx.FileDialog(self, "Choose a file", 
    276                             self._default_save_location,\ 
     274                            self._default_save_location, 
    277275                            self.window_caption, "*.prv", wx.SAVE) 
    278276        if dlg.ShowModal() == wx.ID_OK: 
     
    280278            self._default_save_location = os.path.dirname(path) 
    281279            if self.parent != None: 
    282                 self.parent._default_save_location =\ 
    283                 self._default_save_location 
     280                self.parent._default_save_location = self._default_save_location 
    284281        else: 
    285282            return None 
    286          
     283 
    287284        dlg.Destroy() 
    288          
     285 
    289286        state = self.get_state() 
    290          
     287 
    291288        # MAC always needs the extension for saving 
    292289        extens = ".prv" 
     
    294291        fName = os.path.splitext(path)[0] + extens 
    295292        self._manager.save_data(filepath=fName, prstate=state) 
    296          
     293 
    297294        return state 
    298      
     295 
    299296    def get_data(self): 
    300297        """ 
    301298        """ 
    302299        return self._manager.get_data() 
    303      
     300 
    304301    def get_state(self): 
    305302        """ 
    306303        Get the current state 
    307          
     304 
    308305        : return: state object 
    309306        """ 
    310         # Construct the state object     
     307        # Construct the state object 
    311308        state = InversionState() 
    312          
     309 
    313310        # Read the panel's parameters 
    314311        flag, alpha, dmax, nfunc, qmin, \ 
    315312        qmax, height, width = self._read_pars() 
    316          
     313 
    317314        state.nfunc = nfunc 
    318315        state.d_max = dmax 
    319316        state.alpha = alpha 
    320         state.qmin  = qmin 
    321         state.qmax  = qmax 
     317        state.qmin = qmin 
     318        state.qmax = qmax 
    322319        state.width = width 
    323320        state.height = height 
    324          
     321 
    325322        # Data file 
    326323        state.file = self.plot_data.GetValue() 
    327          
     324 
    328325        # Background evaluation checkbox 
    329326        state.estimate_bck = self.bck_chk.IsChecked() 
    330          
     327 
    331328        # Estimates 
    332329        state.nterms_estimate = self.nterms_estimate 
    333330        state.alpha_estimate = self.alpha_estimate 
    334          
     331 
    335332        # Read the output values 
    336         state.chi2    = self.chi2 
     333        state.chi2 = self.chi2 
    337334        state.elapsed = self.elapsed 
    338         state.osc     = self.oscillation 
    339         state.pos     = self.pos 
     335        state.osc = self.oscillation 
     336        state.pos = self.pos 
    340337        state.pos_err = self.pos_err 
    341         state.rg      = self.rg 
    342         state.iq0     = self.iq0 
    343         state.bck     = self.bck 
    344          
     338        state.rg = self.rg 
     339        state.iq0 = self.iq0 
     340        state.bck = self.bck 
     341 
    345342        return state 
    346      
     343 
    347344    def set_state(self, state): 
    348345        """ 
    349346        Set the state of the panel and inversion problem to 
    350347        the state passed as a parameter. 
    351         Execute the inversion immediately after filling the  
     348        Execute the inversion immediately after filling the 
    352349        controls. 
    353          
     350 
    354351        :param state: InversionState object 
    355352        """ 
     
    361358            self.alpha = state.alpha 
    362359        if state.qmin is not None: 
    363             self.q_min  = state.qmin 
     360            self.q_min = state.qmin 
    364361        if state.qmax is not None: 
    365             self.q_max  = state.qmax 
     362            self.q_max = state.qmax 
    366363        if state.width is not None: 
    367364            self.slit_width = state.width 
    368365        if state.height is not None: 
    369366            self.slit_height = state.height 
    370          
     367 
    371368        # Data file 
    372369        self.plot_data.SetValue(str(state.file)) 
    373      
     370 
    374371        # Background evaluation checkbox 
    375372        self.bck_chk.SetValue(state.estimate_bck) 
    376          
     373 
    377374        # Estimates 
    378375        if state.nterms_estimate is not None: 
    379376            self.nterms_estimate = state.nterms_estimate 
    380         if state.alpha_estimate is not None:  
    381             self.alpha_estimate = state.alpha_estimate  
    382      
    383          
     377        if state.alpha_estimate is not None: 
     378            self.alpha_estimate = state.alpha_estimate 
     379 
     380 
    384381        # Read the output values 
    385382        if state.chi2 is not None: 
    386             self.chi2    = state.chi2 
     383            self.chi2 = state.chi2 
    387384        if state.elapsed is not None: 
    388385            self.elapsed = state.elapsed 
     
    394391            self.pos_err = state.pos_err 
    395392        if state.rg is not None: 
    396             self.rg      = state.rg 
     393            self.rg = state.rg 
    397394        if state.iq0 is not None: 
    398             self.iq0     = state.iq0 
     395            self.iq0 = state.iq0 
    399396        if state.bck is not None: 
    400             self.bck     = state.bck 
     397            self.bck = state.bck 
    401398 
    402399        # Perform inversion 
    403         self._on_invert(None)     
    404          
     400        self._on_invert(None) 
     401 
    405402    def set_manager(self, manager): 
    406403        self._manager = manager 
    407          
     404 
    408405    def _do_layout(self): 
    409         vbox = wx.GridBagSizer(0,0) 
     406        vbox = wx.GridBagSizer(0, 0) 
    410407        iy_vb = 0 
    411408 
    412409        # ----- I(q) data ----- 
    413410        databox = wx.StaticBox(self, -1, "I(q) data source") 
    414          
     411 
    415412        boxsizer1 = wx.StaticBoxSizer(databox, wx.VERTICAL) 
    416413        boxsizer1.SetMinSize((self._default_width, 50)) 
     
    420417        self.file_radio = wx.StaticText(self, -1, "Name:") 
    421418        pars_sizer.Add(self.file_radio, (iy, 0), (1, 1), 
    422                        wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    423          
    424         self.plot_data = DataFileTextCtrl(self, -1, size=(260,20)) 
    425          
     419                       wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     420 
     421        self.plot_data = DataFileTextCtrl(self, -1, size=(260, 20)) 
     422 
    426423        pars_sizer.Add(self.plot_data, (iy, 1), (1, 1), 
    427                        wx.EXPAND|wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 15) 
    428          
     424                       wx.EXPAND | wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 15) 
     425 
    429426        self.bck_chk = wx.CheckBox(self, -1, "Estimate background level") 
    430427        hint_msg = "Check box to let the fit estimate " 
     
    434431        iy += 1 
    435432        pars_sizer.Add(self.bck_chk, (iy, 0), (1, 2), 
    436                        wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    437         boxsizer1.Add(pars_sizer, 0, wx.EXPAND)   
     433                       wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     434        boxsizer1.Add(pars_sizer, 0, wx.EXPAND) 
    438435        vbox.Add(boxsizer1, (iy_vb, 0), (1, 1), 
    439                  wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE|wx.TOP, 5) 
    440          
     436                 wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE | wx.TOP, 5) 
     437 
    441438        # ----- Add slit parameters ----- 
    442439        if True: 
     
    444441            sboxsizer = wx.StaticBoxSizer(sbox, wx.VERTICAL) 
    445442            sboxsizer.SetMinSize((self._default_width, 20)) 
    446              
     443 
    447444            sizer_slit = wx.GridBagSizer(5, 5) 
    448      
     445 
    449446            label_sheight = wx.StaticText(self, -1, "Height", size=(40, 20)) 
    450447            label_swidth = wx.StaticText(self, -1, "Width", size=(40, 20)) 
    451             #label_sunits1 = wx.StaticText(self, -1, "[A^(-1)]") 
    452             label_sunits2 = wx.StaticText(self, -1, "[A^(-1)]", size=(55,20)) 
    453             self.sheight_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 
    454                                           size=(60,20)) 
    455             self.swidth_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 
    456                                          size=(60,20)) 
     448            label_sunits2 = wx.StaticText(self, -1, "[A^(-1)]", size=(55, 20)) 
     449            self.sheight_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60, 20)) 
     450            self.swidth_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60, 20)) 
    457451            hint_msg = "Enter slit height in units of Q or leave blank." 
    458452            self.sheight_ctl.SetToolTipString(hint_msg) 
    459453            hint_msg = "Enter slit width in units of Q or leave blank." 
    460454            self.swidth_ctl.SetToolTipString(hint_msg) 
    461             #self.sheight_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) 
    462             #self.swidth_ctl.Bind(wx.EVT_TEXT,  self._on_pars_changed) 
    463              
     455 
    464456            iy = 0 
    465             sizer_slit.Add(label_sheight,    (iy, 0), (1, 1), 
    466                            wx.LEFT|wx.EXPAND, 5) 
    467             sizer_slit.Add(self.sheight_ctl, (iy, 1), (1, 1), 
    468                            wx.LEFT|wx.EXPAND, 5) 
    469      
    470             sizer_slit.Add(label_swidth,     (iy, 2), (1, 1), 
    471                            wx.LEFT|wx.EXPAND, 5) 
    472             sizer_slit.Add(self.swidth_ctl,  (iy, 3), (1, 1), 
    473                            wx.LEFT|wx.EXPAND, 5) 
    474             sizer_slit.Add(label_sunits2,    (iy, 4), (1, 1), 
    475                            wx.LEFT|wx.EXPAND, 5) 
    476              
     457            sizer_slit.Add(label_sheight, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 5) 
     458            sizer_slit.Add(self.sheight_ctl, (iy, 1), (1, 1), wx.LEFT | wx.EXPAND, 5) 
     459            sizer_slit.Add(label_swidth, (iy, 2), (1, 1), wx.LEFT | wx.EXPAND, 5) 
     460            sizer_slit.Add(self.swidth_ctl, (iy, 3), (1, 1), wx.LEFT | wx.EXPAND, 5) 
     461            sizer_slit.Add(label_sunits2, (iy, 4), (1, 1), wx.LEFT | wx.EXPAND, 5) 
     462 
    477463            sboxsizer.Add(sizer_slit, wx.TOP, 15) 
    478464            iy_vb += 1 
    479465            vbox.Add(sboxsizer, (iy_vb, 0), (1, 1), 
    480                      wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 
    481          
    482          
     466                     wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 
     467 
    483468        # ----- Q range ----- 
    484469        qbox = wx.StaticBox(self, -1, "Q range") 
    485470        qboxsizer = wx.StaticBoxSizer(qbox, wx.VERTICAL) 
    486471        qboxsizer.SetMinSize((self._default_width, 20)) 
    487          
     472 
    488473        sizer_q = wx.GridBagSizer(5, 5) 
    489474 
    490475        label_qmin = wx.StaticText(self, -1, "Q min", size=(40, 20)) 
    491476        label_qmax = wx.StaticText(self, -1, "Q max", size=(40, 20)) 
    492         #label_qunits1 = wx.StaticText(self, -1, "[A^(-1)]") 
    493477        label_qunits2 = wx.StaticText(self, -1, "[A^(-1)]", size=(55, 20)) 
    494         self.qmin_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 
    495                                    size=(60,20)) 
    496         self.qmax_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 
    497                                    size=(60,20)) 
     478        self.qmin_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60, 20)) 
     479        self.qmax_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60, 20)) 
    498480        hint_msg = "Select a lower bound for Q or leave blank." 
    499481        self.qmin_ctl.SetToolTipString(hint_msg) 
     
    502484        self.qmin_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) 
    503485        self.qmax_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) 
    504          
     486 
    505487        iy = 0 
    506         sizer_q.Add(label_qmin,    (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 5) 
    507         sizer_q.Add(self.qmin_ctl, (iy, 1), (1, 1), wx.LEFT|wx.EXPAND, 5) 
    508         #sizer_q.Add(label_qunits1, (iy,2), (1,1), wx.LEFT|wx.EXPAND, 15) 
    509         sizer_q.Add(label_qmax,    (iy, 2), (1, 1), wx.LEFT|wx.EXPAND, 5) 
    510         sizer_q.Add(self.qmax_ctl, (iy, 3), (1, 1), wx.LEFT|wx.EXPAND, 5) 
    511         sizer_q.Add(label_qunits2, (iy, 4), (1, 1), wx.LEFT|wx.EXPAND, 5) 
     488        sizer_q.Add(label_qmin, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 5) 
     489        sizer_q.Add(self.qmin_ctl, (iy, 1), (1, 1), wx.LEFT | wx.EXPAND, 5) 
     490        sizer_q.Add(label_qmax, (iy, 2), (1, 1), wx.LEFT | wx.EXPAND, 5) 
     491        sizer_q.Add(self.qmax_ctl, (iy, 3), (1, 1), wx.LEFT | wx.EXPAND, 5) 
     492        sizer_q.Add(label_qunits2, (iy, 4), (1, 1), wx.LEFT | wx.EXPAND, 5) 
    512493        qboxsizer.Add(sizer_q, wx.TOP, 15) 
    513494 
    514495        iy_vb += 1 
    515         vbox.Add(qboxsizer, (iy_vb,0), (1,1), 
    516                  wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 
    517      
     496        vbox.Add(qboxsizer, (iy_vb, 0), (1, 1), 
     497                 wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 
     498 
    518499        # ----- Parameters ----- 
    519500        parsbox = wx.StaticBox(self, -1, "Parameters") 
    520501        boxsizer2 = wx.StaticBoxSizer(parsbox, wx.VERTICAL) 
    521         boxsizer2.SetMinSize((self._default_width,50)) 
    522          
    523         explanation  = "P(r) is found by fitting a set of base functions" 
     502        boxsizer2.SetMinSize((self._default_width, 50)) 
     503 
     504        explanation = "P(r) is found by fitting a set of base functions" 
    524505        explanation += " to I(Q). The minimization involves" 
    525506        explanation += " a regularization term to ensure a smooth P(r)." 
    526         explanation += " The regularization constant gives the size of that "   
     507        explanation += " The regularization constant gives the size of that " 
    527508        explanation += "term. The suggested value is the value above which the" 
    528509        explanation += " output P(r) will have only one peak." 
    529         label_explain = wx.StaticText(self, -1, explanation, size=(280,90)) 
    530         boxsizer2.Add(label_explain,  wx.LEFT|wx.BOTTOM, 5) 
    531          
    532          
    533          
     510        label_explain = wx.StaticText(self, -1, explanation, size=(280, 90)) 
     511        boxsizer2.Add(label_explain, wx.LEFT | wx.BOTTOM, 5) 
     512 
    534513        label_nfunc = wx.StaticText(self, -1, "Number of terms") 
    535514        label_nfunc.SetMinSize((120, 20)) 
    536515        label_alpha = wx.StaticText(self, -1, "Regularization constant") 
    537         label_dmax  = wx.StaticText(self, -1, "Max distance [A]") 
    538         self.label_sugg  = wx.StaticText(self, -1, "Suggested value") 
    539         #self.label_sugg.Hide() 
    540          
    541         self.nfunc_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 
    542                                     size=(60,20)) 
     516        label_dmax = wx.StaticText(self, -1, "Max distance [A]") 
     517        self.label_sugg = wx.StaticText(self, -1, "Suggested value") 
     518 
     519        self.nfunc_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60, 20)) 
    543520        self.nfunc_ctl.SetToolTipString("Number of terms in the expansion.") 
    544         self.alpha_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 
    545                                     size=(60,20)) 
     521        self.alpha_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60, 20)) 
    546522        hint_msg = "Control parameter for the size of the regularization term." 
    547523        self.alpha_ctl.SetToolTipString(hint_msg) 
    548         self.dmax_ctl  = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 
    549                                     size=(60,20)) 
     524        self.dmax_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60, 20)) 
    550525        hint_msg = "Maximum distance between any two points in the system." 
    551526        self.dmax_ctl.SetToolTipString(hint_msg) 
    552         id = wx.NewId() 
    553         self.alpha_estimate_ctl  = wx.Button(self, id, "") 
    554         #self.alpha_estimate_ctl.Hide() 
    555         self.Bind(wx.EVT_BUTTON, self._on_accept_alpha, id = id)    
     527        wx_id = wx.NewId() 
     528        self.alpha_estimate_ctl = wx.Button(self, wx_id, "") 
     529        self.Bind(wx.EVT_BUTTON, self._on_accept_alpha, id=wx_id) 
    556530        self.alpha_estimate_ctl.Enable(False) 
    557         #self.alpha_estimate_ctl.SetBackgroundColour('#ffdf85') 
    558         #self.alpha_estimate_ctl.SetBackgroundColour(self.GetBackgroundColour()) 
    559531        self.alpha_estimate_ctl.SetToolTipString("Waiting for estimate...") 
    560          
    561         id = wx.NewId() 
    562         self.nterms_estimate_ctl  = wx.Button(self, id, "") 
     532 
     533        wx_id = wx.NewId() 
     534        self.nterms_estimate_ctl = wx.Button(self, wx_id, "") 
    563535        #self.nterms_estimate_ctl.Hide() 
    564         self.Bind(wx.EVT_BUTTON, self._on_accept_nterms, id = id)    
     536        self.Bind(wx.EVT_BUTTON, self._on_accept_nterms, id=wx_id) 
    565537        self.nterms_estimate_ctl.Enable(False) 
    566        
     538 
    567539        self.nterms_estimate_ctl.SetToolTipString("Waiting for estimate...") 
    568          
     540 
    569541        self.nfunc_ctl.Bind(wx.EVT_TEXT, self._read_pars) 
    570542        self.alpha_ctl.Bind(wx.EVT_TEXT, self._read_pars) 
    571543        self.dmax_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) 
    572          
     544 
    573545        # Distance explorator 
    574         id = wx.NewId() 
    575         self.distance_explorator_ctl = wx.Button(self, id, "Explore") 
    576         self.Bind(wx.EVT_BUTTON, self._on_explore, id = id)            
    577          
    578          
    579         sizer_params = wx.GridBagSizer(5,5) 
     546        wx_id = wx.NewId() 
     547        self.distance_explorator_ctl = wx.Button(self, wx_id, "Explore") 
     548        self.Bind(wx.EVT_BUTTON, self._on_explore, id=wx_id) 
     549 
     550 
     551        sizer_params = wx.GridBagSizer(5, 5) 
    580552 
    581553        iy = 0 
    582554        sizer_params.Add(self.label_sugg, (iy, 2), (1, 1), wx.LEFT, 15) 
    583555        iy += 1 
    584         sizer_params.Add(label_nfunc,      (iy, 0), (1, 1), wx.LEFT, 15) 
    585         sizer_params.Add(self.nfunc_ctl,   (iy, 1), (1, 1), wx.RIGHT, 0) 
     556        sizer_params.Add(label_nfunc, (iy, 0), (1, 1), wx.LEFT, 15) 
     557        sizer_params.Add(self.nfunc_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) 
    586558        sizer_params.Add(self.nterms_estimate_ctl, (iy, 2), (1, 1), wx.LEFT, 15) 
    587559        iy += 1 
    588         sizer_params.Add(label_alpha,      (iy, 0), (1, 1), wx.LEFT, 15) 
    589         sizer_params.Add(self.alpha_ctl,   (iy, 1), (1, 1), wx.RIGHT, 0) 
     560        sizer_params.Add(label_alpha, (iy, 0), (1, 1), wx.LEFT, 15) 
     561        sizer_params.Add(self.alpha_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) 
    590562        sizer_params.Add(self.alpha_estimate_ctl, (iy, 2), (1, 1), wx.LEFT, 15) 
    591563        iy += 1 
    592564        sizer_params.Add(label_dmax, (iy, 0), (1, 1), wx.LEFT, 15) 
    593         sizer_params.Add(self.dmax_ctl,   (iy, 1), (1, 1), wx.RIGHT, 0) 
     565        sizer_params.Add(self.dmax_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) 
    594566        sizer_params.Add(self.distance_explorator_ctl, (iy, 2), 
    595567                         (1, 1), wx.LEFT, 15) 
    596568 
    597569        boxsizer2.Add(sizer_params, 0) 
    598          
     570 
    599571        iy_vb += 1 
    600572        vbox.Add(boxsizer2, (iy_vb, 0), (1, 1), 
    601                  wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 
     573                 wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 
    602574 
    603575 
     
    606578        ressizer = wx.StaticBoxSizer(resbox, wx.VERTICAL) 
    607579        ressizer.SetMinSize((self._default_width, 50)) 
    608          
    609         label_rg       = wx.StaticText(self, -1, "Rg") 
    610         label_rg_unit  = wx.StaticText(self, -1, "[A]") 
    611         label_iq0      = wx.StaticText(self, -1, "I(Q=0)") 
     580 
     581        label_rg = wx.StaticText(self, -1, "Rg") 
     582        label_rg_unit = wx.StaticText(self, -1, "[A]") 
     583        label_iq0 = wx.StaticText(self, -1, "I(Q=0)") 
    612584        label_iq0_unit = wx.StaticText(self, -1, "[A^(-1)]") 
    613         label_bck      = wx.StaticText(self, -1, "Background") 
     585        label_bck = wx.StaticText(self, -1, "Background") 
    614586        label_bck_unit = wx.StaticText(self, -1, "[A^(-1)]") 
    615         self.rg_ctl    = OutputTextCtrl(self, -1, size=(60,20)) 
     587        self.rg_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 
    616588        hint_msg = "Radius of gyration for the computed P(r)." 
    617589        self.rg_ctl.SetToolTipString(hint_msg) 
    618         self.iq0_ctl   = OutputTextCtrl(self, -1, size=(60, 20)) 
     590        self.iq0_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 
    619591        hint_msg = "Scattering intensity at Q=0 for the computed P(r)." 
    620592        self.iq0_ctl.SetToolTipString(hint_msg) 
    621         self.bck_ctl   = OutputTextCtrl(self, -1, size=(60, 20)) 
     593        self.bck_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 
    622594        self.bck_ctl.SetToolTipString("Value of estimated constant background.") 
    623          
     595 
    624596        label_time = wx.StaticText(self, -1, "Computation time") 
    625597        label_time_unit = wx.StaticText(self, -1, "secs") 
    626         label_time.SetMinSize((120,20)) 
     598        label_time.SetMinSize((120, 20)) 
    627599        label_chi2 = wx.StaticText(self, -1, "Chi2/dof") 
    628600        label_osc = wx.StaticText(self, -1, "Oscillations") 
    629601        label_pos = wx.StaticText(self, -1, "Positive fraction") 
    630602        label_pos_err = wx.StaticText(self, -1, "1-sigma positive fraction") 
    631          
     603 
    632604        self.time_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 
    633605        hint_msg = "Computation time for the last inversion, in seconds." 
    634606        self.time_ctl.SetToolTipString(hint_msg) 
    635          
     607 
    636608        self.chi2_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 
    637609        self.chi2_ctl.SetToolTipString("Chi^2 over degrees of freedom.") 
    638          
     610 
    639611        # Oscillation parameter 
    640612        self.osc_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 
     
    642614        hint_msg += " oscillation parameter of 1.1." 
    643615        self.osc_ctl.SetToolTipString(hint_msg) 
    644          
     616 
    645617        # Positive fraction figure of merit 
    646618        self.pos_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 
     
    648620        hint_msg += "Theoretically, P(r) is defined positive." 
    649621        self.pos_ctl.SetToolTipString(hint_msg) 
    650          
     622 
    651623        # 1-simga positive fraction figure of merit 
    652624        self.pos_err_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 
    653         message  = "Fraction of P(r) that is at least 1 standard deviation" 
     625        message = "Fraction of P(r) that is at least 1 standard deviation" 
    654626        message += " greater than zero.\n" 
    655627        message += "This figure of merit tells you about the size of the " 
     
    658630        message += " consider changing the maximum distance." 
    659631        self.pos_err_ctl.SetToolTipString(message) 
    660          
     632 
    661633        sizer_res = wx.GridBagSizer(5, 5) 
    662634 
    663635        iy = 0 
    664         sizer_res.Add(label_rg, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) 
    665         sizer_res.Add(self.rg_ctl,   (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) 
    666         sizer_res.Add(label_rg_unit,   (iy, 2), (1, 1), wx.RIGHT|wx.EXPAND, 15) 
     636        sizer_res.Add(label_rg, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) 
     637        sizer_res.Add(self.rg_ctl, (iy, 1), (1, 1), wx.RIGHT | wx.EXPAND, 15) 
     638        sizer_res.Add(label_rg_unit, (iy, 2), (1, 1), wx.RIGHT | wx.EXPAND, 15) 
    667639        iy += 1 
    668         sizer_res.Add(label_iq0, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) 
    669         sizer_res.Add(self.iq0_ctl,   (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) 
    670         sizer_res.Add(label_iq0_unit, (iy, 2), (1, 1), wx.RIGHT|wx.EXPAND, 15) 
     640        sizer_res.Add(label_iq0, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) 
     641        sizer_res.Add(self.iq0_ctl, (iy, 1), (1, 1), wx.RIGHT | wx.EXPAND, 15) 
     642        sizer_res.Add(label_iq0_unit, (iy, 2), (1, 1), wx.RIGHT | wx.EXPAND, 15) 
    671643        iy += 1 
    672         sizer_res.Add(label_bck, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) 
    673         sizer_res.Add(self.bck_ctl, (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) 
    674         sizer_res.Add(label_bck_unit, (iy, 2), (1, 1), wx.RIGHT|wx.EXPAND, 15) 
     644        sizer_res.Add(label_bck, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) 
     645        sizer_res.Add(self.bck_ctl, (iy, 1), (1, 1), wx.RIGHT | wx.EXPAND, 15) 
     646        sizer_res.Add(label_bck_unit, (iy, 2), (1, 1), wx.RIGHT | wx.EXPAND, 15) 
    675647        iy += 1 
    676         sizer_res.Add(label_time, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) 
    677         sizer_res.Add(self.time_ctl,   (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) 
    678         sizer_res.Add(label_time_unit, (iy, 2), (1, 1), wx.RIGHT|wx.EXPAND, 15) 
     648        sizer_res.Add(label_time, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) 
     649        sizer_res.Add(self.time_ctl, (iy, 1), (1, 1), wx.RIGHT | wx.EXPAND, 15) 
     650        sizer_res.Add(label_time_unit, (iy, 2), (1, 1), wx.RIGHT | wx.EXPAND, 15) 
    679651        iy += 1 
    680         sizer_res.Add(label_chi2, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) 
    681         sizer_res.Add(self.chi2_ctl,   (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) 
     652        sizer_res.Add(label_chi2, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) 
     653        sizer_res.Add(self.chi2_ctl, (iy, 1), (1, 1), wx.RIGHT | wx.EXPAND, 15) 
    682654        iy += 1 
    683         sizer_res.Add(label_osc, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) 
    684         sizer_res.Add(self.osc_ctl,   (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) 
     655        sizer_res.Add(label_osc, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) 
     656        sizer_res.Add(self.osc_ctl, (iy, 1), (1, 1), wx.RIGHT | wx.EXPAND, 15) 
    685657 
    686658        iy += 1 
    687         sizer_res.Add(label_pos, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) 
    688         sizer_res.Add(self.pos_ctl, (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) 
     659        sizer_res.Add(label_pos, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) 
     660        sizer_res.Add(self.pos_ctl, (iy, 1), (1, 1), wx.RIGHT | wx.EXPAND, 15) 
    689661 
    690662        iy += 1 
    691         sizer_res.Add(label_pos_err, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) 
    692         sizer_res.Add(self.pos_err_ctl,  (iy,1), (1, 1), wx.RIGHT|wx.EXPAND, 15) 
     663        sizer_res.Add(label_pos_err, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) 
     664        sizer_res.Add(self.pos_err_ctl, (iy, 1), (1, 1), wx.RIGHT | wx.EXPAND, 15) 
    693665 
    694666        ressizer.Add(sizer_res, 0) 
    695667        iy_vb += 1 
    696668        vbox.Add(ressizer, (iy_vb, 0), (1, 1), 
    697                  wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 
     669                 wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 
    698670 
    699671        # ----- Buttons ----- 
    700         id = wx.NewId() 
    701         button_OK = wx.Button(self, id, "Compute") 
    702         button_OK.SetToolTipString("Perform P(r) inversion.") 
    703         self.Bind(wx.EVT_BUTTON, self._on_invert, id = id)    
    704          
     672        wx_id = wx.NewId() 
     673        button_ok = wx.Button(self, wx_id, "Compute") 
     674        button_ok.SetToolTipString("Perform P(r) inversion.") 
     675        self.Bind(wx.EVT_BUTTON, self._on_invert, id=wx_id) 
     676 
    705677        self._set_reset_flag(True) 
    706678        self._set_save_flag(True) 
    707679        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    708         sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    709         sizer_button.Add(button_OK, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) 
    710         
     680        sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     681        sizer_button.Add(button_ok, 0, wx.LEFT | wx.ADJUST_MINSIZE, 10) 
     682 
    711683        iy_vb += 1 
    712684        vbox.Add(sizer_button, (iy_vb, 0), (1, 1), 
    713                  wx.EXPAND|wx.BOTTOM|wx.TOP|wx.RIGHT, 10) 
     685                 wx.EXPAND | wx.BOTTOM | wx.TOP | wx.RIGHT, 10) 
    714686 
    715687        self.Bind(wx.EVT_TEXT_ENTER, self._on_invert) 
    716688 
    717689        self.SetSizer(vbox) 
    718          
     690 
    719691    def _on_accept_alpha(self, evt): 
    720692        """ 
    721         User has accepted the estimated alpha,  
     693        User has accepted the estimated alpha, 
    722694        set it as part of the input parameters 
    723695        """ 
    724696        try: 
    725697            alpha = self.alpha_estimate_ctl.GetLabel() 
    726             tmp = float(alpha) 
    727             self.alpha_ctl.SetValue(alpha) 
     698            self.alpha_ctl.SetValue(float(alpha)) 
    728699        except: 
    729700            # No estimate or bad estimate, either do nothing 
    730             #import sys 
    731             print "InversionControl._on_accept_alpha: %s" % sys.exc_value 
    732             pass 
    733      
     701            logging.error("InversionControl._on_accept_alpha: %s" % sys.exc_value) 
     702 
    734703    def _on_accept_nterms(self, evt): 
    735704        """ 
    736         User has accepted the estimated number of terms,  
     705        User has accepted the estimated number of terms, 
    737706        set it as part of the input parameters 
    738707        """ 
    739708        try: 
    740709            nterms = self.nterms_estimate_ctl.GetLabel() 
    741             tmp = float(nterms) 
    742             self.nfunc_ctl.SetValue(nterms) 
     710            self.nfunc_ctl.SetValue(float(nterms)) 
    743711        except: 
    744712            # No estimate or bad estimate, either do nothing 
    745             import sys 
    746             print "InversionControl._on_accept_nterms: %s" % sys.exc_value 
    747             pass 
    748          
     713            logging.error("InversionControl._on_accept_nterms: %s" % sys.exc_value) 
     714 
    749715    def clear_panel(self): 
    750716        """ 
     
    752718        self.plot_data.SetValue("") 
    753719        self.on_reset(event=None) 
    754          
     720 
    755721    def on_reset(self, event=None): 
    756722        """ 
     
    775741        self.nterms_estimate_ctl.SetLabel("") 
    776742        self._on_pars_changed() 
    777          
     743 
    778744    def _on_pars_changed(self, evt=None): 
    779745        """ 
    780746        Called when an input parameter has changed 
    781747        We will estimate the alpha parameter behind the 
    782         scenes.  
     748        scenes. 
    783749        """ 
    784750        flag, alpha, dmax, nfunc, qmin, qmax, height, width = self._read_pars() 
    785751        has_bck = self.bck_chk.IsChecked() 
    786          
     752 
    787753        # If the pars are valid, estimate alpha 
    788754        if flag: 
    789755            self.nterms_estimate_ctl.Enable(False) 
    790756            self.alpha_estimate_ctl.Enable(False) 
    791              
     757 
    792758            dataset = self.plot_data.GetValue() 
    793759            if dataset is not None and dataset.strip() != "": 
    794                 self._manager.estimate_plot_inversion(alpha=alpha, nfunc=nfunc,  
    795                                                  d_max=dmax, 
    796                                                  q_min=qmin, q_max=qmax, 
    797                                                  bck=has_bck,  
    798                                                  height=height, 
    799                                                  width=width) 
    800          
     760                self._manager.estimate_plot_inversion(alpha=alpha, nfunc=nfunc, 
     761                                                      d_max=dmax, 
     762                                                      q_min=qmin, q_max=qmax, 
     763                                                      bck=has_bck, 
     764                                                      height=height, 
     765                                                      width=width) 
     766 
    801767    def _read_pars(self, evt=None): 
    802768        """ 
    803         """     
     769        """ 
    804770        alpha = 0 
    805771        nfunc = 5 
    806         dmax  = 120 
    807         qmin  = 0 
    808         qmax  = 0 
     772        dmax = 120 
     773        qmin = 0 
     774        qmax = 0 
    809775        height = 0 
    810         width  = 0 
     776        width = 0 
    811777        flag = True 
    812778        # Read slit height 
     
    823789            self.sheight_ctl.SetBackgroundColour("pink") 
    824790            self.sheight_ctl.Refresh() 
    825              
     791 
    826792        # Read slit width 
    827793        try: 
    828794            width_str = self.swidth_ctl.GetValue() 
    829             if len(width_str.lstrip().rstrip())==0: 
     795            if len(width_str.lstrip().rstrip()) == 0: 
    830796                width = 0 
    831797            else: 
     
    837803            self.swidth_ctl.SetBackgroundColour("pink") 
    838804            self.swidth_ctl.Refresh() 
    839          
     805 
    840806        # Read alpha 
    841807        try: 
     
    847813            self.alpha_ctl.SetBackgroundColour("pink") 
    848814            self.alpha_ctl.Refresh() 
    849          
    850         # Read d_max     
     815 
     816        # Read d_max 
    851817        try: 
    852818            dmax = float(self.dmax_ctl.GetValue()) 
     
    857823            self.dmax_ctl.SetBackgroundColour("pink") 
    858824            self.dmax_ctl.Refresh() 
    859              
     825 
    860826        # Read nfunc 
    861827        try: 
     
    873839            self.nfunc_ctl.SetBackgroundColour("pink") 
    874840            self.nfunc_ctl.Refresh() 
    875          
     841 
    876842        # Read qmin 
    877843        try: 
     
    887853            self.qmin_ctl.SetBackgroundColour("pink") 
    888854            self.qmin_ctl.Refresh() 
    889          
     855 
    890856        # Read qmax 
    891857        try: 
     
    901867            self.qmax_ctl.SetBackgroundColour("pink") 
    902868            self.qmax_ctl.Refresh() 
    903          
     869 
    904870        return flag, alpha, dmax, nfunc, qmin, qmax, height, width 
    905      
     871 
    906872    def _on_explore(self, evt): 
    907873        """ 
     
    916882            message = "No data to analyze. Please load a data set to proceed." 
    917883            wx.PostEvent(self._manager.parent, StatusEvent(status=message)) 
    918              
     884 
    919885    def _on_invert(self, evt): 
    920886        """ 
    921887        Perform inversion 
    922          
    923         :param silent: when True, there will be no output for the user  
    924          
     888 
     889        :param silent: when True, there will be no output for the user 
     890 
    925891        """ 
    926892        # Get the data from the form 
    927893        # Push it to the manager 
    928          
     894 
    929895        flag, alpha, dmax, nfunc, qmin, qmax, height, width = self._read_pars() 
    930896        has_bck = self.bck_chk.IsChecked() 
    931          
     897 
    932898        if flag: 
    933899            dataset = self.plot_data.GetValue() 
    934             if dataset==None or len(dataset.strip())==0: 
     900            if dataset == None or len(dataset.strip()) == 0: 
    935901                message = "No data to invert. Select a data set before" 
    936902                message += " proceeding with P(r) inversion." 
    937903                wx.PostEvent(self._manager.parent, StatusEvent(status=message)) 
    938904            else: 
    939                 self._manager.setup_plot_inversion(alpha=alpha, nfunc=nfunc,  
    940                                                   d_max=dmax, 
    941                                                   q_min=qmin, q_max=qmax, 
    942                                                   bck=has_bck, 
    943                                                   height=height, 
    944                                                   width=width) 
     905                self._manager.setup_plot_inversion(alpha=alpha, nfunc=nfunc, 
     906                                                   d_max=dmax, 
     907                                                   q_min=qmin, q_max=qmax, 
     908                                                   bck=has_bck, 
     909                                                   height=height, 
     910                                                   width=width) 
    945911        else: 
    946912            message = "The P(r) form contains invalid values: " 
    947913            message += "please submit it again." 
    948914            wx.PostEvent(self.parent, StatusEvent(status=message)) 
    949          
     915 
    950916    def _change_file(self, evt=None, filepath=None, data=None): 
    951917        """ 
     
    960926            except: 
    961927                msg = "InversionControl._change_file: %s" % sys.exc_value 
    962                 logging.error(msg)                     
     928                logging.error(msg) 
    963929 
    964930class HelpDialog(wx.Dialog): 
     
    970936        from sas.pr.invertor import help 
    971937        wx.Dialog.__init__(self, parent, id, size=(400, 450)) 
    972         self.SetTitle("P(r) help")  
     938        self.SetTitle("P(r) help") 
    973939        self.SetWindowVariant(variant=FONT_VARIANT) 
    974940 
     
    976942 
    977943        explanation = help() 
    978             
     944 
    979945        label_explain = wx.StaticText(self, -1, explanation, size=(360, 350)) 
    980              
    981         vbox.Add(label_explain, 0, wx.ALL|wx.EXPAND, 15) 
     946 
     947        vbox.Add(label_explain, 0, wx.ALL | wx.EXPAND, 15) 
    982948 
    983949 
    984950        static_line = wx.StaticLine(self, -1) 
    985951        vbox.Add(static_line, 0, wx.EXPAND, 0) 
    986          
    987         button_OK = wx.Button(self, wx.ID_OK, "OK") 
    988         #button_Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") 
    989          
     952 
     953        button_ok = wx.Button(self, wx.ID_OK, "OK") 
     954 
    990955        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    991         sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    992         sizer_button.Add(button_OK, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
    993          
    994         vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 
     956        sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     957        sizer_button.Add(button_ok, 0, wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 
     958 
     959        vbox.Add(sizer_button, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 10) 
    995960 
    996961        self.SetSizer(vbox) 
    997962        self.SetAutoLayout(True) 
    998          
     963 
    999964        self.Layout() 
    1000965        self.Centre() 
     
    1008973        from sas.pr.invertor import help 
    1009974        wx.Dialog.__init__(self, parent, id, size=(250, 120)) 
    1010         self.SetTitle("P(r) distribution")  
    1011          
     975        self.SetTitle("P(r) distribution") 
     976 
    1012977 
    1013978        vbox = wx.BoxSizer(wx.VERTICAL) 
    1014          
     979 
    1015980        label_npts = wx.StaticText(self, -1, "Number of points") 
    1016981        self.npts_ctl = PrTextCtrl(self, -1, size=(100, 20)) 
    1017                   
     982 
    1018983        pars_sizer = wx.GridBagSizer(5, 5) 
    1019984        iy = 0 
    1020985        pars_sizer.Add(label_npts, (iy, 0), (1, 1), wx.LEFT, 15) 
    1021986        pars_sizer.Add(self.npts_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) 
    1022          
    1023         vbox.Add(pars_sizer, 0, wx.ALL|wx.EXPAND, 15) 
     987 
     988        vbox.Add(pars_sizer, 0, wx.ALL | wx.EXPAND, 15) 
    1024989 
    1025990        static_line = wx.StaticLine(self, -1) 
    1026991        vbox.Add(static_line, 0, wx.EXPAND, 0) 
    1027          
    1028         button_OK = wx.Button(self, wx.ID_OK, "OK") 
    1029         self.Bind(wx.EVT_BUTTON, self._checkValues, button_OK) 
    1030         button_Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") 
    1031          
     992 
     993        button_ok = wx.Button(self, wx.ID_OK, "OK") 
     994        self.Bind(wx.EVT_BUTTON, self._checkValues, button_ok) 
     995        button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") 
     996 
    1032997        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    1033         sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    1034         sizer_button.Add(button_OK, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
    1035         sizer_button.Add(button_Cancel, 0, 
    1036                          wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)         
    1037         vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 
     998        sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     999        sizer_button.Add(button_ok, 0, wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 
     1000        sizer_button.Add(button_cancel, 0, 
     1001                         wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 
     1002        vbox.Add(sizer_button, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 10) 
    10381003 
    10391004        self.SetSizer(vbox) 
    10401005        self.SetAutoLayout(True) 
    1041          
     1006 
    10421007        self.Layout() 
    10431008        self.Centre() 
     
    10671032        value = int(self.npts_ctl.GetValue()) 
    10681033        return value 
    1069      
     1034 
    10701035    def set_content(self, npts): 
    10711036        """ 
     
    10731038        """ 
    10741039        self.npts_ctl.SetValue("%i" % npts) 
    1075  
    1076 ##### testing code ############################################################ 
    1077 """ 
    1078 Example: :: 
    1079  
    1080 class TestPlot: 
    1081     def __init__(self, text): 
    1082         self.name = text 
    1083      
    1084 class MyApp(wx.App): 
    1085     def OnInit(self): 
    1086         wx.InitAllImageHandlers() 
    1087         dialog = PrDistDialog(None, -1) 
    1088         if dialog.ShowModal() == wx.ID_OK: 
    1089             pass 
    1090         dialog.Destroy() 
    1091          
    1092         return 1 
    1093  
    1094 # end of class MyApp 
    1095  
    1096 if __name__ == "__main__": 
    1097     app = MyApp(0) 
    1098     app.MainLoop() 
    1099      
    1100 """ 
    1101 ##### end of testing code #####################################################     
  • src/sas/perspectives/pr/inversion_state.py

    rc4f6851 r8b21fa7  
    55#This software was developed by the University of Tennessee as part of the 
    66#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    7 #project funded by the US National Science Foundation.  
     7#project funded by the US National Science Foundation. 
    88# 
    99#See the license text in license.txt 
     
    2626 
    2727# Translation of names between stored and object data 
    28 ## List of P(r) inversion inputs  
    29 in_list =  [["nterms",      "nfunc"], 
    30            ["d_max",        "d_max"], 
    31            ["alpha",        "alpha"], 
    32            ["slit_width",   "width"], 
    33            ["slit_height",  "height"], 
    34            ["qmin",         "qmin"], 
    35            ["qmax",         "qmax"], 
    36            ["estimate_bck", "estimate_bck"]]                       
     28## List of P(r) inversion inputs 
     29in_list = [["nterms", "nfunc"], 
     30           ["d_max", "d_max"], 
     31           ["alpha", "alpha"], 
     32           ["slit_width", "width"], 
     33           ["slit_height", "height"], 
     34           ["qmin", "qmin"], 
     35           ["qmax", "qmax"], 
     36           ["estimate_bck", "estimate_bck"]] 
    3737 
    3838## List of P(r) inversion outputs 
    3939out_list = [["elapsed", "elapsed"], 
    40            ["rg",      "rg"], 
    41            ["iq0",    "iq0"], 
    42            ["bck",    "bck"], 
    43            ["chi2",    "chi2"], 
    44            ["osc",    "osc"], 
    45            ["pos",    "pos"], 
    46            ["pos_err", "pos_err"], 
    47            ["alpha_estimate", "alpha_estimate"], 
    48            ["nterms_estimate", "nterms_estimate"]] 
     40            ["rg", "rg"], 
     41            ["iq0", "iq0"], 
     42            ["bck", "bck"], 
     43            ["chi2", "chi2"], 
     44            ["osc", "osc"], 
     45            ["pos", "pos"], 
     46            ["pos_err", "pos_err"], 
     47            ["alpha_estimate", "alpha_estimate"], 
     48            ["nterms_estimate", "nterms_estimate"]] 
    4949 
    5050class InversionState(object): 
     
    5656        Default values 
    5757        """ 
    58         # Input  
    59         self.file  = None 
     58        # Input 
     59        self.file = None 
    6060        self.estimate_bck = False 
    6161        self.timestamp = time.time() 
    62          
     62 
    6363        # Inversion parameters 
    6464        self.nfunc = None 
    6565        self.d_max = None 
    6666        self.alpha = None 
    67          
     67 
    6868        # Slit parameters 
    6969        self.height = None 
    70         self.width  = None 
    71          
     70        self.width = None 
     71 
    7272        # Q range 
    73         self.qmin  = None 
    74         self.qmax  = None 
    75          
     73        self.qmin = None 
     74        self.qmax = None 
     75 
    7676        # Outputs 
    7777        self.elapsed = None 
    78         self.rg    = None 
    79         self.iq0   = None 
    80         self.bck   = None 
    81         self.chi2  = None 
    82         self.osc   = None 
    83         self.pos   = None 
     78        self.rg = None 
     79        self.iq0 = None 
     80        self.bck = None 
     81        self.chi2 = None 
     82        self.osc = None 
     83        self.pos = None 
    8484        self.pos_err = None 
    85          
     85 
    8686        # Estimates 
    8787        self.alpha_estimate = None 
    8888        self.nterms_estimate = None 
    89          
     89 
    9090        # Data 
    91         self.q       = None 
    92         self.iq_obs  = None 
     91        self.q = None 
     92        self.iq_obs = None 
    9393        self.iq_calc = None 
    94          
     94 
    9595        # Coefficients 
    9696        self.coefficients = None 
    9797        self.covariance = None 
    98      
     98 
    9999    def __str__(self): 
    100100        """ 
    101101        Pretty print 
    102          
     102 
    103103        :return: string representing the state 
    104          
    105         """ 
    106         state  = "File:         %s\n" % self.file 
     104 
     105        """ 
     106        state = "File:         %s\n" % self.file 
    107107        state += "Timestamp:    %s\n" % self.timestamp 
    108108        state += "Estimate bck: %s\n" % str(self.estimate_bck) 
     
    110110        state += "D_max:        %s\n" % str(self.d_max) 
    111111        state += "Alpha:        %s\n" % str(self.alpha) 
    112          
     112 
    113113        state += "Slit height:  %s\n" % str(self.height) 
    114114        state += "Slit width:   %s\n" % str(self.width) 
    115          
     115 
    116116        state += "Qmin:         %s\n" % str(self.qmin) 
    117117        state += "Qmax:         %s\n" % str(self.qmax) 
    118          
     118 
    119119        state += "\nEstimates:\n" 
    120120        state += "  Alpha:      %s\n" % str(self.alpha_estimate) 
    121121        state += "  Nterms:     %s\n" % str(self.nterms_estimate) 
    122          
     122 
    123123        state += "\nOutputs:\n" 
    124124        state += "  Elapsed:    %s\n" % str(self.elapsed) 
     
    130130        state += "  Positive:   %s\n" % str(self.pos) 
    131131        state += "  1-sigma pos:%s\n" % str(self.pos_err) 
    132          
     132 
    133133        return state 
    134          
     134 
    135135    def toXML(self, file="pr_state.prv", doc=None, entry_node=None): 
    136136        """ 
    137137        Writes the state of the InversionControl panel to file, as XML. 
    138          
     138 
    139139        Compatible with standalone writing, or appending to an 
    140140        already existing XML document. In that case, the XML document 
    141         is required. An optional entry node in the XML document  
     141        is required. An optional entry node in the XML document 
    142142        may also be given. 
    143          
     143 
    144144        :param file: file to write to 
    145145        :param doc: XML document object [optional] 
    146         :param entry_node: XML node within the XML document at which  
     146        :param entry_node: XML node within the XML document at which 
    147147            we will append the data [optional] 
    148          
     148 
    149149        """ 
    150150        #TODO: Get this to work 
     
    154154        if doc is None: 
    155155            impl = getDOMImplementation() 
    156          
    157             doc_type = impl.createDocumentType(PRNODE_NAME, "1.0", "1.0")      
    158          
     156 
     157            doc_type = impl.createDocumentType(PRNODE_NAME, "1.0", "1.0") 
     158 
    159159            newdoc = impl.createDocument(None, PRNODE_NAME, doc_type) 
    160160            top_element = newdoc.documentElement 
     
    167167            else: 
    168168                entry_node.appendChild(top_element) 
    169              
     169 
    170170        attr = newdoc.createAttribute("version") 
    171171        attr.nodeValue = '1.0' 
    172172        top_element.setAttributeNode(attr) 
    173          
     173 
    174174        # File name 
    175175        element = newdoc.createElement("filename") 
     
    179179            element.appendChild(newdoc.createTextNode(str(file))) 
    180180        top_element.appendChild(element) 
    181          
     181 
    182182        element = newdoc.createElement("timestamp") 
    183183        element.appendChild(newdoc.createTextNode(time.ctime(self.timestamp))) 
     
    186186        element.setAttributeNode(attr) 
    187187        top_element.appendChild(element) 
    188          
     188 
    189189        # Inputs 
    190190        inputs = newdoc.createElement("inputs") 
    191191        top_element.appendChild(inputs) 
    192          
     192 
    193193        for item in in_list: 
    194194            element = newdoc.createElement(item[0]) 
    195195            element.appendChild(newdoc.createTextNode(str(getattr(self, item[1])))) 
    196196            inputs.appendChild(element) 
    197                
     197 
    198198        # Outputs 
    199199        outputs = newdoc.createElement("outputs") 
    200200        top_element.appendChild(outputs) 
    201          
     201 
    202202        for item in out_list: 
    203203            element = newdoc.createElement(item[0]) 
    204204            element.appendChild(newdoc.createTextNode(str(getattr(self, item[1])))) 
    205205            outputs.appendChild(element) 
    206                      
     206 
    207207        # Save output coefficients and its covariance matrix 
    208208        element = newdoc.createElement("coefficients") 
     
    212212        element.appendChild(newdoc.createTextNode(str(self.covariance))) 
    213213        outputs.appendChild(element) 
    214                      
     214 
    215215        # Save the file 
    216216        if doc is None: 
     
    225225        """ 
    226226        Load a P(r) inversion state from a file 
    227          
     227 
    228228        :param file: .prv file 
    229229        :param node: node of a XML document to read from 
    230          
     230 
    231231        """ 
    232232        if file is not None: 
     
    234234            msg += " format for P(r) files" 
    235235            raise RuntimeError, msg 
    236              
     236 
    237237        if node.get('version') and node.get('version') == '1.0': 
    238              
     238 
    239239            # Get file name 
    240240            entry = get_content('ns:filename', node) 
    241241            if entry is not None: 
    242242                self.file = entry.text.strip() 
    243              
     243 
    244244            # Get time stamp 
    245245            entry = get_content('ns:timestamp', node) 
     
    251251                    msg += "timestamp\n %s" % sys.exc_value 
    252252                    logging.error(msg) 
    253              
     253 
    254254            # Parse inversion inputs 
    255255            entry = get_content('ns:inputs', node) 
     
    265265                if input_field is not None: 
    266266                    try: 
    267                         self.estimate_bck = input_field.text.strip()=='True' 
     267                        self.estimate_bck = input_field.text.strip() == 'True' 
    268268                    except: 
    269269                        self.estimate_bck = False 
    270                      
     270 
    271271            # Parse inversion outputs 
    272272            entry = get_content('ns:outputs', node) 
     
    280280                        except: 
    281281                            setattr(self, item[1], None) 
    282              
     282 
    283283                # Look for coefficients 
    284284                # Format is [value, value, value, value] 
     
    286286                if coeff is not None: 
    287287                    # Remove brackets 
    288                     c_values = coeff.text.strip().replace('[','') 
    289                     c_values = c_values.replace(']','') 
     288                    c_values = coeff.text.strip().replace('[', '') 
     289                    c_values = c_values.replace(']', '') 
    290290                    toks = c_values.split() 
    291291                    self.coefficients = [] 
     
    308308                        logging.error(err_msg) 
    309309                        self.coefficients = None 
    310                  
     310 
    311311                # Look for covariance matrix 
    312312                # Format is [ [value, value], [value, value] ] 
     
    320320                        if len(row) == 0: continue 
    321321                        # Remove end bracket 
    322                         row = row.replace(']','') 
     322                        row = row.replace(']', '') 
    323323                        c_values = row.split() 
    324324                        cov_row = [] 
     
    345345                        logging.error(err_msg) 
    346346                        self.covariance = None 
    347      
     347 
    348348class Reader(CansasReader): 
    349349    """ 
     
    352352    ## File type 
    353353    type_name = "P(r)" 
    354      
     354 
    355355    ## Wildcards 
    356356    type = ["P(r) files (*.prv)|*.prv", 
    357357            "SASView files (*.svs)|*.svs"] 
    358358    ## List of allowed extensions 
    359     ext = ['.prv', '.PRV', '.svs', '.SVS']   
    360      
     359    ext = ['.prv', '.PRV', '.svs', '.SVS'] 
     360 
    361361    def __init__(self, call_back, cansas=True): 
    362362        """ 
    363363        Initialize the call-back method to be called 
    364364        after we load a file 
    365          
     365 
    366366        :param call_back: call-back method 
    367367        :param cansas:  True = files will be written/read in CanSAS format 
    368368                        False = write CanSAS format 
    369              
     369 
    370370        """ 
    371371        ## Call back method to be executed after a file is read 
     
    374374        self.cansas = cansas 
    375375        self.state = None 
    376          
     376 
    377377    def read(self, path): 
    378         """  
     378        """ 
    379379        Load a new P(r) inversion state from file 
    380          
     380 
    381381        :param path: file path 
    382          
     382 
    383383        :return: None 
    384          
    385         """ 
    386         if self.cansas==True: 
     384 
     385        """ 
     386        if self.cansas == True: 
    387387            return self._read_cansas(path) 
    388388        else: 
    389389            return self._read_standalone(path) 
    390          
     390 
    391391    def _read_standalone(self, path): 
    392         """  
     392        """ 
    393393        Load a new P(r) inversion state from file. 
    394394        The P(r) node is assumed to be the top element. 
    395          
     395 
    396396        :param path: file path 
    397          
     397 
    398398        :return: None 
    399          
     399 
    400400        """ 
    401401        # Read the new state from file 
    402402        state = InversionState() 
    403403        state.fromXML(file=path) 
    404          
     404 
    405405        # Call back to post the new state 
    406406        self.state = state 
    407407        #self.call_back(state) 
    408408        return None 
    409      
     409 
    410410    def _parse_prstate(self, entry): 
    411411        """ 
    412412        Read a p(r) inversion result from an XML node 
    413          
    414         :param entry: XML node to read from  
    415          
     413 
     414        :param entry: XML node to read from 
     415 
    416416        :return: InversionState object 
    417          
     417 
    418418        """ 
    419419        state = None 
    420          
     420 
    421421        # Locate the P(r) node 
    422422        try: 
    423423            nodes = entry.xpath('ns:%s' % PRNODE_NAME, 
    424424                                namespaces={'ns': CANSAS_NS}) 
    425             if nodes !=[]: 
     425            if nodes != []: 
    426426                # Create an empty state 
    427                 state =  InversionState() 
     427                state = InversionState() 
    428428                state.fromXML(node=nodes[0]) 
    429429        except: 
     
    431431            msg += "information.\n %s" % sys.exc_value 
    432432            logging.info(msg) 
    433              
     433 
    434434        return state 
    435      
     435 
    436436    def _read_cansas(self, path): 
    437         """  
     437        """ 
    438438        Load data and P(r) information from a CanSAS XML file. 
    439          
     439 
    440440        :param path: file path 
    441          
    442         :return: Data1D object if a single SASentry was found,  
     441 
     442        :return: Data1D object if a single SASentry was found, 
    443443                    or a list of Data1D objects if multiple entries were found, 
    444444                    or None of nothing was found 
    445                      
     445 
    446446        :raise RuntimeError: when the file can't be opened 
    447447        :raise ValueError: when the length of the data vectors are inconsistent 
    448          
     448 
    449449        """ 
    450450        output = [] 
    451          
     451 
    452452        if os.path.isfile(path): 
    453             basename  = os.path.basename(path) 
     453            basename = os.path.basename(path) 
    454454            root, extension = os.path.splitext(basename) 
    455455            #TODO: eventually remove the check for .xml once 
    456456            # the P(r) writer/reader is truly complete. 
    457457            if  extension.lower() in self.ext or extension.lower() == '.xml': 
    458                  
     458 
    459459                tree = etree.parse(path, parser=etree.ETCompatXMLParser()) 
    460460                # Check the format version number 
     
    462462                #format version  
    463463                root = tree.getroot() 
    464                  
     464 
    465465                entry_list = root.xpath('/ns:SASroot/ns:SASentry', 
    466466                                        namespaces={'ns': CANSAS_NS}) 
     
    477477        else: 
    478478            raise RuntimeError, "%s is not a file" % path 
    479          
     479 
    480480        # Return output consistent with the loader's api 
    481481        if len(output) == 0: 
     
    483483        elif len(output) == 1: 
    484484            # Call back to post the new state 
    485             self.call_back(output[0].meta_data['prstate'], datainfo = output[0]) 
     485            self.call_back(output[0].meta_data['prstate'], datainfo=output[0]) 
    486486            #self.state = output[0].meta_data['prstate'] 
    487487            return output[0] 
    488488        else: 
    489             return output                 
    490      
    491      
     489            return output 
     490 
     491 
    492492    def write(self, filename, datainfo=None, prstate=None): 
    493493        """ 
    494494        Write the content of a Data1D as a CanSAS XML file 
    495          
     495 
    496496        :param filename: name of the file to write 
    497497        :param datainfo: Data1D object 
    498498        :param prstate: InversionState object 
    499          
     499 
    500500        """ 
    501501        # Sanity check 
    502502        if self.cansas == True: 
    503             doc = self.write_toXML(datainfo, prstate)         
     503            doc = self.write_toXML(datainfo, prstate) 
    504504            # Write the XML document 
    505505            fd = open(filename, 'w') 
     
    508508        else: 
    509509            prstate.toXML(file=filename) 
    510          
     510 
    511511    def write_toXML(self, datainfo=None, state=None): 
    512512        """ 
    513513        Write toXML, a helper for write() 
    514          
     514 
    515515        : return: xml doc 
    516516        """ 
    517517        if datainfo is None: 
    518             datainfo = Data1D(x=[], y=[])     
     518            datainfo = Data1D(x=[], y=[]) 
    519519        elif not issubclass(datainfo.__class__, Data1D): 
    520520            msg = "The cansas writer expects a Data1D " 
    521521            msg += "instance: %s" % str(datainfo.__class__.__name__) 
    522522            raise RuntimeError, msg 
    523      
     523 
    524524        # Create basic XML document 
    525525        doc, sasentry = self._to_xml_doc(datainfo) 
    526          
     526 
    527527        # Add the invariant information to the XML document 
    528528        if state is not None: 
    529529            doc = state.toXML(doc=doc, entry_node=sasentry) 
    530              
    531         return doc  
    532      
     530 
     531        return doc 
  • src/sas/perspectives/pr/pr_thread.py

    r79492222 r8b21fa7  
    33#This software was developed by the University of Tennessee as part of the 
    44#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    5 #project funded by the US National Science Foundation.  
     5#project funded by the US National Science Foundation. 
    66# 
    77#See the license text in license.txt 
     
    1818    Compute P(r) 
    1919    """ 
    20      
    21     def __init__(self, pr, nfunc=5, error_func=None, 
    22                  completefn = None, 
    23                  updatefn   = None, 
    24                  yieldtime  = 0.01, 
    25                  worktime   = 0.01 
    26                  ): 
     20 
     21    def __init__(self, pr, nfunc=5, error_func=None, completefn=None, 
     22                 updatefn=None, yieldtime=0.01, worktime=0.01): 
    2723        """ 
    2824        """ 
    29         CalcThread.__init__(self,completefn, 
    30                  updatefn, 
    31                  yieldtime, 
    32                  worktime) 
     25        CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime) 
    3326        self.pr = pr 
    3427        self.nfunc = nfunc 
    3528        self.error_func = error_func 
    3629        self.starttime = 0 
    37          
     30 
    3831    def compute(self): 
    3932        """ 
     
    4336            self.starttime = time.time() 
    4437            out, cov = self.pr.invert(self.nfunc) 
    45             #out, cov = self.pr.lstsq(self.nfunc) 
    46             #out, cov = self.pr.invert_optimize(self.nfunc) 
    47             elapsed = time.time()-self.starttime 
     38            elapsed = time.time() - self.starttime 
    4839            self.complete(out=out, cov=cov, pr=self.pr, elapsed=elapsed) 
    4940        except KeyboardInterrupt: 
     
    5142            pass 
    5243        except: 
    53             if not self.error_func==None: 
     44            if not self.error_func == None: 
    5445                self.error_func("CalcPr.compute: %s" % sys.exc_value) 
    5546 
     
    5849    Estimate P(r) 
    5950    """ 
    60      
    61     def __init__(self, pr, nfunc=5, error_func=None, 
    62                  completefn = None, 
    63                  updatefn   = None, 
    64                  yieldtime  = 0.01, 
    65                  worktime   = 0.01 
    66                  ): 
    67         CalcThread.__init__(self,completefn, 
    68                  updatefn, 
    69                  yieldtime, 
    70                  worktime) 
     51 
     52    def __init__(self, pr, nfunc=5, error_func=None, completefn=None, 
     53                 updatefn=None, yieldtime=0.01, worktime=0.01): 
     54        CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime) 
    7155        self.pr = pr 
    7256        self.nfunc = nfunc 
    7357        self.error_func = error_func 
    7458        self.starttime = 0 
    75          
     59 
    7660    def compute(self): 
    7761        """ 
    7862        Calculates the estimate 
    7963        """ 
    80         try:             
     64        try: 
    8165            alpha, message, elapsed = self.pr.estimate_alpha(self.nfunc) 
    8266            self.isquit() 
     
    8670            pass 
    8771        except: 
    88             if not self.error_func==None: 
     72            if not self.error_func == None: 
    8973                self.error_func("EstimatePr.compute: %s" % sys.exc_value) 
    9074 
     
    9276    """ 
    9377    """ 
    94     def __init__(self, pr, nfunc=5, error_func=None, 
    95                  completefn = None, 
    96                  updatefn   = None, 
    97                  yieldtime  = 0.01, 
    98                  worktime   = 0.01 
    99                  ): 
    100         CalcThread.__init__(self,completefn, 
    101                  updatefn, 
    102                  yieldtime, 
    103                  worktime) 
     78    def __init__(self, pr, nfunc=5, error_func=None, completefn=None, 
     79                 updatefn=None, yieldtime=0.01, worktime=0.01): 
     80        CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime) 
    10481        self.pr = pr 
    10582        self.nfunc = nfunc 
     
    11491        """ 
    11592        CalcThread.isquit(self) 
    116         if time.time()>self._time_for_sleep+self._sleep_delay: 
     93        if time.time() > self._time_for_sleep + self._sleep_delay: 
    11794            time.sleep(.2) 
    11895            self._time_for_sleep = time.time() 
     
    12299        Calculates the estimate 
    123100        """ 
    124         try:             
     101        try: 
    125102            t_0 = time.time() 
    126103            self._time_for_sleep = t_0 
    127104            nterms, alpha, message = self.pr.estimate_numterms(self.isquit) 
    128             t_1 = time.time()-t_0 
     105            t_1 = time.time() - t_0 
    129106            self.isquit() 
    130107            self.complete(nterms=nterms, alpha=alpha, message=message, elapsed=t_1) 
     
    133110            pass 
    134111        except: 
    135             if not self.error_func==None: 
     112            if not self.error_func == None: 
    136113                self.error_func("EstimatePr2.compute: %s" % sys.exc_value) 
  • src/sas/perspectives/pr/pr_widgets.py

    r79492222 r8b21fa7  
    33#This software was developed by the University of Tennessee as part of the 
    44#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    5 #project funded by the US National Science Foundation.  
     5#project funded by the US National Science Foundation. 
    66# 
    77#See the license text in license.txt 
     
    2626        ScrolledPanel.__init__(self, *args, **kwds) 
    2727        self.SetupScrolling() 
    28          
    29          
     28 
     29 
    3030class PrTextCtrl(wx.TextCtrl): 
    3131    """ 
     
    3434    """ 
    3535    def __init__(self, *args, **kwds): 
    36          
     36 
    3737        wx.TextCtrl.__init__(self, *args, **kwds) 
    38          
     38 
    3939        ## Set to True when the mouse is clicked while the whole string is selected 
    4040        self.full_selection = False 
     
    4949        Catch when the text control is set in focus to highlight the whole 
    5050        text if necessary 
    51          
     51 
    5252        :param event: mouse event 
    53          
     53 
    5454        """ 
    5555        event.Skip() 
    5656        self.full_selection = True 
    57          
     57 
    5858    def _highlight_text(self, event): 
    5959        """ 
    6060        Highlight text of a TextCtrl only of no text has be selected 
    61          
     61 
    6262        :param event: mouse event 
    63          
     63 
    6464        """ 
    6565        # Make sure the mouse event is available to other listeners 
    6666        event.Skip() 
    67         control  = event.GetEventObject() 
     67        control = event.GetEventObject() 
    6868        if self.full_selection: 
    6969            self.full_selection = False 
    7070            # Check that we have a TextCtrl 
    7171            if issubclass(control.__class__, wx.TextCtrl): 
    72                 # Check whether text has been selected,  
     72                # Check whether text has been selected, 
    7373                # if not, select the whole string 
    7474                (start, end) = control.GetSelection() 
    75                 if start==end: 
    76                     control.SetSelection(-1,-1) 
     75                if start == end: 
     76                    control.SetSelection(-1, -1) 
    7777 
    7878class OutputTextCtrl(wx.TextCtrl): 
    7979    """ 
    8080    Text control used to display outputs. 
    81     No editing allowed. The background is  
     81    No editing allowed. The background is 
    8282    grayed out. User can't select text. 
    8383    """ 
     
    8888        self.SetEditable(False) 
    8989        self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) 
    90          
     90 
    9191        # Bind to mouse event to avoid text highlighting 
    9292        # The event will be skipped once the call-back 
    9393        # is called. 
    9494        self.Bind(wx.EVT_MOUSE_EVENTS, self._click) 
    95          
     95 
    9696    def _click(self, event): 
    9797        """ 
    9898        Prevent further handling of the mouse event 
    9999        by not calling Skip(). 
    100         """  
     100        """ 
    101101        pass 
    102          
     102 
    103103 
    104104class DataFileTextCtrl(OutputTextCtrl): 
     
    106106    Text control used to display only the file name 
    107107    given a full path. 
    108       
     108 
    109109    :TODO: now that we no longer choose the data file from the panel, 
    110110        it's no longer necessary to pass around the file path. That code 
    111         should be refactored away and simplified.  
     111        should be refactored away and simplified. 
    112112    """ 
    113113    def __init__(self, *args, **kwds): 
     
    116116        OutputTextCtrl.__init__(self, *args, **kwds) 
    117117        self._complete_path = None 
    118      
     118 
    119119    def SetValue(self, value): 
    120120        """ 
     
    122122        """ 
    123123        self._complete_path = str(value) 
    124         file = os.path.basename(self._complete_path) 
    125         OutputTextCtrl.SetValue(self, file) 
    126          
     124        file_path = os.path.basename(self._complete_path) 
     125        OutputTextCtrl.SetValue(self, file_path) 
     126 
    127127    def GetValue(self): 
    128128        """ 
     
    130130        """ 
    131131        return self._complete_path 
    132      
    133  
    134              
    135              
     132 
     133 
    136134def load_error(error=None): 
    137135    """ 
    138136    Pop up an error message. 
    139      
     137 
    140138    :param error: details error message to be displayed 
    141139    """ 
    142140    message = "The data file you selected could not be loaded.\n" 
    143141    message += "Make sure the content of your file is properly formatted.\n\n" 
    144      
     142 
    145143    if error is not None: 
    146144        message += "When contacting the DANSE team, mention the" 
    147145        message += " following:\n%s" % str(error) 
    148      
     146 
    149147    dial = wx.MessageDialog(None, message, 'Error Loading File', 
    150148                            wx.OK | wx.ICON_EXCLAMATION) 
    151     dial.ShowModal()     
    152  
    153      
     149    dial.ShowModal() 
     150 
     151 
    154152class DataDialog(wx.Dialog): 
    155153    """ 
     
    166164        self._choice_sizer = wx.GridBagSizer(5, 5) 
    167165        self._panel = DialogPanel(self, style=wx.RAISED_BORDER, 
    168                                size=(WIDTH-20, HEIGHT/3)) 
    169         
     166                                  size=(WIDTH - 20, HEIGHT / 3)) 
     167 
    170168        self.__do_layout(data_list, text=text) 
    171          
    172          
     169 
    173170    def __do_layout(self, data_list, text=''): 
    174171        """ 
    175172        layout the dialog 
    176173        """ 
    177         #if not data_list or len(data_list) <= 1: 
    178         #    return  
    179174        #add text 
    180175        if text.strip() == "": 
     
    182177            text += "Please select only one Data.\n" 
    183178        text_ctrl = wx.TextCtrl(self, -1, str(text), style=wx.TE_MULTILINE, 
    184                                 size=(-1, HEIGHT/3)) 
     179                                size=(-1, HEIGHT / 3)) 
    185180        text_ctrl.SetEditable(False) 
    186         self._sizer_txt.Add(text_ctrl , 1, wx.EXPAND|wx.ALL, 10) 
     181        self._sizer_txt.Add(text_ctrl, 1, wx.EXPAND | wx.ALL, 10) 
    187182        iy = 0 
    188183        ix = 0 
    189         rbox = wx.RadioButton(self._panel, -1, str(data_list[0].name),  
    190                                   (10, 10), style= wx.RB_GROUP) 
     184        rbox = wx.RadioButton(self._panel, -1, str(data_list[0].name), 
     185                              (10, 10), style=wx.RB_GROUP) 
    191186        rbox.SetValue(True) 
    192187        self.list_of_ctrl.append((rbox, data_list[0])) 
    193188        self._choice_sizer.Add(rbox, (iy, ix), (1, 1), 
    194                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     189                               wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    195190        for i in range(1, len(data_list)): 
    196191            iy += 1 
    197             rbox = wx.RadioButton(self._panel, -1,  
     192            rbox = wx.RadioButton(self._panel, -1, 
    198193                                  str(data_list[i].name), (10, 10)) 
    199194            rbox.SetValue(False) 
    200195            self.list_of_ctrl.append((rbox, data_list[i])) 
    201196            self._choice_sizer.Add(rbox, (iy, ix), 
    202                            (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     197                                   (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    203198        self._panel.SetSizer(self._choice_sizer) 
    204199        #add sizer 
    205         self._sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     200        self._sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    206201        button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") 
    207202        self._sizer_button.Add(button_cancel, 0, 
    208                           wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
    209         button_OK = wx.Button(self, wx.ID_OK, "Ok") 
    210         button_OK.SetFocus() 
    211         self._sizer_button.Add(button_OK, 0, 
    212                                 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
     203                               wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 
     204        button_ok = wx.Button(self, wx.ID_OK, "Ok") 
     205        button_ok.SetFocus() 
     206        self._sizer_button.Add(button_ok, 0, 
     207                               wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 
    213208        static_line = wx.StaticLine(self, -1) 
    214          
    215         self._sizer_txt.Add(self._panel, 0, wx.EXPAND|wx.ALL, 5) 
    216         self._sizer_main.Add(self._sizer_txt, 0, wx.EXPAND|wx.ALL, 5) 
     209 
     210        self._sizer_txt.Add(self._panel, 0, wx.EXPAND | wx.ALL, 5) 
     211        self._sizer_main.Add(self._sizer_txt, 0, wx.EXPAND | wx.ALL, 5) 
    217212        self._sizer_main.Add(static_line, 0, wx.EXPAND, 0) 
    218         self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND|wx.ALL, 10) 
     213        self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND | wx.ALL, 10) 
    219214        self.SetSizer(self._sizer_main) 
    220          
     215 
    221216    def get_data(self): 
    222217        """ 
     
    226221            rbox, data = item 
    227222            if rbox.GetValue(): 
    228                 return data  
    229  
    230      
    231  
    232   
     223                return data 
Note: See TracChangeset for help on using the changeset viewer.