source: sasview/src/sas/perspectives/calculator/kiessig_calculator_panel.py @ 9df6a03

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 9df6a03 was 3db44fb, checked in by butler, 10 years ago

1) Fixed second issue that was caused by the recent cleanup of
DocumentationWindow?: loading html at anchor point for context help
(broken). In order to preserve the cleanup, the class was refactored to
take another parameter: html instruction string. This keeps it general
to accept not only the # anchor but alos queries of all sorts in the
future. Thus all modules using this class were also edited to match.

2) in process of editing the dozen or so instances did a bit of code
cleanup and pylint cleanup.

  • 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_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/perspectives/calculator/kiessig_calculator_help.html"
175        _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "",
176                                          "Density/Volume Calculator Help")
177
178    def on_close(self, event):
179        """
180        close the window containing this panel
181        """
182        self.parent.Close()
183        if event is not None:
184            event.Skip()
185
186    def on_compute(self, event):
187        """
188        Execute the computation of thickness
189        """
190        # skip for another event
191        if event != None:
192            event.Skip()
193        dq = self.dq_name_tcl.GetValue()
194        self.kiessig.set_deltaq(dq)
195        # calculate the thickness
196        output = self.kiessig.compute_thickness()
197        thickness = self.format_number(output)
198        # set tcl
199        self.thickness_size_tcl.SetValue(str(thickness))
200
201    def format_number(self, value=None):
202        """
203        Return a float in a standardized, human-readable formatted string
204        """
205        try:
206            value = float(value)
207        except:
208            output = None
209            return output
210
211        output = "%-7.4g" % value
212        return output.lstrip().rstrip()
213   
214    def _onparamEnter(self, event = None):
215        """
216        On Text_enter_callback, perform compute
217        """
218        self.on_compute(event)
219
220class KiessigWindow(widget.CHILD_FRAME):
221    def __init__(self, parent=None, manager=None, 
222                 title="Kiessig Thickness Calculator",
223                 size=(PANEL_WIDTH,PANEL_HEIGHT), *args, **kwds):
224        kwds['title'] = title
225        kwds['size'] = size
226        widget.CHILD_FRAME.__init__(self, parent, *args, **kwds)
227        self.parent = parent
228        self.manager = manager
229        self.panel = KiessigThicknessCalculatorPanel(parent=self)
230        self.Bind(wx.EVT_CLOSE, self.on_close)
231        self.SetPosition((wx.LEFT, PANEL_TOP))
232        self.Show(True)
233       
234    def on_close(self, event):
235        """
236        Close event
237        """
238        if self.manager != None:
239            self.manager.kiessig_frame = None
240        self.Destroy()
241
242if __name__ == "__main__":
243    app = wx.PySimpleApp()
244    widget.CHILD_FRAME = wx.Frame
245    frame = KiessigWindow()
246    frame.Show(True)
247    app.MainLoop()
Note: See TracBrowser for help on using the repository browser.