source: sasview/calculatorview/perspectives/calculator/kiessig_calculator_panel.py @ 5cc393b8

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 5cc393b8 was 6996942, checked in by Jae Cho <jhjcho@…>, 14 years ago

adjusted panel size for MAC

  • Property mode set to 100644
File size: 7.7 KB
Line 
1"""
2   This 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#import os
14
15#from sans.guicomm.events import StatusEvent 
16from sans.calculator.kiessig_calculator import KiessigThicknessCalculator
17from calculator_widgets import OutputTextCtrl
18from calculator_widgets import InputTextCtrl
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):
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        #Font size
45        self.SetWindowVariant(variant=FONT_VARIANT) 
46        # Object that receive status event
47        self.parent = parent
48        self.kiessig = KiessigThicknessCalculator()
49        #layout attribute
50        self.hint_sizer = None
51        self._do_layout()
52       
53    def _define_structure(self):
54        """
55        Define the main sizers building to build this application.
56        """
57        self.main_sizer = wx.BoxSizer(wx.VERTICAL)
58        self.box_source = wx.StaticBox(self, -1,
59                                str("Kiessig Thickness Calculator"))
60        self.boxsizer_source = wx.StaticBoxSizer(self.box_source,
61                                                    wx.VERTICAL)
62        self.dq_name_sizer = wx.BoxSizer(wx.HORIZONTAL)
63        self.thickness_size_sizer = wx.BoxSizer(wx.HORIZONTAL)
64        self.hint_sizer = wx.BoxSizer(wx.HORIZONTAL)
65        self.button_sizer = wx.BoxSizer(wx.HORIZONTAL)
66       
67    def _layout_dq_name(self):
68        """
69        Fill the sizer containing dq name
70        """
71        # get the default dq
72        dq_value = str(self.kiessig.get_deltaq())
73        dq_unit_txt = wx.StaticText(self, -1, '[1/A]')
74        dq_name_txt = wx.StaticText(self, -1, 
75                                'Kiessig Fringe Width (Delta Q): ')
76        self.dq_name_tcl = InputTextCtrl(self, -1, 
77                                         size=(_BOX_WIDTH,-1))
78        dq_hint = "Type the Kiessig Fringe Width (Delta Q)"
79        self.dq_name_tcl.SetValue(dq_value)
80        self.dq_name_tcl.SetToolTipString(dq_hint)
81        #control that triggers importing data
82        id = wx.NewId()
83        self.compute_button = wx.Button(self, id, "Compute")
84        hint_on_compute = "Compute the diameter/thickness in the real space."
85        self.compute_button.SetToolTipString(hint_on_compute)
86        self.Bind(wx.EVT_BUTTON, self.on_compute, id=id)
87        self.dq_name_sizer.AddMany([(dq_name_txt, 0, wx.LEFT, 15),
88                                    (self.dq_name_tcl, 0, wx.LEFT, 15),
89                                    (dq_unit_txt,0, wx.LEFT, 10),
90                                (self.compute_button, 0, wx.LEFT, 30)])
91    def _layout_thickness_size(self):
92        """
93        Fill the sizer containing thickness information
94        """
95        thick_unit = '['+self.kiessig.get_thickness_unit() +']'
96        thickness_size_txt = wx.StaticText(self, -1, 
97                                           'Thickness (or Diameter): ')
98        self.thickness_size_tcl = OutputTextCtrl(self, -1, 
99                                                 size=(_BOX_WIDTH,-1))
100        thickness_size_hint = " Estimated Size in Real Space"
101        self.thickness_size_tcl.SetToolTipString(thickness_size_hint)
102        thickness_size_unit_txt = wx.StaticText(self, -1, thick_unit)
103       
104        self.thickness_size_sizer.AddMany([(thickness_size_txt, 0, wx.LEFT, 15),
105                                    (self.thickness_size_tcl, 0, wx.LEFT, 15),
106                                    (thickness_size_unit_txt, 0, wx.LEFT, 10)])
107   
108    def _layout_hint(self):
109        """
110        Fill the sizer containing hint
111        """
112        hint_msg = "This tool is to approximately estimate "
113        hint_msg += "the thickness of a layer"
114        hint_msg += " or the diameter of particles\n "
115        hint_msg += "from the Kiessig fringe width in SANS/NR data."
116        hint_msg += ""
117        self.hint_txt = wx.StaticText(self, -1, hint_msg)
118        self.hint_sizer.AddMany([(self.hint_txt, 0, wx.LEFT, 15)])
119   
120    def _layout_button(self): 
121        """
122        Do the layout for the button widgets
123        """ 
124        self.bt_close = wx.Button(self, wx.ID_CANCEL,'Close')
125        self.bt_close.Bind(wx.EVT_BUTTON, self.on_close)
126        self.bt_close.SetToolTipString("Close this window.")
127        self.button_sizer.AddMany([(self.bt_close, 0, wx.LEFT, 390)])
128       
129    def _do_layout(self):
130        """
131            Draw window content
132        """
133        self._define_structure()
134        self._layout_dq_name()
135        self._layout_thickness_size()
136        self._layout_hint()
137        self._layout_button()
138        self.boxsizer_source.AddMany([(self.dq_name_sizer, 0,
139                                          wx.EXPAND|wx.TOP|wx.BOTTOM, 5),
140                                   (self.thickness_size_sizer, 0,
141                                     wx.EXPAND|wx.TOP|wx.BOTTOM, 5),
142                                     (self.hint_sizer, 0,
143                                     wx.EXPAND|wx.TOP|wx.BOTTOM, 5)])
144        self.main_sizer.AddMany([(self.boxsizer_source, 0, wx.ALL, 10),
145                                  (self.button_sizer, 0,
146                                    wx.EXPAND|wx.TOP|wx.BOTTOM, 5)])
147        self.SetSizer(self.main_sizer)
148        self.SetAutoLayout(True)
149
150    def on_close(self, event):
151        """
152        close the window containing this panel
153        """
154        self.parent.Close()
155        if event is not None:
156            event.Skip()
157       
158    def on_compute(self, event):
159        """
160        Execute the computation of thickness
161        """
162        # skip for another event
163        if event != None:
164            event.Skip()
165        dq = self.dq_name_tcl.GetValue()
166        self.kiessig.set_deltaq(dq)
167        # calculate the thickness
168        output = self.kiessig.compute_thickness()
169        thickness = self.format_number(output)
170        # set tcl
171        self.thickness_size_tcl.SetValue(str(thickness))
172       
173    def format_number(self, value=None):
174        """
175        Return a float in a standardized, human-readable formatted string
176        """
177        try: 
178            value = float(value)
179        except:
180            output = None
181            return output
182
183        output = "%-7.4g" % value
184        return output.lstrip().rstrip()   
185     
186class KiessigWindow(wx.Frame):
187    def __init__(self, parent=None, title="Kiessig Thickness Calculator",
188                  size=(PANEL_WIDTH,PANEL_HEIGHT), *args, **kwds):
189        kwds['title'] = title
190        kwds['size'] = size
191        wx.Frame.__init__(self, parent, *args, **kwds)
192        self.parent = parent
193        self.panel = KiessigThicknessCalculatorPanel(parent=self)
194        self.Centre()
195        self.Show(True)
196       
197if __name__ == "__main__": 
198    app = wx.PySimpleApp()
199    frame = KiessigWindow()   
200    frame.Show(True)
201    app.MainLoop()     
Note: See TracBrowser for help on using the repository browser.