source: sasview/calculatorview/perspectives/calculator/kiessig_calculator_panel.py @ 74b1770

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

added kiessig fringe calculator and fixed slit length by ½ as our definition of slit length

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