source: sasview/src/sas/perspectives/calculator/kiessig_calculator_panel.py @ 26d2d88

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 26d2d88 was 26d2d88, checked in by Doucet, Mathieu <doucetm@…>, 9 years ago

Fix pylint complaints

  • Property mode set to 100644
File size: 9.5 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
19from sas.guiframe.documentation_window import DocumentationWindow
20
21_BOX_WIDTH = 77
22#Slit length panel size
23if sys.platform.count("win32") > 0:
24    PANEL_WIDTH = 500
25    PANEL_HEIGHT = 230
26    FONT_VARIANT = 0
27else:
28    PANEL_WIDTH = 560
29    PANEL_HEIGHT = 230
30    FONT_VARIANT = 1
31 
32class KiessigThicknessCalculatorPanel(wx.Panel, PanelBase):
33    """
34    Provides the Kiessig thickness calculator GUI.
35    """
36    ## Internal nickname for the window, used by the AUI manager
37    window_name = "Kiessig Thickness Calculator"
38    ## Name to appear on the window title bar
39    window_caption = "Kiessig Thickness Calculator"
40    ## Flag to tell the AUI manager to put this panel in the center pane
41    CENTER_PANE = True
42
43    def __init__(self, parent, *args, **kwds):
44        wx.Panel.__init__(self, parent, *args, **kwds)
45        PanelBase.__init__(self)
46        #Font size
47        self.SetWindowVariant(variant=FONT_VARIANT)
48        # Object that receive status event
49        self.parent = parent
50        self.kiessig = KiessigThicknessCalculator()
51        #layout attribute
52        self.hint_sizer = None
53        self._do_layout()
54
55    def _define_structure(self):
56        """
57        Define the main sizers building to build this application.
58        """
59        self.main_sizer = wx.BoxSizer(wx.VERTICAL)
60        self.box_source = wx.StaticBox(self, -1,
61                                str("Kiessig Thickness Calculator"))
62        self.boxsizer_source = wx.StaticBoxSizer(self.box_source,
63                                                 wx.VERTICAL)
64        self.dq_name_sizer = wx.BoxSizer(wx.HORIZONTAL)
65        self.thickness_size_sizer = wx.BoxSizer(wx.HORIZONTAL)
66        self.hint_sizer = wx.BoxSizer(wx.HORIZONTAL)
67        self.button_sizer = wx.BoxSizer(wx.HORIZONTAL)
68
69    def _layout_dq_name(self):
70        """
71        Fill the sizer containing dq name
72        """
73        # get the default dq
74        dq_value = str(self.kiessig.get_deltaq())
75        dq_unit_txt = wx.StaticText(self, -1, '[1/A]')
76        dq_name_txt = wx.StaticText(self, -1,
77                                    'Kiessig Fringe Width (Delta Q): ')
78        self.dq_name_tcl = InputTextCtrl(self, -1, 
79                                         size=(_BOX_WIDTH,-1))
80        dq_hint = "Type the Kiessig Fringe Width (Delta Q)"
81        self.dq_name_tcl.SetValue(dq_value)
82        self.dq_name_tcl.SetToolTipString(dq_hint)
83        #control that triggers importing data
84        id = wx.NewId()
85        self.compute_button = wx.Button(self, id, "Compute")
86        hint_on_compute = "Compute the diameter/thickness in the real space."
87        self.compute_button.SetToolTipString(hint_on_compute)
88        self.Bind(wx.EVT_BUTTON, self.on_compute, id=id)
89        self.dq_name_sizer.AddMany([(dq_name_txt, 0, wx.LEFT, 15),
90                                    (self.dq_name_tcl, 0, wx.LEFT, 15),
91                                    (dq_unit_txt, 0, wx.LEFT, 10),
92                                    (self.compute_button, 0, wx.LEFT, 30)])
93
94    def _layout_thickness_size(self):
95        """
96        Fill the sizer containing thickness information
97        """
98        thick_unit = '['+self.kiessig.get_thickness_unit() +']'
99        thickness_size_txt = wx.StaticText(self, -1,
100                                           'Thickness (or Diameter): ')
101        self.thickness_size_tcl = OutputTextCtrl(self, -1,
102                                                 size=(_BOX_WIDTH,-1))
103        thickness_size_hint = " Estimated Size in Real Space"
104        self.thickness_size_tcl.SetToolTipString(thickness_size_hint)
105        thickness_size_unit_txt = wx.StaticText(self, -1, thick_unit)
106
107        self.thickness_size_sizer.AddMany([(thickness_size_txt, 0, wx.LEFT, 15),
108                                           (self.thickness_size_tcl, 0, wx.LEFT, 15),
109                                           (thickness_size_unit_txt, 0, wx.LEFT, 10)])
110
111    def _layout_hint(self):
112        """
113        Fill the sizer containing hint
114        """
115        hint_msg = "This tool is to approximately estimate "
116        hint_msg += "the thickness of a layer"
117        hint_msg += " or the diameter of particles\n "
118        hint_msg += "from the Kiessig fringe width in SAS/NR data."
119        hint_msg += ""
120        self.hint_txt = wx.StaticText(self, -1, hint_msg)
121        self.hint_sizer.AddMany([(self.hint_txt, 0, wx.LEFT, 15)])
122
123    def _layout_button(self): 
124        """
125        Do the layout for the button widgets
126        """ 
127        id = wx.NewId()
128        self.bt_help = wx.Button(self, id, 'HELP')
129        self.bt_help.Bind(wx.EVT_BUTTON, self.on_help)
130        self.bt_help.SetToolTipString("Help using the Kiessig fringe calculator.")
131
132        self.bt_close = wx.Button(self, wx.ID_CANCEL, 'Close')
133        self.bt_close.Bind(wx.EVT_BUTTON, self.on_close)
134        self.bt_close.SetToolTipString("Close this window.")
135        self.button_sizer.AddMany([(self.bt_help, 0, wx.LEFT, 260),
136                                   (self.bt_close, 0, wx.LEFT, 20)])
137
138    def _do_layout(self):
139        """
140            Draw window content
141        """
142        self._define_structure()
143        self._layout_dq_name()
144        self._layout_thickness_size()
145        self._layout_hint()
146        self._layout_button()
147        self.boxsizer_source.AddMany([(self.dq_name_sizer, 0,
148                                       wx.EXPAND|wx.TOP|wx.BOTTOM, 5),
149                                      (self.thickness_size_sizer, 0,
150                                       wx.EXPAND|wx.TOP|wx.BOTTOM, 5),
151                                      (self.hint_sizer, 0,
152                                       wx.EXPAND|wx.TOP|wx.BOTTOM, 5)])
153        self.main_sizer.AddMany([(self.boxsizer_source, 0, wx.ALL, 10),
154                                 (self.button_sizer, 0,
155                                  wx.EXPAND|wx.TOP|wx.BOTTOM, 5)])
156        self.SetSizer(self.main_sizer)
157        self.SetAutoLayout(True)
158
159    def on_help(self, event):
160        """
161        Bring up the Kiessig fringe calculator Documentation whenever
162        the HELP button is clicked.
163        Calls DocumentationWindow with the path of the location within the
164        documentation tree (after /doc/ ....".  Note that when using old
165        versions of Wx (before 2.9) and thus not the release version of
166        installers, the help comes up at the top level of the file as
167        webbrowser does not pass anything past the # to the browser when it is
168        running "file:///...."
169
170    :param evt: Triggers on clicking the help button
171    """
172        _TreeLocation = "user/perspectives/calculator/kiessig_calculator_help.html"
173        _doc_viewer = DocumentationWindow(self, -1,
174                                          _TreeLocation,
175                                          "Density/Volume Calculator Help")
176
177    def on_close(self, event):
178        """
179        close the window containing this panel
180        """
181        self.parent.Close()
182        if event is not None:
183            event.Skip()
184
185    def on_compute(self, event):
186        """
187        Execute the computation of thickness
188        """
189        # skip for another event
190        if event != None:
191            event.Skip()
192        dq = self.dq_name_tcl.GetValue()
193        self.kiessig.set_deltaq(dq)
194        # calculate the thickness
195        output = self.kiessig.compute_thickness()
196        thickness = self.format_number(output)
197        # set tcl
198        self.thickness_size_tcl.SetValue(str(thickness))
199
200    def format_number(self, value=None):
201        """
202        Return a float in a standardized, human-readable formatted string
203        """
204        try:
205            value = float(value)
206        except:
207            output = None
208            return output
209
210        output = "%-7.4g" % value
211        return output.lstrip().rstrip()
212   
213    def _onparamEnter(self, event = None):
214        """
215        On Text_enter_callback, perform compute
216        """
217        self.on_compute(event)
218
219class KiessigWindow(widget.CHILD_FRAME):
220    def __init__(self, parent=None, manager=None, 
221                 title="Kiessig Thickness Calculator",
222                 size=(PANEL_WIDTH,PANEL_HEIGHT), *args, **kwds):
223        kwds['title'] = title
224        kwds['size'] = size
225        widget.CHILD_FRAME.__init__(self, parent, *args, **kwds)
226        self.parent = parent
227        self.manager = manager
228        self.panel = KiessigThicknessCalculatorPanel(parent=self)
229        self.Bind(wx.EVT_CLOSE, self.on_close)
230        self.SetPosition((25, 10))
231        self.Show(True)
232       
233    def on_close(self, event):
234        """
235        Close event
236        """
237        if self.manager != None:
238            self.manager.kiessig_frame = None
239        self.Destroy()
240
241if __name__ == "__main__":
242    app = wx.PySimpleApp()
243    widget.CHILD_FRAME = wx.Frame
244    frame = KiessigWindow()
245    frame.Show(True)
246    app.MainLoop()
Note: See TracBrowser for help on using the repository browser.