source: sasview/src/sas/sasgui/perspectives/calculator/kiessig_calculator_panel.py @ fd62331

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.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since fd62331 was d0248bd, checked in by butler, 9 years ago

linked new help to all Tools menu panels remaining.

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