Changeset 4a2b054 in sasview for invariantview


Ignore:
Timestamp:
Nov 22, 2010 10:36:42 AM (13 years ago)
Author:
Gervaise Alina <gervyh@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
32c0841
Parents:
cbaa2f4
Message:

working on pylint

Location:
invariantview/perspectives/invariant
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • invariantview/perspectives/invariant/__init__.py

    r85a24d9 r4a2b054  
    2424        media_path = os.path.join(path, media) 
    2525        if os.path.isdir(media_path): 
    26              module_media_path = os.path.join(media_path,'invariant_media') 
    27              if os.path.isdir(module_media_path): 
    28                  return module_media_path 
    29              return media_path 
     26            module_media_path = os.path.join(media_path, 'invariant_media') 
     27            if os.path.isdir(module_media_path): 
     28                return module_media_path 
     29            return media_path 
    3030    
    3131    raise RuntimeError('Could not find invariant media files') 
     
    3939 
    4040    """ 
    41     data_files =[] 
     41    data_files = [] 
    4242    path = get_data_path(media="media") 
    4343    for f in findall(path): 
  • invariantview/perspectives/invariant/help_panel.py

    rd7a39e5 r4a2b054  
    1919        explanation = help() 
    2020            
    21         label_explain = wx.StaticText(self, -1, explanation, size=(350,320)) 
     21        label_explain = wx.StaticText(self, -1, explanation, size=(350, 320)) 
    2222             
    2323        vbox.Add(label_explain, 0, wx.ALL|wx.EXPAND, 15) 
     
    5151        splitter = MultiSplitterWindow(self, style=wx.SP_LIVE_UPDATE) 
    5252        rpanel = wx.Panel(splitter, -1) 
    53         lpanel = wx.Panel(splitter, -1,style=wx.BORDER_SUNKEN) 
     53        lpanel = wx.Panel(splitter, -1, style=wx.BORDER_SUNKEN) 
    5454         
    5555        vbox = wx.BoxSizer(wx.VERTICAL) 
     
    6666        vbox.Add(header, 0, wx.EXPAND) 
    6767        
    68         vboxl= wx.BoxSizer(wx.VERTICAL) 
     68        vboxl = wx.BoxSizer(wx.VERTICAL) 
    6969        headerl = wx.Panel(lpanel, -1, size=(-1, 20)) 
    7070        
     
    8181        self.lhelp = html.HtmlWindow(lpanel, -1, style=wx.NO_BORDER) 
    8282        self.rhelp = html.HtmlWindow(rpanel, -1, style=wx.NO_BORDER,  
    83                                      size=(500,-1)) 
     83                                     size=(500, -1)) 
    8484        import sans.perspectives.invariant as invariant 
    8585        path = invariant.get_data_path(media='media') 
    86         self.path= os.path.join(path,"invariant_help.html") 
     86        self.path = os.path.join(path,"invariant_help.html") 
    8787      
    8888        self.rhelp.LoadPage(self.path) 
    89         page="""<html> 
     89        page = """<html> 
    9090            <body> 
    9191            <ul> 
     
    9393            </ul> 
    9494            </body> 
    95             </html>"""%self.path 
     95            </html>""" % self.path 
    9696         
    9797        self.lhelp.SetPage(page) 
    98         self.lhelp.Bind(wx.html.EVT_HTML_LINK_CLICKED,self.OnLinkClicked ) 
     98        self.lhelp.Bind(wx.html.EVT_HTML_LINK_CLICKED, self.OnLinkClicked) 
    9999         
    100         vbox.Add(self.rhelp,1, wx.EXPAND) 
     100        vbox.Add(self.rhelp, 1, wx.EXPAND) 
    101101        vboxl.Add(self.lhelp, 1, wx.EXPAND) 
    102102        rpanel.SetSizer(vbox) 
     
    105105         
    106106        vbox1 = wx.BoxSizer(wx.HORIZONTAL) 
    107         vbox1.Add(splitter,1,wx.EXPAND) 
     107        vbox1.Add(splitter, 1, wx.EXPAND) 
    108108        splitter.AppendWindow(lpanel, 200) 
    109109        splitter.AppendWindow(rpanel) 
     
    121121 
    122122class ViewApp(wx.App): 
     123    """ 
     124    """ 
    123125    def OnInit(self): 
     126        """ 
     127        """ 
    124128        frame = HelpWindow(None, -1, 'HelpWindow')     
    125129        frame.Show(True) 
  • invariantview/perspectives/invariant/invariant.py

    r7a07864 r4a2b054  
    1111#copyright 2009, University of Tennessee 
    1212################################################################################ 
    13 import os 
     13#import os 
    1414import sys 
    1515import wx 
    1616import copy 
    17 import logging, time 
    18 from sans.invariant import invariant 
     17import logging 
     18#import time 
     19#from sans.invariant import invariant 
    1920 
    2021from DataLoader.data_info import Data1D as LoaderData1D 
    21 from sans.guiframe.dataFitting import Theory1D, Data1D 
    22  
    23 from sans.guicomm.events import NewPlotEvent, StatusEvent 
     22from sans.guiframe.dataFitting import Theory1D 
     23from sans.guiframe.dataFitting import Data1D 
     24 
     25from sans.guicomm.events import NewPlotEvent 
    2426from sans.guicomm.events import ERR_DATA 
    2527from invariant_state import Reader as reader 
     
    142144        self.graph = graph 
    143145        invariant_option = "Compute invariant" 
    144         invariant_hint = "Will displays the invariant panel for futher computation" 
     146        invariant_hint = "Will displays the invariant panel for" 
     147        invairant_hint += " futher computation" 
    145148        
    146149        for item in self.graph.plottables: 
     
    148151                if issubclass(item.__class__,LoaderData1D): 
    149152            
    150                     if item.name !="$I_{obs}(q)$" and item.name !="$P_{fit}(r)$": 
     153                    if item.name != "$I_{obs}(q)$" and \ 
     154                        item.name != " $P_{fit}(r)$": 
    151155                        if hasattr(item, "group_id"): 
    152156                            return [[invariant_option,  
    153                                         invariant_hint, self._compute_invariant]] 
     157                                        invariant_hint,  
     158                                        self._compute_invariant]] 
    154159        return []    
    155160 
     
    220225        """ 
    221226        self.panel = event.GetEventObject() 
    222         Plugin.on_perspective(self,event=event) 
     227        Plugin.on_perspective(self, event=event) 
    223228        for plottable in self.panel.graph.plottables: 
    224229            if plottable.name == self.panel.graph.selected_plottable: 
    225                 ## put the errors values back to the model if the errors were hiden 
    226                 ## before sending them to the fit engine 
    227                 if len(self.err_dy)>0: 
     230                ## put the errors values back to the model if the errors  
     231                ## were hiden before sending them to the fit engine 
     232                if len(self.err_dy) > 0: 
    228233                    dy = plottable.dy 
    229234                    if plottable.name in  self.err_dy.iterkeys(): 
     
    260265            self.state_reader.write(filepath, current_plottable, state) 
    261266        else: 
    262             raise RuntimeError, "invariant.save_file: the data being saved is not a DataLoader.data_info.Data1D object"  
     267            msg = "invariant.save_file: the data being saved is" 
     268            msg += " not a DataLoader.data_info.Data1D object"  
     269            raise RuntimeError, msg 
    263270 
    264271    def set_state(self, state, datainfo=None):     
     
    273280             
    274281            if datainfo is None: 
    275                 raise RuntimeError, "invariant.set_state: datainfo parameter cannot be None in standalone mode" 
    276              
    277             datainfo.meta_data['invstate'].file = datainfo.meta_data['invstate'].file 
    278             datainfo.name = datainfo.meta_data['invstate'].file 
    279             datainfo.filename = datainfo.meta_data['invstate'].file 
     282                msg = "invariant.set_state: datainfo parameter cannot" 
     283                msg += " be None in standalone mode" 
     284                raise RuntimeError, msg 
     285             
     286            name = datainfo.meta_data['invstate'].file 
     287            datainfo.meta_data['invstate'].file = name 
     288            datainfo.name = name 
     289            datainfo.filename = name 
    280290            self.__data = datainfo 
    281291            self.__data.group_id = datainfo.filename 
     
    300310        after a .inv/.svs file is loaded  
    301311        """ 
    302         self.invariant_panel.set_state(state=self.temp_state,data=self.__data) 
     312        self.invariant_panel.set_state(state=self.temp_state, 
     313                                       data=self.__data) 
    303314        self.temp_state = None 
    304315         
     
    312323        :param name: Data's name to use for the legend 
    313324        """ 
    314         import copy 
     325        #import copy 
    315326        if data is None: 
    316327            new_plot = Theory1D(x=[], y=[], dy=None) 
    317328        else: 
    318             scale =self.invariant_panel.get_scale() 
     329            scale = self.invariant_panel.get_scale() 
    319330            background = self.invariant_panel.get_background() 
    320331             
     
    335346        if data != None: 
    336347            name_head = name.split('-') 
    337             if name_head[0]=='Low': 
     348            if name_head[0] == 'Low': 
    338349                self.invariant_panel.state.theory_lowQ = copy.deepcopy(new_plot) 
    339             elif name_head[0]=='High': 
     350            elif name_head[0] == 'High': 
    340351                self.invariant_panel.state.theory_highQ = copy.deepcopy(new_plot) 
    341352 
    342         wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=self.__data.name)) 
     353        wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, 
     354                                               title=self.__data.name)) 
    343355         
    344356    def plot_data(self, scale, background): 
     
    354366        if new_plot != None: 
    355367            self.invariant_panel.state.data = copy.deepcopy(new_plot) 
    356         wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=new_plot.name)) 
    357          
     368        wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, 
     369                                               title=new_plot.name)) 
     370         
  • invariantview/perspectives/invariant/invariant_details.py

    rd7a39e5 r4a2b054  
    22import wx 
    33import sys 
    4  
    54import numpy 
    6 from sans.guiframe.utils import format_number, check_float 
     5from sans.guiframe.utils import format_number 
     6from sans.guiframe.utils import check_float 
    77from invariant_widgets import OutputTextCtrl 
    88# Dimensions related to chart 
     
    1616DEFAULT_QSTAR = 1.0   
    1717   
    18 if sys.platform.count("win32")>0: 
     18if sys.platform.count("win32") > 0: 
    1919    _STATICBOX_WIDTH = 450 
    2020    PANEL_WIDTH = 500 
     
    2828     
    2929   
    30      
    3130class InvariantContainer(wx.Object): 
    3231    """ 
     
    8483        else: 
    8584            try: 
    86                 self.qstar_low_percent = float(self.qstar_low)/float(self.qstar_total) 
     85                self.qstar_low_percent = float(self.qstar_low)\ 
     86                                            /float(self.qstar_total) 
    8787            except: 
    8888                self.qstar_low_percent = 'error' 
     
    9292        else: 
    9393            try: 
    94                 self.qstar_high_percent = float(self.qstar_high)/float(self.qstar_total) 
     94                self.qstar_high_percent = float(self.qstar_high)\ 
     95                                                /float(self.qstar_total) 
    9596            except: 
    9697                self.qstar_high_percent = 'error' 
     
    105106            return  
    106107        if self.qstar_total == 0: 
    107              self.existing_warning = True 
    108              self.warning_msg = "Invariant is zero. \n" 
    109              self.warning_msg += "The calculations are likely to be unreliable!\n" 
    110              return  
     108            self.existing_warning = True 
     109            self.warning_msg = "Invariant is zero. \n" 
     110            self.warning_msg += "The calculations are likely " 
     111            self.warning_msg += "to be unreliable!\n" 
     112            return  
    111113        #warning to the user when the extrapolated invariant is greater than %5 
    112114        msg = '' 
     
    117119        if self.qstar_low_percent == 'error': 
    118120            self.existing_warning = True 
    119             msg = 'Error occurred when computing extrapolated invariant at low-Q region.\n' 
    120         elif self.qstar_low_percent is not None and self.qstar_low_percent >= 0.05: 
     121            msg = "Error occurred when computing extrapolated invariant" 
     122            msg += " at low-Q region.\n" 
     123        elif self.qstar_low_percent is not None and \ 
     124             self.qstar_low_percent >= 0.05: 
    121125            self.existing_warning = True 
    122126            msg += "Extrapolated contribution at Low Q is higher " 
     
    124128        if self.qstar_high_percent == 'error': 
    125129            self.existing_warning = True 
    126             msg += 'Error occurred when computing extrapolated invariant at high-Q region.\n' 
    127         elif self.qstar_high_percent is not None and self.qstar_high_percent >= 0.05: 
     130            msg += 'Error occurred when computing extrapolated' 
     131            msg += ' invariant at high-Q region.\n' 
     132        elif self.qstar_high_percent is not None and \ 
     133            self.qstar_high_percent >= 0.05: 
    128134            self.existing_warning = True 
    129135            msg += "Extrapolated contribution at High Q is higher " 
     
    139145            self.warning_msg = '' 
    140146            self.warning_msg += msg  
    141             self.warning_msg += "The calculations are likely to be unreliable!\n" 
     147            self.warning_msg += "The calculations are likely to be" 
     148            self.warning_msg += " unreliable!\n" 
    142149        else: 
    143150            self.warning_msg = "No Details on calculations available...\n" 
     
    150157                                    title="Invariant Details", 
    151158                                    size=(PANEL_WIDTH, PANEL_HEIGHT)): 
    152         wx.Dialog.__init__(self, parent=parent, id=id,title=title,size=size) 
     159        wx.Dialog.__init__(self, parent=parent, id=id, title=title, size=size) 
    153160         
    154161        #Font size  
     
    184191        Define main sizers needed for this panel 
    185192        """ 
    186         #Box sizers must be defined first before defining buttons/textctrls (MAC). 
     193        #Box sizers must be defined first before defining buttons/textctrls 
     194        # (MAC). 
    187195        self.main_sizer = wx.BoxSizer(wx.VERTICAL) 
    188196        #Sizer related to chart 
    189197        chart_box = wx.StaticBox(self, -1, "Invariant Chart") 
    190198        self.chart_sizer = wx.StaticBoxSizer(chart_box, wx.VERTICAL) 
    191         self.chart_sizer.SetMinSize((PANEL_WIDTH - 50,110)) 
     199        self.chart_sizer.SetMinSize((PANEL_WIDTH - 50, 110)) 
    192200        #Sizer related to invariant values 
    193201        self.invariant_sizer =  wx.GridBagSizer(4, 4) 
     
    196204                                                      wx.HORIZONTAL) 
    197205 
    198         self.invariant_box_sizer.SetMinSize((PANEL_WIDTH - 50,-1)) 
     206        self.invariant_box_sizer.SetMinSize((PANEL_WIDTH - 50, -1)) 
    199207        #Sizer related to warning message 
    200208        warning_box = wx.StaticBox(self, -1, "Warning") 
    201209        self.warning_sizer = wx.StaticBoxSizer(warning_box, wx.VERTICAL) 
    202         self.warning_sizer.SetMinSize((PANEL_WIDTH-50,-1)) 
     210        self.warning_sizer.SetMinSize((PANEL_WIDTH-50, -1)) 
    203211        #Sizer related to button 
    204212        self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) 
     
    221229        invariant_txt = wx.StaticText(self, -1, 'Q* from Data ') 
    222230        invariant_txt.SetToolTipString("Invariant in the data set's Q range.") 
    223         self.invariant_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 
    224         self.invariant_tcl.SetToolTipString("Invariant in the data set's Q range.") 
    225         self.invariant_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 
    226         self.invariant_err_tcl.SetToolTipString("Uncertainty on the invariant from data's range.") 
     231        self.invariant_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
     232        hint_msg = "Invariant in the data set's Q range." 
     233        self.invariant_tcl.SetToolTipString(hint_msg) 
     234        self.invariant_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
     235        hint_msg = "Uncertainty on the invariant from data's range." 
     236        self.invariant_err_tcl.SetToolTipString(hint_msg) 
    227237        invariant_units_txt = wx.StaticText(self, -1, unit_invariant) 
    228         invariant_units_txt.SetToolTipString("Unit of the invariant from data's Q range") 
     238        hint_msg = "Unit of the invariant from data's Q range" 
     239        invariant_units_txt.SetToolTipString(hint_msg) 
    229240        
    230241        invariant_low_txt = wx.StaticText(self, -1, 'Q* from Low-Q') 
    231         invariant_low_txt.SetToolTipString("Extrapolated invariant from low-Q range.") 
    232         self.invariant_low_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 
    233         self.invariant_low_tcl.SetToolTipString("Extrapolated invariant from low-Q range.") 
    234         self.invariant_low_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 
    235         self.invariant_low_err_tcl.SetToolTipString("Uncertainty on the invariant from low-Q range.") 
    236         invariant_low_units_txt = wx.StaticText(self, -1,  unit_invariant) 
    237         invariant_low_units_txt.SetToolTipString("Unit of the extrapolated invariant from  low-Q range") 
     242        hint_msg = "Extrapolated invariant from low-Q range." 
     243        invariant_low_txt.SetToolTipString(hint_msg) 
     244        self.invariant_low_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
     245        hint_msg = "Extrapolated invariant from low-Q range." 
     246        self.invariant_low_tcl.SetToolTipString(hint_msg) 
     247        self.invariant_low_err_tcl = OutputTextCtrl(self, -1, 
     248                                                    size=(_BOX_WIDTH, -1)) 
     249        hint_msg = "Uncertainty on the invariant from low-Q range." 
     250        self.invariant_low_err_tcl.SetToolTipString(hint_msg) 
     251        invariant_low_units_txt = wx.StaticText(self, -1, unit_invariant) 
     252        hint_msg = "Unit of the extrapolated invariant from  low-Q range" 
     253        invariant_low_units_txt.SetToolTipString(hint_msg) 
    238254         
    239255        invariant_high_txt = wx.StaticText(self, -1, 'Q* from High-Q') 
    240         invariant_high_txt.SetToolTipString("Extrapolated invariant from  high-Q range") 
    241         self.invariant_high_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 
    242         self.invariant_high_tcl.SetToolTipString("Extrapolated invariant from  high-Q range") 
    243         self.invariant_high_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 
    244         self.invariant_high_err_tcl.SetToolTipString("Uncertainty on the invariant from high-Q range.") 
    245         invariant_high_units_txt = wx.StaticText(self, -1,  unit_invariant) 
    246         invariant_high_units_txt.SetToolTipString("Unit of the extrapolated invariant from  high-Q range") 
     256        hint_msg = "Extrapolated invariant from  high-Q range" 
     257        invariant_high_txt.SetToolTipString(hint_msg) 
     258        self.invariant_high_tcl = OutputTextCtrl(self, -1, 
     259                                                 size=(_BOX_WIDTH, -1)) 
     260        hint_msg = "Extrapolated invariant from  high-Q range" 
     261        self.invariant_high_tcl.SetToolTipString(hint_msg) 
     262        self.invariant_high_err_tcl = OutputTextCtrl(self, -1, 
     263                                                     size=(_BOX_WIDTH, -1)) 
     264        hint_msg = "Uncertainty on the invariant from high-Q range." 
     265        self.invariant_high_err_tcl.SetToolTipString() 
     266        invariant_high_units_txt = wx.StaticText(self, -1, unit_invariant) 
     267        hint_msg = "Unit of the extrapolated invariant from  high-Q range" 
     268        invariant_high_units_txt.SetToolTipString(hint_msg) 
    247269    
    248270        #Invariant low 
    249271        iy = 0 
    250272        ix = 0  
    251         self.invariant_sizer.Add(invariant_low_txt, (iy, ix), (1,1), 
     273        self.invariant_sizer.Add(invariant_low_txt, (iy, ix), (1, 1), 
    252274                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    253275        ix += 1 
    254         self.invariant_sizer.Add(self.invariant_low_tcl, (iy, ix), (1,1), 
     276        self.invariant_sizer.Add(self.invariant_low_tcl, (iy, ix), (1, 1), 
    255277                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    256278        ix += 1 
    257279        self.invariant_sizer.Add( wx.StaticText(self, -1, uncertainty), 
    258                          (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    259         ix += 1 
    260         self.invariant_sizer.Add(self.invariant_low_err_tcl, (iy, ix), (1,1), 
     280                         (iy, ix), (1, 1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
     281        ix += 1 
     282        self.invariant_sizer.Add(self.invariant_low_err_tcl, (iy, ix), (1, 1), 
    261283                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    262284        ix += 1 
    263285        self.invariant_sizer.Add(invariant_low_units_txt 
    264                          ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)   
     286                         ,(iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)   
    265287        #Invariant  
    266288        iy += 1 
    267289        ix = 0  
    268         self.invariant_sizer.Add(invariant_txt, (iy, ix), (1,1), 
     290        self.invariant_sizer.Add(invariant_txt, (iy, ix), (1, 1), 
    269291                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    270292        ix += 1 
    271         self.invariant_sizer.Add(self.invariant_tcl, (iy, ix), (1,1), 
     293        self.invariant_sizer.Add(self.invariant_tcl, (iy, ix), (1, 1), 
    272294                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    273295        ix += 1 
    274296        self.invariant_sizer.Add(wx.StaticText(self, -1, uncertainty), 
    275                          (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    276         ix += 1 
    277         self.invariant_sizer.Add(self.invariant_err_tcl, (iy, ix), (1,1), 
     297                         (iy, ix), (1, 1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
     298        ix += 1 
     299        self.invariant_sizer.Add(self.invariant_err_tcl, (iy, ix), (1, 1), 
    278300                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    279301        ix +=1 
    280302        self.invariant_sizer.Add(invariant_units_txt 
    281                          ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)   
     303                         ,(iy, ix), (1, 1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)   
    282304        #Invariant high 
    283305        iy += 1 
    284306        ix = 0  
    285         self.invariant_sizer.Add(invariant_high_txt, (iy, ix), (1,1), 
     307        self.invariant_sizer.Add(invariant_high_txt, (iy, ix), (1, 1), 
    286308                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    287309        ix += 1 
    288         self.invariant_sizer.Add(self.invariant_high_tcl, (iy, ix), (1,1), 
     310        self.invariant_sizer.Add(self.invariant_high_tcl, (iy, ix), (1, 1), 
    289311                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    290312        ix += 1 
    291313        self.invariant_sizer.Add(wx.StaticText(self, -1, uncertainty), 
    292                          (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    293         ix += 1 
    294         self.invariant_sizer.Add(self.invariant_high_err_tcl, (iy, ix), (1,1), 
     314                         (iy, ix), (1, 1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
     315        ix += 1 
     316        self.invariant_sizer.Add(self.invariant_high_err_tcl, (iy, ix), (1, 1), 
    295317                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    296318        ix += 1 
    297319        self.invariant_sizer.Add(invariant_high_units_txt 
    298                          ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    299         self.invariant_box_sizer.Add(self.invariant_sizer, 0, wx.TOP|wx.BOTTOM, 10)   
     320                         ,(iy, ix), (1, 1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     321        self.invariant_box_sizer.Add(self.invariant_sizer, 0, 
     322                                     wx.TOP|wx.BOTTOM, 10)   
    300323        
    301324    def _layout_warning(self): 
     
    319342        button_ok.SetToolTipString("Give Details on Computation") 
    320343        self.Bind(wx.EVT_BUTTON, self.on_close, id=id) 
    321         self.button_sizer.AddMany([((20,20), 0 , wx.LEFT, 350), 
     344        self.button_sizer.AddMany([((20, 20), 0 , wx.LEFT, 350), 
    322345                                   (button_ok, 0 , wx.RIGHT, 10)]) 
    323346    def _do_layout(self): 
     
    341364        Set value of txtcrtl 
    342365        """ 
    343         self.invariant_tcl.SetValue(format_number(self.qstar_container.qstar)) 
    344         self.invariant_err_tcl.SetValue(format_number(self.qstar_container.qstar_err))  
    345         self.invariant_low_tcl.SetValue(format_number(self.qstar_container.qstar_low)) 
    346         self.invariant_low_err_tcl.SetValue(format_number(self.qstar_container.qstar_low_err))  
    347         self.invariant_high_tcl.SetValue(format_number(self.qstar_container.qstar_high)) 
    348         self.invariant_high_err_tcl.SetValue(format_number(self.qstar_container.qstar_high_err))  
     366        value = format_number(self.qstar_container.qstar) 
     367        self.invariant_tcl.SetValue(value) 
     368        value = format_number(self.qstar_container.qstar_err) 
     369        self.invariant_err_tcl.SetValue(value)  
     370        value = format_number(self.qstar_container.qstar_low) 
     371        self.invariant_low_tcl.SetValue(value) 
     372        value = format_number(self.qstar_container.qstar_low_err) 
     373        self.invariant_low_err_tcl.SetValue(value)  
     374        value = format_number(self.qstar_container.qstar_high) 
     375        self.invariant_high_tcl.SetValue(value) 
     376        value = format_number(self.qstar_container.qstar_high_err) 
     377        self.invariant_high_err_tcl.SetValue(value)  
    349378 
    350379    def get_scale(self, percentage, scale_name='scale'): 
     
    361390            scale = RECTANGLE_SCALE 
    362391            self.warning_msg += "Receive an invalid scale for %s\n" 
    363             self.warning_msg += "check this value : %s\n"%(str(scale_name),str(percentage)) 
     392            self.warning_msg += "check this value : %s\n"%(str(scale_name), 
     393                                                           str(percentage)) 
    364394        return  scale 
    365395     
     
    388418            gc = wx.GraphicsContext.Create(dc) 
    389419        except NotImplementedError: 
    390             dc.DrawText("This build of wxPython does not support the wx.GraphicsContext " 
    391                         "family of classes.", 25, 25) 
     420            msg = "This build of wxPython does not support " 
     421            msg += "the wx.GraphicsContext family of classes." 
     422            dc.DrawText(msg, 25, 25) 
    392423            return 
    393424        #Start the drawing 
  • invariantview/perspectives/invariant/invariant_panel.py

    reffce1d r4a2b054  
    33 
    44""" 
    5  
     5import copy 
     6import time 
     7import sys 
     8import os 
    69import wx 
    7  
    8 import sys,os 
    9  
    1010from wx.lib.scrolledpanel import ScrolledPanel 
    1111from sans.invariant import invariant 
    12 from sans.guiframe.utils import format_number, check_float 
     12from sans.guiframe.utils import format_number 
     13from sans.guiframe.utils import check_float 
    1314from sans.guicomm.events import NewPlotEvent, StatusEvent 
    14 from invariant_details import InvariantDetailsPanel, InvariantContainer 
    15 from invariant_widgets import OutputTextCtrl, InvTextCtrl 
     15from invariant_details import InvariantDetailsPanel 
     16from invariant_details import InvariantContainer 
     17from invariant_widgets import OutputTextCtrl 
     18from invariant_widgets import InvTextCtrl 
    1619from invariant_state import InvariantState as IState 
    17 import copy,time 
     20 
    1821# The minimum q-value to be used when extrapolating 
    1922Q_MINIMUM  = 1e-5 
     
    3639 
    3740 
    38 if sys.platform.count("win32")>0: 
     41if sys.platform.count("win32") > 0: 
    3942    _STATICBOX_WIDTH = 450 
    4043    PANEL_WIDTH = 500  
     
    5861    ## Flag to tell the AUI manager to put this panel in the center pane 
    5962    CENTER_PANE = True 
    60     def __init__(self, parent, data=None, manager=None,*args, **kwds): 
    61         kwds["size"]= (PANEL_WIDTH, PANEL_HEIGHT) 
    62         kwds["style"]= wx.FULL_REPAINT_ON_RESIZE 
     63    def __init__(self, parent, data=None, manager=None, *args, **kwds): 
     64        kwds["size"] = (PANEL_WIDTH, PANEL_HEIGHT) 
     65        kwds["style"] = wx.FULL_REPAINT_ON_RESIZE 
    6366        ScrolledPanel.__init__(self, parent=parent, *args, **kwds) 
    6467        self.SetupScrolling() 
     
    108111            if len(self._data.x[self._data.x==0]) > 0: 
    109112                flag = True 
    110                 msg = "Invariant: one of your q-values is zero. Delete that entry before proceeding" 
     113                msg = "Invariant: one of your q-values is zero. " 
     114                msg += "Delete that entry before proceeding" 
    111115                self.hint_msg_txt.SetLabel(msg) 
    112116                wx.PostEvent(self.parent, StatusEvent(status=msg, 
     
    137141            self._reset_state_list() 
    138142        return True   
     143     
    139144    def set_message(self): 
    140145        """ 
     
    147152                self.hint_msg_txt.SetForegroundColour("red") 
    148153     
    149                 wx.PostEvent(self.parent,StatusEvent(status=msg,info="warning")) 
     154                wx.PostEvent(self.parent, 
     155                             StatusEvent(status=msg,info="warning")) 
    150156            else: 
    151157                msg = "For more information, click on Details button." 
    152158                self.hint_msg_txt.SetForegroundColour("black") 
    153                 wx.PostEvent(self.parent,StatusEvent(status=msg,info="info")) 
     159                wx.PostEvent(self.parent, 
     160                             StatusEvent(status=msg,info="info")) 
    154161            self.hint_msg_txt.SetLabel(msg) 
    155162             
     
    178185            if num > 0 : 
    179186                self._undo_enable() 
    180             if num < len(state.state_list)-1: 
     187            if num < len(state.state_list) - 1: 
    181188                self._redo_enable() 
    182189                 
     
    184191            self.bookmark_num = len(self.state.bookmark_list) 
    185192 
    186             total_bookmark_num = self.bookmark_num+1 
     193            total_bookmark_num = self.bookmark_num + 1 
    187194            for ind in range(1,total_bookmark_num): 
    188195                #bookmark_num = ind 
     
    197204             
    198205            self._get_input_list()  
    199             #make sure that the data is reset (especially when loaded from a inv file) 
     206            #make sure that the data is reset (especially 
     207            # when loaded from a inv file) 
    200208            self.state.data = self._data 
    201209 
     
    238246            return float(background) 
    239247        else: 
    240             raise ValueError, "Receive invalid value for background : %s"%(background) 
     248            msg = "Receive invalid value for background : %s" % (background) 
     249            raise ValueError, msg 
    241250     
    242251    def get_scale(self): 
     
    248257            raise ValueError, "Need a background" 
    249258        if check_float(self.scale_tcl): 
    250             if float(scale)<= 0.0: 
     259            if float(scale) <= 0.0: 
    251260                self.scale_tcl.SetBackgroundColour("pink") 
    252261                self.scale_tcl.Refresh() 
    253                 raise ValueError, "Receive invalid value for scale: %s"%(scale) 
     262                msg = "Receive invalid value for scale: %s" % (scale) 
     263                raise ValueError, msg 
    254264            return float(scale) 
    255265        else: 
    256             raise ValueError, "Receive invalid value for scale : %s"%(scale) 
     266            raise ValueError, "Receive invalid value for scale : %s" % (scale) 
    257267         
    258268    def get_contrast(self): 
     
    262272        par_str = self.contrast_tcl.GetValue().strip() 
    263273        contrast = None 
    264         if par_str !="" and check_float(self.contrast_tcl): 
     274        if par_str !=" " and check_float(self.contrast_tcl): 
    265275            contrast = float(par_str) 
    266276        return contrast 
     
    284294        par_str = self.porod_constant_tcl.GetValue().strip() 
    285295        porod_const = None 
    286         if par_str !="" and check_float(self.porod_constant_tcl): 
     296        if par_str != "" and check_float(self.porod_constant_tcl): 
    287297            porod_const = float(par_str) 
    288298        return porod_const 
     
    294304            try: 
    295305                v, dv = inv.get_volume_fraction_with_error(contrast=contrast,  
    296                                                            extrapolation=extrapolation) 
     306                                                extrapolation=extrapolation) 
    297307                self.volume_tcl.SetValue(format_number(v)) 
    298308                self.volume_err_tcl.SetValue(format_number(dv)) 
     
    300310                self.volume_tcl.SetValue(format_number(None)) 
    301311                self.volume_err_tcl.SetValue(format_number(None)) 
    302                 msg= "Error occurred computing volume fraction: %s"%sys.exc_value 
     312                msg = "Error occurred computing volume " 
     313                msg += " fraction: %s" % sys.exc_value 
    303314                wx.PostEvent(self.parent, StatusEvent(status=msg, 
    304315                                                      info="error", 
     
    318329                self.surface_tcl.SetValue(format_number(None)) 
    319330                self.surface_err_tcl.SetValue(format_number(None)) 
    320                 msg = "Error occurred computing specific surface: %s"%sys.exc_value 
     331                msg = "Error occurred computing " 
     332                msg += "specific surface: %s" % sys.exc_value 
    321333                wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", 
    322334                                                       type="stop")) 
     
    338350            self.invariant_total_tcl.SetValue(format_number(None)) 
    339351            self.invariant_total_err_tcl.SetValue(format_number(None)) 
    340             msg= "Error occurred computing invariant using extrapolation: %s"%sys.exc_value 
     352            msg = "Error occurred computing invariant using" 
     353            msg += " extrapolation: %s" % sys.exc_value 
    341354            wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))   
    342355             
     
    359372                self.inv_container.qstar_low_err = "ERROR" 
    360373                self._manager.plot_theory(name="Low-Q extrapolation") 
    361                 msg= "Error occurred computing low-Q invariant: %s"%sys.exc_value 
    362                 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 
     374                msg = "Error occurred computing low-Q " 
     375                msg += "invariant: %s" % sys.exc_value 
     376                wx.PostEvent(self.parent, 
     377                             StatusEvent(status=msg, type="stop")) 
    363378        else: 
    364379            try: 
     
    378393                power_high = inv.get_extrapolation_power(range='high')  
    379394                self.power_high_tcl.SetValue(format_number(power_high)) 
    380                 high_out_data = inv.get_extra_data_high(q_end=qmax_plot,npts=500) 
     395                high_out_data = inv.get_extra_data_high(q_end=qmax_plot, 
     396                                                        npts=500) 
    381397                self._manager.plot_theory(data=high_out_data, 
    382398                                           name="High-Q extrapolation") 
     
    385401                self.inv_container.qstar_high_err = "ERROR" 
    386402                self._manager.plot_theory(name="High-Q extrapolation") 
    387                 msg= "Error occurred computing high-Q invariant: %s"%sys.exc_value 
    388                 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 
     403                msg = "Error occurred computing high-Q " 
     404                msg += "invariant: %s" % sys.exc_value 
     405                wx.PostEvent(self.parent, StatusEvent(status=msg, 
     406                                                      type="stop")) 
    389407        else: 
    390408            try: 
     
    420438                    if low_q : 
    421439                        #Raise error only when qstar at low q is requested 
    422                         msg = "Expect float for power at low q , got %s"%(power_low) 
     440                        msg = "Expect float for power at low q, " 
     441                        msg += " got %s" % (power_low) 
    423442                        raise ValueError, msg 
    424443        
     
    429448        else: 
    430449            if low_q: 
    431                 msg = "Expect float for number of points at low q , got %s"%(npts_low) 
     450                msg = "Expect float for number of points at low q," 
     451                msg += " got %s" % (npts_low) 
    432452                raise ValueError, msg 
    433453        #Set the invariant calculator 
     
    454474                if high_q : 
    455475                    #Raise error only when qstar at high q is requested 
    456                     msg = "Expect float for power at high q , got %s"%(power_high) 
     476                    msg = "Expect float for power at high q," 
     477                    msg += " got %s" % (power_high) 
    457478                    raise ValueError, msg 
    458479                           
     
    462483        else: 
    463484            if high_q: 
    464                 msg = "Expect float for number of points at high q , got %s"%(npts_high) 
     485                msg = "Expect float for number of points at high q," 
     486                msg += " got %s" % (npts_high) 
    465487                raise ValueError, msg 
    466488        inv.set_extrapolation(range="high", npts=npts_high, 
     
    483505        """ 
    484506        if self._data == None: 
    485             msg = "\n\nData must be loaded first in order to perform a compution..." 
     507            msg = "\n\nData must be loaded first in order" 
     508            msg += " to perform a compution..." 
    486509            wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    487510        # set a state for this computation for saving 
     
    502525            scale = self.get_scale() 
    503526        except: 
    504             msg= "Invariant Error: %s"%(sys.exc_value) 
    505             wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 
     527            msg = "Invariant Error: %s" % (sys.exc_value) 
     528            wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 
    506529            return 
    507530         
     
    516539            inv, npts_high = self.set_extrapolation_high(inv=inv, high_q=high_q) 
    517540        except: 
    518             msg = "Error occurred computing invariant: %s"%sys.exc_value 
     541            msg = "Error occurred computing invariant: %s" % sys.exc_value 
    519542            wx.PostEvent(self.parent, StatusEvent(status=msg, 
    520543                                                 info="warning",type="stop")) 
     
    532555             
    533556        except: 
    534             msg= "Error occurred computing invariant: %s"%sys.exc_value 
     557            msg= "Error occurred computing invariant: %s" % sys.exc_value 
    535558            wx.PostEvent(self.parent, StatusEvent(status=msg,  
    536                                                   info="warning",type="stop")) 
     559                                                  info="warning", 
     560                                                  type="stop")) 
    537561            return 
    538562        
     
    549573        try: 
    550574            #Compute volume and set value to txtcrtl 
    551             self.get_volume(inv=inv, contrast=contrast, extrapolation=extrapolation) 
     575            self.get_volume(inv=inv, contrast=contrast, 
     576                            extrapolation=extrapolation) 
    552577            #compute surface and set value to txtcrtl 
    553578        except: 
    554             msg = "Error occurred computing invariant: %s"%sys.exc_value 
     579            msg = "Error occurred computing invariant: %s" % sys.exc_value 
    555580            wx.PostEvent(self.parent, StatusEvent(status=msg, 
    556                                                   info="warning",type="stop")) 
     581                                                  info="warning", 
     582                                                  type="stop")) 
    557583        try: 
    558             self.get_surface(inv=inv, contrast=contrast, porod_const=porod_const,  
     584            self.get_surface(inv=inv, contrast=contrast, 
     585                                    porod_const=porod_const,  
    559586                                    extrapolation=extrapolation) 
    560587             
    561588        except: 
    562             msg = "Error occurred computing invariant: %s"%sys.exc_value 
     589            msg = "Error occurred computing invariant: %s" % sys.exc_value 
    563590            wx.PostEvent(self.parent, StatusEvent(status=msg, 
    564                                                   info="warning",type="stop")) 
     591                                                  info="warning", 
     592                                                  type="stop")) 
    565593             
    566594        #compute percentage of each invariant 
     
    583611         
    584612        if event != None:  
    585             if not self.button_report.IsEnabled(): self.button_report.Enable(True) 
    586             if not self.button_save.IsEnabled(): self.button_save.Enable(True) 
    587             wx.PostEvent(self.parent, StatusEvent(status = '\nFinished invariant computation...')) 
     613            if not self.button_report.IsEnabled(): 
     614                self.button_report.Enable(True) 
     615            if not self.button_save.IsEnabled(): 
     616                self.button_save.Enable(True) 
     617            wx.PostEvent(self.parent, 
     618                StatusEvent(status='\nFinished invariant computation...')) 
    588619             
    589620 
     
    594625        : param event: undo button event 
    595626        """ 
    596         if event != None: event.Skip() 
    597         if self.state.state_num <0: return 
     627        if event != None:  
     628            event.Skip() 
     629        if self.state.state_num < 0: 
     630            return 
    598631        self.is_power_out = True 
    599632        # get the previous state_num 
     
    601634        self.get_state_by_num(state_num=str(pre_state_num)) 
    602635         
    603         if float(pre_state_num) <=0: 
     636        if float(pre_state_num) <= 0: 
    604637            self._undo_disable() 
    605638        else: 
     
    617650        : param event: redo button event 
    618651        """ 
    619         if event != None: event.Skip() 
     652        if event != None: 
     653            event.Skip() 
    620654        self.is_power_out = True 
    621655        # get the next state_num 
     
    663697        try: 
    664698            current_state = copy.deepcopy(self.state.state_list[str(state_num)]) 
    665             # get the previously computed state number (computation before the state changes happened) 
     699            # get the previously computed state number  
     700            #(computation before the state changes happened) 
    666701            current_compute_num = str(current_state['compute_num']) 
    667702        except : 
     
    789824        name = str(obj.GetName()) 
    790825        value = str(obj.GetValue()) 
    791         rb_list = [['power_law_low','guinier'],['fit_enable_low','fix_enable_low'],['fit_enable_high','fix_enable_high']] 
     826        rb_list = [['power_law_low','guinier'], 
     827                   ['fit_enable_low','fix_enable_low'], 
     828                   ['fit_enable_high','fix_enable_high']] 
    792829 
    793830        try: 
     
    797834            exec "self.state.saved_state['%s'] = %s" %  (name, value) 
    798835             
    799             # set the count part of radio button clicked False for the saved_state 
     836            # set the count part of radio button clicked  
     837            #False for the saved_state 
    800838            for title,content in rb_list: 
    801839                if name ==  title: 
     
    808846             
    809847            # Instead of changing the future, create a new future. 
    810             max_state_num = len(self.state.state_list)-1    
     848            max_state_num = len(self.state.state_list) - 1    
    811849            self.state.saved_state['state_num'] = max_state_num    
    812850             
    813             self.state.saved_state['state_num'] +=1 
     851            self.state.saved_state['state_num'] += 1 
    814852            self.state.state_num = self.state.saved_state['state_num'] 
    815853            self.state.state_list[str(self.state.state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 
     
    825863        Notify the compute_invariant state to self.state 
    826864         
    827         : param state: set 'compute' when the computation is activated by the 'compute' button, else None 
     865        : param state: set 'compute' when the computation is 
     866        activated by the 'compute' button, else None 
    828867         
    829868        """ 
     
    838877        self.state.saved_state['state_num'] = max_state_num         
    839878        # A new computation is also A state 
    840         temp_saved_states = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 
    841         temp_saved_states['state_num'] +=1 
     879        #copy.deepcopy(self.state.saved_state) 
     880        temp_saved_states = self.state.clone_state() 
     881        temp_saved_states['state_num'] += 1 
    842882        self.state.state_num = temp_saved_states['state_num'] 
    843883 
     
    847887            temp_saved_states['compute_num'] = self.state.state_num 
    848888        self.state.saved_state= copy.deepcopy(temp_saved_states) 
    849         self.state.state_list[str(self.state.state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 
    850          
    851         # A computation is a new state, so delete the states with any higher state numbers 
     889        #copy.deepcopy(self.state.saved_state) 
     890        self.state.state_list[str(self.state.state_num)] = self.state.clone_state() 
     891         
     892        # A computation is a new state, so delete the states with any higher 
     893        # state numbers 
    852894        for i in range(self.state.state_num+1,len(self.state.state_list)): 
    853895            try: 
     
    860902         
    861903         
    862     def _reset_state_list(self,data=None): 
    863         """ 
    864         Reset the state_list just before data was loading: Used in 'set_current_data()' 
     904    def _reset_state_list(self, data=None): 
     905        """ 
     906        Reset the state_list just before data was loading: 
     907        Used in 'set_current_data()' 
    865908        """ 
    866909        #if data == None: return 
    867         #temp_state = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 
     910        #temp_state = self.state.clone_state() 
     911        #copy.deepcopy(self.state.saved_state) 
    868912        # Clear the list  
    869913        self.state.state_list.clear() 
     
    882926 
    883927        # Put only the current state in the list 
    884         self.state.state_list[str(self.state.state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 
     928        #copy.deepcopy(self.state.saved_state) 
     929        self.state.state_list[str(self.state.state_num)] = self.state.clone_state() 
    885930        self._undo_disable() 
    886931         
     
    927972                    self.state.saved_state['state_num'] += 1 
    928973            self.state.state_num = self.state.saved_state['state_num'] 
    929             self.state.state_list[str(self.state.state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 
     974            #copy.deepcopy(self.state.saved_state) 
     975            self.state.state_list[str(self.state.state_num)] = self.state.clone_state() 
    930976        except: 
    931977            pass 
     
    9761022        self.popUpMenu = wx.Menu() 
    9771023        id = wx.NewId() 
    978         self._bmark = wx.MenuItem(self.popUpMenu,id,"BookMark"," Bookmark the panel to recall it later") 
     1024        self._bmark = wx.MenuItem(self.popUpMenu,id,"BookMark", 
     1025                                  " Bookmark the panel to recall it later") 
    9791026        self.popUpMenu.AppendItem(self._bmark) 
    9801027        self._bmark.Enable(True) 
     
    9851032    def _on_bookmark(self,event): 
    9861033        """ 
    987         Save the panel state in memory and add the list on the popup menu on bookmark context menu event 
     1034        Save the panel state in memory and add the list on 
     1035        the popup menu on bookmark context menu event 
    9881036        """  
    9891037        if self._data == None: return 
     
    10101058        state = self.state.clone_state() 
    10111059        comp_state = copy.deepcopy(self.state.state_list[str(compute_num)]) 
    1012         self.state.bookmark_list[self.bookmark_num] = [my_time,date,state,comp_state] 
     1060        self.state.bookmark_list[self.bookmark_num] = [my_time, date, 
     1061                                                       state,comp_state] 
    10131062        self.state.toXML(self, doc=None, entry_node=None) 
    10141063         
     
    10171066    def _back_to_bookmark(self,event): 
    10181067        """ 
    1019         Bring the panel back to the state of bookmarked requested by context menu event 
     1068        Bring the panel back to the state of bookmarked requested by 
     1069        context menu event 
    10201070        and set it as a new state 
    10211071        """ 
     
    10321082         
    10331083        self.state.saved_state['state_num'] = state_num 
    1034         self.state.state_list[str(state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 
     1084        #copy.deepcopy(self.state.saved_state) 
     1085        self.state.state_list[str(state_num)] = self.state.clone_state() 
    10351086        self.state.state_num = state_num 
    10361087        self._undo_enable() 
     
    11051156        # Ask the user the location of the file to write to. 
    11061157        path = None 
    1107         dlg = wx.FileDialog(self, "Choose a file", self._default_save_location, "", "*.inv", wx.SAVE) 
     1158        dlg = wx.FileDialog(self, "Choose a file", 
     1159                            self._default_save_location, "", "*.inv", wx.SAVE) 
    11081160        if dlg.ShowModal() == wx.ID_OK: 
    11091161            path = dlg.GetPath() 
     
    11241176        count_bf = self.data_cbbox.GetCount() 
    11251177        if count_bf > 1: 
    1126             mssg += 'Loading a new data set will reset all the work done in this panel. \n\r' 
    1127             mssg += 'Please make sure to save it first... \n\r' 
    1128             answer = wx.MessageBox(mssg, msg, wx.CANCEL|wx.OK|wx.ICON_EXCLAMATION) 
     1178            msg += "Loading a new data set will reset all the work" 
     1179            msg += " done in this panel. \n\r" 
     1180            mssg += "Please make sure to save it first... \n\r" 
     1181            answer = wx.MessageBox(mssg, msg, 
     1182                                   wx.CANCEL|wx.OK|wx.ICON_EXCLAMATION) 
    11291183     
    11301184            if answer == wx.OK: 
     
    11591213        Define main sizers needed for this panel 
    11601214        """ 
    1161         ## Box sizers must be defined first before defining buttons/textctrls (MAC). 
     1215        ## Box sizers must be defined first before  
     1216        #defining buttons/textctrls (MAC). 
    11621217        self.main_sizer = wx.BoxSizer(wx.VERTICAL) 
    11631218        #Sizer related to outputs 
     
    11931248        #Sizer related to extrapolation at low q range 
    11941249        high_q_box = wx.StaticBox(self, -1, "High Q") 
    1195         self.high_extrapolation_sizer = wx.StaticBoxSizer(high_q_box, wx.VERTICAL) 
     1250        self.high_extrapolation_sizer = wx.StaticBoxSizer(high_q_box, 
     1251                                                          wx.VERTICAL) 
    11961252        self.high_q_sizer = wx.GridBagSizer(5,5) 
    11971253        #sizer to define outputs 
     
    12091265        """ 
    12101266        #Sizer hint  
    1211         hint_msg = "First open data file from 'File' menu.  Then Highlight and right click on the data plot. \n" 
     1267        hint_msg = "First open data file from 'File' menu." 
     1268        hint_msg += "Then Highlight and right click on the data plot. \n" 
    12121269        hint_msg += "Finally, select 'Compute Invariant'." 
    12131270        self.hint_msg_txt = wx.StaticText(self, -1, hint_msg)   
    12141271        self.hint_msg_txt.SetForegroundColour("red") 
    1215         msg = "Highlight = mouse the mouse's cursor on the data until the plot's color changes to yellow" 
     1272        msg = "Highlight = mouse the mouse's cursor on the data until" 
     1273        msg += " the plot's color changes to yellow" 
    12161274        self.hint_msg_txt.SetToolTipString(msg) 
    12171275        self.hint_msg_sizer.Add(self.hint_msg_txt) 
     
    12191277        data_name_txt = wx.StaticText(self, -1, 'Data : ')   
    12201278        
    1221         self.data_name_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0)  
     1279        self.data_name_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), 
     1280                                            style=0)  
    12221281        self.data_name_tcl.SetToolTipString("Data's name.") 
    12231282        self.data_name_sizer.AddMany([(data_name_txt, 0, wx.LEFT|wx.RIGHT, 10), 
     
    12261285        data_range_txt = wx.StaticText(self, -1, 'Total Q Range (1/A): ')  
    12271286        data_min_txt = wx.StaticText(self, -1, 'Min : ')   
    1228         self.data_min_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0, name='data_min_tcl') 
     1287        self.data_min_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
     1288                                           style=0, name='data_min_tcl') 
    12291289        self.data_min_tcl.SetToolTipString("The minimum value of q range.") 
    12301290        data_max_txt = wx.StaticText(self, -1, 'Max : ')  
    1231         self.data_max_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0, name='data_max_tcl')  
     1291        self.data_max_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
     1292                                           style=0, name='data_max_tcl')  
    12321293        self.data_max_tcl.SetToolTipString("The maximum value of q range.") 
    12331294        self.data_range_sizer.AddMany([(data_range_txt, 0, wx.RIGHT, 10), 
     
    12451306        """ 
    12461307        background_txt = wx.StaticText(self, -1, 'Background : ')   
    1247         self.background_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0, name='background_tcl')  
     1308        self.background_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
     1309                                          style=0, name='background_tcl')  
    12481310        wx.EVT_TEXT(self, self.background_tcl.GetId(), self._on_text) 
    12491311        background_hint_txt = "Background" 
     
    12511313        background_unit_txt = wx.StaticText(self, -1, '[1/cm]')   
    12521314        scale_txt = wx.StaticText(self, -1, 'Scale : ')   
    1253         self.scale_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0, name='scale_tcl') 
     1315        self.scale_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0, 
     1316                                     name='scale_tcl') 
    12541317        wx.EVT_TEXT(self, self.scale_tcl.GetId(), self._on_text) 
    12551318        scale_hint_txt = "Scale" 
     
    12661329        """ 
    12671330        contrast_txt = wx.StaticText(self, -1, 'Contrast : ')   
    1268         self.contrast_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0,name='contrast_tcl') 
     1331        self.contrast_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
     1332                                        style=0,name='contrast_tcl') 
    12691333        wx.EVT_TEXT(self, self.contrast_tcl.GetId(), self._on_text) 
    12701334        contrast_hint_txt = "Contrast" 
     
    12731337        porod_const_txt = wx.StaticText(self, -1, 'Porod Constant:')   
    12741338        self.porod_constant_tcl = InvTextCtrl(self, -1,  
    1275                                               size=(_BOX_WIDTH, 20), style=0,name='porod_constant_tcl')  
     1339                                              size=(_BOX_WIDTH, 20), style=0, 
     1340                                              name='porod_constant_tcl')  
    12761341        wx.EVT_TEXT(self, self.porod_constant_tcl.GetId(), self._on_text) 
    12771342        porod_const_hint_txt = "Porod Constant" 
     
    13551420        Draw widgets related to extrapolation at low q range 
    13561421        """ 
    1357         self.enable_low_cbox = wx.CheckBox(self, -1, "Enable Extrapolate Low Q",name='enable_low_cbox') 
     1422        self.enable_low_cbox = wx.CheckBox(self, -1, 
     1423                                           "Enable Extrapolate Low Q", 
     1424                                           name='enable_low_cbox') 
    13581425        wx.EVT_CHECKBOX(self, self.enable_low_cbox.GetId(), 
    13591426                                         self._enable_low_q_section) 
    13601427        self.fix_enable_low = wx.RadioButton(self, -1, 'Fix', 
    1361                                          (10, 10),style=wx.RB_GROUP,name='fix_enable_low') 
     1428                                         (10, 10), style=wx.RB_GROUP, 
     1429                                         name='fix_enable_low') 
    13621430        self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, 
    13631431                                     id=self.fix_enable_low.GetId()) 
    1364         self.fit_enable_low = wx.RadioButton(self, -1, 'Fit', (10, 10),name='fit_enable_low') 
     1432        self.fit_enable_low = wx.RadioButton(self, -1, 'Fit', (10, 10), 
     1433                                             name='fit_enable_low') 
    13651434        self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low,  
    13661435                                        id=self.fit_enable_low.GetId()) 
    13671436        self.guinier = wx.RadioButton(self, -1, 'Guinier', 
    1368                                          (10, 10),style=wx.RB_GROUP, name='guinier') 
     1437                                         (10, 10), style=wx.RB_GROUP, 
     1438                                         name='guinier') 
    13691439        self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, 
    13701440                                     id=self.guinier.GetId())         
    1371         self.power_law_low = wx.RadioButton(self, -1, 'Power Law', (10, 10),name='power_law_low') 
     1441        self.power_law_low = wx.RadioButton(self, -1, 'Power Law', 
     1442                                            (10, 10), name='power_law_low') 
    13721443        self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low,  
    13731444                                        id=self.power_law_low.GetId()) 
    13741445         
    13751446        npts_low_txt = wx.StaticText(self, -1, 'Npts') 
    1376         self.npts_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1),name='npts_low_tcl') 
     1447        self.npts_low_tcl = InvTextCtrl(self, -1, 
     1448                                        size=(_BOX_WIDTH*2/3, -1), 
     1449                                        name='npts_low_tcl') 
    13771450        wx.EVT_TEXT(self, self.npts_low_tcl.GetId(), self._on_text) 
    13781451        msg_hint = "Number of Q points to consider" 
     
    13801453        self.npts_low_tcl.SetToolTipString(msg_hint) 
    13811454        power_txt = wx.StaticText(self, -1, 'Power') 
    1382         self.power_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1),name='power_low_tcl') 
     1455        self.power_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1), 
     1456                                         name='power_low_tcl') 
    13831457        wx.EVT_TEXT(self, self.power_low_tcl.GetId(), self._on_text) 
    13841458        
     
    13871461        iy = 0 
    13881462        ix = 0 
    1389         self.low_q_sizer.Add(self.enable_low_cbox,(iy, ix),(1,5), 
     1463        self.low_q_sizer.Add(self.enable_low_cbox,(iy, ix), (1, 5), 
    13901464                            wx.TOP|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    13911465        iy += 1 
    13921466        ix = 0 
    1393         self.low_q_sizer.Add(npts_low_txt,(iy, ix),(1,1), 
     1467        self.low_q_sizer.Add(npts_low_txt,(iy, ix), (1, 1), 
    13941468                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    13951469        ix += 1 
     
    14021476        iy += 1 
    14031477        ix = 0 
    1404         self.low_q_sizer.Add(self.power_law_low,(iy, ix),(1,2), 
     1478        self.low_q_sizer.Add(self.power_law_low,(iy, ix), (1, 2), 
    14051479                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    14061480        
     
    14081482        ix = 1 
    14091483        iy += 1 
    1410         self.low_q_sizer.Add(self.fix_enable_low,(iy, ix),(1,1), 
     1484        self.low_q_sizer.Add(self.fix_enable_low,(iy, ix), (1, 1), 
    14111485                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    14121486        ix += 1 
     
    14151489        ix = 1 
    14161490        iy += 1 
    1417         self.low_q_sizer.Add(power_txt,(iy, ix),(1,1), 
     1491        self.low_q_sizer.Add(power_txt,(iy, ix), (1, 1), 
    14181492                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    14191493        ix += 1 
    1420         self.low_q_sizer.Add(self.power_low_tcl, (iy, ix), (1,1), 
     1494        self.low_q_sizer.Add(self.power_low_tcl, (iy, ix), (1, 1), 
    14211495                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    14221496        self.low_extrapolation_sizer.AddMany([(self.low_q_sizer, 0, 
     
    14661540        Draw widgets related to extrapolation at high q range 
    14671541        """ 
    1468         self.enable_high_cbox = wx.CheckBox(self, -1, "Enable Extrapolate high-Q", name='enable_high_cbox') 
     1542        self.enable_high_cbox = wx.CheckBox(self, -1, 
     1543                                            "Enable Extrapolate high-Q", 
     1544                                            name='enable_high_cbox') 
    14691545        wx.EVT_CHECKBOX(self, self.enable_high_cbox.GetId(), 
    14701546                                         self._enable_high_q_section) 
    14711547        self.fix_enable_high = wx.RadioButton(self, -1, 'Fix', 
    1472                                          (10, 10),style=wx.RB_GROUP,name='fix_enable_high') 
     1548                                         (10, 10), style=wx.RB_GROUP, 
     1549                                         name='fix_enable_high') 
    14731550        self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, 
    14741551                                     id=self.fix_enable_high.GetId()) 
    1475         self.fit_enable_high = wx.RadioButton(self, -1, 'Fit', (10, 10),name='fit_enable_high')      
     1552        self.fit_enable_high = wx.RadioButton(self, -1, 'Fit', (10, 10), 
     1553                                              name='fit_enable_high')      
    14761554        self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high,  
    14771555                                        id=self.fit_enable_high.GetId()) 
     
    14811559        self.power_law_high.SetToolTipString(msg_hint) 
    14821560        npts_high_txt = wx.StaticText(self, -1, 'Npts') 
    1483         self.npts_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1),name='npts_high_tcl') 
     1561        self.npts_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1), 
     1562                                         name='npts_high_tcl') 
    14841563        wx.EVT_TEXT(self, self.npts_high_tcl.GetId(), self._on_text) 
    14851564        msg_hint = "Number of Q points to consider" 
     
    14871566        self.npts_high_tcl.SetToolTipString(msg_hint) 
    14881567        power_txt = wx.StaticText(self, -1, 'Power') 
    1489         self.power_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1),name='power_high_tcl') 
     1568        self.power_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1), 
     1569                                          name='power_high_tcl') 
    14901570        wx.EVT_TEXT(self, self.power_high_tcl.GetId(), self._on_text) 
    14911571        power_hint_txt = "Exponent to apply to the Power_law function." 
     
    14931573        iy = 0 
    14941574        ix = 0 
    1495         self.high_q_sizer.Add(self.enable_high_cbox,(iy, ix),(1,5), 
     1575        self.high_q_sizer.Add(self.enable_high_cbox, (iy, ix), (1, 5), 
    14961576                            wx.TOP|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    14971577        iy += 1 
    14981578        ix = 0 
    1499         self.high_q_sizer.Add(npts_high_txt,(iy, ix),(1,1), 
     1579        self.high_q_sizer.Add(npts_high_txt, (iy, ix), (1, 1), 
    15001580                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    15011581        ix += 1 
    1502         self.high_q_sizer.Add(self.npts_high_tcl, (iy, ix), (1,1), 
     1582        self.high_q_sizer.Add(self.npts_high_tcl, (iy, ix), (1, 1), 
    15031583                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    15041584        iy += 2 
    15051585        ix = 0 
    1506         self.high_q_sizer.Add(self.power_law_high,(iy, ix),(1,2), 
     1586        self.high_q_sizer.Add(self.power_law_high, (iy, ix),(1, 2), 
    15071587                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    15081588        
     
    15101590        ix = 1 
    15111591        iy += 1 
    1512         self.high_q_sizer.Add(self.fix_enable_high,(iy, ix),(1,1), 
     1592        self.high_q_sizer.Add(self.fix_enable_high,(iy, ix), (1, 1), 
    15131593                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    15141594        ix += 1 
    1515         self.high_q_sizer.Add(self.fit_enable_high,(iy, ix),(1,1), 
     1595        self.high_q_sizer.Add(self.fit_enable_high,(iy, ix), (1, 1), 
    15161596                           wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    15171597        ix = 1 
    15181598        iy += 1 
    1519         self.high_q_sizer.Add(power_txt,(iy, ix),(1,1), 
     1599        self.high_q_sizer.Add(power_txt,(iy, ix), (1, 1), 
    15201600                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    15211601        ix += 1 
    1522         self.high_q_sizer.Add(self.power_high_tcl, (iy, ix), (1,1), 
     1602        self.high_q_sizer.Add(self.power_high_tcl, (iy, ix),  (1, 1), 
    15231603                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    15241604        self.high_extrapolation_sizer.AddMany([(self.high_q_sizer, 0,  
     
    15341614        extrapolation_min_txt = wx.StaticText(self, -1, 'Min :')   
    15351615        self.extrapolation_min_tcl = OutputTextCtrl(self, -1,  
    1536                                                 size=(_BOX_WIDTH, 20), style=0,name='extrapolation_min_tcl') 
     1616                                                size=(_BOX_WIDTH, 20), style=0, 
     1617                                                name='extrapolation_min_tcl') 
    15371618        self.extrapolation_min_tcl.SetValue(str(Q_MINIMUM)) 
    1538         self.extrapolation_min_tcl.SetToolTipString("The minimum extrapolated q value.") 
     1619        hint_msg = "The minimum extrapolated q value." 
     1620        self.extrapolation_min_tcl.SetToolTipString(hint_msg) 
    15391621        extrapolation_max_txt = wx.StaticText(self, -1, 'Max :')  
    15401622        self.extrapolation_max_tcl = OutputTextCtrl(self, -1, 
    1541                                                   size=(_BOX_WIDTH, 20), style=0,name='extrapolation_max_tcl')  
     1623                                                  size=(_BOX_WIDTH, 20), 
     1624                                                  style=0, 
     1625                                                  name='extrapolation_max_tcl')  
    15421626        self.extrapolation_max_tcl.SetValue(str(Q_MAXIMUM)) 
    1543         self.extrapolation_max_tcl.SetToolTipString("The maximum extrapolated q value.") 
    1544         self.extrapolation_range_sizer.AddMany([(extra_hint_txt, 0, wx.LEFT, 10), 
    1545                                                 (extrapolation_min_txt, 0, wx.LEFT, 10), 
     1627        hint_msg = "The maximum extrapolated q value." 
     1628        self.extrapolation_max_tcl.SetToolTipString(hint_msg) 
     1629        self.extrapolation_range_sizer.AddMany([(extra_hint_txt, 0,  
     1630                                                 wx.LEFT, 10), 
     1631                                                (extrapolation_min_txt, 0, 
     1632                                                 wx.LEFT, 10), 
    15461633                                                (self.extrapolation_min_tcl, 
    15471634                                                            0, wx.LEFT, 10), 
    1548                                                 (extrapolation_max_txt, 0, wx.LEFT, 10), 
     1635                                                (extrapolation_max_txt, 0, 
     1636                                                 wx.LEFT, 10), 
    15491637                                                (self.extrapolation_max_tcl, 
    15501638                                                            0, wx.LEFT, 10), 
     
    15691657        uncertainty = "+/-"  
    15701658        volume_txt = wx.StaticText(self, -1, 'Volume Fraction      ') 
    1571         self.volume_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='volume_tcl') 
     1659        self.volume_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1), 
     1660                                         name='volume_tcl') 
    15721661        wx.EVT_TEXT(self, self.volume_tcl.GetId(), self._on_out_text) 
    15731662        self.volume_tcl.SetToolTipString("Volume fraction.") 
    1574         self.volume_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='volume_err_tcl') 
     1663        self.volume_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1), 
     1664                                             name='volume_err_tcl') 
    15751665        wx.EVT_TEXT(self, self.volume_err_tcl.GetId(), self._on_out_text) 
    1576         self.volume_err_tcl.SetToolTipString("Uncertainty on the volume fraction.") 
     1666        hint_msg = "Uncertainty on the volume fraction." 
     1667        self.volume_err_tcl.SetToolTipString(hint_msg) 
    15771668        volume_units_txt = wx.StaticText(self, -1, unit_volume) 
    15781669         
    15791670        surface_txt = wx.StaticText(self, -1, 'Specific Surface') 
    1580         self.surface_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='surface_tcl') 
     1671        self.surface_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1), 
     1672                                          name='surface_tcl') 
    15811673        wx.EVT_TEXT(self, self.surface_tcl.GetId(), self._on_out_text) 
    15821674        self.surface_tcl.SetToolTipString("Specific surface value.") 
    1583         self.surface_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='surface_err_tcl') 
     1675        self.surface_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1), 
     1676                                              name='surface_err_tcl') 
    15841677        wx.EVT_TEXT(self, self.surface_err_tcl.GetId(), self._on_out_text) 
    1585         self.surface_err_tcl.SetToolTipString("Uncertainty on the specific surface.") 
     1678        hint_msg = "Uncertainty on the specific surface." 
     1679        self.surface_err_tcl.SetToolTipString(hint_msg) 
    15861680        surface_units_txt = wx.StaticText(self, -1, unit_surface) 
    15871681        iy = 0 
    15881682        ix = 0 
    1589         self.volume_surface_sizer.Add(volume_txt, (iy, ix), (1,1), 
     1683        self.volume_surface_sizer.Add(volume_txt, (iy, ix), (1, 1), 
    15901684                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    15911685        ix += 1 
    1592         self.volume_surface_sizer.Add(self.volume_tcl, (iy, ix), (1,1), 
     1686        self.volume_surface_sizer.Add(self.volume_tcl, (iy, ix), (1, 1), 
    15931687                            wx.EXPAND|wx.ADJUST_MINSIZE, 10) 
    15941688        ix += 1 
     
    15961690                         (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10)  
    15971691        ix += 1 
    1598         self.volume_surface_sizer.Add(self.volume_err_tcl, (iy, ix), (1,1), 
     1692        self.volume_surface_sizer.Add(self.volume_err_tcl, (iy, ix), (1, 1), 
    15991693                            wx.EXPAND|wx.ADJUST_MINSIZE, 10)  
    16001694        ix += 1 
    1601         self.volume_surface_sizer.Add(volume_units_txt, (iy, ix), (1,1), 
     1695        self.volume_surface_sizer.Add(volume_units_txt, (iy, ix), (1, 1), 
    16021696                             wx.EXPAND|wx.ADJUST_MINSIZE, 10) 
    16031697        iy += 1 
    16041698        ix = 0 
    1605         self.volume_surface_sizer.Add(surface_txt, (iy, ix), (1,1), 
     1699        self.volume_surface_sizer.Add(surface_txt, (iy, ix), (1, 1), 
    16061700                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    16071701        ix += 1 
    1608         self.volume_surface_sizer.Add(self.surface_tcl, (iy, ix), (1,1), 
     1702        self.volume_surface_sizer.Add(self.surface_tcl, (iy, ix), (1, 1), 
    16091703                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    16101704        ix += 1 
     
    16121706                         (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    16131707        ix += 1 
    1614         self.volume_surface_sizer.Add(self.surface_err_tcl, (iy, ix), (1,1), 
     1708        self.volume_surface_sizer.Add(self.surface_err_tcl, (iy, ix), (1, 1), 
    16151709                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    16161710        ix += 1 
    1617         self.volume_surface_sizer.Add(surface_units_txt, (iy, ix), (1,1), 
     1711        self.volume_surface_sizer.Add(surface_units_txt, (iy, ix), (1, 1), 
    16181712                            wx.EXPAND|wx.ADJUST_MINSIZE, 10) 
    16191713         
     
    16251719        unit_invariant = '[1/(cm * A)]' 
    16261720        invariant_total_txt = wx.StaticText(self, -1, 'Invariant Total [Q*]') 
    1627         self.invariant_total_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='invariant_total_tcl') 
     1721        self.invariant_total_tcl = OutputTextCtrl(self, -1, 
     1722                                                  size=(_BOX_WIDTH,-1), 
     1723                                                  name='invariant_total_tcl') 
    16281724        msg_hint = "Total invariant [Q*], including extrapolated regions." 
    16291725        self.invariant_total_tcl.SetToolTipString(msg_hint) 
    1630         self.invariant_total_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='invariant_total_err_tcl') 
    1631         self.invariant_total_err_tcl.SetToolTipString("Uncertainty on invariant.") 
     1726        self.invariant_total_err_tcl = OutputTextCtrl(self, -1, 
     1727                                                      size=(_BOX_WIDTH,-1), 
     1728                                                name='invariant_total_err_tcl') 
     1729        hint_msg = "Uncertainty on invariant." 
     1730        self.invariant_total_err_tcl.SetToolTipString(hint_msg) 
    16321731        invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant) 
    16331732     
     
    16351734        iy = 0 
    16361735        ix = 0 
    1637         self.invariant_sizer.Add(invariant_total_txt, (iy, ix), (1,1), 
     1736        self.invariant_sizer.Add(invariant_total_txt, (iy, ix), (1, 1), 
    16381737                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    16391738        ix += 1 
    1640         self.invariant_sizer.Add(self.invariant_total_tcl, (iy, ix), (1,1), 
     1739        self.invariant_sizer.Add(self.invariant_total_tcl, (iy, ix), (1, 1), 
    16411740                          wx.EXPAND|wx.ADJUST_MINSIZE, 10) 
    16421741        ix += 1 
     
    16441743                         (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10)  
    16451744        ix += 1 
    1646         self.invariant_sizer.Add(self.invariant_total_err_tcl, (iy, ix), (1,1), 
     1745        self.invariant_sizer.Add(self.invariant_total_err_tcl, (iy, ix), (1, 1), 
    16471746                             wx.EXPAND|wx.ADJUST_MINSIZE, 10) 
    16481747        ix += 1 
    1649         self.invariant_sizer.Add(invariant_total_units_txt,(iy, ix), (1,1), 
     1748        self.invariant_sizer.Add(invariant_total_units_txt,(iy, ix), (1, 1), 
    16501749                          wx.EXPAND|wx.ADJUST_MINSIZE, 10) 
    16511750  
     
    16751774        #compute button 
    16761775        id = wx.NewId() 
    1677         self.button_calculate = wx.Button(self, id, "Compute", name ='compute_invariant' ) 
     1776        self.button_calculate = wx.Button(self, id, "Compute", 
     1777                                          name='compute_invariant') 
    16781778        self.button_calculate.SetToolTipString("Compute invariant") 
    16791779        self.Bind(wx.EVT_BUTTON, self.compute_invariant, id=id)    
     
    16811781        id = wx.NewId() 
    16821782        self.button_details = wx.Button(self, id, "Details?") 
    1683         self.button_details.SetToolTipString("Details about the results of the computation") 
     1783        hint_msg = "Details about the results of the computation" 
     1784        self.button_details.SetToolTipString(hint_msg) 
    16841785        self.Bind(wx.EVT_BUTTON, self.display_details, id=id) 
    16851786        details = "Details on Invariant Total Calculations" 
     
    16891790                                    wx.RIGHT|wx.BOTTOM|wx.TOP, 10), 
    16901791                                   (self.button_details, 0 , wx.ALL, 10), 
    1691                         (self.button_calculate, 0 , wx.RIGHT|wx.TOP|wx.BOTTOM, 10)])#, 
     1792                        (self.button_calculate, 0 , 
     1793                         wx.RIGHT|wx.TOP|wx.BOTTOM, 10)])#, 
    16921794                                   #(self.button_undo, 0 , wx.ALL, 10), 
    16931795                                   #(self.button_redo, 0 , wx.ALL, 10)]) 
     
    17061808        #undo button 
    17071809        id = wx.NewId() 
    1708         self.button_undo = wx.BitmapButton(self, id,wx.Bitmap(self.undo_png))#wx.Button(self, id, "Undo",size=(50,20)) 
     1810        #wx.Button(self, id, "Undo",size=(50,20)) 
     1811        self.button_undo = wx.BitmapButton(self, id,wx.Bitmap(self.undo_png)) 
    17091812        self.button_undo.SetToolTipString("Undo") 
    17101813         
     
    17141817        #redo button 
    17151818        id = wx.NewId() 
    1716         self.button_redo = wx.BitmapButton(self, id,wx.Bitmap(self.redo_png))#wx.Button(self, id, "Redo",size=(50,20)) 
     1819        #wx.Button(self, id, "Redo",size=(50,20)) 
     1820        self.button_redo = wx.BitmapButton(self, id,wx.Bitmap(self.redo_png)) 
    17171821        self.button_redo.SetToolTipString("Redo") 
    17181822        self.Bind(wx.EVT_BUTTON, self.redo, id=id) 
     
    17201824        #bookmark button 
    17211825        id = wx.NewId() 
    1722         self.button_bookmark = wx.BitmapButton(self, id,wx.Bitmap(self.bookmark_png))#wx.Button(self, id, "Undo",size=(50,20)) 
    1723         self.button_bookmark.SetToolTipString("Bookmark: right-click on the panel to retrieve it") 
     1826        #wx.Button(self, id, "Undo",size=(50,20)) 
     1827        self.button_bookmark = wx.BitmapButton(self, id, 
     1828                                               wx.Bitmap(self.bookmark_png)) 
     1829        hint_msg = "Bookmark: right-click on the panel to retrieve it" 
     1830        self.button_bookmark.SetToolTipString(hint_msg) 
    17241831        self.Bind(wx.EVT_BUTTON, self._on_bookmark, id=id) 
    17251832        #report button 
    17261833        id = wx.NewId() 
    1727         self.button_report = wx.BitmapButton(self, id,wx.Bitmap(self.report_png))#wx.Button(self, id, "Redo",size=(50,20)) 
    1728         self.button_report.SetToolTipString("Report the result of the computation") 
     1834        #wx.Button(self, id, "Redo",size=(50,20)) 
     1835        self.button_report = wx.BitmapButton(self, id, 
     1836                                             wx.Bitmap(self.report_png)) 
     1837        hint_msg = "Report the result of the computation" 
     1838        self.button_report.SetToolTipString(hint_msg) 
    17291839        self.Bind(wx.EVT_BUTTON, self.report, id=id) 
    17301840        #self.button_report.Disable()    
    17311841        #save button 
    17321842        id = wx.NewId() 
    1733         self.button_save = wx.BitmapButton(self, id,wx.Bitmap(self.save_png), name ='Save_invariant')#wx.Button(self, id, "Save", name ='Save_invariant' ) 
     1843        #wx.Button(self, id, "Save", name ='Save_invariant' ) 
     1844        self.button_save = wx.BitmapButton(self, id, wx.Bitmap(self.save_png), 
     1845                                           name='Save_invariant') 
    17341846        self.button_save.SetToolTipString("Save as a file") 
    17351847        self.Bind(wx.EVT_BUTTON, self._on_save_button, id=id)    
    17361848        self.button_save.Disable()   
    1737         self.save_button_sizer.AddMany([((PANEL_WIDTH/2,20), 1 , wx.EXPAND|wx.ADJUST_MINSIZE,0), 
    1738                                    (self.button_undo, 0 ,wx.LEFT|wx.ADJUST_MINSIZE, 10), 
    1739                                    (self.button_redo, 0 ,wx.LEFT|wx.ADJUST_MINSIZE, 10), 
    1740                                    (self.button_bookmark, 0 ,wx.LEFT|wx.ADJUST_MINSIZE, 10), 
    1741                                    (self.button_report, 0 ,wx.LEFT|wx.ADJUST_MINSIZE, 10), 
    1742                                    (self.button_save, 0 ,wx.LEFT|wx.ADJUST_MINSIZE, 10)])         
     1849        self.save_button_sizer.AddMany([((PANEL_WIDTH/2,20), 1 , 
     1850                                         wx.EXPAND|wx.ADJUST_MINSIZE,0), 
     1851                                   (self.button_undo, 0 , 
     1852                                    wx.LEFT|wx.ADJUST_MINSIZE, 10), 
     1853                                   (self.button_redo, 0 , 
     1854                                    wx.LEFT|wx.ADJUST_MINSIZE, 10), 
     1855                                   (self.button_bookmark, 0 , 
     1856                                    wx.LEFT|wx.ADJUST_MINSIZE, 10), 
     1857                                   (self.button_report, 0 , 
     1858                                    wx.LEFT|wx.ADJUST_MINSIZE, 10), 
     1859                                   (self.button_save, 0 , 
     1860                                    wx.LEFT|wx.ADJUST_MINSIZE, 10)])         
    17431861    def _do_layout(self): 
    17441862        """ 
     
    17811899    """ 
    17821900    """ 
    1783     def __init__(self, parent=None, id=1,graph=None,  
    1784                  data=None, title="Invariant",base=None): 
     1901    def __init__(self, parent=None, id=1, graph=None,  
     1902                 data=None, title="Invariant", base=None): 
    17851903         
    17861904        wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH +100, 
     
    17891907        self.loader = Loader() 
    17901908        import invariant 
    1791  
    1792         data= self.loader.load("C:/ECLPS/workspace/trunk/DataLoader/test/ascii_test_3.txt") 
     1909        path = "C:/ECLPS/workspace/trunk/DataLoader/test/ascii_test_3.txt" 
     1910        data= self.loader.load(path) 
    17931911        self.panel = InvariantPanel(self) 
    17941912 
  • invariantview/perspectives/invariant/invariant_state.py

    r5069a18 r4a2b054  
    1 import time, os, sys 
     1""" 
     2""" 
     3 
     4import time 
     5import os 
     6import sys 
    27import logging 
    38import copy 
     
    813from DataLoader.readers.cansas_reader import get_content 
    914from sans.guiframe.utils import format_number 
    10 from sans.guiframe.dataFitting import Theory1D, Data1D 
     15from sans.guiframe.dataFitting import Theory1D 
     16from sans.guiframe.dataFitting import Data1D 
     17 
    1118INVNODE_NAME = 'invariant' 
    1219CANSAS_NS = "cansas1d/1.0" 
     20 
    1321# default state 
    1422list = {'file': 'None', 
     
    3745        'surface_tcl':'', 
    3846        'surface_err_tcl':''} 
    39 # list of states: This list will be filled as panel init and the number of states increases 
     47# list of states: This list will be filled as panel  
     48# init and the number of states increases 
    4049state_list = {} 
    4150bookmark_list = {} 
     
    5059        'power_low_tcl': 0}   
    5160# list of output parameters (order sensitive) used by __str__     
    52 output_list = [["qstar_low",                  "Q* from low Q extrapolation [1/(cm*A)]"], 
     61output_list = [["qstar_low",      "Q* from low Q extrapolation [1/(cm*A)]"], 
    5362               ["qstar_low_err",             "dQ* from low Q extrapolation"], 
    5463               ["qstar_low_percent",  "Q* percent from low Q extrapolation"], 
    55                ["qstar",                                     "Q* from data [1/(cm*A)]"], 
     64               ["qstar",              "Q* from data [1/(cm*A)]"], 
    5665               ["qstar_err",                                "dQ* from data"], 
    5766               ["qstar_percent",                     "Q* percent from data"], 
    58                ["qstar_high",                "Q* from high Q extrapolation [1/(cm*A)]"], 
     67               ["qstar_high",    "Q* from high Q extrapolation [1/(cm*A)]"], 
    5968               ["qstar_high_err",           "dQ* from high Q extrapolation"], 
    6069               ["qstar_high_percent", "Q* percent from low Q extrapolation"], 
    61                ["qstar_total",                                   "total Q* [1/(cm*A)]"], 
     70               ["qstar_total",         "total Q* [1/(cm*A)]"], 
    6271               ["qstar_total_err",                              "total dQ*"], 
    6372               ["volume",                                 "volume fraction"], 
     
    97106        import sans.perspectives.invariant as invariant 
    98107        path = invariant.get_data_path(media='media') 
    99         path_report_html= os.path.join(path,"report_template.html") 
    100         html_template=open(path_report_html,"r") 
     108        path_report_html = os.path.join(path,"report_template.html") 
     109        html_template = open(path_report_html,"r") 
    101110        self.template_str = html_template.read() 
    102111        self.report_str = self.template_str 
    103112        #self.report_str_save = None 
    104113        html_template.close() 
    105          
    106  
    107114         
    108115    def __str__(self): 
     
    119126 
    120127        state_num = int(self.saved_state['state_num']) 
    121         state = "\n[Invariant computation for %s: "% file_name 
    122         state += "performed at %s on %s] \n"%(my_time, date) 
    123         state += "State No.: %d \n"% state_num 
     128        state = "\n[Invariant computation for %s: " % file_name 
     129        state += "performed at %s on %s] \n" % (my_time, date) 
     130        state += "State No.: %d \n" % state_num 
    124131        state += "\n=== Inputs ===\n" 
    125132         
    126133        # text ctl general inputs ( excluding extrapolation text ctl) 
    127         for key,value in self.input_list.iteritems():  
     134        for key, value in self.input_list.iteritems():  
    128135            if value == '': 
    129136                continue 
     
    131138            max_ind = len(key_split)-1 
    132139            if key_split[max_ind] == 'tcl':  
    133                 name ="" 
    134                 if key_split[1]== 'low' or key_split[1]== 'high': 
     140                name = "" 
     141                if key_split[1] == 'low' or key_split[1] == 'high': 
    135142                    continue 
    136                 for ind in range(0,max_ind): 
    137                     name +=" %s"%key_split[ind] 
    138                 state += "%s:   %s\n"% (name.lstrip(" "),value) 
     143                for ind in range(0, max_ind): 
     144                    name += " %s" % key_split[ind] 
     145                state += "%s:   %s\n" % (name.lstrip(" "), value) 
    139146                 
    140147        # other input parameters        
     
    148155        if compute_state['enable_high_cbox']: 
    149156            extra_hi = 'Power law' 
    150         state += "\nExtrapolation:  High=%s; Low=%s\n" %(extra_hi,extra_lo)    
     157        state += "\nExtrapolation:  High=%s; Low=%s\n" %(extra_hi, extra_lo)    
    151158        low_off = False 
    152159        high_off = False 
    153         for key,value in self.input_list.iteritems():  
     160        for key, value in self.input_list.iteritems():  
    154161            key_split = key.split('_')  
    155             max_ind = len(key_split)-1    
     162            max_ind = len(key_split) - 1    
    156163            if key_split[max_ind] == 'tcl':  
    157                 name =""  
     164                name = ""  
    158165                # check each buttons whether or not ON or OFF 
    159                 if key_split[1]== 'low' or key_split[1]== 'high': 
    160                     if not compute_state['enable_low_cbox'] and key_split[max_ind-1] == 'low': 
     166                if key_split[1] == 'low' or key_split[1] == 'high': 
     167                    if not compute_state['enable_low_cbox'] and \ 
     168                        key_split[max_ind-1] == 'low': 
    161169                        low_off = True 
    162170                        continue               
    163                     elif not compute_state['enable_high_cbox'] and key_split[max_ind-1]== 'high': 
     171                    elif not compute_state['enable_high_cbox'] and \ 
     172                        key_split[max_ind-1] == 'high': 
    164173                        high_off = True 
    165174                        continue 
    166                     elif extra_lo == 'Guinier' and key_split[0]== 'power' and key_split[max_ind-1]== 'low': 
     175                    elif extra_lo == 'Guinier' and key_split[0] == 'power' and \ 
     176                        key_split[max_ind-1] == 'low': 
    167177                        continue 
    168                     for ind in range(0,max_ind): 
    169                         name +=" %s"%key_split[ind] 
     178                    for ind in range(0, max_ind): 
     179                        name += " %s" % key_split[ind] 
    170180                    name = name.lstrip(" ") 
    171181                    if name == "power low" : 
     
    179189                        else: 
    180190                            name += ' (Fitted)' 
    181                     state += "%s:   %s\n"% (name,value) 
     191                    state += "%s:   %s\n" % (name, value) 
    182192        # Outputs 
    183193        state += "\n=== Outputs ===" 
     
    185195            item_split = item[0].split('_')  
    186196            # Exclude the extrapolation that turned off 
    187             if len(item_split)>1: 
    188                 if low_off and item_split[1] == 'low': continue 
    189                 if high_off and item_split[1] == 'high': continue 
    190             max_ind = len(item_split)-1 
     197            if len(item_split) > 1: 
     198                if low_off and item_split[1] == 'low': 
     199                    continue 
     200                if high_off and item_split[1] == 'high': 
     201                    continue 
     202            max_ind = len(item_split) - 1 
    191203            value = None 
    192204            try: 
    193205                # Q* outputs 
    194                 exec "value = self.container.%s\n"% item[0] 
     206                exec "value = self.container.%s\n" % item[0] 
    195207            except: 
    196208                # other outputs than Q* 
    197                 name = item[0]+"_tcl" 
    198                 exec "value = self.saved_state['%s']"% name 
     209                name = item[0] + "_tcl" 
     210                exec "value = self.saved_state['%s']" % name 
    199211                 
    200212            # Exclude the outputs w/''     
    201             if value == '': continue     
    202              
     213            if value == '': 
     214                continue     
    203215            # Error outputs 
    204216            if item_split[max_ind] == 'err': 
    205                 state += "+- %s "%format_number(value) 
    206                  
     217                state += "+- %s " % format_number(value) 
    207218            # Percentage outputs 
    208219            elif item_split[max_ind] == 'percent': 
    209220                try: 
    210                     value = float(value)*100 
     221                    value = float(value) * 100 
    211222                except: 
    212223                    pass 
    213                 state += "(%s %s)"%(format_number(value),'%') 
     224                state += "(%s %s)" % (format_number(value), '%') 
    214225            # Outputs 
    215226            else: 
    216                 state += "\n%s:   %s "%(item[1],format_number(value,high=True)) 
     227                state += "\n%s:   %s " % (item[1],  
     228                                        format_number(value, high=True)) 
    217229        # Include warning msg 
    218230        state += "\n\nNote:\n" + self.container.warning_msg 
    219          
    220231        return state 
    221232 
    222      
    223233    def clone_state(self): 
    224234        """ 
     
    226236        """ 
    227237        return copy.deepcopy(self.saved_state) 
    228      
    229238 
    230239    def toXML(self, file="inv_state.inv", doc=None, entry_node=None): 
     
    234243        Compatible with standalone writing, or appending to an 
    235244        already existing XML document. In that case, the XML document 
    236         is required. An optional entry node in the XML document may also be given. 
     245        is required. An optional entry node in the XML document  
     246        may also be given. 
    237247         
    238248        : param file: file to write to 
    239249        : param doc: XML document object [optional] 
    240         : param entry_node: XML node within the XML document at which we will append the data [optional]    
     250        : param entry_node: XML node within the XML document at which  
     251            we will append the data [optional]    
    241252        """ 
    242253        from xml.dom.minidom import getDOMImplementation 
    243         import time 
     254        #import time 
    244255        timestamp = time.time() 
    245256        # Check whether we have to write a standalone XML file 
     
    266277        # File name 
    267278        element = newdoc.createElement("filename") 
    268         if self.file != None and self.file !='': 
     279        if self.file != None and self.file != '': 
    269280            element.appendChild(newdoc.createTextNode(str(self.file))) 
    270281        else: 
     
    293304         
    294305        for name, value in self.state_list.iteritems(): 
    295             history_element = newdoc.createElement('state_'+str(name)) 
     306            history_element = newdoc.createElement('state_' + str(name)) 
    296307            for state_name,state_value in value.iteritems(): 
    297308                state_element = newdoc.createElement(str(state_name)) 
    298                 state_element.appendChild(newdoc.createTextNode(str(state_value))) 
     309                child = newdoc.createTextNode(str(state_value)) 
     310                state_element.appendChild(child) 
    299311                history_element.appendChild(state_element) 
    300312            #history_element.appendChild(state_list_element) 
    301313            history.appendChild(history_element) 
    302314 
    303         # Bookmarks  bookmark_list[self.bookmark_num] = [my_time,date,state,comp_state] 
     315        # Bookmarks  bookmark_list[self.bookmark_num] = [\ 
     316        #my_time,date,state,comp_state] 
    304317        bookmark = newdoc.createElement("bookmark") 
    305318        top_element.appendChild(bookmark) 
     
    314327            state_list_element = newdoc.createElement('state') 
    315328            comp_state_list_element = newdoc.createElement('comp_state') 
    316             for state_name,state_value in value_list[2].iteritems(): 
     329            for state_name, state_value in value_list[2].iteritems(): 
    317330                state_element = newdoc.createElement(str(state_name)) 
    318                 state_element.appendChild(newdoc.createTextNode(str(state_value))) 
     331                child = newdoc.createTextNode(str(state_value)) 
     332                state_element.appendChild(child) 
    319333                state_list_element.appendChild(state_element) 
    320             for comp_name,comp_value in value_list[3].iteritems(): 
     334            for comp_name, comp_value in value_list[3].iteritems(): 
    321335                comp_element = newdoc.createElement(str(comp_name)) 
    322336                comp_element.appendChild(newdoc.createTextNode(str(comp_value))) 
     
    345359        """ 
    346360        if file is not None: 
    347             raise RuntimeError, "InvariantSate no longer supports non-CanSAS format for invariant files" 
     361            msg = "InvariantSate no longer supports non-CanSAS" 
     362            msg += " format for invariant files" 
     363            raise RuntimeError, msg 
    348364         
    349365        if node.get('version')\ 
     
    361377                    timestamp = (entry.get('epoch')) 
    362378                except: 
    363                     logging.error("InvariantSate.fromXML: Could not read timestamp\n %s" % sys.exc_value) 
     379                    msg = "InvariantSate.fromXML: Could not read" 
     380                    msg += " timestamp\n %s" % sys.exc_value 
     381                    logging.error(msg) 
    364382             
    365383            # Parse bookmarks 
    366384            entry_bookmark = get_content('ns:bookmark', node) 
    367385 
    368             for ind in range(1,len(entry_bookmark)+1): 
     386            for ind in range(1, len(entry_bookmark) + 1): 
    369387                temp_state = {} 
    370388                temp_bookmark = {} 
     
    372390                                 
    373391                if entry is not None: 
    374                     time = get_content('ns:time', entry ) 
     392                    time = get_content('ns:time', entry) 
    375393                    val_time = str(time.text.strip()) 
    376                     date = get_content('ns:date', entry ) 
     394                    date = get_content('ns:date', entry) 
    377395                    val_date = str(date.text.strip()) 
    378                     state_entry = get_content('ns:state', entry ) 
     396                    state_entry = get_content('ns:state', entry) 
    379397                    for item in list: 
    380398 
    381                         input_field = get_content('ns:%s' % item, state_entry ) 
    382                         val = str(input_field.text.strip()) 
    383  
    384                         if input_field is not None: 
    385                             try: 
    386                                 exec "temp_state['%s'] = %s"% (item,val)       
    387                             except: 
    388                                 exec "temp_state['%s'] = '%s'"% (item,val) 
    389                              
    390                     comp_entry = get_content('ns:comp_state', entry ) 
    391                      
    392                     for item in list: 
    393                         input_field = get_content('ns:%s' % item, comp_entry ) 
     399                        input_field = get_content('ns:%s' % item, state_entry) 
    394400                        val = str(input_field.text.strip()) 
    395401                        if input_field is not None: 
    396402                            try: 
    397                                 exec "temp_bookmark['%s'] = %s"% (item,val)       
     403                                exec "temp_state['%s'] = %s" % (item, val)       
    398404                            except: 
    399                                 exec "temp_bookmark['%s'] = '%s'"% (item,val) 
     405                                exec "temp_state['%s'] = '%s'" % (item, val) 
     406                    comp_entry = get_content('ns:comp_state', entry) 
     407                     
     408                    for item in list: 
     409                        input_field = get_content('ns:%s' % item, comp_entry) 
     410                        val = str(input_field.text.strip()) 
     411                        if input_field is not None: 
     412                            try: 
     413                                exec "temp_bookmark['%s'] = %s" % (item, val)       
     414                            except: 
     415                                exec "temp_bookmark['%s'] = '%s'" % (item, val) 
    400416                    try: 
    401                         exec "self.bookmark_list[%s] = [val_time,val_date,temp_state,temp_bookmark]"% ind 
    402  
     417                        cmd = "self.bookmark_list[%s] = [val_time," 
     418                        cmd += "val_date,temp_state,temp_bookmark]" 
     419                        exec cmd % ind 
    403420                    except: 
    404421                        raise "missing components of bookmarks..." 
    405      
    406422            # Parse histories 
    407423            entry_history = get_content('ns:history', node) 
    408424 
    409             for ind in range(0,len(entry_history)): 
     425            for ind in range(0, len(entry_history)): 
    410426                temp_state = {} 
    411427                entry = get_content('ns:state_%s' % ind, entry_history)  
     
    418434                        if input_field is not None: 
    419435                            try: 
    420                                 exec "temp_state['%s'] = %s"% (item,val)          
     436                                exec "temp_state['%s'] = %s" % (item, val)          
    421437                            except: 
    422                                 exec "temp_state['%s'] = '%s'"% (item,val) 
     438                                exec "temp_state['%s'] = '%s'" % (item, val) 
    423439                            finally: 
    424                                 exec "self.state_list['%s'] = temp_state"% ind  
    425              
     440                                exec "self.state_list['%s'] = temp_state" % ind  
    426441            # Parse current state (ie, saved_state) 
    427442            entry = get_content('ns:state', node)            
     
    432447                    if input_field is not None: 
    433448                        self.set_saved_state(name=item, value=val) 
    434                          
    435449            self.file = file_name 
    436450             
     
    442456     
    443457        # default string values 
    444         for num in range (1,19): 
    445             exec "s_%s = 'NA'"% str(num) 
     458        for num in range (1, 19): 
     459            exec "s_%s = 'NA'" % str(num) 
    446460        lines = strings.split('\n') 
    447461        # get all string values from __str__() 
    448         for line in range(0,len(lines)): 
     462        for line in range(0, len(lines)): 
    449463            if line == 1: 
    450464                s_1 = lines[1] 
     
    454468                item = lines[line].split(':') 
    455469                item[0] = item[0].strip() 
    456                 if item[0]== "scale": 
     470                if item[0] == "scale": 
    457471                    s_3 = item[1] 
    458472                elif item[0] == "porod constant": 
     
    466480                    bool_0 = extra[0].split("=") 
    467481                    bool_1 = extra[1].split("=") 
    468                     s_7 = " "+bool_0[0]+"Q region = "+bool_0[1] 
    469                     s_8 = " "+bool_1[0]+"Q region = "+bool_1[1] 
    470                 elif item[0]=="npts low": 
     482                    s_7 = " " + bool_0[0] + "Q region = " + bool_0[1] 
     483                    s_8 = " " + bool_1[0] + "Q region = " + bool_1[1] 
     484                elif item[0] == "npts low": 
    471485                    s_9 = item[1] 
    472                 elif item[0]=="npts high": 
     486                elif item[0] == " npts high": 
    473487                    s_10 = item[1] 
    474488                elif item[0] == "volume fraction": 
    475489                    val=item[1].split("+-")[0].strip() 
    476490                    error = item[1].split("+-")[1].strip() 
    477                     s_17 = val+" &plusmn; "+error 
     491                    s_17 = val + " &plusmn; " + error 
    478492                elif item[0] == "specific surface": 
    479                     val=item[1].split("+-")[0].strip() 
     493                    val = item[1].split("+-")[0].strip() 
    480494                    error = item[1].split("+-")[1].strip() 
    481                     s_18 = val+" &plusmn; "+error 
    482                 elif item[0].split("(")[0].strip()=="power high": 
     495                    s_18 = val + " &plusmn; " + error 
     496                elif item[0].split("(")[0].strip() == "power high": 
    483497                    s_11 = item[0]+" ="+item[1] 
    484                 elif item[0].split("(")[0].strip()=="power low": 
     498                elif item[0].split("(")[0].strip() == "power low": 
    485499                    s_12 = item[0]+" ="+item[1] 
    486                 elif item[0].split("[")[0].strip()=="Q* from low Q extrapolation": 
     500                elif item[0].split("[")[0].strip() == "Q* from low Q extrapolation": 
    487501                    #looks messy but this way the symbols +_ and % work on html 
    488                     val=item[1].split("+-")[0].strip() 
     502                    val = item[1].split("+-")[0].strip() 
    489503                    error = item[1].split("+-")[1].strip() 
    490504                    err = error.split("%")[0].strip() 
    491505                    percent = error.split("%")[1].strip() 
    492                     s_13 = val+" &plusmn; "+err+"&#37"+percent 
    493                 elif item[0].split("[")[0].strip()=="Q* from data": 
    494                     val=item[1].split("+-")[0].strip() 
     506                    s_13 = val + " &plusmn; " + err + "&#37" + percent 
     507                elif item[0].split("[")[0].strip() == "Q* from data": 
     508                    val = item[1].split("+-")[0].strip() 
    495509                    error = item[1].split("+-")[1].strip() 
    496510                    err = error.split("%")[0].strip() 
    497511                    percent = error.split("%")[1].strip() 
    498                     s_14 = val+" &plusmn; "+err+"&#37"+percent 
    499                 elif item[0].split("[")[0].strip()=="Q* from high Q extrapolation": 
    500                     val=item[1].split("+-")[0].strip() 
     512                    s_14 = val + " &plusmn; " + err + "&#37" + percent 
     513                elif item[0].split("[")[0].strip() == "Q* from high Q extrapolation": 
     514                    val = item[1].split("+-")[0].strip() 
    501515                    error = item[1].split("+-")[1].strip() 
    502516                    err = error.split("%")[0].strip() 
    503517                    percent = error.split("%")[1].strip() 
    504                     s_15 = val+" &plusmn; "+err+"&#37"+percent 
    505                 elif item[0].split("[")[0].strip()=="total Q*": 
    506                     val=item[1].split("+-")[0].strip() 
     518                    s_15 = val + " &plusmn; " + err + "&#37" + percent 
     519                elif item[0].split("[")[0].strip() == "total Q*": 
     520                    val = item[1].split("+-")[0].strip() 
    507521                    error = item[1].split("+-")[1].strip() 
    508                     s_16 = val+" &plusmn; "+error 
     522                    s_16 = val + " &plusmn; " + error 
    509523                else: 
    510524                    continue 
     
    513527        self.set_plot_state(extra_high=bool_0[1],extra_low=bool_1[1]) 
    514528        # get ready for report with setting all the html strings 
    515         self.report_str =  str(self.template_str)% (s_1,s_2,s_3,s_4,s_5,s_6,s_7,s_8,s_9,s_10,s_11,s_12,s_13,s_14,s_15,s_16,s_17,s_18,self.file,"%s") 
    516  
     529        self.report_str = str(self.template_str) % (s_1, s_2, 
     530                                        s_3, s_4, s_5, s_6, s_7, s_8, 
     531                                    s_9, s_10, s_11, s_12, s_13, s_14, s_15, 
     532                                        s_16, s_17, s_18, self.file, "%s") 
    517533 
    518534    def set_saved_state(self, name, value): 
     
    523539        : param value: value of the state component 
    524540        """ 
    525         rb_list = [['power_law_low','guinier'],['fit_enable_low','fix_enable_low'],['fit_enable_high','fix_enable_high']] 
     541        rb_list = [['power_law_low','guinier'], 
     542                   ['fit_enable_low','fix_enable_low'], 
     543                   ['fit_enable_high','fix_enable_high']] 
    526544 
    527545        try: 
    528             if value == None or value.lstrip().rstrip() =='': 
     546            if value == None or value.lstrip().rstrip() == '': 
    529547                exec "self.%s = '%s'" % (name, value) 
    530                 exec "self.saved_state['%s'] = '%s'" %  (name, value) 
     548                exec "self.saved_state['%s'] = '%s'" % (name, value) 
    531549            else: 
    532550                exec 'self.%s = %s' % (name, value) 
    533                 exec "self.saved_state['%s'] = %s" %  (name, value) 
    534  
    535              
    536             # set the count part of radio button clicked False for the saved_state 
    537             for title,content in rb_list: 
     551                exec "self.saved_state['%s'] = %s" % (name, value) 
     552            # set the count part of radio button clicked  
     553            # False for the saved_state 
     554            for title, content in rb_list: 
    538555                if name ==  title: 
    539556                    name = content  
     
    542559                    name = title 
    543560                    value = False  
    544             exec "self.saved_state['%s'] = '%s'" %  (name, value)      
     561            exec "self.saved_state['%s'] = '%s'" % (name, value)      
    545562            self.state_num = self.saved_state['state_num'] 
    546563        except:            
    547564            pass 
    548565 
    549     def set_plot_state(self,extra_high=False,extra_low=False): 
     566    def set_plot_state(self, extra_high=False, extra_low=False): 
    550567        """ 
    551568        Build image state that wx.html understand 
    552569        by plotting, putting it into wx.FileSystem image object 
    553570         
    554         : extrap_high,extra_low: low/high extrapolations are possible extra-plots 
     571        : extrap_high,extra_low: low/high extrapolations 
     572        are possible extra-plots 
    555573        """ 
    556574        # some imports 
     
    583601        #make python.Image object  
    584602        #size 
    585         w,h =canvas.get_width_height() 
     603        w, h = canvas.get_width_height() 
    586604        #convert to wx.Image 
    587605        wximg = wx.EmptyImage(w,h) 
     
    595613        self.imgRAM = wx.MemoryFSHandler() 
    596614        #AddFile, image can be retrieved with 'memory:filename' 
    597         self.imgRAM.AddFile('img_inv.png',wximgbmp, wx.BITMAP_TYPE_PNG) 
     615        self.imgRAM.AddFile('img_inv.png', wximgbmp, wx.BITMAP_TYPE_PNG) 
    598616         
    599617        self.wximgbmp = 'memory:img_inv.png' 
     
    611629            "SANSView file (*.svs)|*.svs"] 
    612630    ## List of allowed extensions 
    613     ext=['.inv', '.INV', '.svs', 'SVS']   
     631    ext = ['.inv', '.INV', '.svs', 'SVS']   
    614632     
    615633    def __init__(self, call_back, cansas=True): 
     
    634652        : return: None 
    635653        """ 
    636         if self.cansas==True: 
     654        if self.cansas == True: 
    637655            return self._read_cansas(path) 
    638656        else: 
     
    666684        # Locate the invariant node 
    667685        try: 
    668             nodes = entry.xpath('ns:%s' % INVNODE_NAME, namespaces={'ns': CANSAS_NS}) 
     686            nodes = entry.xpath('ns:%s' % INVNODE_NAME, 
     687                                namespaces={'ns': CANSAS_NS}) 
    669688            # Create an empty state 
    670             if nodes !=[]: 
     689            if nodes != []: 
    671690                state = InvariantState() 
    672691                state.fromXML(node=nodes[0]) 
    673692        except: 
    674             logging.info("XML document does not contain invariant information.\n %s" % sys.exc_value)   
     693            msg = "XML document does not contain invariant" 
     694            msg += " information.\n %s" % sys.exc_value 
     695            logging.info(msg)   
    675696        return state 
    676697     
     
    696717        
    697718                # Check the format version number 
    698                 # Specifying the namespace will take care of the file format version  
     719                # Specifying the namespace will take care of  
     720                # the file format version  
    699721                root = tree.getroot() 
    700722                 
    701                 entry_list = root.xpath('/ns:SASroot/ns:SASentry', namespaces={'ns': CANSAS_NS}) 
     723                entry_list = root.xpath('/ns:SASroot/ns:SASentry', 
     724                                        namespaces={'ns': CANSAS_NS}) 
    702725                 
    703726                for entry in entry_list: 
     
    716739 
    717740        # Return output consistent with the loader's api 
    718         if len(output)==0: 
     741        if len(output) == 0: 
    719742            return None 
    720         elif len(output)==1: 
     743        elif len(output) == 1: 
    721744            # Call back to post the new state 
    722745 
    723             self.call_back(state=output[0].meta_data['invstate'], datainfo = output[0]) 
     746            self.call_back(state=output[0].meta_data['invstate'], 
     747                           datainfo = output[0]) 
    724748            return output[0] 
    725749        else: 
     
    754778            datainfo = DataLoader.data_info.Data1D(x=[], y=[])     
    755779        elif not issubclass(datainfo.__class__, DataLoader.data_info.Data1D): 
    756             raise RuntimeError, "The cansas writer expects a Data1D instance: %s" % str(datainfo.__class__.__name__) 
     780            msg = "The cansas writer expects a Data1D" 
     781            msg += " instance: %s" % str(datainfo.__class__.__name__) 
     782            raise RuntimeError, msg 
    757783        #make sure title and data run is filled up. 
    758         if datainfo.title == None or datainfo.title=='': datainfo.title = datainfo.name 
    759         if datainfo.run_name == None or datainfo.run_name=={}:  
     784        if datainfo.title == None or datainfo.title == '': 
     785            datainfo.title = datainfo.name 
     786        if datainfo.run_name == None or datainfo.run_name == {}:  
    760787            datainfo.run = [str(datainfo.name)] 
    761788            datainfo.run_name[0] = datainfo.name 
    762  
    763789        # Create basic XML document 
    764790        doc, sasentry = self._to_xml_doc(datainfo) 
    765      
    766791        # Add the invariant information to the XML document 
    767792        if state is not None: 
    768793            state.toXML(datainfo.name,doc=doc, entry_node=sasentry) 
    769              
    770794        return doc 
     795 
  • invariantview/perspectives/invariant/invariant_widgets.py

    r4e1c362 r4a2b054  
    1414 
    1515import wx 
    16 import os 
    17 from invariant_state import InvariantState as IState 
    18 import copy 
     16#import os 
     17#from invariant_state import InvariantState as IState 
     18#import copy 
    1919 
    2020class InvTextCtrl(wx.TextCtrl): 
     
    2525    def __init__(self, *args, **kwds): 
    2626        wx.TextCtrl.__init__(self, *args, **kwds) 
    27         ## Set to True when the mouse is clicked while the whole string is selected 
     27        ## Set to True when the mouse is clicked while  
     28        #the whole string is selected 
    2829        self.full_selection = False 
    2930        ## Call back for EVT_SET_FOCUS events 
     
    6061                # if not, select the whole string 
    6162                (start, end) = control.GetSelection() 
    62                 if start==end: 
    63                     control.SetSelection(-1,-1) 
     63                if start == end: 
     64                    control.SetSelection(-1, -1) 
    6465            
    6566 
    66      
    6767class OutputTextCtrl(wx.TextCtrl): 
    6868    """ 
  • invariantview/perspectives/invariant/report_dialog.py

    r5b03122 r4a2b054  
    1111 
    1212""" 
    13 Dialog report panel to show and summarize the results of the invariant calculation. 
     13Dialog report panel to show and summarize the results of  
     14the invariant calculation. 
    1415""" 
    1516import wx 
    16 import sys,os 
     17import sys 
     18import os 
    1719import wx.html as html 
    1820 
    19 if sys.platform.count("win32")>0: 
     21if sys.platform.count("win32") > 0: 
    2022    _STATICBOX_WIDTH = 450 
    2123    PANEL_WIDTH = 500  
     
    3941        Initialization. The parameters added to Dialog are: 
    4042         
    41         :param list: report_list (list of html_str, text_str, image) from invariant_state 
     43        :param list: report_list (list of html_str, text_str, image) 
     44        from invariant_state 
    4245        """ 
    4346        kwds["style"] = wx.RESIZE_BORDER|wx.DEFAULT_DIALOG_STYLE 
     
    5154        self.SetWindowVariant(variant=FONT_VARIANT) 
    5255        # report string 
    53         self.report_list =list 
     56        self.report_list = list 
    5457        # put image path in the report string 
    55         self.report_html = self.report_list[0]% "memory:img_inv.png" 
     58        self.report_html = self.report_list[0] % "memory:img_inv.png" 
    5659        # layout 
    5760        self._setup_layout() 
     
    7477        button_preview = wx.Button(self, id, "Preview") 
    7578        button_preview.SetToolTipString("Print preview this report.") 
    76         button_preview.Bind(wx.EVT_BUTTON, self.onPreview, id = button_preview.GetId())  
     79        button_preview.Bind(wx.EVT_BUTTON, self.onPreview, 
     80                            id=button_preview.GetId())  
    7781        hbox.Add(button_preview) 
    7882 
     
    8084        button_print = wx.Button(self, id, "Print") 
    8185        button_print.SetToolTipString("Print this report.") 
    82         button_print.Bind(wx.EVT_BUTTON, self.onPrint, id = button_print.GetId())  
     86        button_print.Bind(wx.EVT_BUTTON, self.onPrint, 
     87                          id=button_print.GetId())  
    8388        hbox.Add(button_print) 
    8489         
     
    9196        # panel for report page 
    9297        panel = wx.Panel(self, -1) 
    93         vbox= wx.BoxSizer(wx.VERTICAL) 
     98        vbox = wx.BoxSizer(wx.VERTICAL) 
    9499        # html window 
    95100        self.hwindow = html.HtmlWindow(panel,style=wx.BORDER,size=(700,500)) 
     
    98103         
    99104        # add panels to boxsizers 
    100         vbox.Add(hbox,30) 
    101         vbox.Add(panel,500, wx.EXPAND|wx.ALL) 
     105        vbox.Add(hbox, 30) 
     106        vbox.Add(panel, 500, wx.EXPAND|wx.ALL) 
    102107 
    103108        self.SetSizerAndFit(vbox) 
     
    105110        self.Show(True) 
    106111 
    107     def onSave(self,event=None): 
     112    def onSave(self, event=None): 
    108113        """ 
    109114        Save 
    110115        """ 
    111116        #todo: complete saving fig file and as a txt file 
    112         dlg = wx.FileDialog(self, "Choose a file",\ 
    113                             wildcard ='HTML files (*.html)|*.html|'+ 
     117        dlg = wx.FileDialog(self, "Choose a file", 
     118                            wildcard='HTML files (*.html)|*.html|'+ 
    114119                            'Text files (*.txt)|*.txt', 
    115                             style = wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR) 
     120                            style=wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR) 
    116121        dlg.SetFilterIndex(0) #Set .html files to be default 
    117122 
    118123        if dlg.ShowModal() != wx.ID_OK: 
    119           dlg.Destroy() 
    120           return 
     124            dlg.Destroy() 
     125            return 
    121126         
    122127        fName = dlg.GetPath() 
     
    126131        if ext_num == 0: 
    127132            ext = '.html' 
    128             img_ext= '_img4html.png' 
     133            img_ext = '_img4html.png' 
    129134            report_frame = self.report_list[0] 
    130135        elif ext_num == 1: 
    131136            ext = '.txt'    
    132             # changing the image extension actually changes the image format on saving 
    133             img_ext= '_img4txt.pdf' 
     137            # changing the image extension actually changes the image 
     138            # format on saving 
     139            img_ext = '_img4txt.pdf' 
    134140            report = self.report_list[1] 
    135141        else: 
     
    142148        pic_fname = os.path.splitext(fName)[0] + img_ext 
    143149        #put the image path in html string 
    144         if ext_num == 0: report = report_frame % pic_fname 
     150        if ext_num == 0: 
     151            report = report_frame % pic_fname 
    145152        f = open(fName, 'w') 
    146153        f.write(report) 
     
    150157         
    151158             
    152     def onPreview(self,event=None): 
     159    def onPreview(self, event=None): 
    153160        """ 
    154161        Preview 
     
    156163        : event: Preview button event 
    157164        """ 
    158         previewh=html.HtmlEasyPrinting(name="Printing", parentWindow=self) 
     165        previewh = html.HtmlEasyPrinting(name="Printing", parentWindow=self) 
    159166        previewh.PreviewText(self.report_html) 
    160      
    161     def onPrint(self,event=None): 
     167        if event is not None: 
     168            event.Skip() 
     169     
     170    def onPrint(self, event=None): 
    162171        """ 
    163172        Print 
     
    165174        : event: Print button event 
    166175        """ 
    167         printh=html.HtmlEasyPrinting(name="Printing", parentWindow=self) 
     176        printh = html.HtmlEasyPrinting(name="Printing", parentWindow=self) 
    168177        printh.PrintText(self.report_html) 
    169  
     178        if event is not None: 
     179            event.Skip() 
    170180 
    171181    def OnClose(self,event=None): 
     
    175185        : event: Close button event 
    176186        """ 
    177          
    178187        self.Close() 
    179188     
     
    188197        f = file(filename, "wb") 
    189198        # pisa requires some extra packages, see their web-site 
    190         pdf = pisa.CreatePDF(data,f) 
    191         # close the file here otherwise it will be open until quitting the application. 
     199        pdf = pisa.CreatePDF(data, f) 
     200        # close the file here otherwise it will be open until quitting 
     201        #the application. 
    192202        f.close() 
    193203 
Note: See TracChangeset for help on using the changeset viewer.