source: sasview/src/sas/sasgui/perspectives/calculator/sld_panel.py @ bd8411d5

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.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since bd8411d5 was bd8411d5, checked in by Tim Snow <tim.snow@…>, 7 years ago

Implementation finished

Code the underpins the GUI created yesterday is now finished to give a
richer x-ray SLD calculator for users.

  • Property mode set to 100644
File size: 22.4 KB
Line 
1"""
2This module provide GUI for the neutron scattering length density calculator
3
4"""
5
6import wx
7import math
8import sys
9
10from sas.sasgui.guiframe.panel_base import PanelBase
11
12from sas.sasgui.guiframe.utils import format_number
13from sas.sasgui.guiframe.utils import check_float
14from sas.sasgui.guiframe.events import StatusEvent
15
16# the calculator default value for wavelength is 6
17#import periodictable
18from periodictable import formula
19from periodictable.xsf import xray_energy
20from periodictable.xsf import xray_sld_from_atoms
21from periodictable.nsf import neutron_scattering
22from sas.sasgui.perspectives.calculator import calculator_widgets as widget
23from sas.sasgui.guiframe.documentation_window import DocumentationWindow
24
25WAVELENGTH = 6.0
26_BOX_WIDTH = 76
27_STATICBOX_WIDTH = 350
28_SCALE = 1e-6
29
30#SLD panel size
31if sys.platform.count("win32") > 0:
32    PANEL_TOP = 0
33    _STATICBOX_WIDTH = 350
34    PANEL_SIZE = 400
35    FONT_VARIANT = 0
36else:
37    PANEL_TOP = 60
38    _STATICBOX_WIDTH = 380
39    PANEL_SIZE = 410
40    FONT_VARIANT = 1
41
42class SldPanel(wx.Panel, PanelBase):
43    """
44    Provides the SLD calculator GUI.
45    """
46    ## Internal nickname for the window, used by the AUI manager
47    window_name = "SLD Calculator"
48    ## Name to appear on the window title bar
49    window_caption = "SLD Calculator"
50    ## Flag to tell the AUI manager to put this panel in the center pane
51    CENTER_PANE = True
52
53    def __init__(self, parent, base=None, *args, **kwds):
54        """
55        """
56        wx.Panel.__init__(self, parent, *args, **kwds)
57        PanelBase.__init__(self)
58        #Font size
59        self.SetWindowVariant(variant=FONT_VARIANT)
60        # Object that receive status event
61        self.base = base
62        self.neutron_wavelength = WAVELENGTH
63        self.xray_source_input = WAVELENGTH
64        self.parent = parent
65        #layout attribute
66        self.compound_ctl = None
67        self.density_ctl = None
68        self.compound = ""
69        self.density = ""
70        self.neutron_wavelength_ctl = None
71        self.xray_source_input_ctl = None
72        self.xray_cbox = None
73        self.neutron_sld_real_ctl = None
74        self.neutron_sld_im_ctl = None
75        self.xray_sld_real_ctl = None
76        self.xray_sld_im_ctl = None
77        self.neutron_abs_ctl = None
78        self.neutron_inc_ctl = None
79        self.neutron_length_ctl = None
80        self.button_calculate = None
81        self.xray_source = None
82        #Draw the panel
83        self._do_layout()
84        self.SetAutoLayout(True)
85        self.Layout()
86        self.fill_xray_cbox()
87
88    def _do_layout(self):
89        """
90        Draw window content
91        """
92        unit_a = '[A]'
93        unit_density = '[g/cm^(3)]'
94        unit_sld = '[1/A^(2)]'
95        unit_cm1 = '[1/cm]'
96        unit_cm = '[cm]'
97        sizer_input = wx.GridBagSizer(5, 5)
98        sizer_output = wx.GridBagSizer(5, 5)
99        sizer_button = wx.BoxSizer(wx.HORIZONTAL)
100        sizer1 = wx.BoxSizer(wx.HORIZONTAL)
101        sizer2 = wx.BoxSizer(wx.HORIZONTAL)
102        sizer3 = wx.BoxSizer(wx.HORIZONTAL)
103        #---------inputs----------------
104        inputbox = wx.StaticBox(self, -1, "Input")
105        boxsizer1 = wx.StaticBoxSizer(inputbox, wx.VERTICAL)
106        boxsizer1.SetMinSize((_STATICBOX_WIDTH, -1))
107
108        compound_txt = wx.StaticText(self, -1, 'Compound ')
109        self.compound_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH * 2, -1))
110        density_txt = wx.StaticText(self, -1, 'Density ')
111        self.density_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1))
112        unit_density_txt = wx.StaticText(self, -1, unit_density)
113        neutron_wavelength_txt = wx.StaticText(self, -1, 'Neutron wavelength')
114        self.neutron_wavelength_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1))
115        self.neutron_wavelength_ctl.SetValue(str(self.neutron_wavelength))
116        xray_source_input_txt = wx.StaticText(self, -1, 'X-ray wavelength')
117        self.xray_source_input_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1))
118        self.xray_source_input_ctl.SetValue(str(self.xray_source_input))
119        neutron_unit_a_txt = wx.StaticText(self, -1, unit_a)
120
121        self.xray_cbox = wx.ComboBox(self, -1, size=(70, 20), style=wx.CB_READONLY)
122        xray_cbox_tip = "Select an element, wavelength or energy"
123        self.xray_cbox.SetToolTipString(xray_cbox_tip)
124        wx.EVT_COMBOBOX(self.xray_cbox, -1, self.on_select_xray)
125
126        iy = 0
127        ix = 0
128        sizer_input.Add(compound_txt, (iy, ix), (1, 1),
129                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
130        ix += 1
131        sizer_input.Add(self.compound_ctl, (iy, ix), (1, 1),
132                            wx.EXPAND | wx.ADJUST_MINSIZE, 0)
133        iy += 1
134        ix = 0
135        sizer_input.Add(density_txt, (iy, ix), (1, 1),
136                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
137        ix += 1
138        sizer_input.Add(self.density_ctl, (iy, ix), (1, 1),
139                            wx.EXPAND | wx.ADJUST_MINSIZE, 0)
140        ix += 1
141        sizer_input.Add(unit_density_txt, (iy, ix), (1, 1),
142                            wx.EXPAND | wx.ADJUST_MINSIZE, 0)
143        iy += 1
144        ix = 0
145        sizer_input.Add(neutron_wavelength_txt, (iy, ix), (1, 1),
146                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
147        ix += 1
148        sizer_input.Add(self.neutron_wavelength_ctl, (iy, ix), (1, 1),
149                            wx.EXPAND | wx.ADJUST_MINSIZE, 0)
150        ix += 1
151        sizer_input.Add(neutron_unit_a_txt, (iy, ix), (1, 1),
152                            wx.EXPAND | wx.ADJUST_MINSIZE, 0)
153        iy += 1
154        ix = 0
155        sizer_input.Add(xray_source_input_txt, (iy, ix), (1, 1),
156                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
157        ix += 1
158        sizer_input.Add(self.xray_source_input_ctl, (iy, ix), (1, 1),
159                            wx.EXPAND | wx.ADJUST_MINSIZE, 0)
160        ix += 1
161        sizer_input.Add(self.xray_cbox, (iy, ix), (1, 1),
162                            wx.EXPAND | wx.ADJUST_MINSIZE, 0)
163        boxsizer1.Add(sizer_input)
164        sizer1.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10)
165        #---------Outputs sizer--------
166        outputbox = wx.StaticBox(self, -1, "Output")
167        boxsizer2 = wx.StaticBoxSizer(outputbox, wx.VERTICAL)
168        boxsizer2.SetMinSize((_STATICBOX_WIDTH, -1))
169
170        i_complex = '- i'
171        neutron_sld_txt = wx.StaticText(self, -1, 'Neutron SLD')
172        self.neutron_sld_real_ctl = wx.TextCtrl(self, -1,
173                                                 size=(_BOX_WIDTH, -1))
174        self.neutron_sld_real_ctl.SetEditable(False)
175        self.neutron_sld_real_ctl.SetToolTipString("Neutron SLD real")
176        self.neutron_sld_im_ctl = wx.TextCtrl(self, -1,
177                                              size=(_BOX_WIDTH, -1))
178        self.neutron_sld_im_ctl.SetEditable(False)
179        self.neutron_sld_im_ctl.SetToolTipString("Neutron SLD imaginary")
180        neutron_sld_units_txt = wx.StaticText(self, -1, unit_sld)
181
182        xray_sld_txt = wx.StaticText(self, -1, 'X-ray SLD')
183        self.xray_sld_real_ctl = wx.TextCtrl(self, -1,
184                                               size=(_BOX_WIDTH, -1))
185        self.xray_sld_real_ctl.SetEditable(False)
186        self.xray_sld_real_ctl.SetToolTipString("X-ray SLD real")
187        self.xray_sld_im_ctl = wx.TextCtrl(self, -1,
188                                            size=(_BOX_WIDTH, -1))
189        self.xray_sld_im_ctl.SetEditable(False)
190        self.xray_sld_im_ctl.SetToolTipString("X-ray SLD imaginary")
191        xray_sld_units_txt = wx.StaticText(self, -1, unit_sld)
192
193        neutron_inc_txt = wx.StaticText(self, -1, 'Neutron Inc. Xs')
194        self.neutron_inc_ctl = wx.TextCtrl(self, -1,
195                                            size=(_BOX_WIDTH, -1))
196        self.neutron_inc_ctl.SetEditable(False)
197        self.neutron_inc_ctl.SetToolTipString("Neutron Inc. Xs")
198        neutron_inc_units_txt = wx.StaticText(self, -1, unit_cm1)
199
200        neutron_abs_txt = wx.StaticText(self, -1, 'Neutron Abs. Xs')
201        self.neutron_abs_ctl = wx.TextCtrl(self, -1,
202                                           size=(_BOX_WIDTH, -1))
203        self.neutron_abs_ctl.SetEditable(False)
204        self.neutron_abs_ctl.SetToolTipString("Neutron Abs. Xs")
205        neutron_abs_units_txt = wx.StaticText(self, -1, unit_cm1)
206
207        neutron_length_txt = wx.StaticText(self, -1, 'Neutron 1/e length')
208        self.neutron_length_ctl = wx.TextCtrl(self, -1,
209                                               size=(_BOX_WIDTH, -1))
210        self.neutron_length_ctl.SetEditable(False)
211        self.neutron_length_ctl.SetToolTipString("Neutron 1/e length")
212        neutron_length_units_txt = wx.StaticText(self, -1, unit_cm)
213
214        iy = 0
215        ix = 0
216        sizer_output.Add(neutron_sld_txt, (iy, ix), (1, 1),
217                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
218        ix += 1
219        sizer_output.Add(self.neutron_sld_real_ctl, (iy, ix), (1, 1),
220                            wx.EXPAND | wx.ADJUST_MINSIZE, 0)
221        ix += 1
222        sizer_output.Add(wx.StaticText(self, -1, i_complex),
223                         (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0)
224        ix += 1
225        sizer_output.Add(self.neutron_sld_im_ctl,
226                         (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0)
227        ix += 1
228        sizer_output.Add(neutron_sld_units_txt,
229                         (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0)
230        iy += 1
231        ix = 0
232        sizer_output.Add(xray_sld_txt, (iy, ix), (1, 1),
233                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
234        ix += 1
235        sizer_output.Add(self.xray_sld_real_ctl, (iy, ix), (1, 1),
236                            wx.EXPAND | wx.ADJUST_MINSIZE, 0)
237        ix += 1
238        sizer_output.Add(wx.StaticText(self, -1, i_complex),
239                         (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0)
240        ix += 1
241        sizer_output.Add(self.xray_sld_im_ctl,
242                         (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0)
243        ix += 1
244        sizer_output.Add(xray_sld_units_txt,
245                         (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0)
246        iy += 1
247        ix = 0
248        sizer_output.Add(neutron_inc_txt, (iy, ix), (1, 1),
249                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
250        ix += 1
251        sizer_output.Add(self.neutron_inc_ctl, (iy, ix), (1, 1),
252                            wx.EXPAND | wx.ADJUST_MINSIZE, 0)
253        ix += 2
254        sizer_output.Add(neutron_inc_units_txt, (iy, ix), (1, 1),
255                            wx.EXPAND | wx.ADJUST_MINSIZE, 0)
256        iy += 1
257        ix = 0
258        sizer_output.Add(neutron_abs_txt, (iy, ix), (1, 1),
259                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
260        ix += 1
261        sizer_output.Add(self.neutron_abs_ctl, (iy, ix), (1, 1),
262                            wx.EXPAND | wx.ADJUST_MINSIZE, 0)
263        ix += 2
264        sizer_output.Add(neutron_abs_units_txt, (iy, ix), (1, 1),
265                            wx.EXPAND | wx.ADJUST_MINSIZE, 0)
266        iy += 1
267        ix = 0
268        sizer_output.Add(neutron_length_txt, (iy, ix), (1, 1),
269                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
270        ix += 1
271        sizer_output.Add(self.neutron_length_ctl, (iy, ix), (1, 1),
272                            wx.EXPAND | wx.ADJUST_MINSIZE, 0)
273        ix += 2
274        sizer_output.Add(neutron_length_units_txt, (iy, ix), (1, 1),
275                            wx.EXPAND | wx.ADJUST_MINSIZE, 0)
276        boxsizer2.Add(sizer_output)
277        sizer2.Add(boxsizer2, 0, wx.EXPAND | wx.ALL, 10)
278        #-----Button  sizer------------
279
280        id = wx.NewId()
281        self.button_calculate = wx.Button(self, id, "Calculate")
282        self.button_calculate.SetToolTipString("Calculate SLD.")
283        self.Bind(wx.EVT_BUTTON, self.calculateSld, id=id)
284
285        id = wx.NewId()
286        self.button_help = wx.Button(self, id, "HELP")
287        self.button_help.SetToolTipString("help on SLD calculator.")
288        self.Bind(wx.EVT_BUTTON, self.on_help, id=id)
289
290        self.button_close = wx.Button(self, wx.ID_CANCEL, 'Close')
291        self.button_close.Bind(wx.EVT_BUTTON, self.on_close)
292        self.button_close.SetToolTipString("Close this window.")
293
294        sizer_button.Add((150, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
295        sizer_button.Add(self.button_calculate, 0, wx.RIGHT | wx.ADJUST_MINSIZE, 20)
296        sizer_button.Add(self.button_help, 0, wx.RIGHT | wx.ADJUST_MINSIZE, 20)
297        sizer_button.Add(self.button_close, 0, wx.RIGHT | wx.ADJUST_MINSIZE, 20)
298        sizer3.Add(sizer_button)
299        #---------layout----------------
300        vbox = wx.BoxSizer(wx.VERTICAL)
301        vbox.Add(sizer1)
302        vbox.Add(sizer2)
303        vbox.Add(sizer3)
304        vbox.Fit(self)
305        self.SetSizer(vbox)
306
307    def fill_xray_cbox(self):
308        """
309        fill the x-ray combobox with the sources
310        """
311        source_list = ['[A]', '[keV]', 'Element']
312        for source in source_list:
313            pos = self.xray_cbox.Append(str(source))
314            self.xray_cbox.SetClientData(pos, str(source.strip()))
315        self.xray_cbox.SetSelection(0)
316        self.xray_source = source_list[0]
317
318    def on_select_xray(self, event=None):
319        """
320        On Selecting a source
321        """
322        item = event.GetEventObject()
323        self.xray_source = item.GetValue().strip()
324
325    def on_help(self, event):
326        """
327        Bring up the SLD Documentation whenever
328        the HELP button is clicked.
329
330        Calls DocumentationWindow with the path of the location within the
331        documentation tree (after /doc/ ....".  Note that when using old
332        versions of Wx (before 2.9) and thus not the release version of
333        installers, the help comes up at the top level of the file as
334        webbrowser does not pass anything past the # to the browser when it is
335        running "file:///...."
336
337    :param evt: Triggers on clicking the help button
338    """
339
340        _TreeLocation = "user/sasgui/perspectives/calculator/"
341        _TreeLocation += "sld_calculator_help.html"
342        _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "",
343                                          "General Scattering Calculator Help")
344
345    def on_close(self, event):
346        """
347        close the window containing this panel
348        """
349        self.parent.Close()
350
351    def calculate_xray_sld(self, element):
352        """
353        Get an element and compute the corresponding SLD for a given formula
354
355        :param element:  elements a string of existing atom
356
357        """
358        myformula = formula(str(element))
359        if len(myformula.atoms) != 1:
360            return
361        element = myformula.atoms.keys()[0]
362        energy = xray_energy(element.K_alpha)
363
364        self.sld_formula = formula(str(self.compound), density=self.density)
365        atom = self.sld_formula.atoms
366        return xray_sld_from_atoms(atom, density=self.density, energy=energy)
367
368    def check_inputs(self):
369        """Check validity user inputs"""
370        flag = True
371        msg = ""
372        if check_float(self.density_ctl):
373            self.density = float(self.density_ctl.GetValue())
374        else:
375            flag = False
376            msg += "Error for Density value :expect float"
377
378        self.neutron_wavelength = self.neutron_wavelength_ctl.GetValue()
379        self.xray_source_input = self.xray_source_input_ctl.GetValue()
380
381        if str(self.neutron_wavelength).lstrip().rstrip() == "":
382            self.neutron_wavelength = WAVELENGTH
383            self.neutron_wavelength_ctl.SetValue(str(WAVELENGTH))
384            self.neutron_wavelength_ctl.SetBackgroundColour(wx.WHITE)
385            self.neutron_wavelength_ctl.Refresh()
386            msg += "Default value for wavelength is 6.0"
387        else:
388            if check_float(self.neutron_wavelength_ctl):
389                self.neutron_wavelength = float(self.neutron_wavelength)
390            else:
391                flag = False
392                msg += "Error for wavelength value :expect float"
393
394        if str(self.xray_source_input).lstrip().rstrip() == "":
395            self.xray_source_input = WAVELENGTH
396            self.xray_source_input_ctl.SetValue(str(WAVELENGTH))
397            self.xray_source_input_ctl.SetBackgroundColour(wx.WHITE)
398            self.xray_source_input_ctl.Refresh()
399            msg += "Default value for wavelength is 6.0"
400        else:
401            if (self.xray_source == '[A]') or (self.xray_source == '[keV]'):
402                if check_float(self.xray_source_input_ctl):
403                    self.xray_source_input = float(self.xray_source_input)
404                else:
405                    flag = False
406                    msg += "Error for wavelength value :expect float"
407            elif (self.xray_source == 'Element'):
408                try:
409                    import periodictable
410                    exec("periodictable." + self.xray_source_input)
411                except AttributeError:
412                    flag = False
413                    msg += "X-ray element supplied isn't in the database"
414
415
416
417        self.compound = self.compound_ctl.GetValue().lstrip().rstrip()
418        if self.compound != "":
419            try :
420                formula(self.compound)
421                self.compound_ctl.SetBackgroundColour(wx.WHITE)
422                self.compound_ctl.Refresh()
423            except:
424                self.compound_ctl.SetBackgroundColour("pink")
425                self.compound_ctl.Refresh()
426                flag = False
427                msg += "Enter correct formula"
428        else:
429            self.compound_ctl.SetBackgroundColour("pink")
430            self.compound_ctl.Refresh()
431            flag = False
432            msg += "Enter a formula"
433        return flag, msg
434
435    def calculate_sld_helper(self, element, density, molecule_formula):
436        """
437        Get an element and compute the corresponding SLD for a given formula
438
439        :param element:  elements a string of existing atom
440
441        """
442        element_formula = formula(str(element))
443        if len(element_formula.atoms) != 1:
444            return
445        element = element_formula.atoms.keys()[0]
446        energy = xray_energy(element.K_alpha)
447        atom = molecule_formula.atoms
448        return xray_sld_from_atoms(atom, density=density, energy=energy)
449
450    def calculateSld(self, event):
451        """
452            Calculate the neutron scattering density length of a molecule
453        """
454        self.clear_outputs()
455        try:
456            #Check validity user inputs
457            flag, msg = self.check_inputs()
458            if self.base is not None and msg.lstrip().rstrip() != "":
459                msg = "SLD Calculator: %s" % str(msg)
460                wx.PostEvent(self.base, StatusEvent(status=msg))
461            if not flag:
462               return
463            #get ready to compute
464            self.sld_formula = formula(self.compound,
465                                            density=self.density)
466            (sld_real, sld_im, _), (_, absorp, incoh), \
467                        length = neutron_scattering(compound=self.compound,
468                                   density=self.density,
469                                   wavelength=self.neutron_wavelength)
470            if self.xray_source == "[A]":
471                energy = xray_energy(self.xray_source_input)
472                xray_real, xray_im = xray_sld_from_atoms(self.sld_formula.atoms,
473                                                         density=self.density,
474                                                         energy=energy)
475            elif self.xray_source == "[keV]":
476                xray_real, xray_im = xray_sld_from_atoms(self.sld_formula.atoms,
477                                                         density=self.density,
478                                                         energy=self.xray_source_input)
479            elif self.xray_source == "Element":
480                xray_real, xray_im = self.calculate_sld_helper(element=self.xray_source_input,
481                                                               density=self.density,
482                                                               molecule_formula=self.sld_formula)
483            # set neutron sld values
484            val = format_number(sld_real * _SCALE)
485            self.neutron_sld_real_ctl.SetValue(val)
486            val = format_number(math.fabs(sld_im) * _SCALE)
487            self.neutron_sld_im_ctl.SetValue(val)
488            # Compute the Cu SLD
489            self.xray_sld_real_ctl.SetValue(format_number(xray_real * _SCALE))
490            val = format_number(math.fabs(xray_im) * _SCALE)
491            self.xray_sld_im_ctl.SetValue(val)
492            # set incoherence and absorption
493            self.neutron_inc_ctl.SetValue(format_number(incoh))
494            self.neutron_abs_ctl.SetValue(format_number(absorp))
495            # Neutron length
496            self.neutron_length_ctl.SetValue(format_number(length))
497            # display wavelength
498            #self.wavelength_ctl.SetValue(str(self.wavelength))
499            #self.wavelength_ctl.SetValue(str(self.wavelength))
500        except:
501            if self.base is not None:
502                msg = "SLD Calculator: %s" % (sys.exc_value)
503                wx.PostEvent(self.base, StatusEvent(status=msg))
504        if event is not None:
505            event.Skip()
506
507    def clear_outputs(self):
508        """
509        Clear the outputs textctrl
510        """
511        self.neutron_sld_real_ctl.SetValue("")
512        self.neutron_sld_im_ctl.SetValue("")
513        self.xray_sld_real_ctl.SetValue("")
514        self.xray_sld_im_ctl.SetValue("")
515        self.neutron_abs_ctl.SetValue("")
516        self.neutron_inc_ctl.SetValue("")
517        self.neutron_length_ctl.SetValue("")
518
519
520class SldWindow(widget.CHILD_FRAME):
521    """
522    """
523    def __init__(self, parent=None, title="SLD Calculator",
524                  base=None, manager=None,
525                  size=(PANEL_SIZE, PANEL_SIZE), *args, **kwds):
526        """
527        """
528        kwds['title'] = title
529        kwds['size'] = size
530        widget.CHILD_FRAME.__init__(self, parent, *args, **kwds)
531        """
532        """
533        self.parent = parent
534        self.base = base
535        self.manager = manager
536        self.panel = SldPanel(self, base=base)
537        self.Bind(wx.EVT_CLOSE, self.on_close)
538        self.SetPosition((wx.LEFT, PANEL_TOP))
539        self.Show(True)
540
541    def on_close(self, event):
542        """
543        On close event
544        """
545        if self.manager != None:
546            self.manager.sld_frame = None
547        self.Destroy()
548
549
550class ViewApp(wx.App):
551    """
552    """
553    def OnInit(self):
554        """
555        """
556        widget.CHILD_FRAME = wx.Frame
557        frame = SldWindow(None, title='SLD Calculator')
558        frame.Show(True)
559        self.SetTopWindow(frame)
560        return True
561
562
563if __name__ == "__main__":
564    app = ViewApp(0)
565    app.MainLoop()
Note: See TracBrowser for help on using the repository browser.