source: sasview/src/sas/perspectives/calculator/kiessig_calculator_panel.py @ 98f6916

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 98f6916 was b9a5f0e, checked in by krzywon, 10 years ago

90% complete with the conversion.

  • Property mode set to 100644
File size: 8.3 KB
Line 
1"""
2This software was developed by the University of Tennessee as part of the
3Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
4project funded by the US National Science Foundation.
5
6See the license text in license.txt
7
8copyright 2008, 2009, University of Tennessee
9"""
10
11import wx
12import sys
13
14from sas.guiframe.panel_base import PanelBase
15from sas.calculator.kiessig_calculator import KiessigThicknessCalculator
16from calculator_widgets import OutputTextCtrl
17from calculator_widgets import InputTextCtrl
18from sas.perspectives.calculator import calculator_widgets as widget   
19
20_BOX_WIDTH = 77
21#Slit length panel size
22if sys.platform.count("win32") > 0:
23    PANEL_WIDTH = 500
24    PANEL_HEIGHT = 210
25    FONT_VARIANT = 0
26else:
27    PANEL_WIDTH = 560
28    PANEL_HEIGHT = 230
29    FONT_VARIANT = 1
30 
31class KiessigThicknessCalculatorPanel(wx.Panel, PanelBase):
32    """
33    Provides the Kiessig thickness calculator GUI.
34    """
35    ## Internal nickname for the window, used by the AUI manager
36    window_name = "Kiessig Thickness Calculator"
37    ## Name to appear on the window title bar
38    window_caption = "Kiessig Thickness Calculator"
39    ## Flag to tell the AUI manager to put this panel in the center pane
40    CENTER_PANE = True
41   
42    def __init__(self, parent, *args, **kwds):
43        wx.Panel.__init__(self, parent, *args, **kwds)
44        PanelBase.__init__(self)
45        #Font size
46        self.SetWindowVariant(variant=FONT_VARIANT) 
47        # Object that receive status event
48        self.parent = parent
49        self.kiessig = KiessigThicknessCalculator()
50        #layout attribute
51        self.hint_sizer = None
52        self._do_layout()
53       
54    def _define_structure(self):
55        """
56        Define the main sizers building to build this application.
57        """
58        self.main_sizer = wx.BoxSizer(wx.VERTICAL)
59        self.box_source = wx.StaticBox(self, -1,
60                                str("Kiessig Thickness Calculator"))
61        self.boxsizer_source = wx.StaticBoxSizer(self.box_source,
62                                                    wx.VERTICAL)
63        self.dq_name_sizer = wx.BoxSizer(wx.HORIZONTAL)
64        self.thickness_size_sizer = wx.BoxSizer(wx.HORIZONTAL)
65        self.hint_sizer = wx.BoxSizer(wx.HORIZONTAL)
66        self.button_sizer = wx.BoxSizer(wx.HORIZONTAL)
67       
68    def _layout_dq_name(self):
69        """
70        Fill the sizer containing dq name
71        """
72        # get the default dq
73        dq_value = str(self.kiessig.get_deltaq())
74        dq_unit_txt = wx.StaticText(self, -1, '[1/A]')
75        dq_name_txt = wx.StaticText(self, -1, 
76                                'Kiessig Fringe Width (Delta Q): ')
77        self.dq_name_tcl = InputTextCtrl(self, -1, 
78                                         size=(_BOX_WIDTH,-1))
79        dq_hint = "Type the Kiessig Fringe Width (Delta Q)"
80        self.dq_name_tcl.SetValue(dq_value)
81        self.dq_name_tcl.SetToolTipString(dq_hint)
82        #control that triggers importing data
83        id = wx.NewId()
84        self.compute_button = wx.Button(self, id, "Compute")
85        hint_on_compute = "Compute the diameter/thickness in the real space."
86        self.compute_button.SetToolTipString(hint_on_compute)
87        self.Bind(wx.EVT_BUTTON, self.on_compute, id=id)
88        self.dq_name_sizer.AddMany([(dq_name_txt, 0, wx.LEFT, 15),
89                                    (self.dq_name_tcl, 0, wx.LEFT, 15),
90                                    (dq_unit_txt,0, wx.LEFT, 10),
91                                (self.compute_button, 0, wx.LEFT, 30)])
92    def _layout_thickness_size(self):
93        """
94        Fill the sizer containing thickness information
95        """
96        thick_unit = '['+self.kiessig.get_thickness_unit() +']'
97        thickness_size_txt = wx.StaticText(self, -1, 
98                                           'Thickness (or Diameter): ')
99        self.thickness_size_tcl = OutputTextCtrl(self, -1, 
100                                                 size=(_BOX_WIDTH,-1))
101        thickness_size_hint = " Estimated Size in Real Space"
102        self.thickness_size_tcl.SetToolTipString(thickness_size_hint)
103        thickness_size_unit_txt = wx.StaticText(self, -1, thick_unit)
104       
105        self.thickness_size_sizer.AddMany([(thickness_size_txt, 0, wx.LEFT, 15),
106                                    (self.thickness_size_tcl, 0, wx.LEFT, 15),
107                                    (thickness_size_unit_txt, 0, wx.LEFT, 10)])
108   
109    def _layout_hint(self):
110        """
111        Fill the sizer containing hint
112        """
113        hint_msg = "This tool is to approximately estimate "
114        hint_msg += "the thickness of a layer"
115        hint_msg += " or the diameter of particles\n "
116        hint_msg += "from the Kiessig fringe width in SAS/NR data."
117        hint_msg += ""
118        self.hint_txt = wx.StaticText(self, -1, hint_msg)
119        self.hint_sizer.AddMany([(self.hint_txt, 0, wx.LEFT, 15)])
120   
121    def _layout_button(self): 
122        """
123        Do the layout for the button widgets
124        """ 
125        self.bt_close = wx.Button(self, wx.ID_CANCEL,'Close')
126        self.bt_close.Bind(wx.EVT_BUTTON, self.on_close)
127        self.bt_close.SetToolTipString("Close this window.")
128        self.button_sizer.AddMany([(self.bt_close, 0, wx.LEFT, 390)])
129       
130    def _do_layout(self):
131        """
132            Draw window content
133        """
134        self._define_structure()
135        self._layout_dq_name()
136        self._layout_thickness_size()
137        self._layout_hint()
138        self._layout_button()
139        self.boxsizer_source.AddMany([(self.dq_name_sizer, 0,
140                                          wx.EXPAND|wx.TOP|wx.BOTTOM, 5),
141                                   (self.thickness_size_sizer, 0,
142                                     wx.EXPAND|wx.TOP|wx.BOTTOM, 5),
143                                     (self.hint_sizer, 0,
144                                     wx.EXPAND|wx.TOP|wx.BOTTOM, 5)])
145        self.main_sizer.AddMany([(self.boxsizer_source, 0, wx.ALL, 10),
146                                  (self.button_sizer, 0,
147                                    wx.EXPAND|wx.TOP|wx.BOTTOM, 5)])
148        self.SetSizer(self.main_sizer)
149        self.SetAutoLayout(True)
150
151    def on_close(self, event):
152        """
153        close the window containing this panel
154        """
155        self.parent.Close()
156        if event is not None:
157            event.Skip()
158       
159    def on_compute(self, event):
160        """
161        Execute the computation of thickness
162        """
163        # skip for another event
164        if event != None:
165            event.Skip()
166        dq = self.dq_name_tcl.GetValue()
167        self.kiessig.set_deltaq(dq)
168        # calculate the thickness
169        output = self.kiessig.compute_thickness()
170        thickness = self.format_number(output)
171        # set tcl
172        self.thickness_size_tcl.SetValue(str(thickness))
173       
174    def format_number(self, value=None):
175        """
176        Return a float in a standardized, human-readable formatted string
177        """
178        try: 
179            value = float(value)
180        except:
181            output = None
182            return output
183
184        output = "%-7.4g" % value
185        return output.lstrip().rstrip()   
186   
187    def _onparamEnter(self, event = None):
188        """
189        On Text_enter_callback, perform compute
190        """
191        self.on_compute(event)
192             
193class KiessigWindow(widget.CHILD_FRAME):
194    def __init__(self, parent=None, manager=None, 
195                 title="Kiessig Thickness Calculator",
196                 size=(PANEL_WIDTH,PANEL_HEIGHT), *args, **kwds):
197        kwds['title'] = title
198        kwds['size'] = size
199        widget.CHILD_FRAME.__init__(self, parent, *args, **kwds)
200        self.parent = parent
201        self.manager = manager
202        self.panel = KiessigThicknessCalculatorPanel(parent=self)
203        self.Bind(wx.EVT_CLOSE, self.on_close)
204        self.SetPosition((25, 160))
205        self.Show(True)
206       
207    def on_close(self, event):
208        """
209        Close event
210        """
211        if self.manager != None:
212            self.manager.kiessig_frame = None
213        self.Destroy()
214
215       
216if __name__ == "__main__": 
217    app = wx.PySimpleApp()
218    widget.CHILD_FRAME = wx.Frame
219    frame = KiessigWindow()   
220    frame.Show(True)
221    app.MainLoop()     
Note: See TracBrowser for help on using the repository browser.