Changeset 2db1d66 in sasview for sansview


Ignore:
Timestamp:
Jan 8, 2010 10:30:45 AM (15 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:
277aab4e
Parents:
dfa8832
Message:

add invarinat panel

Location:
sansview/perspectives/fitting
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sansview/perspectives/fitting/fitting.py

    r484faf7 r2db1d66  
    135135        self.menu1.Append(id1, '&Simultaneous Page',simul_help) 
    136136        wx.EVT_MENU(owner, id1, self.on_add_sim_page) 
    137         #menu for SLD Calculator 
    138         #self.tool_menu = wx.Menu() 
    139         #id_tool_menu = wx.NewId() 
    140         #sld_id = wx.NewId() 
    141         #sld_help= "Compute the scattering length density of molecules" 
    142         #self.tool_menu.Append(sld_id, "SLD Calculator",sld_help) 
    143         #wx.EVT_MENU(owner,sld_id,  self.onCalculateSld) 
    144      
     137        
    145138        #menu for model 
    146139        menu2 = wx.Menu() 
     
    155148        #create  menubar items 
    156149        return [(id, self.menu1, "Fitting")] 
    157                 #(id_tool_menu, self.tool_menu,"Tools" ), 
    158                 #(id2, menu2, "Model")] 
    159         
    160      
     150                
    161151    def on_add_sim_page(self, event): 
    162152        """ 
     
    170160         
    171161        self.sim_page= self.fit_panel.add_sim_page() 
    172          
    173          
    174162         
    175163    def help(self, evt): 
     
    291279            @param return  
    292280        """ 
    293         id=None 
     281        id = None 
    294282        if hasattr(item,"id"): 
    295283            id = copy.deepcopy(item.id) 
     
    330318                fitproblem.schedule_tofit(value) 
    331319           
    332                        
    333                      
    334320    def get_page_finder(self): 
    335321        """ @return self.page_finder used also by simfitpage.py"""   
     
    353339                    value.set_model_param(names,values) 
    354340                    break 
    355  
    356     
    357                              
     341          
    358342    def split_string(self,item):  
    359343        """ 
     
    373357            return model_name,param_name 
    374358         
    375     
    376359    def stop_fit(self): 
    377360        """ 
     
    383366                is cancelled" , type="stop")) 
    384367             
    385      
    386        
    387368    def set_smearer(self,smearer, qmin=None, qmax=None): 
    388369        """ 
     
    403384                qmin= qmin, qmax= qmax) 
    404385 
    405      
    406      
    407386    def draw_model(self, model, data= None,smearer= None, 
    408387                   enable1D= True, enable2D= False, 
     
    431410                           qmax=qmax, 
    432411                           qstep=qstep) 
    433          
    434    
    435                          
     412             
    436413    def onFit(self): 
    437414        """ 
     
    520497            return  
    521498         
    522          
    523499    def ready_fit(self): 
    524500        """ 
     
    531507            time.sleep(0.4) 
    532508              
    533     def onCalculateSld(self, event): 
    534         """ 
    535             Compute the scattering length density of molecula 
    536         """   
    537         from sldPanel import SldWindow 
    538         frame = SldWindow(base=self.parent) 
    539         frame.Show(True)  
    540        
    541            
    542509    def _onEVT_SLICER_PANEL(self, event): 
    543510        """ 
     
    554521        self.parent._mgr.Update() 
    555522                
    556              
    557523    def _compute_invariant(self, event):     
    558524        """ 
    559525            Open the invariant panel to invariant computation 
    560526        """ 
    561          
    562          
     527        self.panel = event.GetEventObject() 
     528        Plugin.on_perspective(self,event=event) 
     529        for plottable in self.panel.graph.plottables: 
     530            if plottable.name == self.panel.graph.selected_plottable: 
     531                data = self.copy_data(item= plottable, dy=plottable.dy) 
     532                 
     533                print "_compute_invariant",data._yaxis 
     534                print "_compute_invariant" ,data._yunit 
     535                from invariant_panel import InvariantWindow 
     536                frame = InvariantWindow(base=self.parent, data=plottable)    
     537                frame.Show(True) 
     538                #from invariant_panel import InvariantDialog 
     539                #self.invariant_dlg = InvariantDialog(base=self.parent, 
     540                #                                     data=plottable) 
     541                #if self.invariant_dlg.ShowModal() == wx.ID_OK: 
     542                #    pass 
     543                #self.invariant_dlg.Destroy() 
     544                 
    563545    def _closed_fitpage(self, event):    
    564546        """ 
     
    10871069            Complete plotting 1D data 
    10881070        """  
    1089         
    10901071        try: 
    10911072            new_plot = Theory1D(x=x, y=y) 
     
    11021083                new_plot.is_data =False  
    11031084            
    1104             
    11051085            title= new_plot.name 
    1106             new_plot. perspective = self.get_perspective() 
     1086            #new_plot.perspective = self.get_perspective() 
    11071087            # Pass the reset flag to let the plotting event handler 
    11081088            # know that we are replacing the whole plot 
     
    11111091            if data ==None: 
    11121092                wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, 
    1113                              title= str(title), reset=True )) 
     1093                             title=str(title), reset=True)) 
    11141094            else: 
    11151095                wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, 
     
    11231103            return   
    11241104                   
    1125      
    1126          
    11271105    def _update2D(self, output,time=None): 
    11281106        """ 
     
    11401118            that can be plot. 
    11411119        """ 
    1142        
    1143      
    11441120        err_image = numpy.zeros(numpy.shape(image)) 
    11451121        
  • sansview/perspectives/fitting/invariant_panel.py

    r484faf7 r2db1d66  
    77import sys 
    88 
     9from sans.invariant import invariant 
     10from sans.guiframe.dataFitting import Theory1D 
    911from sans.guiframe.utils import format_number, check_float 
    10 from sans.guicomm.events import StatusEvent   
     12from sans.guicomm.events import NewPlotEvent, StatusEvent 
    1113 
    12  
     14# The minimum q-value to be used when extrapolating 
     15Q_MINIMUM  = 1e-5 
     16# The maximum q-value to be used when extrapolating 
     17Q_MAXIMUM  = 10 
     18# the number of points to consider during fit 
     19NPTS = 10 
     20#Default value for background 
     21BACKGROUND = 0.0 
     22#default value for the scale 
     23SCALE = 1.0 
     24#Invariant panel size  
    1325_BOX_WIDTH = 76 
    14 _STATICBOX_WIDTH = 350 
    1526_SCALE = 1e-6 
    1627 
    17 #SLD panel size  
    1828if sys.platform.count("win32")>0: 
    19     _STATICBOX_WIDTH = 350 
     29    _STATICBOX_WIDTH = 450 
    2030    PANEL_WIDTH = 500 
    21     PANEL_HEIGHT = 600 
     31    PANEL_HEIGHT = 700 
    2232    FONT_VARIANT = 0 
    2333else: 
    24     _STATICBOX_WIDTH = 380 
     34    _STATICBOX_WIDTH = 480 
    2535    PANEL_WIDTH = 530 
    26     PANEL_HEIGHT = 600 
     36    PANEL_HEIGHT = 700 
    2737    FONT_VARIANT = 1 
    2838     
    2939class InvariantPanel(wx.Panel): 
    3040    """ 
    31         Provides the SLD calculator GUI. 
     41        Provides the Invariant GUI. 
    3242    """ 
    3343    ## Internal nickname for the window, used by the AUI manager 
    34     window_name = "SLD Calculator" 
     44    window_name = "Invariant" 
    3545    ## Name to appear on the window title bar 
    36     window_caption = "SLD Calculator" 
     46    window_caption = "Invariant" 
    3747    ## Flag to tell the AUI manager to put this panel in the center pane 
    3848    CENTER_PANE = True 
    39     def __init__(self, parent, base=None): 
     49    def __init__(self, parent, data=None, base=None): 
    4050        wx.Panel.__init__(self, parent) 
    4151        #Font size  
    4252        self.SetWindowVariant(variant=FONT_VARIANT) 
    4353        #Object that receive status event 
    44         self.base = base 
     54        self.parent = base 
     55       
     56        #Default power value 
     57        self.power_law_exponant = 4  
     58         
     59        #Data uses for computation 
     60        self.data = data 
     61        #Draw the panel 
    4562        self._do_layout() 
    4663        self.SetAutoLayout(True) 
    4764        self.Layout() 
    4865        
     66    def compute_invariant(self, event): 
     67        """ 
     68            compute invariant  
     69        """ 
     70        #clear outputs textctrl  
     71        self._reset_output() 
     72        background = self.background_ctl.GetValue().lstrip().rstrip() 
     73        scale = self.scale_ctl.GetValue().lstrip().rstrip() 
     74        if background == "": 
     75            background = 0 
     76        if scale == "": 
     77            scale = 1 
     78        if check_float(self.background_ctl) and check_float(self.scale_ctl): 
     79            inv = invariant.InvariantCalculator(data=self.data, 
     80                                      background=float(background), 
     81                                       scale=float(scale)) 
     82             
     83            low_q = self.enable_low_cbox.GetValue()  
     84            high_q = self.enable_high_cbox.GetValue() 
     85             
     86            #Get the number of points to extrapolated 
     87            npts_low = self.npts_low_ctl.GetValue() 
     88            if check_float(self.npts_low_ctl): 
     89                npts_low = float(npts_low) 
     90            power_low = self.power_low_ctl.GetValue() 
     91            if check_float(self.power_low_ctl): 
     92                power_low = float(power_low) 
     93            npts_high = self.npts_high_ctl.GetValue()     
     94            if check_float(self.npts_high_ctl): 
     95                npts_high = float(npts_high) 
     96            power_high = self.power_high_ctl.GetValue() 
     97            if check_float(self.power_high_ctl): 
     98                power_high = float(power_high) 
     99            # get the function 
     100            if self.power_law_low.GetValue(): 
     101                function_low = "power_law" 
     102            if self.guinier.GetValue(): 
     103                function_low = "guinier" 
     104                #power_low = None 
     105                 
     106            function_high = "power_law" 
     107            if self.power_law_high.GetValue(): 
     108                function_high = "power_law" 
     109            #check the type of extrapolation 
     110            extrapolation = None 
     111            if low_q  and not high_q: 
     112                extrapolation = "low" 
     113            elif not low_q  and high_q: 
     114                extrapolation = "high" 
     115            elif low_q and high_q: 
     116                extrapolation = "both" 
     117                 
     118            #Set the invariant calculator 
     119            inv.set_extrapolation(range="low", npts=npts_low, 
     120                                       function=function_low, power=power_low) 
     121            inv.set_extrapolation(range="high", npts=npts_high, 
     122                                       function=function_high, power=power_high) 
     123            #Compute invariant 
     124            try: 
     125                qstar, qstar_err = inv.get_qstar_with_error() 
     126                self.invariant_ctl.SetValue(format_number(qstar)) 
     127                self.invariant_err_ctl.SetValue(format_number(qstar)) 
     128                check_float(self.invariant_ctl) 
     129                check_float(self.invariant_err_ctl) 
     130            except: 
     131                raise 
     132                #msg= "Error occurs for invariant: %s"%sys.exc_value 
     133                #wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 
     134                #return 
     135            #Compute qstar extrapolated to low q range 
     136            #Clear the previous extrapolated plot 
     137            self._plot_data( name=self.data.name+" Extra_low_Q") 
     138            self._plot_data( name=self.data.name+" Extra_high_Q") 
     139            if low_q: 
     140                try:  
     141                    qstar_low = inv.get_qstar_low() 
     142                    self.invariant_low_ctl.SetValue(format_number(qstar_low)) 
     143                    check_float(self.invariant_low_ctl) 
     144                    #plot data 
     145                    low_data = inv.get_extra_data_low() 
     146                    self._plot_data(data=low_data, name=self.data.name+" Extra_low_Q") 
     147                except: 
     148                    raise 
     149                    #msg= "Error occurs for low q invariant: %s"%sys.exc_value 
     150                    #wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 
     151            if high_q: 
     152                try:  
     153                    qstar_high = inv.get_qstar_high() 
     154                    self.invariant_high_ctl.SetValue(format_number(qstar_high)) 
     155                    check_float(self.invariant_high_ctl) 
     156                    #plot data 
     157                    high_data = inv.get_extra_data_high() 
     158                    self._plot_data(data=high_data, name=self.data.name+" Extra_high_Q") 
     159                except: 
     160                    raise 
     161                    #msg= "Error occurs for high q invariant: %s"%sys.exc_value 
     162                    #wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 
     163            try: 
     164                qstar_total, qstar_total_err = inv.get_qstar_with_error(extrapolation) 
     165                self.invariant_total_ctl.SetValue(format_number(qstar_total)) 
     166                self.invariant_total_err_ctl.SetValue(format_number(qstar_total)) 
     167                check_float(self.invariant_total_ctl) 
     168                check_float(self.invariant_total_err_ctl) 
     169            except: 
     170                raise 
     171                #msg= "Error occurs for total invariant: %s"%sys.exc_value 
     172                #wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 
     173                 
     174            contrast = self.contrast_ctl.GetValue().lstrip().rstrip() 
     175            if not check_float(self.contrast_ctl): 
     176                contrast = None 
     177            else: 
     178                contrast = float(contrast) 
     179            porod_const = self.porod_const_ctl.GetValue().lstrip().rstrip() 
     180            if not check_float(self.porod_const_ctl): 
     181                porod_const = None 
     182            else: 
     183                porod_const = float(porod_const) 
     184            try: 
     185                v, dv = inv.get_volume_fraction_with_error(contrast=contrast) 
     186                self.volume_ctl.SetValue(format_number(v)) 
     187                self.volume_err_ctl.SetValue(format_number(dv)) 
     188                check_float(self.volume_ctl) 
     189                check_float(self.volume_err_ctl) 
     190            except: 
     191                raise 
     192                #msg= "Error occurs for volume fraction: %s"%sys.exc_value 
     193                #wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 
     194            try: 
     195                s, ds = inv.get_surface_with_error(contrast=contrast, 
     196                                        porod_const=porod_const) 
     197                self.surface_ctl.SetValue(format_number(s)) 
     198                self.surface_err_ctl.SetValue(format_number(ds)) 
     199                check_float(self.surface_ctl) 
     200                check_float(self.surface_err_ctl) 
     201            except: 
     202                raise 
     203                #msg= "Error occurs for surface: %s"%sys.exc_value 
     204                #wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 
     205                 
     206        else: 
     207            msg= "invariant: Need float for background and scale" 
     208            wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 
     209            return 
     210         
     211    def _plot_data(self, data=None, name="Unknown"): 
     212        """ 
     213            Receive a data and post a NewPlotEvent to parent 
     214            @param data: data created frome xtrapolation to plot 
     215            @param name: Data's name to use for the legend 
     216        """ 
     217        # Create a plottable data 
     218        new_plot = Theory1D(x=[], y=[], dy=None) 
     219        if data is not None: 
     220            new_plot.copy_from_datainfo(data)  
     221            data.clone_without_data(clone=new_plot)  
     222             
     223        new_plot.name = name 
     224        title = self.data.name 
     225        new_plot.xaxis(self.data._xaxis, self.data._xunit) 
     226        new_plot.yaxis(self.data._yaxis, self.data._yunit) 
     227        new_plot.group_id = self.data.group_id 
     228        new_plot.id = self.data.id + name 
     229        ##post data to plot 
     230        wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title)) 
     231         
     232    def _reset_output(self): 
     233        """ 
     234            clear outputs textcrtl 
     235        """ 
     236        self.invariant_ctl.Clear() 
     237        self.invariant_err_ctl.Clear() 
     238        self.invariant_low_ctl.Clear() 
     239        self.invariant_high_ctl.Clear() 
     240        self.invariant_total_ctl.Clear() 
     241        self.invariant_total_err_ctl.Clear() 
     242        self.volume_ctl.Clear() 
     243        self.volume_err_ctl.Clear() 
     244        self.surface_ctl.Clear() 
     245        self.surface_err_ctl.Clear() 
     246         
    49247    def _do_layout(self): 
    50248        """ 
     
    55253        unit_surface = '' 
    56254        uncertainty = "+/-" 
    57         sizer_input = wx.GridBagSizer(5,5) 
     255        npts_hint_txt = "Number of points to consider during extrapolation." 
     256        power_hint_txt = "Exponent to apply to the Power_law function." 
     257         
     258        sizer_input = wx.FlexGridSizer(5,4)#wx.GridBagSizer(5,5) 
    58259        sizer_output = wx.GridBagSizer(5,5) 
    59260        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    60         sizer1 = wx.BoxSizer(wx.HORIZONTAL) 
    61         sizer2 = wx.BoxSizer(wx.HORIZONTAL) 
     261         
     262        sizer1 = wx.BoxSizer(wx.VERTICAL) 
     263        sizer2 = wx.BoxSizer(wx.VERTICAL) 
    62264        sizer3 = wx.BoxSizer(wx.HORIZONTAL) 
    63         
     265         
     266        sizer1.SetMinSize((_STATICBOX_WIDTH, -1)) 
     267        sizer2.SetMinSize((_STATICBOX_WIDTH, -1)) 
     268        sizer3.SetMinSize((_STATICBOX_WIDTH, -1)) 
    64269        #---------inputs---------------- 
     270        data_txt = wx.StaticText(self, -1, 'Data : ') 
     271        data_name = "" 
     272        data_range = "[? - ?]" 
     273        if self.data is not None: 
     274            data_name = self.data.name 
     275            data_qmin = min (self.data.x) 
     276            data_qmax = max (self.data.x) 
     277            data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax)) 
     278             
     279        data_name_txt = wx.StaticText(self, -1, str(data_name)) 
     280        data_range_txt = wx.StaticText(self, -1, "Range : ") 
     281        data_range_value_txt = wx.StaticText(self, -1, str(data_range)) 
     282         
    65283        background_txt = wx.StaticText(self, -1, 'Background') 
    66284        self.background_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 
     285        self.background_ctl.SetValue(str(BACKGROUND)) 
    67286        self.background_ctl.SetToolTipString("Background to subtract to data.") 
    68287        scale_txt = wx.StaticText(self, -1, 'Scale') 
    69288        self.scale_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 
     289        self.scale_ctl.SetValue(str(SCALE)) 
    70290        self.scale_ctl.SetToolTipString("Scale to apply to data.") 
    71291        contrast_txt = wx.StaticText(self, -1, 'Contrast') 
     
    76296        self.porod_const_ctl.SetToolTipString("Invariant in q range.") 
    77297        
    78         iy = 0 
    79         ix = 0 
    80         sizer_input.Add(background_txt,(iy, ix),(1,1),\ 
    81                              wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    82         ix +=1 
    83         sizer_input.Add(self.background_ctl,(iy, ix),(1,1),\ 
    84                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    85         iy += 1 
    86         ix = 0 
    87         sizer_input.Add(scale_txt,(iy, ix),(1,1),\ 
    88                              wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    89         ix += 1 
    90         sizer_input.Add(self.scale_ctl, (iy, ix), (1,1),\ 
    91                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    92         iy += 1 
    93         ix = 0 
    94         sizer_input.Add(contrast_txt, (iy, ix),(1,1),\ 
    95                              wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    96         ix += 1 
    97         sizer_input.Add(self.contrast_ctl,(iy, ix),(1,1),\ 
    98                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    99         iy += 1 
    100         ix = 0 
    101         sizer_input.Add(porod_const_txt, (iy, ix),(1,1),\ 
    102                              wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    103         ix += 1 
    104         sizer_input.Add(self.porod_const_ctl,(iy, ix),(1,1),\ 
    105                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    106          
     298        sizer_input.Add(data_txt, 0, wx.LEFT, 5) 
     299        sizer_input.Add(data_name_txt) 
     300        sizer_input.Add(data_range_txt, 0, wx.LEFT, 10) 
     301        sizer_input.Add(data_range_value_txt) 
     302        sizer_input.Add(background_txt, 0, wx.ALL, 5) 
     303        sizer_input.Add(self.background_ctl, 0, wx.ALL, 5) 
     304        sizer_input.Add((10,10)) 
     305        sizer_input.Add((10,10)) 
     306        sizer_input.Add(scale_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) 
     307        sizer_input.Add(self.scale_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) 
     308        sizer_input.Add((10,10)) 
     309        sizer_input.Add((10,10)) 
     310        sizer_input.Add(contrast_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) 
     311        sizer_input.Add(self.contrast_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) 
     312        sizer_input.Add((10,10)) 
     313        sizer_input.Add((10,10)) 
     314        sizer_input.Add(porod_const_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) 
     315        sizer_input.Add(self.porod_const_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) 
     316        #-------------Extrapolation sizer---------------- 
    107317        sizer_low_q = wx.GridBagSizer(5,5) 
     318         
     319        self.enable_low_cbox = wx.CheckBox(self, -1, "Enable low Q") 
     320        self.enable_low_cbox.SetValue(False) 
     321        self.enable_high_cbox = wx.CheckBox(self, -1, "Enable High Q") 
     322        self.enable_high_cbox.SetValue(False) 
     323         
    108324        self.guinier = wx.RadioButton(self, -1, 'Guinier', 
    109                                          (10, 10), style=wx.RB_GROUP) 
     325                                         (10, 10),style=wx.RB_GROUP) 
    110326        self.power_law_low = wx.RadioButton(self, -1, 'Power_law', (10, 10)) 
    111327        #self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 
     
    115331        #MAC needs SetValue 
    116332        self.guinier.SetValue(True) 
    117         power_low_txt = wx.StaticText(self, -1, 'Power') 
    118         self.power_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 
    119         self.power_low_ctl.SetToolTipString("Power to apply to the\ 
    120                                          Power_law function.") 
     333         
     334        npts_low_txt = wx.StaticText(self, -1, 'Npts') 
     335        self.npts_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) 
     336        self.npts_low_ctl.SetValue(str(NPTS)) 
     337        self.power_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) 
     338        self.power_low_ctl.SetValue(str(self.power_law_exponant)) 
     339        self.power_low_ctl.SetToolTipString(power_hint_txt) 
    121340        iy = 0 
    122341        ix = 0 
     342        sizer_low_q.Add(self.guinier,(iy, ix),(1,1), 
     343                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     344        iy += 1 
     345        ix = 0 
    123346        sizer_low_q.Add(self.power_law_low,(iy, ix),(1,1), 
    124                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    125         iy += 1 
    126         ix = 0 
    127         sizer_low_q.Add(power_low_txt,(iy, ix),(1,1), 
    128347                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    129348        ix += 1 
     
    132351        iy += 1 
    133352        ix = 0 
    134         sizer_low_q.Add(self.guinier,(iy, ix),(1,1), 
    135                              wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    136        
     353        sizer_low_q.Add(npts_low_txt,(iy, ix),(1,1), 
     354                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     355        ix += 1 
     356        sizer_low_q.Add(self.npts_low_ctl, (iy, ix), (1,1), 
     357                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     358        iy += 1 
     359        ix = 0 
     360        sizer_low_q.Add(self.enable_low_cbox,(iy, ix),(1,1), 
     361                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    137362        sizer_high_q = wx.GridBagSizer(5,5) 
    138         self.power_law_high = wx.RadioButton(self, -1, 'Power_law', (10, 10)) 
     363        self.power_law_high = wx.RadioButton(self, -1, 'Power_law', 
     364                                              (10, 10), style=wx.RB_GROUP) 
    139365        #self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 
    140366        #           id=self.power_law_high.GetId()) 
    141367        #MAC needs SetValue 
    142368        self.power_law_high.SetValue(True) 
    143         power_high_txt = wx.StaticText(self, -1, 'Power') 
    144         self.power_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 
    145         self.power_high_ctl.SetToolTipString("Power to apply to the\ 
    146                                          Power_law function.") 
    147         iy = 0 
     369        npts_high_txt = wx.StaticText(self, -1, 'Npts') 
     370        self.npts_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) 
     371        self.npts_high_ctl.SetValue(str(NPTS)) 
     372        self.power_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) 
     373        self.power_high_ctl.SetValue(str(self.power_law_exponant)) 
     374        self.power_high_ctl.SetToolTipString(power_hint_txt) 
     375         
     376        iy = 1 
    148377        ix = 0 
    149378        sizer_high_q.Add(self.power_law_high,(iy, ix),(1,1), 
    150                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    151         iy += 1 
    152         ix = 0 
    153         sizer_high_q.Add(power_high_txt,(iy, ix),(1,1), 
    154379                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    155380        ix += 1 
    156381        sizer_high_q.Add(self.power_high_ctl, (iy, ix), (1,1), 
    157382                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     383        iy += 1 
     384        ix = 0 
     385        sizer_high_q.Add(npts_high_txt,(iy, ix),(1,1), 
     386                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     387        ix += 1 
     388        sizer_high_q.Add(self.npts_high_ctl, (iy, ix), (1,1), 
     389                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     390        iy += 1 
     391        ix = 0 
     392        sizer_high_q.Add(self.enable_high_cbox,(iy, ix),(1,1), 
     393                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    158394         
    159395        high_q_box = wx.StaticBox(self, -1, "High Q") 
     
    165401        boxsizer_low_q.Add(sizer_low_q) 
    166402         
    167         sizer_extrapolation = wx.BoxSizer(wx.HORIZONTAL) 
     403        #-------------Enable extrapolation------- 
     404        extra_hint = "Extrapolation Maximum Range: " 
     405        extra_hint_txt= wx.StaticText(self, -1,extra_hint ) 
     406        enable_sizer = wx.BoxSizer(wx.HORIZONTAL) 
     407        extra_range = "[%s - %s]"%(str(Q_MINIMUM), str(Q_MAXIMUM)) 
     408        extra_range_value_txt = wx.StaticText(self, -1, str(extra_range)) 
     409        enable_sizer.Add(extra_hint_txt, 0, wx.ALL, 5) 
     410        enable_sizer.Add(extra_range_value_txt, 0, wx.ALL, 5) 
     411         
     412        type_extrapolation_sizer = wx.BoxSizer(wx.HORIZONTAL) 
     413        type_extrapolation_sizer.Add((10,10)) 
     414        type_extrapolation_sizer.Add(boxsizer_low_q, 0, wx.ALL, 10) 
     415        type_extrapolation_sizer.Add((20,20)) 
     416        type_extrapolation_sizer.Add(boxsizer_high_q, 0, wx.ALL, 10) 
     417        type_extrapolation_sizer.Add((10,10)) 
     418         
    168419        extrapolation_box = wx.StaticBox(self, -1, "Extrapolation") 
    169         boxsizer_extra = wx.StaticBoxSizer(extrapolation_box, wx.HORIZONTAL) 
    170         boxsizer_extra.Add(boxsizer_low_q) 
    171         boxsizer_extra.Add((10,10)) 
    172         boxsizer_extra.Add(boxsizer_high_q) 
     420        boxsizer_extra = wx.StaticBoxSizer(extrapolation_box, wx.VERTICAL) 
     421        boxsizer_extra.Add(enable_sizer, 0, wx.ALL, 10) 
     422        boxsizer_extra.Add(type_extrapolation_sizer) 
    173423     
    174424        inputbox = wx.StaticBox(self, -1, "Input") 
     
    176426        boxsizer1.SetMinSize((_STATICBOX_WIDTH,-1)) 
    177427        boxsizer1.Add(sizer_input) 
    178         boxsizer1.Add(boxsizer_extra) 
    179          
     428        boxsizer1.Add(boxsizer_extra, 0, wx.ALL, 10) 
    180429        sizer1.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) 
     430         
    181431        #---------Outputs sizer-------- 
    182432        invariant_txt = wx.StaticText(self, -1, 'Invariant') 
     
    245495        ix +=1 
    246496        sizer_output.Add(self.invariant_high_ctl, (iy, ix), (1,1), 
    247                             wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     497                            wx.EXPAND|wx.ADJUST_MINSIZE, ) 
    248498        ix += 2 
    249499        sizer_output.Add(invariant_high_units_txt, (iy, ix), (1,1), 
     
    279529                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
    280530        ix +=1 
    281         sizer_output.Add(invariant_total_units_txt 
    282                          ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)  
     531        sizer_output.Add(invariant_total_units_txt,(iy, ix), 
     532                        (1,1),wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    283533        iy += 1 
    284534        ix = 0 
     
    320570        sizer2.Add(boxsizer2,0, wx.EXPAND|wx.ALL, 10) 
    321571        #-----Button  sizer------------ 
    322      
    323572        id = wx.NewId() 
    324573        button_calculate = wx.Button(self, id, "Compute") 
     
    337586        self.SetSizer(vbox) 
    338587     
    339     def compute_invariant(self, event): 
    340         """ 
    341             compute invariant 
    342         """ 
    343           
    344588class InvariantDialog(wx.Dialog): 
    345     def __init__(self, parent=None, id=1, title="Invariant",base=None): 
     589    def __init__(self, parent=None, id=1,data=None, title="Invariant",base=None): 
    346590        wx.Dialog.__init__(self, parent, id, title, size=( PANEL_WIDTH, 
    347591                                                             PANEL_HEIGHT)) 
    348          
    349         self.panel = InvariantPanel(self, base=base) 
     592        self.panel = InvariantPanel(self, data=data, base=base) 
     593        self.Centre() 
     594        self.Show(True) 
     595         
     596class InvariantWindow(wx.Frame): 
     597    def __init__(self, parent=None, id=1,data=None, title="SLD Calculator",base=None): 
     598        wx.Frame.__init__(self, parent, id, title, size=( PANEL_WIDTH, 
     599                                                             PANEL_HEIGHT)) 
     600         
     601        self.panel = InvariantPanel(self, data=data, base=base) 
    350602        self.Centre() 
    351603        self.Show(True) 
     
    354606    def OnInit(self): 
    355607        wx.InitAllImageHandlers() 
    356         
    357         dialog = InvariantDialog(None) 
    358         if dialog.ShowModal() == wx.ID_OK: 
    359             pass 
    360         dialog.Destroy() 
    361          
    362         return 1 
     608        frame = InvariantWindow() 
     609        frame.Show(True) 
     610        self.SetTopWindow(frame) 
     611         
     612        return True 
     613        #wx.InitAllImageHandlers() 
     614        #dialog = InvariantDialog(None) 
     615        #if dialog.ShowModal() == wx.ID_OK: 
     616        #    pass 
     617        #dialog.Destroy() 
     618        #return 1 
    363619    
    364620# end of class MyApp 
Note: See TracChangeset for help on using the changeset viewer.