Changeset 49ab5d7 in sasview for src/sas/perspectives/calculator/slit_length_calculator_panel.py
- Timestamp:
- Mar 4, 2015 3:28:39 PM (10 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 2f732b0
- Parents:
- 76aed53
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/perspectives/calculator/slit_length_calculator_panel.py
r9654baf r49ab5d7 2 2 This software was developed by the University of Tennessee as part of the 3 3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 project funded by the US National Science Foundation. 4 project funded by the US National Science Foundation. 5 5 6 6 See the license text in license.txt … … 15 15 from sas.guiframe.panel_base import PanelBase 16 16 17 from sas.guiframe.events import StatusEvent 18 from sas.calculator.slit_length_calculator import SlitlengthCalculator 17 from sas.guiframe.events import StatusEvent 18 from sas.calculator.slit_length_calculator import SlitlengthCalculator 19 19 from calculator_widgets import OutputTextCtrl 20 20 from calculator_widgets import InterActiveOutputTextCtrl 21 from sas.perspectives.calculator import calculator_widgets as widget 21 from sas.perspectives.calculator import calculator_widgets as widget 22 22 from sas.guiframe.documentation_window import DocumentationWindow 23 23 … … 32 32 PANEL_HEIGHT = 210 33 33 FONT_VARIANT = 1 34 34 35 35 class SlitLengthCalculatorPanel(wx.Panel, PanelBase): 36 36 """ … … 43 43 ## Flag to tell the AUI manager to put this panel in the center pane 44 44 CENTER_PANE = True 45 45 46 46 def __init__(self, parent, *args, **kwds): 47 47 wx.Panel.__init__(self, parent, *args, **kwds) … … 52 52 self.reader = None 53 53 # Default location 54 self._default_save_location = os.getcwd() 54 self._default_save_location = os.getcwd() 55 55 # Object that receive status event 56 56 self.parent = parent 57 57 self._do_layout() 58 58 59 59 def _define_structure(self): 60 60 """ … … 62 62 """ 63 63 self.main_sizer = wx.BoxSizer(wx.VERTICAL) 64 self.box_source = wx.StaticBox(self, -1, str("Slit Size Calculator"))64 self.box_source = wx.StaticBox(self, -1, str("Slit Size Calculator")) 65 65 self.boxsizer_source = wx.StaticBoxSizer(self.box_source, 66 66 wx.VERTICAL) … … 69 69 self.hint_sizer = wx.BoxSizer(wx.HORIZONTAL) 70 70 self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) 71 71 72 72 def _layout_data_name(self): 73 73 """ … … 75 75 """ 76 76 data_name_txt = wx.StaticText(self, -1, 'Data: ') 77 self.data_name_tcl = OutputTextCtrl(self, -1, 78 size=(_BOX_WIDTH *4, -1))77 self.data_name_tcl = OutputTextCtrl(self, -1, 78 size=(_BOX_WIDTH * 4, -1)) 79 79 data_hint = "Loaded data" 80 80 self.data_name_tcl.SetToolTipString(data_hint) … … 98 98 self.slit_size_tcl.SetToolTipString(slit_size_hint) 99 99 slit_size_unit_txt = wx.StaticText(self, -1, 'Unit: ') 100 self.slit_size_unit_tcl = OutputTextCtrl(self, -1, 101 size=(_BOX_WIDTH, -1)) 100 self.slit_size_unit_tcl = OutputTextCtrl(self, -1, 101 size=(_BOX_WIDTH, -1)) 102 102 slit_size_unit_hint = "Full slit size's unit" 103 103 self.slit_size_unit_tcl.SetToolTipString(slit_size_unit_hint) … … 106 106 (slit_size_unit_txt, 0, wx.LEFT, 10), 107 107 (self.slit_size_unit_tcl, 0, wx.LEFT, 10)]) 108 108 109 109 def _layout_hint(self): 110 110 """ 111 Fill the sizer containing hint 111 Fill the sizer containing hint 112 112 """ 113 113 hint_msg = "This calculation works only for SAXSess beam profile data." 114 114 self.hint_txt = wx.StaticText(self, -1, hint_msg) 115 115 self.hint_sizer.AddMany([(self.hint_txt, 0, wx.LEFT, 15)]) 116 117 def _layout_button(self): 116 117 def _layout_button(self): 118 118 """ 119 119 Do the layout for the button widgets 120 """ 121 self.bt_close = wx.Button(self, wx.ID_CANCEL, 'Close')120 """ 121 self.bt_close = wx.Button(self, wx.ID_CANCEL, 'Close') 122 122 self.bt_close.Bind(wx.EVT_BUTTON, self.on_close) 123 123 self.bt_close.SetToolTipString("Close this window.") 124 124 125 125 id = wx.NewId() 126 126 self.button_help = wx.Button(self, id, "HELP") 127 127 self.button_help.SetToolTipString("Help for slit length calculator.") 128 self.Bind(wx.EVT_BUTTON, self.on_help, id=id)128 self.Bind(wx.EVT_BUTTON, self.on_help, id=id) 129 129 130 130 self.button_sizer.AddMany([(self.button_help, 0, wx.LEFT, 280), 131 131 (self.bt_close, 0, wx.LEFT, 20)]) 132 132 133 133 def _do_layout(self): 134 134 """ … … 141 141 self._layout_button() 142 142 self.boxsizer_source.AddMany([(self.data_name_sizer, 0, 143 wx.EXPAND |wx.TOP|wx.BOTTOM, 5),143 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 144 144 (self.slit_size_sizer, 0, 145 wx.EXPAND |wx.TOP|wx.BOTTOM, 5),145 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 146 146 (self.hint_sizer, 0, 147 wx.EXPAND |wx.TOP|wx.BOTTOM, 5)])147 wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) 148 148 self.main_sizer.AddMany([(self.boxsizer_source, 0, wx.ALL, 10), 149 149 (self.button_sizer, 0, 150 wx.EXPAND |wx.TOP|wx.BOTTOM, 5)])150 wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) 151 151 self.SetSizer(self.main_sizer) 152 152 self.SetAutoLayout(True) 153 153 154 154 def choose_data_file(self, location=None): 155 155 path = None … … 157 157 if location == None: 158 158 location = os.getcwd() 159 160 wildcard = "SAXSess Data 1D (*.DAT, *.dat)|*.DAT" 161 159 160 wildcard = "SAXSess Data 1D (*.DAT, *.dat)|*.DAT" 161 162 162 dlg = wx.FileDialog(self, "Choose a file", location, 163 163 "", wildcard, wx.OPEN) … … 166 166 filename = os.path.basename(path) 167 167 dlg.Destroy() 168 168 169 169 return path 170 170 171 def on_help(self, event): 171 def on_help(self, event): 172 172 """ 173 173 Bring up the slit length calculator Documentation whenever 174 the HELP button is clicked. 175 174 the HELP button is clicked. 175 176 176 Calls DocumentationWindow with the path of the location within the 177 documentation tree (after /doc/ ....". Note that when using old 178 versions of Wx (before 2.9) and thus not the release version of 179 installers, the help comes up at the top level of the file as 177 documentation tree (after /doc/ ....". Note that when using old 178 versions of Wx (before 2.9) and thus not the release version of 179 installers, the help comes up at the top level of the file as 180 180 webbrowser does not pass anything past the # to the browser when it is 181 181 running "file:///...." 182 182 183 183 :param evt: Triggers on clicking the help button 184 184 """ 185 185 186 186 _TreeLocation = "user/perspectives/calculator/slit_calculator_help.html" 187 187 _doc_viewer = DocumentationWindow(self, -1, \ 188 _TreeLocation, "Slit Length Calculator Help")188 _TreeLocation, "Slit Length Calculator Help") 189 189 190 190 def on_close(self, event): … … 193 193 """ 194 194 self.parent.Close() 195 195 196 196 def on_load_data(self, event): 197 197 """ … … 201 201 """ 202 202 path = self.choose_data_file(location=self._default_save_location) 203 203 204 204 if path is None: 205 return 205 return 206 206 self._default_save_location = path 207 207 try: … … 212 212 self.reader.stop() 213 213 if self.parent.parent is not None: 214 wx.PostEvent(self.parent.parent, 214 wx.PostEvent(self.parent.parent, 215 215 StatusEvent(status="Loading...", 216 216 type="progress")) … … 222 222 except: 223 223 if self.parent.parent is None: 224 return 224 return 225 225 msg = "Slit Length Calculator: %s" % (sys.exc_value) 226 226 wx.PostEvent(self.parent.parent, 227 227 StatusEvent(status=msg, type='stop')) 228 return 229 228 return 229 230 230 def load_update(self): 231 231 """ … … 233 233 """ 234 234 if self.parent.parent is None: 235 return 235 return 236 236 if self.reader.isrunning(): 237 237 type = "progress" … … 240 240 wx.PostEvent(self.parent.parent, StatusEvent(status="", 241 241 type=type)) 242 242 243 243 def complete_loading(self, data=None, filename=''): 244 244 """ … … 247 247 if data is None or data.__class__.__name__ == 'Data2D': 248 248 if self.parent.parent is None: 249 return 249 return 250 250 msg = "Slit Length cannot be computed for 2D Data" 251 wx.PostEvent(self.parent.parent, 251 wx.PostEvent(self.parent.parent, 252 252 StatusEvent(status=msg, type='stop')) 253 return 253 return 254 254 self.data_name_tcl.SetValue(str(data.filename)) 255 255 #compute the slit size … … 265 265 except: 266 266 if self.parent.parent is None: 267 return 267 return 268 268 msg = "Slit Size Calculator: %s" % (sys.exc_value) 269 269 wx.PostEvent(self.parent.parent, 270 270 StatusEvent(status=msg, type='stop')) 271 return 271 return 272 272 self.slit_size_tcl.SetValue(str(slit_length)) 273 273 #Display unit 274 274 self.slit_size_unit_tcl.SetValue('[Unknown]') 275 275 if self.parent.parent is None: 276 return 276 return 277 277 msg = "Load Complete" 278 278 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, type='stop')) 279 280 279 280 281 281 class SlitLengthCalculatorWindow(widget.CHILD_FRAME): 282 282 """ 283 283 """ 284 284 def __init__(self, parent=None, manager=None, title="Slit Size Calculator", 285 size=(PANEL_WIDTH, PANEL_HEIGHT), *args, **kwds):286 """ 287 """ 288 kwds['size'] = size289 kwds['title'] = title285 size=(PANEL_WIDTH, PANEL_HEIGHT), *args, **kwds): 286 """ 287 """ 288 kwds['size'] = size 289 kwds['title'] = title 290 290 widget.CHILD_FRAME.__init__(self, parent, *args, **kwds) 291 291 self.parent = parent … … 303 303 self.manager.cal_slit_frame = None 304 304 self.Destroy() 305 306 if __name__ == "__main__": 305 306 if __name__ == "__main__": 307 307 app = wx.PySimpleApp() 308 308 widget.CHILD_FRAME = wx.Frame 309 frame = SlitLengthCalculatorWindow() 309 frame = SlitLengthCalculatorWindow() 310 310 frame.Show(True) 311 app.MainLoop() 311 app.MainLoop()
Note: See TracChangeset
for help on using the changeset viewer.