Changeset d0cc0bbc in sasview


Ignore:
Timestamp:
Apr 5, 2010 12:57:26 PM (14 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:
46dda00
Parents:
c7c5ef8
Message:

change panel according to feedback

Location:
invariantview/perspectives/invariant
Files:
2 edited

Legend:

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

    r277fad8 rd0cc0bbc  
    99RECTANGLE_WIDTH  = 400.0   
    1010RECTANGLE_HEIGHT = 20 
    11 RECTANGLE_SCALE  = 0.0001 
    12 DEFAULT_QSTAR = 1.0 
    1311#Invariant panel size  
    1412_BOX_WIDTH = 76 
    15 _BOX_PERCENT_WIDTH = 100   
     13 
     14#scale to use for a bar of value zero 
     15RECTANGLE_SCALE  = 0.0001 
     16DEFAULT_QSTAR = 1.0   
    1617   
    1718if sys.platform.count("win32")>0: 
    1819    _STATICBOX_WIDTH = 450 
    1920    PANEL_WIDTH = 500 
    20     PANEL_HEIGHT = 700 
     21    PANEL_HEIGHT = 430 
    2122    FONT_VARIANT = 0 
    2223else: 
    2324    _STATICBOX_WIDTH = 480 
    2425    PANEL_WIDTH = 530 
    25     PANEL_HEIGHT = 700 
     26    PANEL_HEIGHT = 430 
    2627    FONT_VARIANT = 1 
    2728     
     29   
    2830     
     31class InvariantContainer(wx.Object): 
     32    def __init__(self): 
     33        #invariant at low range 
     34        self.qstar_low = 0.0 
     35        #invariant at low range error 
     36        self.qstar_low_err = 0.0 
     37        #invariant  
     38        self.qstar = 0.0 
     39        #invariant error 
     40        self.qstar_err = 0.0 
     41        #invariant at high range 
     42        self.qstar_high = 0.0 
     43        #invariant at high range error 
     44        self.qstar_high_err = 0.0 
     45        #invariant total 
     46        self.qstar_total = None 
     47        #invariant error 
     48        self.qstar_total_err = None 
     49        #scale 
     50        self.qstar_low_percent = 0.0 
     51        self.qstar_high_percent = 0.0 
     52        self.qstar_percent = 0.0 
     53        # warning message 
     54        self.existing_warning = False 
     55        self.warning_msg = "No Details on calculations available...\n" 
     56         
     57    def compute_percentage(self): 
     58        """ 
     59            Compute percentage of each invariant 
     60        """ 
     61        if self.qstar_total is not None and self.qstar_total != 0: 
     62            #compute invariant percentage 
     63            if self.qstar is None: 
     64                self.qstar = 0.0 
     65            self.qstar_percent = self.qstar/self.qstar_total 
     66            #compute low q invariant percentage 
     67            if self.qstar_low is None: 
     68                self.qstar_low = 0.0 
     69            self.qstar_low_percent = self.qstar_low/self.qstar_total 
     70            #compute high q invariant percentage 
     71            if self.qstar_high is None: 
     72                self.qstar_high = 0.0 
     73            self.qstar_high_percent = self.qstar_high/self.qstar_total 
     74        self.check_values() 
     75    
     76    def check_values(self): 
     77        """ 
     78            check the validity if invariant 
     79        """ 
     80        #warning to the user when the extrapolated invariant is greater than %5 
     81        if self.qstar_low_percent >= 0.05: 
     82            self.existing_warning = True 
     83            self.warning_msg += "Extrapolated contribution at Low Q is higher " 
     84            self.warning_msg += "than 5% of the invariant.\n" 
     85        if self.qstar_high_percent >= 0.05: 
     86            self.existing_warning = True 
     87            self.warning_msg += "Extrapolated contribution at High Q is higher " 
     88            self.warning_msg += "than 5% of the invariant.\n" 
     89        if self.qstar_low_percent + self.qstar_high_percent >= 0.05: 
     90            self.existing_warning = True 
     91            self.warning_msg += "The sum of all extrapolated contributions is higher " 
     92            self.warning_msg += "than 5% of the invariant.\n" 
     93             
     94        if self.existing_warning: 
     95            self.warning_msg += "The calculations are likely to be unreliable!\n" 
     96        else: 
     97            self.warning_msg = "No Details on calculations available...\n" 
     98             
    2999class InvariantDetailsPanel(wx.Dialog): 
    30100    """ 
     
    32102    """ 
    33103    def __init__(self, parent=None, id=-1, qstar_container=None, title="", 
    34                  size=(PANEL_WIDTH, 450)): 
     104                 size=(PANEL_WIDTH, PANEL_HEIGHT)): 
    35105        wx.Dialog.__init__(self, parent, id=id, title=title, size=size) 
    36         
     106         
    37107        #Font size  
    38108        self.SetWindowVariant(variant=FONT_VARIANT) 
     
    40110        #self.qstar_container 
    41111        self.qstar_container = qstar_container 
    42         self.compute_scale() 
    43112        #warning message 
    44         self.warning_msg = "" 
     113        self.warning_msg = self.qstar_container.warning_msg 
     114    
    45115        #Define scale of each bar 
    46         low_inv_scale = self.qstar_container.qstar_low_scale 
    47         self.low_scale = self.check_scale(scale=low_inv_scale, scale_name="Low") 
    48         inv_scale = self.qstar_container.qstar_scale 
    49         self.inv_scale = self.check_scale(scale=inv_scale, scale_name="Inv") 
    50         high_inv_scale = self.qstar_container.qstar_high_scale 
    51         self.high_scale = self.check_scale(scale=high_inv_scale, scale_name="High") 
     116        self.low_inv_percent = self.qstar_container.qstar_low_percent 
     117        self.low_scale = self.get_scale(percentage=self.low_inv_percent, 
     118                                         scale_name="Extrapolated at Low Q") 
     119        self.inv_percent = self.qstar_container.qstar_percent 
     120        self.inv_scale = self.get_scale(percentage=self.inv_percent,  
     121                                            scale_name="Inv in Q range") 
     122        self.high_inv_percent = self.qstar_container.qstar_high_percent 
     123        self.high_scale = self.get_scale(percentage=self.high_inv_percent, 
     124                                         scale_name="Extrapolated at High Q") 
     125         
    52126        #Default color the extrapolation bar is grey 
    53127        self.extrapolation_color_low = wx.Colour(169,  169, 168, 128) 
     
    58132        self._do_layout() 
    59133        self.set_values() 
    60   
     134    
    61135    def _define_structure(self): 
    62136        """ 
     
    68142        chart_box = wx.StaticBox(self, -1, "Invariant Chart") 
    69143        self.chart_sizer = wx.StaticBoxSizer(chart_box, wx.VERTICAL) 
    70         self.chart_sizer.SetMinSize((PANEL_WIDTH - 50,-1)) 
     144        self.chart_sizer.SetMinSize((PANEL_WIDTH - 50,100)) 
    71145        #Sizer related to invariant values 
    72146        self.invariant_sizer =  wx.GridBagSizer(4, 4) 
     147        invariant_box = wx.StaticBox(self, -1, "Numerical Values") 
     148        self.invariant_box_sizer = wx.StaticBoxSizer(invariant_box, 
     149                                                      wx.HORIZONTAL) 
     150 
     151        self.invariant_box_sizer.SetMinSize((PANEL_WIDTH - 50,-1)) 
    73152        #Sizer related to warning message 
    74153        warning_box = wx.StaticBox(self, -1, "Warning") 
     
    91170        """ 
    92171        uncertainty = "+/-"  
    93         unit_invariant = '[1/cm 1/A]' 
     172        unit_invariant = '[1/(cm * A)]' 
    94173      
    95174        invariant_txt = wx.StaticText(self, -1, 'Invariant') 
     
    115194    
    116195        #Invariant low 
    117         iy = 1 
     196        iy = 0 
    118197        ix = 0  
    119198        self.invariant_sizer.Add(invariant_low_txt, (iy, ix), (1,1), 
     
    164243        ix += 1 
    165244        self.invariant_sizer.Add(invariant_high_units_txt 
    166                          ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)   
     245                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     246        self.invariant_box_sizer.Add(self.invariant_sizer, 0, wx.TOP|wx.BOTTOM, 10)   
    167247        
    168248    def _layout_warning(self): 
     
    172252        #Warning [string] 
    173253        self.warning_msg_txt = wx.StaticText(self, -1,self.warning_msg)   
    174         self.warning_msg_txt.SetForegroundColour('red')  
     254        if self.qstar_container.existing_warning: 
     255            self.warning_msg_txt.SetForegroundColour('red')  
    175256        self.warning_sizer.AddMany([(self.warning_msg_txt, 0, 
    176257                                     wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10)]) 
     
    196277        self._layout_warning() 
    197278        self._layout_button() 
    198         self.main_sizer.AddMany([(self.chart_sizer, 1, wx.ALL, 10), 
    199                                  (self.invariant_sizer, 0, wx.ALL, 10), 
     279        self.main_sizer.AddMany([(self.chart_sizer, 0, wx.ALL, 10), 
     280                                 ( self.invariant_box_sizer, 0, wx.ALL, 10), 
    200281                                  (self.warning_sizer, 0, wx.ALL, 10), 
    201282                                  (self.button_sizer, 0, wx.ALL, 10)]) 
     
    213294        self.invariant_high_tcl.SetValue(format_number(self.qstar_container.qstar_high)) 
    214295        self.invariant_high_err_tcl.SetValue(format_number(self.qstar_container.qstar_high_err))  
    215      
    216     def compute_scale(self): 
    217         """ 
    218             Compute scale 
    219         """ 
    220         qstar_total = self.qstar_container.qstar_total 
    221         if qstar_total is None: 
    222             qstar_total = DEFAULT_QSTAR 
    223         #compute the percentage of invariant 
    224         inv = self.qstar_container.qstar 
    225         if inv is None: 
    226             inv = 0.0  
    227         inv_scale = inv/qstar_total 
    228         self.qstar_container.qstar_scale = inv_scale 
    229         #compute the percentage of low q invariant 
    230         inv_low = self.qstar_container.qstar_low 
    231         if inv_low is None: 
    232             inv_low = 0.0  
    233         inv_scale = inv_low/qstar_total 
    234         self.qstar_container.qstar_low_scale = inv_scale 
    235         #compute the percentage of high q invariant 
    236         inv_high = self.qstar_container.qstar_high 
    237         if inv_high is None: 
    238             inv_high = 0.0  
    239         inv_scale = inv_high/qstar_total 
    240         self.qstar_container.qstar_high_scale = inv_scale 
    241         
    242     def check_scale(self, scale, scale_name='scale'): 
    243         """ 
    244             Check scale receive in this panel. i 
     296 
     297    def get_scale(self, percentage, scale_name='scale'): 
     298        """ 
     299            Check scale receive in this panel.  
    245300        """ 
    246301        try:  
    247             if scale is None: 
    248                 scale = 0.0 
    249             scale = float(scale) 
    250             if  scale == 0.0: 
    251                 scale = RECTANGLE_SCALE 
     302            if percentage is None or percentage == 0.0: 
     303                 percentage = RECTANGLE_SCALE 
     304            percentage = float(percentage)  
    252305        except: 
    253             scale = RECTANGLE_SCALE 
     306            percentage = RECTANGLE_SCALE 
    254307            self.warning_msg += "Receive an invalid scale for %s\n" 
    255             self.warning_msg += "check this value : %s\n"%(str(scale_name),str(scale)) 
    256         return scale 
     308            self.warning_msg += "check this value : %s\n"%(str(scale_name),str(percentage)) 
     309        return  percentage 
    257310     
    258311    def set_color_bar(self): 
     
    263316        if self.low_scale >= 0.05: 
    264317            self.extrapolation_color_low = wx.Colour(255,  0, 0, 128) 
    265             self.warning_msg += "The value of invariant extrapolated at \n" 
    266             self.warning_msg += "low q range is %s percent \n"%(str(self.low_scale*100)) 
    267318        if self.high_scale >= 0.05: 
    268319            self.extrapolation_color_high = wx.Colour(255,  0, 0, 128) 
    269             self.warning_msg += "The value of invariant extrapolated at \n" 
    270             self.warning_msg += "high q range is %s percent \n"%(str(self.high_scale*100)) 
    271      
     320             
    272321    def on_close(self, event): 
    273322        """ 
     
    295344        path.AddRectangle(-RECTANGLE_WIDTH/2,-RECTANGLE_HEIGHT/2, 
    296345                          RECTANGLE_WIDTH/2,RECTANGLE_HEIGHT/2) 
    297         x_origine = 50 
     346        x_origine = 20 
    298347        y_origine = 15 
    299348        #Draw low rectangle 
    300349        gc.PushState()         
    301         label = "Low" 
     350        label = "Q* At Low-Q" 
    302351        PathFunc = gc.DrawPath 
    303352        w, h = gc.GetTextExtent(label) 
     
    309358        gc.SetPen(wx.Pen("black", 1)) 
    310359        gc.SetBrush(wx.Brush(self.extrapolation_color_low)) 
     360        low_percent = format_number(self.low_inv_percent*100)+ '%' 
     361        x_center = 20 
     362        y_center = -h 
     363        gc.DrawText(low_percent, x_center, y_center) 
    311364        # Increase width by self.low_scale 
    312365        gc.Scale(self.low_scale, 1.0)  
     
    316369        gc.PushState()    # save it again 
    317370        y_origine += 20          
    318         gc.DrawText("Inv", x_origine, y_origine) 
     371        gc.DrawText("Q* In range", x_origine, y_origine) 
    319372        # offset to the lower part of the window 
    320373        x_center = x_origine + RECTANGLE_WIDTH * self.inv_scale/2 + w + 10 
     
    324377        gc.SetBrush(wx.Brush(wx.Colour(67,  208,  128, 128)))  
    325378        # Increase width by self.inv_scale 
     379        inv_percent = format_number(self.inv_percent*100)+ '%' 
     380        x_center = 20  
     381        y_center = -h 
     382        gc.DrawText(inv_percent, x_center, y_center) 
    326383        gc.Scale(self.inv_scale, 1.0)     
    327384        gc.DrawPath(path) 
     
    331388        gc.PushState()  
    332389        y_origine += 20  
    333         gc.DrawText("High", x_origine, y_origine)  
     390        gc.DrawText("Q* At High-Q", x_origine, y_origine)  
    334391        #define the position of the new rectangle 
    335392        x_center = x_origine + RECTANGLE_WIDTH * self.high_scale/2 + w + 10 
     
    338395        gc.SetBrush(wx.Brush(self.extrapolation_color_high))  
    339396        # increase scale by self.high_scale 
     397        high_percent = format_number(self.high_inv_percent*100)+ '%' 
     398        x_center = 20 
     399        y_center = -h 
     400        gc.DrawText(high_percent, x_center, y_center) 
     401        
    340402        gc.Scale(self.high_scale, 1.0)   
    341403        gc.DrawPath(path) 
     
    348410        self.container = qstar_container 
    349411        if self.container is None: 
    350             from invariant_panel import InvariantContainer 
    351412            self.container = InvariantContainer() 
    352             self.container.qstar_total = 1 
     413            self.container.qstar_total = 1.0 
    353414            self.container.qstar = 0.75 
    354415            self.container.qstar_low = 0.60 
     
    362423class InvariantDetailsTest(wx.Frame): 
    363424    def __init__(self, parent, qstar_container=None, *args, **kwds): 
    364         kwds["size"]= (PANEL_WIDTH , 450) 
     425        kwds["size"]= (PANEL_WIDTH , PANEL_HEIGHT) 
    365426        wx.Frame.__init__(self, parent, *args, **kwds) 
    366427        self.container = qstar_container 
    367428        if self.container is None: 
    368             from invariant_panel import InvariantContainer 
    369429            self.container = InvariantContainer() 
    370             self.container.qstar_total = 1 
     430            self.container.qstar_total = 1.0 
    371431            self.container.qstar = 0.75 
    372432            self.container.qstar_low = 0.60 
     
    381441if __name__ =="__main__": 
    382442    app  = wx.App() 
    383     from invariant_panel import InvariantContainer 
     443 
    384444    container = InvariantContainer() 
    385     container.qstar_total = 1 
    386     container.qstar = 0.75 
    387     container.qstar_low = 0.60 
    388     container.qstar_high = 0.0049 
     445    container.qstar_total = 100.0 
     446    container.qstar = 15.0 
     447    container.qstar_low = 0.001 
     448    container.qstar_high = 100.0 
     449    container.compute_percentage() 
     450    
    389451    window = InvariantDetailsTest(parent=None, id=-1,qstar_container=container, 
    390                                     title="Source Editor") 
     452                                    title="Invariant Details") 
    391453    window.Show() 
    392454    app.MainLoop() 
  • invariantview/perspectives/invariant/invariant_panel.py

    rf338d3b rd0cc0bbc  
    1010from sans.guiframe.utils import format_number, check_float 
    1111from sans.guicomm.events import NewPlotEvent, StatusEvent 
    12 from invariant_details import InvariantDetailsPanel 
     12from invariant_details import InvariantDetailsPanel, InvariantContainer 
    1313from invariant_widgets import OutputTextCtrl, InvTextCtrl 
    1414# The minimum q-value to be used when extrapolating 
     
    2626#default value of the contrast 
    2727CONTRAST = 1.0 
     28#default value of the power used for power law 
     29POWER = 4.0 
    2830#Invariant panel size  
    2931_BOX_WIDTH = 76 
    30 #scale to use for a bar of value zero 
    31 RECTANGLE_SCALE  = 0.0001 
    3232 
    3333if sys.platform.count("win32")>0: 
     
    4141    PANEL_HEIGHT = 700 
    4242    FONT_VARIANT = 1 
    43      
    44 class InvariantContainer(wx.Object): 
    45     def __init__(self): 
    46         #invariant at low range 
    47         self.qstar_low = None 
    48         #invariant at low range error 
    49         self.qstar_low_err = None 
    50         #invariant  
    51         self.qstar = None 
    52         #invariant error 
    53         self.qstar_err = None 
    54         #invariant at high range 
    55         self.qstar_high = None 
    56         #invariant at high range error 
    57         self.qstar_high_err = None 
    58         #invariant total 
    59         self.qstar_total = None 
    60         #invariant error 
    61         self.qstar_total_err = None 
    62         #scale 
    63         self.qstar_low_scale = RECTANGLE_SCALE 
    64         self.qstar_scale = RECTANGLE_SCALE 
    65         self.qstar_high_scale = RECTANGLE_SCALE 
    66   
     43 
     44 
    6745class InvariantPanel(wx.ScrolledWindow): 
    6846    """ 
     
    8361        #plug-in using this panel 
    8462        self._manager = manager  
    85         #Default power value 
    86         self.power_law_exponant = 4  
    8763        #Data uses for computation 
    8864        self._data = data 
     
    9167        #Draw the panel 
    9268        self._do_layout() 
     69        self.reset_panel() 
    9370        if self.parent is not None: 
    9471            msg = "" 
     
    123100            self.data_max_tcl.SetLabel(str(data_qmax)) 
    124101            self.hint_msg_txt.SetLabel('') 
    125          
     102            self.reset_panel() 
     103            self.compute_invariant(event=None) 
     104             
     105    def set_message(self): 
     106        """ 
     107            Display warning message if available 
     108        """ 
     109        if self.inv_container is not None: 
     110            if self.inv_container.existing_warning: 
     111                msg = "Warning! Computations on invariant require your " 
     112                msg += "attention.\n Please click on Details button." 
     113                self.hint_msg_txt.SetForegroundColour("red") 
     114            else: 
     115                msg = "For more information, click on Details button." 
     116                self.hint_msg_txt.SetForegroundColour("black") 
     117            self.hint_msg_txt.SetLabel(msg) 
     118            wx.PostEvent(self.parent, StatusEvent(status=msg)) 
     119        self.data_name_boxsizer.Layout() 
     120        
    126121    def set_manager(self, manager): 
    127122        """ 
     
    239234                power_low = inv.get_extrapolation_power(range='low')   
    240235                if self.power_law_low.GetValue(): 
    241                     self.power_low_tcl.SetValue(str(power_low)) 
     236                    self.power_low_tcl.SetValue(format_number(power_low)) 
    242237                self._manager.plot_theory(data=extrapolated_data, 
    243238                                           name="Low-Q extrapolation") 
     
    257252                self.inv_container.qstar_high_err = qstar_high_err 
    258253                power_high = inv.get_extrapolation_power(range='high')  
    259                 self.power_high_tcl.SetValue(str(power_high)) 
     254                self.power_high_tcl.SetValue(format_number(power_high)) 
    260255                high_out_data = inv.get_extra_data_high(q_end=Q_MAXIMUM_PLOT) 
    261256                self._manager.plot_theory(data=high_out_data, 
     
    346341            open another panel for more details on invariant calculation 
    347342        """ 
    348         #panel = InvariantDetailsWindow(parent=self.parent, 
    349         #                               qstar_container=self.inv_container) 
    350343        panel = InvariantDetailsPanel(parent=self,  
    351344                                           qstar_container=self.inv_container) 
    352345        panel.ShowModal() 
    353346        panel.Destroy() 
    354          
    355     def compute_invariant(self, event): 
     347        self.button_calculate.SetFocus() 
     348         
     349    def compute_invariant(self, event=None): 
    356350        """ 
    357351            compute invariant  
     
    418412            msg= "Error occurred computing invariant: %s"%sys.exc_value 
    419413            wx.PostEvent(self.parent, StatusEvent(status= msg)) 
    420        
     414             
     415        #compute percentage of each invariant 
     416        self.inv_container.compute_percentage() 
     417        #display a message 
     418        self.set_message() 
    421419        #enable the button_ok for more details 
    422         self.button_ok.Enable() 
     420        self.button_details.Enable() 
     421        self.button_details.SetFocus() 
    423422     
    424423    def reset_panel(self): 
     
    426425            set the panel at its initial state. 
    427426        """ 
     427        self.background_tcl.SetValue(str(BACKGROUND)) 
     428        self.scale_tcl.SetValue(str(SCALE))  
     429        self.contrast_tcl.SetValue(str(CONTRAST))  
     430        self.npts_low_tcl.SetValue(str(NPTS)) 
     431        self.enable_low_cbox.SetValue(False) 
     432        self.fix_enable_low.SetValue(True) 
     433        self.power_low_tcl.SetValue(str(POWER)) 
     434        self.guinier.SetValue(True) 
     435        self.power_low_tcl.Disable() 
     436        self.enable_high_cbox.SetValue(False) 
     437        self.fix_enable_high.SetValue(True) 
     438        self.power_high_tcl.SetValue(str(POWER)) 
     439        self.npts_high_tcl.SetValue(str(NPTS)) 
     440        self.button_details.Disable() 
     441        #Change the state of txtcrtl to enable/disable 
     442        self._enable_low_q_section() 
     443        #Change the state of txtcrtl to enable/disable 
     444        self._enable_high_q_section() 
     445        self._reset_output() 
     446        self.button_calculate.SetFocus() 
    428447         
    429448    def _reset_output(self): 
     
    457476        self.data_name_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    458477        self.data_range_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    459         #Sizer related to background 
    460         self.background_sizer = wx.BoxSizer(wx.HORIZONTAL)  
    461         #Sizer related to scale 
    462         self.scale_sizer = wx.BoxSizer(wx.HORIZONTAL)  
    463         #Sizer related to contrast 
    464         self.contrast_sizer = wx.BoxSizer(wx.HORIZONTAL)  
    465         #Sizer related to Porod Constant 
    466         self.porod_constant_sizer = wx.BoxSizer(wx.HORIZONTAL)  
     478        #Sizer related to background and scale 
     479        self.bkg_scale_sizer = wx.BoxSizer(wx.HORIZONTAL)  
     480        #Sizer related to contrast and porod constant 
     481        self.contrast_porod_sizer = wx.BoxSizer(wx.HORIZONTAL)  
     482        #Sizer related to inputs 
     483        inputs_box = wx.StaticBox(self, -1, "Customized Inputs") 
     484        self.inputs_sizer = wx.StaticBoxSizer(inputs_box, wx.VERTICAL) 
     485        #Sizer related to extrapolation 
    467486        extrapolation_box = wx.StaticBox(self, -1, "Extrapolation") 
    468487        self.extrapolation_sizer = wx.StaticBoxSizer(extrapolation_box, 
    469488                                                        wx.VERTICAL) 
    470489        self.extrapolation_sizer.SetMinSize((PANEL_WIDTH,-1)) 
    471         self.extrapolation_hint_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    472490        self.extrapolation_range_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    473491        self.extrapolation_low_high_sizer = wx.BoxSizer(wx.HORIZONTAL) 
     
    520538                                         (self.data_range_sizer, 0 , wx.ALL, 10)]) 
    521539     
    522     def _layout_background(self): 
    523         """ 
    524             Draw widgets related to background 
     540    def _layout_bkg_scale(self): 
     541        """ 
     542            Draw widgets related to background and scale 
    525543        """ 
    526544        background_txt = wx.StaticText(self, -1, 'Background : ')   
    527545        self.background_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0)  
    528         self.background_tcl.SetValue(str(BACKGROUND)) 
    529546        background_hint_txt = "background" 
    530547        self.background_tcl.SetToolTipString(background_hint_txt) 
    531548        background_unit_txt = wx.StaticText(self, -1, '[1/cm]')   
    532         self.background_sizer.AddMany([(background_txt, 0, wx.LEFT, 10), 
    533                                        (self.background_tcl, 0, wx.LEFT, 15), 
    534                                        (background_unit_txt, 0, wx.LEFT, 10)]) 
    535     def _layout_scale(self): 
    536         """ 
    537             Draw widgets related to scale 
    538         """ 
    539549        scale_txt = wx.StaticText(self, -1, 'Scale : ')   
    540550        self.scale_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 
    541551        scale_hint_txt = "Scale" 
    542552        self.scale_tcl.SetToolTipString(scale_hint_txt) 
    543         self.scale_tcl.SetValue(str(SCALE))  
    544         self.scale_sizer.AddMany([(scale_txt, 0, wx.LEFT|wx.RIGHT, 10), 
    545                                        (self.scale_tcl, 0, wx.LEFT, 35)]) 
    546          
    547     def _layout_contrast(self): 
    548         """ 
    549             Draw widgets related to contrast 
     553        self.bkg_scale_sizer.AddMany([(background_txt, 0, wx.LEFT, 10), 
     554                                       (self.background_tcl, 0, wx.LEFT, 5), 
     555                                       (background_unit_txt, 0, wx.LEFT, 10), 
     556                                       (scale_txt, 0, wx.LEFT, 70), 
     557                                       (self.scale_tcl, 0, wx.LEFT, 40)]) 
     558  
     559    def _layout_contrast_porod(self): 
     560        """ 
     561            Draw widgets related to porod constant and contrast 
    550562        """ 
    551563        contrast_txt = wx.StaticText(self, -1, 'Contrast : ')   
    552564        self.contrast_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 
    553         self.contrast_tcl.SetValue(str(CONTRAST))  
    554565        contrast_hint_txt = "Contrast" 
    555566        self.contrast_tcl.SetToolTipString(contrast_hint_txt) 
    556567        contrast_unit_txt = wx.StaticText(self, -1, '[1/A^(2)]')   
    557         self.contrast_sizer.AddMany([(contrast_txt, 0, wx.LEFT|wx.RIGHT, 10), 
    558                                        (self.contrast_tcl, 0, wx.LEFT, 18), 
    559                                        (contrast_unit_txt, 0, wx.LEFT, 10)]) 
    560      
    561     def _layout_porod_constant(self): 
    562         """ 
    563             Draw widgets related to porod constant 
    564         """ 
    565568        porod_const_txt = wx.StaticText(self, -1, 'Porod Constant:')   
    566569        self.porod_constant_tcl = InvTextCtrl(self, -1,  
     
    569572        self.porod_constant_tcl.SetToolTipString(porod_const_hint_txt) 
    570573        optional_txt = wx.StaticText(self, -1, '(Optional)')   
    571         self.porod_constant_sizer.AddMany([(porod_const_txt, 0, wx.LEFT, 10), 
     574        self.contrast_porod_sizer.AddMany([(contrast_txt, 0, wx.LEFT, 10), 
     575                                           (self.contrast_tcl, 0, wx.LEFT, 20), 
     576                                           (contrast_unit_txt, 0, wx.LEFT, 10), 
     577                                           (porod_const_txt, 0, wx.LEFT, 50), 
    572578                                       (self.porod_constant_tcl, 0, wx.LEFT, 0), 
    573579                                       (optional_txt, 0, wx.LEFT, 10)]) 
     
    602608        self._enable_power_law_low() 
    603609        self._enable_fit_power_law_low() 
     610        self.button_calculate.SetFocus() 
    604611     
    605612    def _enable_power_law_low(self, event=None): 
     
    622629        """ 
    623630        self.enable_low_cbox = wx.CheckBox(self, -1, "Enable Extrapolate Low Q") 
    624         self.enable_low_cbox.SetValue(False) 
    625631        wx.EVT_CHECKBOX(self, self.enable_low_cbox.GetId(), 
    626632                                         self._enable_low_q_section) 
    627633        self.fix_enable_low = wx.RadioButton(self, -1, 'Fix', 
    628634                                         (10, 10),style=wx.RB_GROUP) 
    629         self.fix_enable_low.SetValue(True) 
    630635        self.fit_enable_low = wx.RadioButton(self, -1, 'Fit', (10, 10)) 
    631636        self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, 
     
    635640        self.guinier = wx.RadioButton(self, -1, 'Guinier', 
    636641                                         (10, 10),style=wx.RB_GROUP) 
    637         self.guinier.SetValue(True) 
    638642        self.power_law_low = wx.RadioButton(self, -1, 'Power Law', (10, 10)) 
    639643        self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, 
     
    644648        npts_low_txt = wx.StaticText(self, -1, 'Npts') 
    645649        self.npts_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) 
    646         self.npts_low_tcl.SetValue(str(NPTS)) 
    647650        msg_hint = "Number of Q points to consider" 
    648651        msg_hint +="while extrapolating the low-Q region" 
     
    650653        power_txt = wx.StaticText(self, -1, 'Power') 
    651654        self.power_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) 
    652         self.power_low_tcl.SetValue(str(self.power_law_exponant)) 
    653         self.power_low_tcl.Disable() 
     655        
    654656        power_hint_txt = "Exponent to apply to the Power_law function." 
    655657        self.power_low_tcl.SetToolTipString(power_hint_txt) 
     
    689691        self.low_q_sizer.Add(self.power_low_tcl, (iy, ix), (1,1), 
    690692                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    691         #Change the state of txtcrtl to enable/disable 
    692         self._enable_low_q_section() 
    693693        self.low_extrapolation_sizer.AddMany([(self.low_q_sizer, 0, 
    694                                                 wx.BOTTOM|wx.RIGHT, 10)]) 
     694                                                wx.BOTTOM|wx.RIGHT, 15)]) 
     695         
    695696    def _enable_fit_power_law_high(self, event=None): 
    696697        """ 
     
    720721            self.fit_enable_high.Disable() 
    721722        self._enable_fit_power_law_high() 
     723        self.button_calculate.SetFocus() 
    722724   
    723725    def _layout_extrapolation_high(self): 
     
    726728        """ 
    727729        self.enable_high_cbox = wx.CheckBox(self, -1, "Enable Extrapolate high-Q") 
    728         self.enable_high_cbox.SetValue(False) 
    729730        wx.EVT_CHECKBOX(self, self.enable_high_cbox.GetId(), 
    730731                                         self._enable_high_q_section) 
     
    732733        self.fix_enable_high = wx.RadioButton(self, -1, 'Fix', 
    733734                                         (10, 10),style=wx.RB_GROUP) 
    734         self.fix_enable_high.SetValue(True) 
    735735        self.fit_enable_high = wx.RadioButton(self, -1, 'Fit', (10, 10)) 
    736736        self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, 
     
    740740         
    741741        self.power_law_high = wx.StaticText(self, -1, 'Power Law') 
    742         #msg_hint ="Check to extrapolate data at high-Q" 
    743         #self.power_law_high.SetToolTipString(msg_hint) 
     742        msg_hint ="Check to extrapolate data at high-Q" 
     743        self.power_law_high.SetToolTipString(msg_hint) 
    744744        npts_high_txt = wx.StaticText(self, -1, 'Npts') 
    745745        self.npts_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) 
     
    747747        msg_hint += "while extrapolating the high-Q region" 
    748748        self.npts_high_tcl.SetToolTipString(msg_hint) 
    749         self.npts_high_tcl.SetValue(str(NPTS)) 
    750749        power_txt = wx.StaticText(self, -1, 'Power') 
    751750        self.power_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) 
    752         self.power_high_tcl.SetValue(str(self.power_law_exponant)) 
    753751        power_hint_txt = "Exponent to apply to the Power_law function." 
    754752        self.power_high_tcl.SetToolTipString(power_hint_txt) 
     
    784782        self.high_q_sizer.Add(self.power_high_tcl, (iy, ix), (1,1), 
    785783                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    786         #Change the state of txtcrtl to enable/disable 
    787         self._enable_high_q_section() 
    788         self.high_extrapolation_sizer.AddMany([(self.high_q_sizer, 0, wx.RIGHT, 10)]) 
     784        self.high_extrapolation_sizer.AddMany([(self.high_q_sizer, 0,  
     785                                                wx.BOTTOM|wx.RIGHT, 10)]) 
    789786         
    790787    def _layout_extrapolation(self): 
     
    813810                                                            0, wx.LEFT, 10), 
    814811                                                ]) 
    815         extra_enable_hint = "Hint: Check any box to enable a specific extrapolation !" 
    816         extra_enable_hint_txt = wx.StaticText(self, -1, extra_enable_hint ) 
    817         self.extrapolation_hint_sizer.AddMany([(extra_enable_hint_txt, 0, wx.LEFT, 0) 
    818                                                ]) 
    819812        self._layout_extrapolation_low() 
    820813        self._layout_extrapolation_high() 
     
    825818        self.extrapolation_sizer.AddMany([(self.extrapolation_range_sizer, 0, 
    826819                                            wx.RIGHT, 10), 
    827                                          (self.extrapolation_hint_sizer, 0, 
    828                                            wx.ALL, 10), 
    829820                                        (self.extrapolation_low_high_sizer, 0, 
    830821                                           wx.ALL, 10)]) 
     
    915906                          wx.EXPAND|wx.ADJUST_MINSIZE, 10) 
    916907  
     908    def _layout_inputs_sizer(self): 
     909        """ 
     910            Draw widgets related to inputs 
     911        """ 
     912        self._layout_bkg_scale() 
     913        self._layout_contrast_porod() 
     914        self.inputs_sizer.AddMany([(self.bkg_scale_sizer, 0, wx.ALL, 5), 
     915                                    (self.contrast_porod_sizer, 0, wx.ALL, 5)]) 
     916         
    917917    def _layout_outputs_sizer(self): 
    918918        """ 
     
    931931        #compute button 
    932932        id = wx.NewId() 
    933         button_calculate = wx.Button(self, id, "Compute") 
    934         button_calculate.SetToolTipString("Compute invariant") 
     933        self.button_calculate = wx.Button(self, id, "Compute") 
     934        self.button_calculate.SetToolTipString("Compute invariant") 
    935935        self.Bind(wx.EVT_BUTTON, self.compute_invariant, id=id)    
    936936        #detail button 
    937937        id = wx.NewId() 
    938         self.button_ok = wx.Button(self, id, "Details?") 
    939         self.button_ok.SetToolTipString("Give Details on Computation") 
     938        self.button_details = wx.Button(self, id, "Details?") 
     939        self.button_details.SetToolTipString("Give Details on Computation") 
    940940        self.Bind(wx.EVT_BUTTON, self.display_details, id=id) 
    941         self.button_ok.Disable() 
    942941        details = "Details on Invariant Total Calculations" 
    943942        details_txt = wx.StaticText(self, -1, details) 
    944         self.button_sizer.AddMany([((20,20), 0 , wx.LEFT, 100), 
    945                                    (details_txt, 0 , wx.ALL, 10), 
    946                                    (self.button_ok, 0 , wx.ALL, 10), 
    947                         (button_calculate, 0 , wx.RIGHT|wx.TOP|wx.BOTTOM, 10)]) 
     943        self.button_sizer.AddMany([((10,10), 0 , wx.LEFT,0), 
     944                                   (details_txt, 0 ,  
     945                                    wx.RIGHT|wx.BOTTOM|wx.TOP, 10), 
     946                                   (self.button_details, 0 , wx.ALL, 10), 
     947                        (self.button_calculate, 0 , wx.RIGHT|wx.TOP|wx.BOTTOM, 10)]) 
    948948         
    949949    def _do_layout(self): 
     
    953953        self._define_structure() 
    954954        self._layout_data_name() 
    955         self._layout_background() 
    956         self._layout_scale() 
    957         self._layout_contrast() 
    958         self._layout_porod_constant() 
    959955        self._layout_extrapolation() 
     956        self._layout_inputs_sizer() 
    960957        self._layout_outputs_sizer() 
    961958        self._layout_button() 
    962         self.main_sizer.AddMany([(self.data_name_boxsizer, 0, wx.ALL, 10), 
    963                                  (self.background_sizer, 0, 
    964                                    wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), 
    965                                  (self.scale_sizer, 0, 
    966                                    wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), 
    967                                  (self.contrast_sizer, 0, 
    968                                   wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), 
    969                                   (self.porod_constant_sizer, 0, 
    970                                   wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), 
    971                                   (self.extrapolation_sizer, 0, 
    972                                   wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), 
     959        self.main_sizer.AddMany([(self.data_name_boxsizer, 1, wx.ALL, 10), 
    973960                                  (self.outputs_sizer, 0, 
    974961                                  wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), 
    975962                                  (self.button_sizer, 0, 
     963                                  wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), 
     964                                 (self.inputs_sizer, 0, 
     965                                  wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), 
     966                                  (self.extrapolation_sizer, 0, 
    976967                                  wx.LEFT|wx.RIGHT|wx.BOTTOM, 10)]) 
    977968        self.SetSizer(self.main_sizer) 
Note: See TracChangeset for help on using the changeset viewer.