source: sasview/invariantview/perspectives/invariant/invariant_panel.py @ d5f0dcb9

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since d5f0dcb9 was d5f0dcb9, checked in by Jae Cho <jhjcho@…>, 14 years ago

Fixed "Can't click buttons & textctrls on MAC"

  • Property mode set to 100644
File size: 28.5 KB
Line 
1"""
2    This module provide GUI for the neutron scattering length density calculator
3    @author: Gervaise B. Alina
4"""
5
6import wx
7import sys
8
9from sans.invariant import invariant
10
11from sans.guiframe.utils import format_number, check_float
12from sans.guicomm.events import NewPlotEvent, StatusEvent
13
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 maximum value to plot the theory data
19Q_MAXIMUM_PLOT = 2
20# the number of points to consider during fit
21NPTS = 10
22#Default value for background
23BACKGROUND = 0.0
24#default value for the scale
25SCALE = 1.0
26#Invariant panel size
27_BOX_WIDTH = 76
28_SCALE = 1e-6
29
30if sys.platform.count("win32")>0:
31    _STATICBOX_WIDTH = 450
32    PANEL_WIDTH = 500
33    PANEL_HEIGHT = 700
34    FONT_VARIANT = 0
35else:
36    _STATICBOX_WIDTH = 480
37    PANEL_WIDTH = 530
38    PANEL_HEIGHT = 700
39    FONT_VARIANT = 1
40   
41class InvariantPanel(wx.ScrolledWindow):
42    """
43        Provides the Invariant GUI.
44    """
45    ## Internal nickname for the window, used by the AUI manager
46    window_name = "Invariant"
47    ## Name to appear on the window title bar
48    window_caption = "Invariant"
49    ## Flag to tell the AUI manager to put this panel in the center pane
50    CENTER_PANE = True
51    def __init__(self, parent, data=None, manager=None):
52        wx.ScrolledWindow.__init__(self, parent, style= wx.FULL_REPAINT_ON_RESIZE )
53        #Font size
54        self.SetWindowVariant(variant=FONT_VARIANT)
55        #Object that receive status event
56        self.parent = parent
57        #plug-in using this panel
58        self._manager = manager
59        #Default power value
60        self.power_law_exponant = 4 
61        #Data uses for computation
62        self._data = data
63        #Draw the panel
64        self._do_layout()
65        self.SetScrollbars(20,20,25,65)
66        self.SetAutoLayout(True)
67        self.Layout()
68   
69    def set_data(self, data):
70        """
71            Set the data
72        """
73        self._data = data
74        #edit the panel
75        if self._data is not None:
76            data_name = self._data.name
77            data_qmin = min (self._data.x)
78            data_qmax = max (self._data.x)
79            data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax))
80           
81        self.data_name_txt.SetLabel('Data : '+str(data_name))
82        self.data_range_value_txt.SetLabel(str(data_range))
83       
84    def set_manager(self, manager):
85        """
86            set value for the manager
87        """
88        self._manager = manager
89       
90    def compute_invariant(self, event):
91        """
92            compute invariant
93        """
94        #clear outputs textctrl
95        self._reset_output()
96        background = self.background_ctl.GetValue().lstrip().rstrip()
97        scale = self.scale_ctl.GetValue().lstrip().rstrip()
98        if background == "":
99            background = 0
100        if scale == "":
101            scale = 1
102        if check_float(self.background_ctl) and check_float(self.scale_ctl):
103            inv = invariant.InvariantCalculator(data=self._data,
104                                      background=float(background),
105                                       scale=float(scale))
106           
107            #Get the number of points to extrapolated
108            npts_low = self.npts_low_ctl.GetValue()
109            if check_float(self.npts_low_ctl):
110                npts_low = float(npts_low)
111            power_low = self.power_low_ctl.GetValue()
112            if check_float(self.power_low_ctl):
113                power_low = float(power_low)
114            npts_high = self.npts_high_ctl.GetValue()   
115            if check_float(self.npts_high_ctl):
116                npts_high = float(npts_high)
117            power_high = self.power_high_ctl.GetValue()
118            if check_float(self.power_high_ctl):
119                power_high = float(power_high)
120            # get the function
121            if self.power_law_low.GetValue():
122                function_low = "power_law"
123            if self.guinier.GetValue():
124                function_low = "guinier"
125                #power_low = None
126               
127            function_high = "power_law"
128            if self.power_law_high.GetValue():
129                function_high = "power_law"
130            #check the type of extrapolation
131            extrapolation = None
132            low_q = self.enable_low_cbox.GetValue()
133            high_q = self.enable_high_cbox.GetValue()
134            if low_q  and not high_q:
135                extrapolation = "low"
136            elif not low_q  and high_q:
137                extrapolation = "high"
138            elif low_q and high_q:
139                extrapolation = "both"
140               
141            #Set the invariant calculator
142            inv.set_extrapolation(range="low", npts=npts_low,
143                                       function=function_low, power=power_low)
144            inv.set_extrapolation(range="high", npts=npts_high,
145                                       function=function_high, power=power_high)
146            #Compute invariant
147            try:
148                qstar, qstar_err = inv.get_qstar_with_error()
149                self.invariant_ctl.SetValue(format_number(qstar))
150                self.invariant_err_ctl.SetValue(format_number(qstar))
151            except:
152                msg= "Error occurs for invariant: %s"%sys.exc_value
153                wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))
154                return
155            #Compute qstar extrapolated to low q range
156            #Clear the previous extrapolated plot
157            if low_q:
158                try: 
159                    qstar_low = inv.get_qstar_low()
160                    self.invariant_low_ctl.SetValue(format_number(qstar_low))
161                    #plot data
162                    low_out_data, low_in_data = inv.get_extra_data_low()
163                    self._manager._plot_theory(reel_data=self._data,
164                                               extra_data=low_out_data,
165                                     name=self._data.name+" Extra_low_Q")
166                    self._manager._plot_data(reel_data=self._data,
167                                             extra_data=low_in_data, 
168                                name=self._data.name+"Fitted data for low_Q")
169                except:
170                    msg= "Error occurs for low q invariant: %s"%sys.exc_value
171                    wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))
172            if high_q:
173                try: 
174                    qstar_high = inv.get_qstar_high()
175                    self.invariant_high_ctl.SetValue(format_number(qstar_high))
176                    #plot data
177                    high_out_data, high_in_data = inv.get_extra_data_high(q_end=Q_MAXIMUM_PLOT)
178                    self._manager._plot_theory(reel_data=self._data,
179                                               extra_data=high_out_data,
180                                     name=self._data.name+" Extra_high_Q")
181                    self._manager._plot_data(reel_data=self._data,
182                                             extra_data=high_in_data,
183                                 name=self._data.name+"Fitted data for high_Q")
184                except:
185                    msg= "Error occurs for high q invariant: %s"%sys.exc_value
186                    wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))
187            try:
188                qstar_total, qstar_total_err = inv.get_qstar_with_error(extrapolation)
189                self.invariant_total_ctl.SetValue(format_number(qstar_total))
190                self.invariant_total_err_ctl.SetValue(format_number(qstar_total))
191                check_float(self.invariant_total_ctl)
192                check_float(self.invariant_total_err_ctl)
193            except:
194                msg= "Error occurs for total invariant: %s"%sys.exc_value
195                wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 
196           
197            porod_const = self.porod_const_ctl.GetValue().lstrip().rstrip()
198            if porod_const == "":
199                porod_const = None
200            if not (porod_const is None):
201                if check_float(self.porod_const_ctl):
202                    porod_const = float(porod_const)
203                    try:
204                        v, dv = inv.get_volume_fraction_with_error(contrast=contrast)
205                        self.volume_ctl.SetValue(format_number(v))
206                        self.volume_err_ctl.SetValue(format_number(dv))
207                    except:
208                        msg= "Error occurs for volume fraction: %s"%sys.exc_value
209                        wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))
210            contrast = self.contrast_ctl.GetValue().lstrip().rstrip()
211            if contrast == "":
212                contrast = None
213            if not (contrast is None):
214                if check_float(self.contrast_ctl):
215                    contrast = float(contrast)
216                    try:
217                        if not (porod_const is None):
218                            s, ds = inv.get_surface_with_error(contrast=contrast,
219                                                    porod_const=porod_const)
220                            self.surface_ctl.SetValue(format_number(s))
221                            self.surface_err_ctl.SetValue(format_number(ds))
222                    except:
223                        msg= "Error occurs for surface: %s"%sys.exc_value
224                        wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))
225                       
226        else:
227            msg= "invariant: Need float for background and scale"
228            wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))
229            return
230 
231    def _reset_output(self):
232        """
233            clear outputs textcrtl
234        """
235        self.invariant_ctl.Clear()
236        self.invariant_err_ctl.Clear()
237        self.invariant_low_ctl.Clear()
238        self.invariant_high_ctl.Clear()
239        self.invariant_total_ctl.Clear()
240        self.invariant_total_err_ctl.Clear()
241        self.volume_ctl.Clear()
242        self.volume_err_ctl.Clear()
243        self.surface_ctl.Clear()
244        self.surface_err_ctl.Clear()
245       
246    def _do_layout(self):
247        """
248            Draw window content
249        """
250        unit_invariant = '[1/cm][1/A]'
251        unit_volume = ''
252        unit_surface = ''
253        uncertainty = "+/-"
254        npts_hint_txt = "Number of points to consider during extrapolation."
255        power_hint_txt = "Exponent to apply to the Power_law function."
256       
257        sizer_input = wx.FlexGridSizer(5,4)#wx.GridBagSizer(5,5)
258        sizer_output = wx.GridBagSizer(5,5)
259        sizer_button = wx.BoxSizer(wx.HORIZONTAL)
260       
261        sizer1 = wx.BoxSizer(wx.VERTICAL)
262        sizer2 = wx.BoxSizer(wx.VERTICAL)
263        sizer3 = wx.BoxSizer(wx.HORIZONTAL)
264       
265        sizer1.SetMinSize((_STATICBOX_WIDTH, -1))
266        sizer2.SetMinSize((_STATICBOX_WIDTH, -1))
267        sizer3.SetMinSize((_STATICBOX_WIDTH, -1))
268       
269        ## Box sizers must be defined first before defining buttons/textctrls (MAC).
270        vbox  = wx.BoxSizer(wx.VERTICAL)
271        inputbox = wx.StaticBox(self, -1, "Input")
272        extrapolation_box = wx.StaticBox(self, -1, "Extrapolation")
273        boxsizer1 = wx.StaticBoxSizer(inputbox, wx.VERTICAL)
274        high_q_box = wx.StaticBox(self, -1, "High Q")
275        boxsizer_high_q = wx.StaticBoxSizer(high_q_box, wx.VERTICAL)   
276        low_q_box = wx.StaticBox(self, -1, "Low Q")
277        boxsizer_low_q = wx.StaticBoxSizer(low_q_box, wx.VERTICAL)
278       
279        #---------inputs----------------
280        data_name = ""
281        data_range = "[? - ?]"
282        if self._data is not None:
283            data_name = self._data.name
284            data_qmin = min (self._data.x)
285            data_qmax = max (self._data.x)
286            data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax))
287           
288        self.data_name_txt = wx.StaticText(self, -1, 'Data : '+str(data_name))
289        data_range_txt = wx.StaticText(self, -1, "Range : ")
290        self.data_range_value_txt = wx.StaticText(self, -1, str(data_range))
291       
292        background_txt = wx.StaticText(self, -1, 'Background (Optional)')
293        self.background_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
294        self.background_ctl.SetValue(str(BACKGROUND))
295        self.background_ctl.SetToolTipString("Background to subtract to data.")
296        scale_txt = wx.StaticText(self, -1, 'Scale (Optional)')
297        self.scale_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
298        self.scale_ctl.SetValue(str(SCALE))
299        self.scale_ctl.SetToolTipString("Scale to apply to data.")
300        contrast_txt = wx.StaticText(self, -1, 'Contrast (Optional)')
301        self.contrast_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
302        msg_hint = "Enter a value for the contrast to get the volume fraction"
303        self.contrast_ctl.SetToolTipString(str(msg_hint))
304        porod_const_txt = wx.StaticText(self, -1, 'Porod Constant(Optional)')
305        self.porod_const_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
306        msg_hint ="Need both the contrast and surface to get the surface"
307        self.porod_const_ctl.SetToolTipString(str(msg_hint))
308       
309        sizer_input.Add(self.data_name_txt, 0, wx.LEFT, 5)
310        sizer_input.Add((10,10), 0, wx.LEFT, 5)
311        sizer_input.Add(data_range_txt, 0, wx.LEFT, 10)
312        sizer_input.Add(self.data_range_value_txt)
313        sizer_input.Add(background_txt, 0, wx.ALL, 5)
314        sizer_input.Add(self.background_ctl, 0, wx.ALL, 5)
315        sizer_input.Add((10,10))
316        sizer_input.Add((10,10))
317        sizer_input.Add(scale_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5)
318        sizer_input.Add(self.scale_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5)
319        sizer_input.Add((10,10))
320        sizer_input.Add((10,10))
321        sizer_input.Add(contrast_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5)
322        sizer_input.Add(self.contrast_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5)
323        sizer_input.Add((10,10))
324        sizer_input.Add((10,10))
325        sizer_input.Add(porod_const_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5)
326        sizer_input.Add(self.porod_const_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5)
327        #-------------Extrapolation sizer----------------
328        sizer_low_q = wx.GridBagSizer(5,5)
329       
330        self.enable_low_cbox = wx.CheckBox(self, -1, "Enable low Q")
331        self.enable_low_cbox.SetValue(False)
332        self.enable_high_cbox = wx.CheckBox(self, -1, "Enable High Q")
333        self.enable_high_cbox.SetValue(False)
334       
335        self.guinier = wx.RadioButton(self, -1, 'Guinier',
336                                         (10, 10),style=wx.RB_GROUP)
337        self.power_law_low = wx.RadioButton(self, -1, 'Power_law', (10, 10))
338        self.guinier.SetValue(True)
339       
340        npts_low_txt = wx.StaticText(self, -1, 'Npts')
341        self.npts_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1))
342        self.npts_low_ctl.SetValue(str(NPTS))
343        msg_hint = "the number of first q points to consider"
344        msg_hint +="during the fit for extrapolation at low Q"
345        self.npts_low_ctl.SetToolTipString(msg_hint)
346        self.power_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1))
347        self.power_low_ctl.SetValue(str(self.power_law_exponant))
348        self.power_low_ctl.SetToolTipString(power_hint_txt)
349        iy = 0
350        ix = 0
351        sizer_low_q.Add(self.guinier,(iy, ix),(1,1),
352                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
353        iy += 1
354        ix = 0
355        sizer_low_q.Add(self.power_law_low,(iy, ix),(1,1),
356                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
357        ix += 1
358        sizer_low_q.Add(self.power_low_ctl, (iy, ix), (1,1),
359                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
360        iy += 1
361        ix = 0
362        sizer_low_q.Add(npts_low_txt,(iy, ix),(1,1),
363                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
364        ix += 1
365        sizer_low_q.Add(self.npts_low_ctl, (iy, ix), (1,1),
366                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
367        iy += 1
368        ix = 0
369        sizer_low_q.Add(self.enable_low_cbox,(iy, ix),(1,1),
370                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
371        sizer_high_q = wx.GridBagSizer(5,5)
372        self.power_law_high = wx.RadioButton(self, -1, 'Power_law',
373                                              (10, 10), style=wx.RB_GROUP)
374        msg_hint ="Check it to extrapolate data to high Q"
375        self.power_law_high.SetToolTipString(msg_hint)
376       
377        #MAC needs SetValue
378        self.power_law_high.SetValue(True)
379        npts_high_txt = wx.StaticText(self, -1, 'Npts')
380        self.npts_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1))
381        msg_hint = "the number of last q points to consider"
382        msg_hint += "during the fit for extrapolation high Q"
383        self.npts_high_ctl.SetToolTipString(msg_hint)
384        self.npts_high_ctl.SetValue(str(NPTS))
385        self.power_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1))
386        self.power_high_ctl.SetValue(str(self.power_law_exponant))
387        self.power_high_ctl.SetToolTipString(power_hint_txt)
388       
389        iy = 1
390        ix = 0
391        sizer_high_q.Add(self.power_law_high,(iy, ix),(1,1),
392                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
393        ix += 1
394        sizer_high_q.Add(self.power_high_ctl, (iy, ix), (1,1),
395                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
396        iy += 1
397        ix = 0
398        sizer_high_q.Add(npts_high_txt,(iy, ix),(1,1),
399                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
400        ix += 1
401        sizer_high_q.Add(self.npts_high_ctl, (iy, ix), (1,1),
402                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
403        iy += 1
404        ix = 0
405        sizer_high_q.Add(self.enable_high_cbox,(iy, ix),(1,1),
406                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
407             
408        boxsizer_high_q.Add(sizer_high_q)               
409        boxsizer_low_q.Add(sizer_low_q)
410       
411        #-------------Enable extrapolation-------
412        extra_hint = "Extrapolation Maximum Range: "
413        extra_hint_txt= wx.StaticText(self, -1,extra_hint )
414        extra_range = "[%s - %s]"%(str(Q_MINIMUM), str(Q_MAXIMUM))
415        extra_range_value_txt = wx.StaticText(self, -1, str(extra_range))
416        extra_enable_hint = "Hint: Check any box to enable a specific extrapolation !"
417        extra_enable_hint_txt= wx.StaticText(self, -1, extra_enable_hint )
418       
419        enable_sizer = wx.GridBagSizer(5,5)
420       
421        iy = 0
422        ix = 0
423        enable_sizer.Add(extra_hint_txt,(iy, ix),(1,1),
424                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
425        ix += 1
426        enable_sizer.Add(extra_range_value_txt, (iy, ix), (1,1),
427                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
428        ix = 0
429        iy += 1
430        enable_sizer.Add(extra_enable_hint_txt,(iy, ix),(1,1),
431                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
432       
433        type_extrapolation_sizer = wx.BoxSizer(wx.HORIZONTAL)
434        type_extrapolation_sizer.Add((10,10))
435        type_extrapolation_sizer.Add(boxsizer_low_q, 0, wx.ALL, 10)
436        type_extrapolation_sizer.Add((20,20))
437        type_extrapolation_sizer.Add(boxsizer_high_q, 0, wx.ALL, 10)
438        type_extrapolation_sizer.Add((10,10))
439               
440        boxsizer_extra = wx.StaticBoxSizer(extrapolation_box, wx.VERTICAL)
441        boxsizer_extra.Add(enable_sizer, 0, wx.ALL, 10)
442        boxsizer_extra.Add(type_extrapolation_sizer)
443           
444        boxsizer1.SetMinSize((_STATICBOX_WIDTH,-1))
445        boxsizer1.Add(sizer_input)
446        boxsizer1.Add(boxsizer_extra, 0, wx.ALL, 10)
447        sizer1.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10)
448       
449        #---------Outputs sizer--------
450        invariant_txt = wx.StaticText(self, -1, 'Invariant')
451        self.invariant_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
452        self.invariant_ctl.SetEditable(False)
453        self.invariant_ctl.SetToolTipString("Invariant in q range.")
454        self.invariant_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
455        self.invariant_err_ctl.SetEditable(False)
456        self.invariant_err_ctl.SetToolTipString("Uncertainty on invariant.")
457        invariant_units_txt = wx.StaticText(self, -1, unit_invariant)
458       
459        invariant_total_txt = wx.StaticText(self, -1, 'Invariant Total')
460        self.invariant_total_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
461        self.invariant_total_ctl.SetEditable(False)
462        msg_hint = "Invariant in q range and extra polated range."
463        self.invariant_total_ctl.SetToolTipString(msg_hint)
464        self.invariant_total_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
465        self.invariant_total_err_ctl.SetEditable(False)
466        self.invariant_total_err_ctl.SetToolTipString("Uncertainty on invariant.")
467        invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant)
468       
469        volume_txt = wx.StaticText(self, -1, 'Volume Fraction')
470        self.volume_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
471        self.volume_ctl.SetEditable(False)
472        self.volume_ctl.SetToolTipString("volume fraction.")
473        self.volume_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
474        self.volume_err_ctl.SetEditable(False)
475        self.volume_err_ctl.SetToolTipString("Uncertainty of volume fraction.")
476        volume_units_txt = wx.StaticText(self, -1, unit_volume)
477       
478        surface_txt = wx.StaticText(self, -1, 'Surface')
479        self.surface_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
480        self.surface_ctl.SetEditable(False)
481        self.surface_ctl.SetToolTipString("Surface.")
482        self.surface_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
483        self.surface_err_ctl.SetEditable(False)
484        self.surface_err_ctl.SetToolTipString("Uncertainty of surface.")
485        surface_units_txt = wx.StaticText(self, -1, unit_surface)
486       
487        invariant_low_txt = wx.StaticText(self, -1, 'Invariant in low Q')
488        self.invariant_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
489        self.invariant_low_ctl.SetEditable(False)
490        self.invariant_low_ctl.SetToolTipString("Invariant compute in low Q")
491        invariant_low_units_txt = wx.StaticText(self, -1,  unit_invariant)
492       
493        invariant_high_txt = wx.StaticText(self, -1, 'Invariant in high Q')
494        self.invariant_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
495        self.invariant_high_ctl.SetEditable(False)
496        self.invariant_high_ctl.SetToolTipString("Invariant compute in high Q")
497        invariant_high_units_txt = wx.StaticText(self, -1,  unit_invariant)
498       
499        iy = 0
500        ix = 0
501        sizer_output.Add(invariant_low_txt, (iy, ix), (1,1),
502                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
503        ix +=1
504        sizer_output.Add(self.invariant_low_ctl, (iy, ix), (1,1),
505                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
506        ix += 2
507        sizer_output.Add(invariant_low_units_txt, (iy, ix), (1,1),
508                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
509        iy += 1
510        ix = 0 
511        sizer_output.Add(invariant_high_txt, (iy, ix), (1,1),
512                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
513        ix +=1
514        sizer_output.Add(self.invariant_high_ctl, (iy, ix), (1,1),
515                            wx.EXPAND|wx.ADJUST_MINSIZE, )
516        ix += 2
517        sizer_output.Add(invariant_high_units_txt, (iy, ix), (1,1),
518                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
519        iy += 1
520        ix = 0
521        sizer_output.Add(invariant_txt,(iy, ix),(1,1),
522                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
523        ix += 1
524        sizer_output.Add(self.invariant_ctl,(iy, ix),(1,1),
525                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
526        ix += 1
527        sizer_output.Add( wx.StaticText(self, -1, uncertainty),
528                         (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
529        ix +=1
530        sizer_output.Add(self.invariant_err_ctl
531                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
532        ix +=1
533        sizer_output.Add(invariant_units_txt
534                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
535        iy += 1
536        ix = 0
537        sizer_output.Add(invariant_total_txt,(iy, ix),(1,1),
538                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
539        ix += 1
540        sizer_output.Add(self.invariant_total_ctl,(iy, ix),(1,1),
541                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
542        ix += 1
543        sizer_output.Add( wx.StaticText(self, -1, uncertainty),
544                         (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
545        ix +=1
546        sizer_output.Add(self.invariant_total_err_ctl
547                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
548        ix +=1
549        sizer_output.Add(invariant_total_units_txt,(iy, ix),
550                        (1,1),wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
551        iy += 1
552        ix = 0
553        sizer_output.Add(volume_txt,(iy, ix),(1,1),
554                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
555        ix +=1
556        sizer_output.Add(self.volume_ctl,(iy, ix),(1,1),
557                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
558        ix +=1
559        sizer_output.Add(wx.StaticText(self, -1, uncertainty)
560                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)
561        ix += 1
562        sizer_output.Add(self.volume_err_ctl
563                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
564        ix += 1
565        sizer_output.Add(volume_units_txt
566                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
567        iy += 1
568        ix = 0
569        sizer_output.Add(surface_txt,(iy, ix),(1,1),
570                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
571        ix +=1
572        sizer_output.Add(self.surface_ctl,(iy, ix),(1,1),
573                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
574        ix +=1
575        sizer_output.Add(wx.StaticText(self, -1, uncertainty)
576                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)
577        ix += 1
578        sizer_output.Add(self.surface_err_ctl
579                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
580        ix +=1
581        sizer_output.Add(surface_units_txt
582                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)
583       
584        outputbox = wx.StaticBox(self, -1, "Output")
585        boxsizer2 = wx.StaticBoxSizer(outputbox, wx.VERTICAL)
586        boxsizer2.SetMinSize((_STATICBOX_WIDTH,-1))
587        boxsizer2.Add( sizer_output )
588        sizer2.Add(boxsizer2,0, wx.EXPAND|wx.ALL, 10)
589        #-----Button  sizer------------
590        id = wx.NewId()
591        button_calculate = wx.Button(self, id, "Compute")
592        button_calculate.SetToolTipString("Compute SlD of neutrons.")
593        self.Bind(wx.EVT_BUTTON, self.compute_invariant, id = id)   
594       
595        sizer_button.Add((250, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
596        sizer_button.Add(button_calculate, 0, wx.RIGHT|wx.ADJUST_MINSIZE,20)
597        sizer3.Add(sizer_button)
598        #---------layout----------------
599       
600        vbox.Add(sizer1)
601        vbox.Add(sizer2)
602        vbox.Add(sizer3)
603        vbox.Fit(self) 
604        self.SetSizer(vbox)
605   
606class InvariantDialog(wx.Dialog):
607    def __init__(self, parent=None, id=1,graph=None,
608                 data=None, title="Invariant",base=None):
609        wx.Dialog.__init__(self, parent, id, title, size=(PANEL_WIDTH,
610                                                             PANEL_HEIGHT))
611        self.panel = InvariantPanel(self)
612        self.Centre()
613        self.Show(True)
614       
615class InvariantWindow(wx.Frame):
616    def __init__(self, parent=None, id=1,graph=None, 
617                 data=None, title="Invariant",base=None):
618       
619        wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH,
620                                                             PANEL_HEIGHT))
621       
622        self.panel = InvariantPanel(self)
623        self.Centre()
624        self.Show(True)
625       
626class MyApp(wx.App):
627    def OnInit(self):
628        wx.InitAllImageHandlers()
629        frame = InvariantWindow()
630        frame.Show(True)
631        self.SetTopWindow(frame)
632       
633        return True
634     
635# end of class MyApp
636
637if __name__ == "__main__":
638    app = MyApp(0)
639    app.MainLoop()
Note: See TracBrowser for help on using the repository browser.