source: sasview/invariantview/perspectives/invariant/invariant_panel.py @ 272d91e

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 272d91e was 272d91e, checked in by Gervaise Alina <gervyh@…>, 14 years ago

create an invariant calculator only on compute invariant

  • Property mode set to 100644
File size: 28.4 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        #---------inputs----------------
269        data_name = ""
270        data_range = "[? - ?]"
271        if self._data is not None:
272            data_name = self._data.name
273            data_qmin = min (self._data.x)
274            data_qmax = max (self._data.x)
275            data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax))
276           
277        self.data_name_txt = wx.StaticText(self, -1, 'Data : '+str(data_name))
278        data_range_txt = wx.StaticText(self, -1, "Range : ")
279        self.data_range_value_txt = wx.StaticText(self, -1, str(data_range))
280       
281        background_txt = wx.StaticText(self, -1, 'Background (Optional)')
282        self.background_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
283        self.background_ctl.SetValue(str(BACKGROUND))
284        self.background_ctl.SetToolTipString("Background to subtract to data.")
285        scale_txt = wx.StaticText(self, -1, 'Scale (Optional)')
286        self.scale_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
287        self.scale_ctl.SetValue(str(SCALE))
288        self.scale_ctl.SetToolTipString("Scale to apply to data.")
289        contrast_txt = wx.StaticText(self, -1, 'Contrast (Optional)')
290        self.contrast_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
291        msg_hint = "Enter a value for the contrast to get the volume fraction"
292        self.contrast_ctl.SetToolTipString(str(msg_hint))
293        porod_const_txt = wx.StaticText(self, -1, 'Porod Constant(Optional)')
294        self.porod_const_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
295        msg_hint ="Need both the contrast and surface to get the surface"
296        self.porod_const_ctl.SetToolTipString(str(msg_hint))
297       
298        sizer_input.Add(self.data_name_txt, 0, wx.LEFT, 5)
299        sizer_input.Add((10,10), 0, wx.LEFT, 5)
300        sizer_input.Add(data_range_txt, 0, wx.LEFT, 10)
301        sizer_input.Add(self.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----------------
317        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       
324        self.guinier = wx.RadioButton(self, -1, 'Guinier',
325                                         (10, 10),style=wx.RB_GROUP)
326        self.power_law_low = wx.RadioButton(self, -1, 'Power_law', (10, 10))
327        self.guinier.SetValue(True)
328       
329        npts_low_txt = wx.StaticText(self, -1, 'Npts')
330        self.npts_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1))
331        self.npts_low_ctl.SetValue(str(NPTS))
332        msg_hint = "the number of first q points to consider"
333        msg_hint +="during the fit for extrapolation at low Q"
334        self.npts_low_ctl.SetToolTipString(msg_hint)
335        self.power_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1))
336        self.power_low_ctl.SetValue(str(self.power_law_exponant))
337        self.power_low_ctl.SetToolTipString(power_hint_txt)
338        iy = 0
339        ix = 0
340        sizer_low_q.Add(self.guinier,(iy, ix),(1,1),
341                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
342        iy += 1
343        ix = 0
344        sizer_low_q.Add(self.power_law_low,(iy, ix),(1,1),
345                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
346        ix += 1
347        sizer_low_q.Add(self.power_low_ctl, (iy, ix), (1,1),
348                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
349        iy += 1
350        ix = 0
351        sizer_low_q.Add(npts_low_txt,(iy, ix),(1,1),
352                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
353        ix += 1
354        sizer_low_q.Add(self.npts_low_ctl, (iy, ix), (1,1),
355                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
356        iy += 1
357        ix = 0
358        sizer_low_q.Add(self.enable_low_cbox,(iy, ix),(1,1),
359                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
360        sizer_high_q = wx.GridBagSizer(5,5)
361        self.power_law_high = wx.RadioButton(self, -1, 'Power_law',
362                                              (10, 10), style=wx.RB_GROUP)
363        msg_hint ="Check it to extrapolate data to high Q"
364        self.power_law_high.SetToolTipString(msg_hint)
365       
366        #MAC needs SetValue
367        self.power_law_high.SetValue(True)
368        npts_high_txt = wx.StaticText(self, -1, 'Npts')
369        self.npts_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1))
370        msg_hint = "the number of last q points to consider"
371        msg_hint += "during the fit for extrapolation high Q"
372        self.npts_high_ctl.SetToolTipString(msg_hint)
373        self.npts_high_ctl.SetValue(str(NPTS))
374        self.power_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1))
375        self.power_high_ctl.SetValue(str(self.power_law_exponant))
376        self.power_high_ctl.SetToolTipString(power_hint_txt)
377       
378        iy = 1
379        ix = 0
380        sizer_high_q.Add(self.power_law_high,(iy, ix),(1,1),
381                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
382        ix += 1
383        sizer_high_q.Add(self.power_high_ctl, (iy, ix), (1,1),
384                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
385        iy += 1
386        ix = 0
387        sizer_high_q.Add(npts_high_txt,(iy, ix),(1,1),
388                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
389        ix += 1
390        sizer_high_q.Add(self.npts_high_ctl, (iy, ix), (1,1),
391                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
392        iy += 1
393        ix = 0
394        sizer_high_q.Add(self.enable_high_cbox,(iy, ix),(1,1),
395                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
396       
397        high_q_box = wx.StaticBox(self, -1, "High Q")
398        boxsizer_high_q = wx.StaticBoxSizer(high_q_box, wx.VERTICAL)
399        boxsizer_high_q.Add(sizer_high_q)
400       
401        low_q_box = wx.StaticBox(self, -1, "Low Q")
402        boxsizer_low_q = wx.StaticBoxSizer(low_q_box, wx.VERTICAL)
403        boxsizer_low_q.Add(sizer_low_q)
404       
405        #-------------Enable extrapolation-------
406        extra_hint = "Extrapolation Maximum Range: "
407        extra_hint_txt= wx.StaticText(self, -1,extra_hint )
408        extra_range = "[%s - %s]"%(str(Q_MINIMUM), str(Q_MAXIMUM))
409        extra_range_value_txt = wx.StaticText(self, -1, str(extra_range))
410        extra_enable_hint = "Hint: Check any box to enable a specific extrapolation !"
411        extra_enable_hint_txt= wx.StaticText(self, -1, extra_enable_hint )
412       
413        enable_sizer = wx.GridBagSizer(5,5)
414       
415        iy = 0
416        ix = 0
417        enable_sizer.Add(extra_hint_txt,(iy, ix),(1,1),
418                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
419        ix += 1
420        enable_sizer.Add(extra_range_value_txt, (iy, ix), (1,1),
421                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
422        ix = 0
423        iy += 1
424        enable_sizer.Add(extra_enable_hint_txt,(iy, ix),(1,1),
425                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
426       
427        type_extrapolation_sizer = wx.BoxSizer(wx.HORIZONTAL)
428        type_extrapolation_sizer.Add((10,10))
429        type_extrapolation_sizer.Add(boxsizer_low_q, 0, wx.ALL, 10)
430        type_extrapolation_sizer.Add((20,20))
431        type_extrapolation_sizer.Add(boxsizer_high_q, 0, wx.ALL, 10)
432        type_extrapolation_sizer.Add((10,10))
433       
434        extrapolation_box = wx.StaticBox(self, -1, "Extrapolation")
435        boxsizer_extra = wx.StaticBoxSizer(extrapolation_box, wx.VERTICAL)
436        boxsizer_extra.Add(enable_sizer, 0, wx.ALL, 10)
437        boxsizer_extra.Add(type_extrapolation_sizer)
438   
439        inputbox = wx.StaticBox(self, -1, "Input")
440        boxsizer1 = wx.StaticBoxSizer(inputbox, wx.VERTICAL)
441        boxsizer1.SetMinSize((_STATICBOX_WIDTH,-1))
442        boxsizer1.Add(sizer_input)
443        boxsizer1.Add(boxsizer_extra, 0, wx.ALL, 10)
444        sizer1.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10)
445       
446        #---------Outputs sizer--------
447        invariant_txt = wx.StaticText(self, -1, 'Invariant')
448        self.invariant_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
449        self.invariant_ctl.SetEditable(False)
450        self.invariant_ctl.SetToolTipString("Invariant in q range.")
451        self.invariant_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
452        self.invariant_err_ctl.SetEditable(False)
453        self.invariant_err_ctl.SetToolTipString("Uncertainty on invariant.")
454        invariant_units_txt = wx.StaticText(self, -1, unit_invariant)
455       
456        invariant_total_txt = wx.StaticText(self, -1, 'Invariant Total')
457        self.invariant_total_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
458        self.invariant_total_ctl.SetEditable(False)
459        msg_hint = "Invariant in q range and extra polated range."
460        self.invariant_total_ctl.SetToolTipString(msg_hint)
461        self.invariant_total_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
462        self.invariant_total_err_ctl.SetEditable(False)
463        self.invariant_total_err_ctl.SetToolTipString("Uncertainty on invariant.")
464        invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant)
465       
466        volume_txt = wx.StaticText(self, -1, 'Volume Fraction')
467        self.volume_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
468        self.volume_ctl.SetEditable(False)
469        self.volume_ctl.SetToolTipString("volume fraction.")
470        self.volume_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
471        self.volume_err_ctl.SetEditable(False)
472        self.volume_err_ctl.SetToolTipString("Uncertainty of volume fraction.")
473        volume_units_txt = wx.StaticText(self, -1, unit_volume)
474       
475        surface_txt = wx.StaticText(self, -1, 'Surface')
476        self.surface_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
477        self.surface_ctl.SetEditable(False)
478        self.surface_ctl.SetToolTipString("Surface.")
479        self.surface_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
480        self.surface_err_ctl.SetEditable(False)
481        self.surface_err_ctl.SetToolTipString("Uncertainty of surface.")
482        surface_units_txt = wx.StaticText(self, -1, unit_surface)
483       
484        invariant_low_txt = wx.StaticText(self, -1, 'Invariant in low Q')
485        self.invariant_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
486        self.invariant_low_ctl.SetEditable(False)
487        self.invariant_low_ctl.SetToolTipString("Invariant compute in low Q")
488        invariant_low_units_txt = wx.StaticText(self, -1,  unit_invariant)
489       
490        invariant_high_txt = wx.StaticText(self, -1, 'Invariant in high Q')
491        self.invariant_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
492        self.invariant_high_ctl.SetEditable(False)
493        self.invariant_high_ctl.SetToolTipString("Invariant compute in high Q")
494        invariant_high_units_txt = wx.StaticText(self, -1,  unit_invariant)
495       
496        iy = 0
497        ix = 0
498        sizer_output.Add(invariant_low_txt, (iy, ix), (1,1),
499                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
500        ix +=1
501        sizer_output.Add(self.invariant_low_ctl, (iy, ix), (1,1),
502                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
503        ix += 2
504        sizer_output.Add(invariant_low_units_txt, (iy, ix), (1,1),
505                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
506        iy += 1
507        ix = 0 
508        sizer_output.Add(invariant_high_txt, (iy, ix), (1,1),
509                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
510        ix +=1
511        sizer_output.Add(self.invariant_high_ctl, (iy, ix), (1,1),
512                            wx.EXPAND|wx.ADJUST_MINSIZE, )
513        ix += 2
514        sizer_output.Add(invariant_high_units_txt, (iy, ix), (1,1),
515                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
516        iy += 1
517        ix = 0
518        sizer_output.Add(invariant_txt,(iy, ix),(1,1),
519                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
520        ix += 1
521        sizer_output.Add(self.invariant_ctl,(iy, ix),(1,1),
522                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
523        ix += 1
524        sizer_output.Add( wx.StaticText(self, -1, uncertainty),
525                         (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
526        ix +=1
527        sizer_output.Add(self.invariant_err_ctl
528                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
529        ix +=1
530        sizer_output.Add(invariant_units_txt
531                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
532        iy += 1
533        ix = 0
534        sizer_output.Add(invariant_total_txt,(iy, ix),(1,1),
535                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
536        ix += 1
537        sizer_output.Add(self.invariant_total_ctl,(iy, ix),(1,1),
538                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
539        ix += 1
540        sizer_output.Add( wx.StaticText(self, -1, uncertainty),
541                         (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
542        ix +=1
543        sizer_output.Add(self.invariant_total_err_ctl
544                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
545        ix +=1
546        sizer_output.Add(invariant_total_units_txt,(iy, ix),
547                        (1,1),wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
548        iy += 1
549        ix = 0
550        sizer_output.Add(volume_txt,(iy, ix),(1,1),
551                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
552        ix +=1
553        sizer_output.Add(self.volume_ctl,(iy, ix),(1,1),
554                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
555        ix +=1
556        sizer_output.Add(wx.StaticText(self, -1, uncertainty)
557                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)
558        ix += 1
559        sizer_output.Add(self.volume_err_ctl
560                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
561        ix += 1
562        sizer_output.Add(volume_units_txt
563                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
564        iy += 1
565        ix = 0
566        sizer_output.Add(surface_txt,(iy, ix),(1,1),
567                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
568        ix +=1
569        sizer_output.Add(self.surface_ctl,(iy, ix),(1,1),
570                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
571        ix +=1
572        sizer_output.Add(wx.StaticText(self, -1, uncertainty)
573                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)
574        ix += 1
575        sizer_output.Add(self.surface_err_ctl
576                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
577        ix +=1
578        sizer_output.Add(surface_units_txt
579                         ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)
580       
581        outputbox = wx.StaticBox(self, -1, "Output")
582        boxsizer2 = wx.StaticBoxSizer(outputbox, wx.VERTICAL)
583        boxsizer2.SetMinSize((_STATICBOX_WIDTH,-1))
584        boxsizer2.Add( sizer_output )
585        sizer2.Add(boxsizer2,0, wx.EXPAND|wx.ALL, 10)
586        #-----Button  sizer------------
587        id = wx.NewId()
588        button_calculate = wx.Button(self, id, "Compute")
589        button_calculate.SetToolTipString("Compute SlD of neutrons.")
590        self.Bind(wx.EVT_BUTTON, self.compute_invariant, id = id)   
591       
592        sizer_button.Add((250, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
593        sizer_button.Add(button_calculate, 0, wx.RIGHT|wx.ADJUST_MINSIZE,20)
594        sizer3.Add(sizer_button)
595        #---------layout----------------
596        vbox  = wx.BoxSizer(wx.VERTICAL)
597        vbox.Add(sizer1)
598        vbox.Add(sizer2)
599        vbox.Add(sizer3)
600        vbox.Fit(self) 
601        self.SetSizer(vbox)
602   
603class InvariantDialog(wx.Dialog):
604    def __init__(self, parent=None, id=1,graph=None,
605                 data=None, title="Invariant",base=None):
606        wx.Dialog.__init__(self, parent, id, title, size=(PANEL_WIDTH,
607                                                             PANEL_HEIGHT))
608        self.panel = InvariantPanel(self)
609        self.Centre()
610        self.Show(True)
611       
612class InvariantWindow(wx.Frame):
613    def __init__(self, parent=None, id=1,graph=None, 
614                 data=None, title="Invariant",base=None):
615       
616        wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH,
617                                                             PANEL_HEIGHT))
618       
619        self.panel = InvariantPanel(self)
620        self.Centre()
621        self.Show(True)
622       
623class MyApp(wx.App):
624    def OnInit(self):
625        wx.InitAllImageHandlers()
626        frame = InvariantWindow()
627        frame.Show(True)
628        self.SetTopWindow(frame)
629       
630        return True
631     
632# end of class MyApp
633
634if __name__ == "__main__":
635    app = MyApp(0)
636    app.MainLoop()
Note: See TracBrowser for help on using the repository browser.