Changeset b0ab6cb in sasview for calculatorview/perspectives
- Timestamp:
- Oct 27, 2010 4:41:30 PM (14 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:
- 6cda91f
- Parents:
- c4d6900
- Location:
- calculatorview/perspectives/calculator
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
calculatorview/perspectives/calculator/aperture_editor.py
r6d48919 rb0ab6cb 31 31 self._reset_aperture = deepcopy(aperture) 32 32 self._notes = "" 33 self_description = "Edit aperture" 33 #self_description = "Edit aperture" 34 35 #Attributes for panel 36 self.aperture_name_tcl = None 37 self.main_sizer = None 38 self.box_aperture = None 39 self.boxsizer_aperture = None 40 self.name_sizer = None 41 self.name_sizer = None 42 self.size_name_tcl = None 43 self.type_sizer = None 44 self.distance_sizer = None 45 self.size_name_sizer = None 46 self.aperture_size_unit_tcl = None 47 self.aperture_size_sizer = None 48 self.button_sizer = None 49 self.aperture_name_tcl = None 50 self.type_tcl = None 51 self.distance_tcl = None 52 self.distance_unit_tcl = None 53 self.x_aperture_size_tcl = None 54 self.y_aperture_size_tcl = None 55 self.z_aperture_size_tcl = None 56 self.bt_apply = None 57 self.bt_cancel = None 58 self.bt_close = None 59 34 60 self._do_layout() 35 61 self.set_values() -
calculatorview/perspectives/calculator/calculator.py
r74b1770 rb0ab6cb 1 1 """ 2 Calculator Module 3 """ 2 4 ################################################################################ 3 5 #This software was developed by the University of Tennessee as part of the … … 10 12 ################################################################################ 11 13 12 import wx14 #import wx 13 15 import logging 14 16 … … 18 20 for calculator perspective 19 21 """ 20 21 22 def __init__(self, standalone=True): 22 23 """ … … 25 26 ## Plug-in name. It will appear on the application menu. 26 27 self.sub_menu = "Calculator" 27 28 #standalone flag 29 self.standalone = standalone 28 30 ## Reference to the parent window. Filled by get_panels() below. 29 31 self.parent = None … … 78 80 frame = HelpWindow(None, -1) 79 81 frame.Show(True) 80 82 evt.Skip() 83 81 84 def get_context_menu(self, graph=None): 82 85 """ … … 117 120 sld_help = "Provides computation related to Scattering Length Density" 118 121 slit_length_help = "Provides computation related to Slit Length Density" 119 data_editor_help = "Meta Data Editor"122 #data_editor_help = "Meta Data Editor" 120 123 return [("SLD Calculator", sld_help, self.on_calculate_sld), 121 124 ("Slit Size Calculator", slit_length_help, … … 130 133 """ 131 134 from data_editor import DataEditorWindow 132 frame = DataEditorWindow(parent=self.parent, data=[], title="Data Editor") 135 frame = DataEditorWindow(parent=self.parent, data=[], 136 title="Data Editor") 133 137 frame.Show(True) 138 event.Skip() 134 139 135 140 def on_calculate_kiessig(self, event): … … 140 145 frame = KiessigWindow() 141 146 frame.Show(True) 142 147 event.Skip() 143 148 144 149 def on_calculate_sld(self, event): … … 149 154 frame = SldWindow(base=self.parent) 150 155 frame.Show(True) 151 156 event.Skip() 157 152 158 def on_calculate_slit_size(self, event): 153 159 """ … … 157 163 frame = SlitLengthCalculatorWindow(parent=self.parent) 158 164 frame.Show(True) 165 event.Skip() 159 166 160 167 def on_perspective(self, event): … … 168 175 """ 169 176 self.parent.set_perspective(self.perspective) 170 171 177 event.Skip() 178 172 179 def post_init(self): 173 180 """ -
calculatorview/perspectives/calculator/calculator_widgets.py
rb7e0fff rb0ab6cb 9 9 """ 10 10 import wx 11 import os11 #import os 12 12 13 13 class InputTextCtrl(wx.TextCtrl): … … 20 20 wx.TextCtrl.__init__(self, *args, **kwds) 21 21 22 ## Set to True when the mouse is clicked while the whole string is selected 23 full_selection = False 22 ## Set to True when the mouse is clicked while the whole 23 #string is selected 24 self.full_selection = False 24 25 ## Call back for EVT_SET_FOCUS events 25 26 _on_set_focus_callback = None … … 52 53 # if not, select the whole string 53 54 (start, end) = control.GetSelection() 54 if start ==end:55 control.SetSelection(-1, -1)55 if start == end: 56 control.SetSelection(-1, -1) 56 57 57 58 -
calculatorview/perspectives/calculator/collimation_editor.py
r6137b150 rb0ab6cb 1 1 """ 2 """ 2 3 import wx 3 4 import sys … … 28 29 """ 29 30 """ 30 kwds['size'] = (PANEL_WIDTH, PANEL_HEIGHT)31 kwds['size'] = (PANEL_WIDTH, PANEL_HEIGHT) 31 32 kwds['title'] = "Collimation Editor" 32 33 wx.Dialog.__init__(self, parent=parent, *args, **kwds) … … 37 38 self._notes = "" 38 39 self._description = "Edit collimation" 40 #layout attributes 41 self.main_sizer = None 42 self.box_collimation = None 43 self.boxsizer_collimation = None 44 45 39 46 self._do_layout() 40 47 self.set_values() … … 45 52 """ 46 53 self.main_sizer = wx.BoxSizer(wx.VERTICAL) 47 self.box_collimation = wx.StaticBox(self, -1,str("Edit Selected Collimation")) 48 self.boxsizer_collimation = wx.StaticBoxSizer(self.box_collimation, wx.VERTICAL) 54 self.box_collimation = wx.StaticBox(self, -1, 55 str("Edit Selected Collimation")) 56 self.boxsizer_collimation = wx.StaticBoxSizer(self.box_collimation, 57 wx.VERTICAL) 49 58 50 59 collimation_box = wx.StaticBox(self, -1, "Edit Number of Collimations") … … 80 89 81 90 self.bt_remove_collimation = wx.Button(self, -1, "Remove") 82 self.bt_remove_collimation.SetToolTipString("Remove data's collimation.") 91 hint = "Remove data's collimation." 92 self.bt_remove_collimation.SetToolTipString(hint) 83 93 self.bt_remove_collimation.Bind(wx.EVT_BUTTON, self.remove_collimation) 84 94 85 self.collimation_button_sizer.AddMany([(collimation_name_txt, 0, wx.LEFT, 15), 95 self.collimation_button_sizer.AddMany([(collimation_name_txt, 0, 96 wx.LEFT, 15), 86 97 (self.collimation_cbox, 0, wx.LEFT, 5), 87 98 (self.bt_add_collimation, 0, wx.LEFT, 10), 88 (self.bt_remove_collimation, 0, wx.LEFT, 5)]) 99 (self.bt_remove_collimation, 100 0, wx.LEFT, 5)]) 89 101 collimation_hint_txt = 'No collimation is available for this data.' 90 102 self.collimation_txt = wx.StaticText(self, -1, collimation_hint_txt) 91 103 self.collimation_hint_sizer.Add(self.collimation_txt, 0, wx.LEFT, 10) 92 self.collimation_sizer.AddMany([(self.collimation_button_sizer, 0, wx.ALL, 10), 93 (self.collimation_hint_sizer, 0, wx.ALL, 10)]) 104 self.collimation_sizer.AddMany([(self.collimation_button_sizer, 105 0, wx.ALL, 10), 106 (self.collimation_hint_sizer, 107 0, wx.ALL, 10)]) 94 108 95 109 self.fill_collimation_combox() … … 115 129 self.length_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 116 130 length_unit_txt = wx.StaticText(self, -1, 'Unit: ') 117 self.length_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) 131 self.length_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), 132 style=0) 118 133 self.length_sizer.AddMany([(length_txt, 0, wx.LEFT|wx.RIGHT, 10), 119 134 (self.length_tcl, 0, wx.LEFT, 12), … … 165 180 self.aperture_txt = wx.StaticText(self, -1, aperture_hint_txt) 166 181 self.aperture_hint_sizer.Add(self.aperture_txt, 0, wx.LEFT, 10) 167 self.aperture_sizer.AddMany([(self.aperture_button_sizer, 0, wx.ALL, 10), 182 self.aperture_sizer.AddMany([(self.aperture_button_sizer, 183 0, wx.ALL, 10), 168 184 (self.aperture_hint_sizer, 0, wx.ALL, 10)]) 169 185 self.fill_aperture_combox() 170 186 self.enable_aperture() 171 187 172 def _do_layout(self , data=None):188 def _do_layout(self): 173 189 """ 174 190 Draw the current panel … … 265 281 def on_select_collimation(self, event): 266 282 """ 267 fill the control on the panel according to the current selected collimation 283 fill the control on the panel according to 284 the current selected collimation 268 285 """ 269 286 self.set_values() … … 275 292 Enable /disable widgets related to collimation 276 293 """ 277 if self._collimation is not None and self.collimation_cbox.GetCount() > 0: 294 if self._collimation is not None and \ 295 self.collimation_cbox.GetCount() > 0: 278 296 self.collimation_cbox.Enable() 279 297 self.bt_remove_collimation.Enable() 280 298 n_collimation = self.collimation_cbox.GetCount() 281 collimation_hint_txt = 'collimations available: %s '%str(n_collimation) 299 collimation_hint_txt = "collimations" 300 collimation_hint_txt += " available: %s "% str(n_collimation) 282 301 if len(self._collimation) > 0: 283 302 self.bt_remove_collimation.Enable() … … 491 510 collimation.length = float(length) 492 511 else: 493 self._notes += "Error: Expected a float for collimation length 494 self._notes += " won't changes length from "512 self._notes += "Error: Expected a float for collimation length" 513 self._notes += " won't changes length from " 495 514 self._notes += "%s to %s"%(collimation.length, length) 496 515 #change length unit … … 518 537 self.set_values() 519 538 if self.manager is not None: 520 539 self.manager.set_collimation(self._collimation) 521 540 522 541 523 if __name__ == "__main__":542 if __name__ == "__main__": 524 543 525 544 app = wx.App() -
calculatorview/perspectives/calculator/console.py
r91f151a rb0ab6cb 1 import wx 2 CONSOLE_WIDTH = 340 3 CONSOLE_HEIGHT = 240 4 1 """ 2 Console Module display message of a dialog 3 """ 5 4 import wx 6 5 import sys … … 8 7 9 8 _BOX_WIDTH = 60 10 9 CONSOLE_WIDTH = 340 10 CONSOLE_HEIGHT = 240 11 11 if sys.platform.count("win32")>0: 12 12 _STATICBOX_WIDTH = 450 … … 22 22 23 23 class ConsoleDialog(wx.Dialog): 24 def __init__(self, parent=None, id=-1,manager=None, data=None,25 title="Data Summary",size=(PANEL_WIDTH, PANEL_HEIGHT)):26 wx.Dialog.__init__(self, parent=parent, id=id,title=title, size=size)24 def __init__(self, parent=None, manager=None, data=None, 25 title="Data Summary", size=(PANEL_WIDTH, PANEL_HEIGHT)): 26 wx.Dialog.__init__(self, parent=parent, title=title, size=size) 27 27 28 28 self.parent = parent … … 43 43 def set_manager(self, manager): 44 44 """ 45 Set the manager of this window 45 46 """ 46 47 self._manager = manager … … 48 49 def set_message(self, msg=""): 49 50 """ 51 Display the message received 50 52 """ 51 53 self.msg_txt.SetValue(str(msg)) 52 54 53 if __name__ == "__main__":55 if __name__ == "__main__": 54 56 55 57 app = wx.App() … … 57 59 loader = Loader() 58 60 # Load data 59 data = loader.load("MAR07232_rest.ASC")60 dlg = ConsoleDialog(data= data)61 test_data = loader.load("MAR07232_rest.ASC") 62 dlg = ConsoleDialog(data=test_data) 61 63 dlg.ShowModal() 62 64 app.MainLoop() -
calculatorview/perspectives/calculator/data_editor.py
rc5dca87 rb0ab6cb 6 6 7 7 from DataLoader.loader import Loader 8 from DataLoader.data_info import DataInfo, Detector, Collimation, Data2D 8 #from DataLoader.data_info import DataInfo 9 #from DataLoader.data_info import Detector 10 #from DataLoader.data_info import Collimation 11 from DataLoader.data_info import Data2D 9 12 from detector_editor import DetectorDialog 10 13 from collimation_editor import CollimationDialog 11 14 from console import ConsoleDialog 12 15 13 from sans.guiframe.utils import check_float16 #from sans.guiframe.utils import check_float 14 17 from sans.guicomm.events import StatusEvent 15 18 … … 19 22 _NPTS_DEFAULT = 50 20 23 #Control panel width 21 if sys.platform.count("darwin") ==0:24 if sys.platform.count("darwin") == 0: 22 25 PANEL_WIDTH = 500 23 26 PANEL_HEIGTH = 350 … … 43 46 44 47 if error is not None: 45 message += "When contacting the DANSE team, mention the following:\n%s" % str(error) 46 47 dial = wx.MessageDialog(None, message, 'Error Loading File', wx.OK | wx.ICON_EXCLAMATION) 48 message += "When contacting the DANSE team," 49 message += " mention the following:\n%s" % str(error) 50 51 dial = wx.MessageDialog(None, message, 52 'Error Loading File', wx.OK | wx.ICON_EXCLAMATION) 48 53 dial.ShowModal() 49 54 … … 51 56 class DataEditorPanel(wx.ScrolledWindow): 52 57 """ 53 @param data: when not empty the class can same information into a dat object 58 :param data: when not empty the class can 59 same information into a dat object 54 60 and post event containing the changed data object to some other frame 55 61 """ 56 62 def __init__(self, parent, data=[], *args, **kwds): 57 58 kwds["size"]= (PANEL_WIDTH, PANEL_HEIGTH)59 60 61 62 63 64 65 self_description = "Edit Data"66 67 68 69 70 71 72 63 kwds['name'] = "Data Editor" 64 kwds["size"] = (PANEL_WIDTH, PANEL_HEIGTH) 65 wx.ScrolledWindow.__init__(self, parent, *args, **kwds) 66 self.parent = parent 67 self._data = data 68 self._reset_data = deepcopy(data) 69 self.reader = None 70 self._notes = "" 71 self._description = "Edit Data" 72 self._default_save_location = os.getcwd() 73 self._do_layout() 74 self.reset_panel() 75 self.bt_apply.Disable() 76 if data: 77 self.complete_loading(data=data) 78 self.bt_apply.Enable() 73 79 74 80 def _define_structure(self): 75 81 """ 76 82 define initial sizer 77 83 """ 78 84 self.main_sizer = wx.BoxSizer(wx.VERTICAL) … … 91 97 def _layout_name(self): 92 98 """ 93 99 Do the layout for data name related widgets 94 100 """ 95 101 #data name [string] … … 110 116 def _layout_title(self): 111 117 """ 112 118 Do the layout for data title related widgets 113 119 """ 114 120 #title name [string] … … 123 129 def _layout_run(self): 124 130 """ 125 131 Do the layout for data run related widgets 126 132 """ 127 133 data_run_txt = wx.StaticText(self, -1, 'Run : ') 128 134 data_run_txt.SetToolTipString('') 129 self.data_run_tcl = wx.TextCtrl(self, -1, size=(PANEL_WIDTH*3/5, -1), style=wx.TE_MULTILINE) 135 self.data_run_tcl = wx.TextCtrl(self, -1, size=(PANEL_WIDTH*3/5, -1), 136 style=wx.TE_MULTILINE) 130 137 hint_run = "Data's run." 131 138 self.data_run_tcl.SetToolTipString(hint_run) … … 135 142 def _layout_instrument(self): 136 143 """ 137 144 Do the layout for instrument related widgets 138 145 """ 139 146 instrument_txt = wx.StaticText(self, -1, 'Instrument : ') … … 148 155 def _layout_editor(self): 149 156 """ 150 157 Do the layout for sample related widgets 151 158 """ 152 159 self.detector_rb = wx.RadioButton(self, -1, "Detector", … … 186 193 Layout widgets related to data's summary 187 194 """ 188 self.data_summary = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE|wx.HSCROLL, 195 self.data_summary = wx.TextCtrl(self, -1, 196 style=wx.TE_MULTILINE|wx.HSCROLL, 189 197 size=(-1, 200)) 190 198 summary = 'No data info available...' … … 196 204 Do the layout for the button widgets 197 205 """ 198 self.bt_summary = wx.Button(self, -1, "View", size=(_BOX_WIDTH, -1))206 self.bt_summary = wx.Button(self, -1, "View", size=(_BOX_WIDTH, -1)) 199 207 self.bt_summary.SetToolTipString("View final changes on data.") 200 208 self.bt_summary.Bind(wx.EVT_BUTTON, self.on_click_view) 201 209 202 self.bt_save = wx.Button(self, -1, "Save As", size=(_BOX_WIDTH, -1))210 self.bt_save = wx.Button(self, -1, "Save As", size=(_BOX_WIDTH, -1)) 203 211 self.bt_save.SetToolTipString("Save changes in a file.") 204 212 self.bt_save.Bind(wx.EVT_BUTTON, self.on_click_save) 205 213 206 self.bt_apply = wx.Button(self, -1, "Apply", size=(_BOX_WIDTH, -1))214 self.bt_apply = wx.Button(self, -1, "Apply", size=(_BOX_WIDTH, -1)) 207 215 self.bt_apply.SetToolTipString("Save changes into the imported data.") 208 216 self.bt_apply.Bind(wx.EVT_BUTTON, self.on_click_apply) 209 217 210 self.bt_reset = wx.Button(self, -1, 'Reset', size=(_BOX_WIDTH,-1))218 self.bt_reset = wx.Button(self, -1, 'Reset', size=(_BOX_WIDTH, -1)) 211 219 self.bt_reset.Bind(wx.EVT_BUTTON, self.on_click_reset) 212 220 self.bt_reset.SetToolTipString("Reset data to its initial state.") 213 221 214 self.bt_close = wx.Button(self, -1, 'Close', size=(_BOX_WIDTH,-1))222 self.bt_close = wx.Button(self, -1, 'Close', size=(_BOX_WIDTH, -1)) 215 223 self.bt_close.Bind(wx.EVT_BUTTON, self.on_close) 216 224 self.bt_close.SetToolTipString("Close this panel.") … … 222 230 (self.bt_close, 0, wx.RIGHT, 10)]) 223 231 224 def _do_layout(self , data=None):225 """ 226 232 def _do_layout(self): 233 """ 234 Draw the current panel 227 235 """ 228 236 self._define_structure() … … 244 252 wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) 245 253 self.SetSizer(self.main_sizer) 246 self.SetScrollbars(20, 20,25,65)254 self.SetScrollbars(20, 20, 25, 65) 247 255 self.SetAutoLayout(True) 248 256 249 257 def fill_data_combox(self): 250 258 """ 251 259 fill the current combobox with the available data 252 260 """ 253 261 if not self._data: … … 275 283 """ 276 284 """ 277 data, data_name, position= self.get_current_data()285 data, _, _ = self.get_current_data() 278 286 self.reset_panel() 279 287 if data is None: … … 322 330 def set_sample(self, sample, notes=None): 323 331 """ 324 325 """ 326 data, data_name, position= self.get_current_data()332 set sample for data 333 """ 334 data, _, _ = self.get_current_data() 327 335 if data is None: 328 336 return … … 333 341 def set_source(self, source, notes=None): 334 342 """ 335 343 set source for data 336 344 """ 337 345 data, data_name, position = self.get_current_data() … … 344 352 def set_detector(self, detector, notes=None): 345 353 """ 346 354 set detector for data 347 355 """ 348 356 data, data_name, position = self.get_current_data() … … 355 363 def set_collimation(self, collimation, notes=None): 356 364 """ 357 365 set collimation for data 358 366 """ 359 367 data, data_name, position = self.get_current_data() … … 366 374 def edit_collimation(self): 367 375 """ 368 376 Edit the selected collimation 369 377 """ 370 378 data, data_name, position = self.get_current_data() … … 377 385 def edit_detector(self): 378 386 """ 379 387 Edit the selected detector 380 388 """ 381 389 data, data_name, position = self.get_current_data() … … 388 396 def edit_sample(self): 389 397 """ 390 391 """ 392 data, data_name, position= self.get_current_data()398 Open the dialog to edit the sample of the current data 399 """ 400 data, _, _ = self.get_current_data() 393 401 if data is None: 394 402 return … … 400 408 def edit_source(self): 401 409 """ 402 410 Open the dialog to edit the saource of the current data 403 411 """ 404 412 data, data_name, position = self.get_current_data() … … 412 420 def choose_data_file(self, location=None): 413 421 """ 414 422 Open a file dialog to allow loading a file 415 423 """ 416 424 path = None … … 432 440 def complete_loading(self, data=None, filename=''): 433 441 """ 434 442 Complete the loading and compute the slit size 435 443 """ 436 444 self.done = True … … 438 446 if data is None: 439 447 msg = "Couldn't load data" 440 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, info="warning",type='stop')) 448 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, 449 info="warning",type='stop')) 441 450 return 442 451 if not data.__class__.__name__ == "list": … … 450 459 return 451 460 msg = "Load Complete" 452 wx.PostEvent(self.parent.parent, StatusEvent(status=msg,info="info",type='stop')) 461 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, 462 info="info",type='stop')) 453 463 454 464 def set_values(self): 455 465 """ 456 457 466 take the aperture values of the current data and display them 467 through the panel 458 468 """ 459 469 if self._data: … … 463 473 def get_data(self): 464 474 """ 465 475 return the current data 466 476 """ 467 477 return self._data … … 469 479 def get_notes(self): 470 480 """ 471 481 return notes 472 482 """ 473 483 return self._notes … … 475 485 def on_change_run(self, event=None): 476 486 """ 477 487 Change run 478 488 """ 479 489 run = [] 480 data, data_name, position= self.get_current_data()490 data, _, _ = self.get_current_data() 481 491 for i in range(self.data_run_tcl.GetNumberOfLines()): 482 492 text = self.data_run_tcl.GetLineText(i).lstrip().rstrip() … … 485 495 if data.run != run: 486 496 self._notes += "Change data 's " 487 self._notes += "run from %s to %s \n" %(data.run, str(run))497 self._notes += "run from %s to %s \n" % (data.run, str(run)) 488 498 data.run = run 489 499 if event is not None: 500 event.Skip() 501 490 502 def on_change_title(self, event=None): 491 503 """ 492 493 """ 494 data, data_name, position= self.get_current_data()504 Change title 505 """ 506 data, _, _ = self.get_current_data() 495 507 #Change data's name 496 508 title = self.data_title_tcl.GetValue().lstrip().rstrip() … … 498 510 if data.title != title: 499 511 self._notes += "Change data 's " 500 self._notes += "title from %s to %s \n" %(data.title, str(title))512 self._notes += "title from %s to %s \n" % (data.title, str(title)) 501 513 data.title = title 502 514 if event is not None: 515 event.Skip() 516 503 517 def on_click_browse(self, event): 504 518 """ 505 506 519 Open a file dialog to allow the user to select a given file. 520 Display the loaded data if available. 507 521 """ 508 522 path = self.choose_data_file(location=self._default_save_location) … … 510 524 return 511 525 if self.parent.parent is not None: 512 wx.PostEvent(self.parent.parent, StatusEvent(status="Loading...", info="info",513 type="progress"))526 wx.PostEvent(self.parent.parent, StatusEvent(status="Loading...", 527 info="info", type="progress")) 514 528 515 529 self.done = False … … 526 540 self.reader.queue() 527 541 except: 528 msg = "Data Editor: %s" %(sys.exc_value)542 msg = "Data Editor: %s" % (sys.exc_value) 529 543 load_error(msg) 530 544 return 545 event.Skip() 531 546 532 547 def on_edit(self, event): … … 541 556 if self.collimation_rb.GetValue(): 542 557 self.edit_collimation() 558 event.Skip() 543 559 544 560 def on_click_apply(self, event): 545 561 """ 546 547 """ 548 data, data_name, position= self.get_current_data()562 changes are saved in data object imported to edit 563 """ 564 data, _, _ = self.get_current_data() 549 565 if data is None: 550 566 return … … 552 568 self.on_change_title(event=None) 553 569 #must post event here 570 event.Skip() 554 571 555 572 def on_click_save(self, event): 556 573 """ 557 574 Save change into a file 558 575 """ 559 576 if not self._data: … … 579 596 loader = Loader() 580 597 format = ".xml" 581 if os.path.splitext(mypath)[1].lower() == format:598 if os.path.splitext(mypath)[1].lower() == format: 582 599 loader.save( path, data, format) 583 600 try: … … 586 603 pass 587 604 dlg.Destroy() 605 event.Skip() 588 606 589 607 def on_click_view(self, event): 590 608 """ 591 609 Display data info 592 610 """ 593 611 data, data_name, position = self.get_current_data() … … 598 616 dlg = ConsoleDialog(data=data) 599 617 dlg.ShowModal() 618 event.Skip() 600 619 601 620 def on_click_reset(self, event): … … 605 624 if data is None: 606 625 return 607 self._data[position] = deepcopy(self._reset_data[position])626 self._data[position] = deepcopy(self._reset_data[position]) 608 627 self.set_values() 628 event.Skip() 609 629 610 630 def on_close(self, event): 611 631 """ 612 632 leave data as it is and close 613 633 """ 614 634 self.parent.Close() 635 event.Skip() 615 636 616 637 class DataEditorWindow(wx.Frame): 617 638 def __init__(self, parent, data=None, *args, **kwds): 618 kwds["size"] = (PANEL_WIDTH, PANEL_HEIGTH)639 kwds["size"] = (PANEL_WIDTH, PANEL_HEIGTH) 619 640 wx.Frame.__init__(self, parent, *args, **kwds) 620 641 self.parent = parent … … 628 649 return self.panel.get_data() 629 650 630 if __name__ == "__main__":651 if __name__ == "__main__": 631 652 632 653 app = wx.App() -
calculatorview/perspectives/calculator/detector_editor.py
rad6f597 rb0ab6cb 5 5 from DataLoader.data_info import Detector 6 6 from sans.guiframe.utils import check_float 7 7 8 _BOX_WIDTH = 60 8 9 if sys.platform.count("win32")>0: 9 if sys.platform.count("win32") > 0: 10 10 _STATICBOX_WIDTH = 465 11 11 PANEL_WIDTH = 500 … … 19 19 20 20 class DetectorDialog(wx.Dialog): 21 def __init__(self, parent=None, id=-1, manager=None, detector=None, 22 title="Detector Editor",size=(PANEL_WIDTH, PANEL_HEIGHT)): 21 def __init__(self, parent=None, manager=None, detector=None, 22 title="Detector Editor", 23 size=(PANEL_WIDTH, PANEL_HEIGHT)): 23 24 wx.Dialog.__init__(self, parent=parent, id=id, title=title, size=size) 24 25 try: … … 86 87 self.detector_txt = wx.StaticText(self, -1, detector_hint_txt) 87 88 self.detector_hint_sizer.Add(self.detector_txt, 0, wx.LEFT, 10) 88 self.detector_sizer.AddMany([(self.detector_button_sizer, 0, wx.ALL, 10), 89 self.detector_sizer.AddMany([(self.detector_button_sizer, 0, 90 wx.ALL, 10), 89 91 (self.detector_hint_sizer, 0, wx.ALL, 10)]) 90 92 … … 98 100 #Instrument 99 101 instrument_name_txt = wx.StaticText(self, -1, 'Instrument Name : ') 100 self.instrument_name_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0) 101 self.instrument_sizer.AddMany([(instrument_name_txt, 0, wx.LEFT|wx.RIGHT, 10), 102 (self.instrument_name_tcl, 0, wx.EXPAND)]) 102 self.instrument_name_tcl = wx.TextCtrl(self, -1, 103 size=(_BOX_WIDTH*5, 20), style=0) 104 self.instrument_sizer.AddMany([(instrument_name_txt, 0, 105 wx.LEFT|wx.RIGHT, 10), 106 (self.instrument_name_tcl, 0, wx.EXPAND)]) 103 107 def _layout_distance(self): 104 108 """ … … 106 110 """ 107 111 distance_txt = wx.StaticText(self, -1, 'Sample to Detector Distance : ') 108 self.distance_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 112 self.distance_tcl = wx.TextCtrl(self, -1, 113 size=(_BOX_WIDTH, 20), style=0) 109 114 distance_unit_txt = wx.StaticText(self, -1, 'Unit: ') 110 self.distance_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 115 self.distance_unit_tcl = wx.TextCtrl(self, -1, 116 size=(_BOX_WIDTH, 20), style=0) 111 117 self.distance_sizer.AddMany([(distance_txt, 0, wx.LEFT|wx.RIGHT, 10), 112 118 (self.distance_tcl, 0, wx.RIGHT, 10), … … 121 127 offset_txt = wx.StaticText(self, -1, 'Offset:') 122 128 x_offset_txt = wx.StaticText(self, -1, 'x = ') 123 self.x_offset_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 129 self.x_offset_tcl = wx.TextCtrl(self, -1, 130 size=(_BOX_WIDTH, 20), style=0) 124 131 y_offset_txt = wx.StaticText(self, -1, 'y = ') 125 self.y_offset_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 132 self.y_offset_tcl = wx.TextCtrl(self, -1, 133 size=(_BOX_WIDTH, 20), style=0) 126 134 z_offset_txt = wx.StaticText(self, -1, 'z = ') 127 self.z_offset_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 135 self.z_offset_tcl = wx.TextCtrl(self, -1, 136 size=(_BOX_WIDTH, 20), style=0) 128 137 offset_unit_txt = wx.StaticText(self, -1, 'Unit: ') 129 self.offset_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 138 self.offset_unit_tcl = wx.TextCtrl(self, -1, 139 size=(_BOX_WIDTH, 20), style=0) 130 140 self.offset_sizer.AddMany([(offset_txt, 0, wx.LEFT|wx.RIGHT, 10), 131 141 (x_offset_txt, 0, wx.LEFT, 30), … … 145 155 orientation_txt = wx.StaticText(self, -1, 'Orientation:') 146 156 x_orientation_txt = wx.StaticText(self, -1, 'x = ') 147 self.x_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 157 self.x_orientation_tcl = wx.TextCtrl(self, -1, 158 size=(_BOX_WIDTH, 20), style=0) 148 159 y_orientation_txt = wx.StaticText(self, -1, 'y = ') 149 self.y_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 160 self.y_orientation_tcl = wx.TextCtrl(self, -1, 161 size=(_BOX_WIDTH, 20), style=0) 150 162 z_orientation_txt = wx.StaticText(self, -1, 'z = ') 151 self.z_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 163 self.z_orientation_tcl = wx.TextCtrl(self, -1, 164 size=(_BOX_WIDTH, 20), style=0) 152 165 orientation_unit_txt = wx.StaticText(self, -1, 'Unit: ') 153 self.orientation_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) 154 self.orientation_sizer.AddMany([(orientation_txt, 0, wx.LEFT|wx.RIGHT, 10), 166 self.orientation_unit_tcl = wx.TextCtrl(self, -1, 167 size=(_BOX_WIDTH, 20), style=0) 168 self.orientation_sizer.AddMany([(orientation_txt, 0, 169 wx.LEFT|wx.RIGHT, 10), 155 170 (x_orientation_txt, 0, wx.LEFT, 7), 156 171 (self.x_orientation_tcl, 0, wx.RIGHT, 10), … … 160 175 (self.z_orientation_tcl, 0, wx.RIGHT, 10), 161 176 (orientation_unit_txt, 0, wx.EXPAND), 162 177 (self.orientation_unit_tcl, 0, wx.RIGHT, 10)]) 163 178 164 179 def _layout_beam_center(self): … … 169 184 beam_center_txt = wx.StaticText(self, -1, 'Beam Center:') 170 185 x_beam_center_txt = wx.StaticText(self, -1, 'x = ') 171 self.x_beam_center_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 186 self.x_beam_center_tcl = wx.TextCtrl(self, -1, 187 size=(_BOX_WIDTH, 20), style=0) 172 188 y_beam_center_txt = wx.StaticText(self, -1, 'y = ') 173 self.y_beam_center_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 189 self.y_beam_center_tcl = wx.TextCtrl(self, -1, 190 size=(_BOX_WIDTH, 20), style=0) 174 191 z_beam_center_txt = wx.StaticText(self, -1, 'z = ') 175 self.z_beam_center_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 192 self.z_beam_center_tcl = wx.TextCtrl(self, -1, 193 size=(_BOX_WIDTH, 20), style=0) 176 194 beam_center_unit_txt = wx.StaticText(self, -1, 'Unit: ') 177 self.beam_center_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 195 self.beam_center_unit_tcl = wx.TextCtrl(self, -1, 196 size=(_BOX_WIDTH, 20), style=0) 178 197 self.beam_sizer.AddMany([(beam_center_txt, 0, wx.LEFT|wx.RIGHT, 10), 179 198 (x_beam_center_txt, 0, wx.EXPAND), … … 184 203 (self.z_beam_center_tcl, 0, wx.RIGHT, 10), 185 204 (beam_center_unit_txt, 0, wx.EXPAND), 186 205 (self.beam_center_unit_tcl, 0,wx.RIGHT, 10)]) 187 206 188 207 def _layout_pixel_size(self): … … 193 212 pixel_size_txt = wx.StaticText(self, -1, 'Pixel Size:') 194 213 x_pixel_size_txt = wx.StaticText(self, -1, 'x = ') 195 self.x_pixel_size_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 214 self.x_pixel_size_tcl = wx.TextCtrl(self, -1, 215 size=(_BOX_WIDTH,20), style=0) 196 216 y_pixel_size_txt = wx.StaticText(self, -1, 'y = ') 197 self.y_pixel_size_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 217 self.y_pixel_size_tcl = wx.TextCtrl(self, -1, 218 size=(_BOX_WIDTH,20), style=0) 198 219 z_pixel_size_txt = wx.StaticText(self, -1, 'z = ') 199 self.z_pixel_size_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 220 self.z_pixel_size_tcl = wx.TextCtrl(self, -1, 221 size=(_BOX_WIDTH,20), style=0) 200 222 pixel_size_unit_txt = wx.StaticText(self, -1, 'Unit: ') 201 self.pixel_size_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 223 self.pixel_size_unit_tcl = wx.TextCtrl(self, -1, 224 size=(_BOX_WIDTH,20), style=0) 202 225 self.pixel_sizer.AddMany([(pixel_size_txt, 0, wx.LEFT|wx.RIGHT, 10), 203 226 (x_pixel_size_txt, 0, wx.LEFT, 17), … … 208 231 (self.z_pixel_size_tcl, 0, wx.RIGHT, 10), 209 232 (pixel_size_unit_txt, 0, wx.EXPAND), 210 233 (self.pixel_size_unit_tcl, 0, wx.RIGHT, 10)]) 211 234 212 235 def _layout_slit_length(self): … … 216 239 #slit length 217 240 slit_length_txt = wx.StaticText(self, -1, 'Slit Length: ') 218 self.slit_length_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 241 self.slit_length_tcl = wx.TextCtrl(self, -1, 242 size=(_BOX_WIDTH,20), style=0) 219 243 slit_length_unit_txt = wx.StaticText(self, -1, 'Unit: ') 220 self.slit_length_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 244 self.slit_length_unit_tcl = wx.TextCtrl(self, -1, 245 size=(_BOX_WIDTH,20), style=0) 221 246 self.slit_sizer.AddMany([(slit_length_txt, 0, wx.LEFT, 10), 222 247 (self.slit_length_tcl, 0, wx.RIGHT, 10), 223 248 (slit_length_unit_txt, 0, wx.EXPAND), 224 249 (self.slit_length_unit_tcl, 0,wx.RIGHT, 10)]) 225 250 226 251 def _layout_button(self): … … 413 438 self.offset_unit_tcl.SetValue(str(detector.offset_unit)) 414 439 #Orientation 415 x, y, z = detector.orientation.x, detector.orientation.y, detector.orientation.z 440 x, y = detector.orientation.x, detector.orientation.y 441 z = detector.orientation.z 416 442 self.x_orientation_tcl.SetValue(str(x)) 417 443 self.y_orientation_tcl.SetValue(str(y)) … … 419 445 self.orientation_unit_tcl.SetValue(str(detector.orientation_unit)) 420 446 #Beam center 421 x, y, z = detector.beam_center.x, detector.beam_center.y, detector.beam_center.z 447 x, y = detector.beam_center.x, detector.beam_center.y 448 z = detector.beam_center.z 422 449 self.x_beam_center_tcl.SetValue(str(x)) 423 450 self.y_beam_center_tcl.SetValue(str(y)) … … 425 452 self.beam_center_unit_tcl.SetValue(str(detector.beam_center_unit)) 426 453 #Pixel size 427 x, y, z = detector.pixel_size.x, detector.pixel_size.y, detector.pixel_size.z 454 x, y = detector.pixel_size.x, detector.pixel_size.y 455 z = detector.pixel_size.z 428 456 self.x_pixel_size_tcl.SetValue(str(x)) 429 457 self.y_pixel_size_tcl.SetValue(str(y)) … … 485 513 detector.distance = float(distance) 486 514 else: 487 self._notes += "Error: Expected a float for the distance won't changes " 515 self._notes += "Error: Expected a float for " 516 self._notes += " the distance won't changes " 488 517 self._notes += "%s to %s"%(detector.distance, distance) 489 518 #change the distance unit … … 513 542 if detector.offset.x != float(x_offset): 514 543 self._notes += "Change x of offset from" 515 self._notes += " %s to %s \n"%(detector.offset.x, x_offset) 544 self._notes += " %s to %s \n" % (detector.offset.x, 545 x_offset) 516 546 detector.offset.x = float(x_offset) 517 547 else: 518 548 self._notes += "Error: Expected a float for the offset 's x " 519 549 self._notes += "won't changes x offset" 520 self._notes += " from %s to %s" %(detector.offset.x, x_offset)550 self._notes += " from %s to %s" % (detector.offset.x, x_offset) 521 551 #Change y coordinate 522 552 y_offset = self.y_offset_tcl.GetValue().lstrip().rstrip() … … 533 563 self._notes += "Error: Expected a float for the offset 's y " 534 564 self._notes += "won't changes y " 535 self._notes += "offset from %s to %s"%(detector.offset.y \536 ,y_offset)565 self._notes += "offset from %s to %s"%(detector.offset.y, 566 y_offset) 537 567 #Change z coordinate 538 568 z_offset = self.z_offset_tcl.GetValue().lstrip().rstrip() … … 543 573 if check_float(self.z_offset_tcl): 544 574 if detector.offset.z != float(z_offset): 545 self._notes += "Change z of "546 self._notes += " offset from %s to %s \n"%(detector.offset.z,\575 self._notes += "Change z of offset from" 576 self._notes += " %s to %s \n" % (detector.offset.z, 547 577 z_offset) 548 578 detector.offset.z = float(z_offset) … … 550 580 self._notes += "Error: Expected a float for the offset 's x " 551 581 self._notes += "won't changes z" 552 self._notes += "offset from %s to %s"%(detector.offset.z, z_offset) 582 self._notes += "offset from %s to %s" % (detector.offset.z, 583 z_offset) 553 584 #change the offset unit 554 585 unit = self.offset_unit_tcl.GetValue().lstrip().rstrip() 555 586 if detector.offset_unit != unit: 556 587 self._notes += " Change Offset's" 557 self._notes += "unit from %s to %s" %(detector.offset_unit, unit)588 self._notes += "unit from %s to %s" % (detector.offset_unit, unit) 558 589 559 590 self.detector_cbox.SetString(position, str(detector.name)) … … 577 608 if detector.orientation.x != float(x_orientation): 578 609 self._notes += "Change x of orientation from " 579 self._notes += "%s to %s \n"%(detector.orientation.x, x_orientation) 610 self._notes += "%s to %s \n" % (detector.orientation.x, 611 x_orientation) 580 612 detector.orientation.x = float(x_orientation) 581 613 else: 582 self._notes += "Error: Expected a float for the orientation 's x " 583 self._notes += "won't changes x orientation from " 584 self._notes += "%s to %s"%(detector.orientation.x, x_orientation) 614 self._notes += "Error: Expected a float for the orientation " 615 self._notes += "'s x won't changes x orientation from " 616 self._notes += "%s to %s" % (detector.orientation.x, 617 x_orientation) 585 618 #Change y coordinate 586 619 y_orientation = self.y_orientation_tcl.GetValue().lstrip().rstrip() … … 592 625 if detector.orientation.y != float(y_orientation): 593 626 self._notes += "Change y of orientation from " 594 self._notes += "%s to %s \n"%(detector.orientation.y, y_orientation) 627 self._notes += "%s to %s \n" % (detector.orientation.y, 628 y_orientation) 595 629 detector.orientation.y = float(y_orientation) 596 630 else: 597 self._notes += "Error: Expected a float for the orientation's y " 598 self._notes += "won't changes y orientation from " 599 self._notes += "%s to %s"%(detector.orientation.y, y_orientation) 631 self._notes += "Error: Expected a float for the orientation's " 632 self._notes += " y won't changes y orientation from " 633 self._notes += "%s to %s" % (detector.orientation.y, 634 y_orientation) 600 635 #Change z coordinate 601 636 z_orientation = self.z_orientation_tcl.GetValue().lstrip().rstrip() … … 607 642 if detector.orientation.z != float(z_orientation): 608 643 self._notes += "Change z of offset from " 609 self._notes += "%s to %s \n"%(detector.orientation.z, z_orientation) 644 self._notes += "%s to %s \n"%(detector.orientation.z, 645 z_orientation) 610 646 detector.orientation.z = float(z_orientation) 611 647 else: 612 self._notes += "Error: Expected a float for the orientation 's x " 613 self._notes += "won't changes z orientation from " 614 self._notes += "%s to %s"%(detector.orientation.z, z_orientation) 648 self._notes += "Error: Expected a float for the orientation 's" 649 self._notes += " x won't changes z orientation from " 650 self._notes += "%s to %s" % (detector.orientation.z, 651 z_orientation) 615 652 #change the orientation unit 616 653 unit = self.orientation_unit_tcl.GetValue().lstrip().rstrip() … … 640 677 if detector.beam_center.x != float(x_beam_center): 641 678 self._notes += "Change x of offset from " 642 self._notes += "%s to %s \n"%(detector.beam_center.x, x_beam_center) 679 self._notes += "%s to %s \n" % (detector.beam_center.x, 680 x_beam_center) 643 681 detector.beam_center.x = float(x_beam_center) 644 682 else: 645 self._notes += "Error: Expected a float for the beam center 's x " 646 self._notes += "won't changes x beam center from " 647 self._notes += "%s to %s"%(detector.beam_center.x, x_beam_center) 683 self._notes += "Error: Expected a float for the beam " 684 self._notes += "center 's x won't changes x beam center from " 685 self._notes += "%s to %s" % (detector.beam_center.x, 686 x_beam_center) 648 687 #Change y coordinate 649 688 y_beam_center = self.y_beam_center_tcl.GetValue().lstrip().rstrip() … … 655 694 if detector.beam_center.y != float(y_beam_center): 656 695 self._notes += "Change y of beam center from " 657 self._notes += "%s to %s \n"%(detector.beam_center.y, y_beam_center) 696 self._notes += "%s to %s \n" % (detector.beam_center.y, 697 y_beam_center) 658 698 detector.beam_center.y = float(y_beam_center) 659 699 else: 660 self._notes += "Error: Expected a float for the beam center 's y " 661 self._notes += "won't changes y beam center from " 662 self._notes += "%s to %s"%(detector.beam_center.y, y_beam_center) 700 self._notes += "Error: Expected a float for the beam " 701 self._notes += "center 's y won't changes y beam center from " 702 self._notes += "%s to %s" % (detector.beam_center.y, 703 y_beam_center) 663 704 #Change z coordinate 664 705 z_beam_center = self.z_beam_center_tcl.GetValue().lstrip().rstrip() … … 670 711 if detector.beam_center.z != float(z_beam_center): 671 712 self._notes += "Change z of beam center from " 672 self._notes += "%s to %s \n"%(detector.beam_center.z, z_beam_center) 713 self._notes += "%s to %s \n" % (detector.beam_center.z, 714 z_beam_center) 673 715 detector.beam_center.z = float(z_beam_center) 674 716 else: 675 717 self._notes += "Error: Expected a float for the offset 's x " 676 718 self._notes += "won't changes z beam center from " 677 self._notes += "%s to %s"%(detector.beam_center.z, z_beam_center) 719 self._notes += "%s to %s"%(detector.beam_center.z, 720 z_beam_center) 678 721 #change the beam center unit 679 722 unit = self.beam_center_unit_tcl.GetValue().lstrip().rstrip() … … 701 744 if detector.pixel_size.x != float(x_pixel_size) : 702 745 self._notes += "Change x of pixel size from " 703 self._notes += "%s to %s \n"%(detector.pixel_size.x, x_pixel_size) 746 self._notes += "%s to %s \n"%(detector.pixel_size.x, 747 x_pixel_size) 704 748 detector.pixel_size.x = float(x_pixel_size) 705 749 else: 706 self._notes += "Error: Expected a float for the pixel size 's x " 707 self._notes += "won't changes x pixel size from " 708 self._notes += "%s to %s"%(detector.pixel_size.x, x_pixel_size) 750 self._notes += "Error: Expected a float for the pixel" 751 self._notes += " size 's x won't changes x pixel size from " 752 self._notes += "%s to %s" % (detector.pixel_size.x, 753 x_pixel_size) 709 754 #Change y coordinate 710 755 y_pixel_size = self.y_pixel_size_tcl.GetValue().lstrip().rstrip() … … 716 761 if detector.pixel_size.y != float(y_pixel_size): 717 762 self._notes += "Change y of pixel size from " 718 self._notes += "%s to %s \n"%(detector.pixel_size.y, y_pixel_size) 763 self._notes += "%s to %s \n"%(detector.pixel_size.y, 764 y_pixel_size) 719 765 detector.pixel_size.y = float(y_pixel_size) 720 766 else: 721 self._notes += "Error: Expected a float for the pixel size's y " 722 self._notes += "won't changes y pixel size from " 723 self._notes += "%s to %s"%(detector.pixel_size.y, y_pixel_size) 767 self._notes += "Error: Expected a float for the pixel " 768 self._notes += "size's y won't changes y pixel size from " 769 self._notes += "%s to %s" % (detector.pixel_size.y, 770 y_pixel_size) 724 771 #Change z coordinate 725 772 z_pixel_size = self.z_pixel_size_tcl.GetValue().lstrip().rstrip() … … 731 778 if detector.pixel_size.z != float(z_pixel_size): 732 779 self._notes += "Change z of pixel size from " 733 self._notes += "%s to %s \n"%(detector.pixel_size.z, z_pixel_size) 780 self._notes += "%s to %s \n"%(detector.pixel_size.z, 781 z_pixel_size) 734 782 detector.pixel_size.z = float(z_pixel_size) 735 783 else: … … 763 811 if detector.slit_length != float(slit_length): 764 812 self._notes += " Change slit length from" 765 self._notes += " %s to %s \n"%(detector.slit_length, slit_length) 813 self._notes += " %s to %s \n"%(detector.slit_length, 814 slit_length) 766 815 detector.slit_length = float(slit_length) 767 816 else: 768 self._notes += "Error: Expected a float for the slit length won't changes " 769 self._notes += "%s to %s"%(detector.slit_length, slit_length) 817 self._notes += "Error: Expected a float" 818 self._notes += " for the slit length won't changes " 819 self._notes += "%s to %s" % (detector.slit_length, slit_length) 770 820 #change the distance unit 771 821 unit = self.slit_length_unit_tcl.GetValue().lstrip().rstrip() … … 804 854 if __name__ == "__main__": 805 855 app = wx.App() 806 detector = Detector()807 dlg = DetectorDialog(detector=[ detector])856 test_detector = Detector() 857 dlg = DetectorDialog(detector=[test_detector]) 808 858 dlg.ShowModal() 809 859 app.MainLoop() -
calculatorview/perspectives/calculator/help_panel.py
r74b1770 rb0ab6cb 1 1 #!/usr/bin/python 2 """ 3 Help panel for calculator 4 """ 5 import os 2 6 import wx 3 7 import wx.html as html 4 8 from wx.lib.splitter import MultiSplitterWindow 5 9 import sans.perspectives.calculator as calculator 6 import os7 def help():8 """9 Provide general online help text10 Future work: extend this function to allow topic selection11 """12 info_txt = "The inversion approach is based on Moore, J. Appl. Cryst. (1980) 13, 168-175.\n\n"13 info_txt += "P(r) is set to be equal to an expansion of base functions of the type "14 info_txt += "phi_n(r) = 2*r*sin(pi*n*r/D_max). The coefficient of each base functions "15 info_txt += "in the expansion is found by performing a least square fit with the "16 info_txt += "following fit function:\n\n"17 info_txt += "chi**2 = sum_i[ I_meas(q_i) - I_th(q_i) ]**2/error**2 + Reg_term\n\n"18 info_txt += "where I_meas(q) is the measured scattering intensity and I_th(q) is "19 info_txt += "the prediction from the Fourier transform of the P(r) expansion. "20 info_txt += "The Reg_term term is a regularization term set to the second derivative "21 info_txt += "d**2P(r)/dr**2 integrated over r. It is used to produce a smooth P(r) output.\n\n"22 info_txt += "The following are user inputs:\n\n"23 info_txt += " - Number of terms: the number of base functions in the P(r) expansion.\n\n"24 info_txt += " - Regularization constant: a multiplicative constant to set the size of "25 info_txt += "the regularization term.\n\n"26 info_txt += " - Maximum distance: the maximum distance between any two points in the system.\n"27 28 return info_txt29 30 class HelpDialog(wx.Dialog):31 def __init__(self, parent, id):32 33 wx.Dialog.__init__(self, parent, id, size=(400, 420))34 self.SetTitle("Calculator help")35 36 37 vbox = wx.BoxSizer(wx.VERTICAL)38 39 explanation = help()40 41 label_explain = wx.StaticText(self, -1, explanation, size=(350,320))42 43 vbox.Add(label_explain, 0, wx.ALL|wx.EXPAND, 15)44 10 45 11 46 static_line = wx.StaticLine(self, -1)47 vbox.Add(static_line, 0, wx.EXPAND, 0)48 49 button_OK = wx.Button(self, wx.ID_OK, "OK")50 51 sizer_button = wx.BoxSizer(wx.HORIZONTAL)52 sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)53 sizer_button.Add(button_OK, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)54 vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10)55 56 self.SetSizer(vbox)57 self.SetAutoLayout(True)58 59 self.Layout()60 self.Centre()61 62 12 class HelpWindow(wx.Frame): 63 def __init__(self, parent, id, title= 'HelpWindow', pageToOpen=None): 64 wx.Frame.__init__(self, parent, id, title, size=(700, 450)) 13 """ 14 """ 15 def __init__(self, parent, title='HelpWindow', pageToOpen=None): 16 wx.Frame.__init__(self, parent, title, size=(700, 450)) 65 17 """ 66 18 contains help info 67 19 """ 68 69 20 splitter = MultiSplitterWindow(self, style=wx.SP_LIVE_UPDATE) 70 21 rpanel = wx.Panel(splitter, -1) 71 lpanel = wx.Panel(splitter, -1, style=wx.BORDER_SUNKEN)22 lpanel = wx.Panel(splitter, -1, style=wx.BORDER_SUNKEN) 72 23 73 24 vbox = wx.BoxSizer(wx.VERTICAL) … … 84 35 vbox.Add(header, 0, wx.EXPAND) 85 36 86 vboxl = wx.BoxSizer(wx.VERTICAL)37 vboxl = wx.BoxSizer(wx.VERTICAL) 87 38 headerl = wx.Panel(lpanel, -1, size=(-1, 20)) 88 39 … … 103 54 self.path = calculator.get_data_path(media='media') 104 55 105 106 page1="""<html> 56 page1 = """<html> 107 57 <body> 108 58 <p>Select topic on Menu</p> … … 110 60 </html>""" 111 61 self.rhelp.SetPage(page1) 112 page ="""<html>62 page = """<html> 113 63 <body> 114 64 <ul> 115 <li><a href ="sld_calculator_help.html" target ="showframe">SLD Calculator</a><br></li> 116 <li><a href ="slit_calculator_help.html" target ="showframe">Slit Size Calculator</a><br></li> 117 <li><a href ="kiessig_calculator_help.html" target ="showframe">Kiessig Thickness Calculator</a><br></li> 65 <li><a href ="sld_calculator_help.html" 66 target ="showframe">SLD Calculator</a><br></li> 67 <li><a href ="slit_calculator_help.html" 68 target ="showframe">Slit Size Calculator</a><br></li> 69 <li><a href ="kiessig_calculator_help.html" 70 target ="showframe">Kiessig Thickness Calculator</a><br></li> 118 71 </ul> 119 72 </body> … … 121 74 122 75 self.lhelp.SetPage(page) 123 self.lhelp.Bind(wx.html.EVT_HTML_LINK_CLICKED, self.OnLinkClicked)76 self.lhelp.Bind(wx.html.EVT_HTML_LINK_CLICKED, self.OnLinkClicked) 124 77 125 vbox.Add(self.rhelp, 1, wx.EXPAND)78 vbox.Add(self.rhelp, 1, wx.EXPAND) 126 79 vboxl.Add(self.lhelp, 1, wx.EXPAND) 127 80 rpanel.SetSizer(vbox) … … 130 83 131 84 vbox1 = wx.BoxSizer(wx.HORIZONTAL) 132 vbox1.Add(splitter, 1,wx.EXPAND)85 vbox1.Add(splitter, 1, wx.EXPAND) 133 86 splitter.AppendWindow(lpanel, 200) 134 87 splitter.AppendWindow(rpanel) … … 138 91 self.Show(True) 139 92 140 141 93 def OnLinkClicked(self, event): 142 94 """ 143 95 Function to diplay html page related to the hyperlinktext selected 144 96 """ 145 146 link= event.GetLinkInfo().GetHref() 147 link = os.path.join(self.path,link) 97 link = event.GetLinkInfo().GetHref() 98 link = os.path.join(self.path, link) 148 99 self.rhelp.LoadPage(link) 100 149 101 150 102 class ViewApp(wx.App): … … 153 105 frame.Show(True) 154 106 self.SetTopWindow(frame) 155 156 107 return True 157 108 158 159 109 if __name__ == "__main__": 160 110 app = ViewApp(0) -
calculatorview/perspectives/calculator/kiessig_calculator_panel.py
r74b1770 rb0ab6cb 11 11 import wx 12 12 import sys 13 import os13 #import os 14 14 15 from sans.guicomm.events import StatusEvent15 #from sans.guicomm.events import StatusEvent 16 16 from sans.calculator.kiessig_calculator import KiessigThicknessCalculator 17 from calculator_widgets import OutputTextCtrl, InputTextCtrl 17 from calculator_widgets import OutputTextCtrl 18 from calculator_widgets import InputTextCtrl 18 19 19 20 _BOX_WIDTH = 77 … … 39 40 CENTER_PANE = True 40 41 41 def __init__(self, parent, id=-1,*args, **kwds):42 wx.Panel.__init__(self, parent, id=id,*args, **kwds)42 def __init__(self, parent, *args, **kwds): 43 wx.Panel.__init__(self, parent, *args, **kwds) 43 44 #Font size 44 45 self.SetWindowVariant(variant=FONT_VARIANT) … … 46 47 self.parent = parent 47 48 self.kiessig = KiessigThicknessCalculator() 49 #layout attribute 50 self.hint_sizer = None 48 51 self._do_layout() 49 52 … … 91 94 """ 92 95 thick_unit = '['+self.kiessig.get_thickness_unit() +']' 93 thickness_size_txt = wx.StaticText(self, -1, 'Thickness (or Diameter): ') 96 thickness_size_txt = wx.StaticText(self, -1, 97 'Thickness (or Diameter): ') 94 98 self.thickness_size_tcl = OutputTextCtrl(self, -1, 95 99 size=(_BOX_WIDTH,-1)) … … 106 110 Fill the sizer containing hint 107 111 """ 108 hint_msg = "This tool is to approximately estimate the thickness of a layer" 112 hint_msg = "This tool is to approximately estimate " 113 hint_msg += "the thickness of a layer" 109 114 hint_msg += " or the diameter of particles\n " 110 115 hint_msg += "from the Kiessig fringe width in SANS/NR data." … … 148 153 """ 149 154 self.parent.Close() 155 if event is not None: 156 event.Skip() 150 157 151 158 def on_compute(self, event): … … 164 171 self.thickness_size_tcl.SetValue(str(thickness)) 165 172 166 def format_number(self, value=None):173 def format_number(self, value=None): 167 174 """ 168 175 Return a float in a standardized, human-readable formatted string … … 174 181 return output 175 182 176 output = "%-7.4g" % value183 output = "%-7.4g" % value 177 184 return output.lstrip().rstrip() 178 185 179 186 class 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)) 187 def __init__(self, parent=None, title="Kiessig Thickness Calculator"): 188 wx.Frame.__init__(self, parent, title, 189 size=(PANEL_WIDTH,PANEL_HEIGHT)) 182 190 self.parent = parent 183 191 self.panel = KiessigThicknessCalculatorPanel(parent=self) -
calculatorview/perspectives/calculator/sample_editor.py
rad6f597 rb0ab6cb 6 6 7 7 _BOX_WIDTH = 60 8 if sys.platform.count("win32") >0:8 if sys.platform.count("win32") > 0: 9 9 _STATICBOX_WIDTH = 450 10 10 PANEL_WIDTH = 500 … … 55 55 ## Short name for sample [string] 56 56 sample_name_txt = wx.StaticText(self, -1, 'Sample Name : ') 57 self.sample_name_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0) 57 self.sample_name_tcl = wx.TextCtrl(self, -1, 58 size=(_BOX_WIDTH*5, 20), style=0) 58 59 self.name_sizer.AddMany([(sample_name_txt, 0, wx.LEFT|wx.RIGHT, 10), 59 60 (self.sample_name_tcl, 0, wx.EXPAND)]) … … 74 75 ## Thickness [float] [mm] 75 76 thickness_txt = wx.StaticText(self, -1, 'Thickness:') 76 self.thickness_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) 77 self.thickness_tcl = wx.TextCtrl(self, -1, 78 size=(_BOX_WIDTH, 20),style=0) 77 79 thickness_unit_txt = wx.StaticText(self, -1, 'Unit: ') 78 80 self.thickness_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), … … 80 82 self.thickness_sizer.AddMany([(thickness_txt, 0, wx.LEFT|wx.RIGHT, 10), 81 83 (self.thickness_tcl, 0, wx.LEFT, 25), 82 84 (thickness_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), 83 85 (self.thickness_unit_tcl, 0, wx.EXPAND)]) 84 86 def _layout_transmission(self): … … 89 91 transmission = None 90 92 transmission_txt = wx.StaticText(self, -1, 'Transmission:') 91 self.transmission_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) 92 self.transmission_sizer.AddMany([(transmission_txt, 0, wx.LEFT|wx.RIGHT, 10), 93 self.transmission_tcl = wx.TextCtrl(self, -1, 94 size=(_BOX_WIDTH, 20),style=0) 95 self.transmission_sizer.AddMany([(transmission_txt, 96 0, wx.LEFT|wx.RIGHT, 10), 93 97 (self.transmission_tcl, 0, wx.LEFT, 12)]) 94 98 … … 99 103 ## Temperature [float] [C] 100 104 temperature_txt = wx.StaticText(self, -1, 'Temperature:') 101 self.temperature_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 105 self.temperature_tcl = wx.TextCtrl(self, -1, 106 size=(_BOX_WIDTH, 20), style=0) 102 107 temperature_unit_txt = wx.StaticText(self, -1, 'Unit: ') 103 108 self.temperature_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), 104 109 style=0) 105 self.temperature_sizer.AddMany([(temperature_txt, 0, wx.LEFT|wx.RIGHT, 10), 110 self.temperature_sizer.AddMany([(temperature_txt, 0, 111 wx.LEFT|wx.RIGHT, 10), 106 112 (self.temperature_tcl, 0, wx.LEFT, 10), 107 113 (temperature_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), 108 114 (self.temperature_unit_tcl, 0, wx.EXPAND)]) 109 115 … … 115 121 position_txt = wx.StaticText(self, -1, 'Position:') 116 122 x_position_txt = wx.StaticText(self, -1, 'x = ') 117 self.x_position_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 123 self.x_position_tcl = wx.TextCtrl(self, -1, 124 size=(_BOX_WIDTH,20), style=0) 118 125 y_position_txt = wx.StaticText(self, -1, 'y = ') 119 self.y_position_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 126 self.y_position_tcl = wx.TextCtrl(self, -1, 127 size=(_BOX_WIDTH,20), style=0) 120 128 z_position_txt = wx.StaticText(self, -1, 'z = ') 121 self.z_position_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 129 self.z_position_tcl = wx.TextCtrl(self, -1, 130 size=(_BOX_WIDTH,20), style=0) 122 131 position_unit_txt = wx.StaticText(self, -1, 'Unit: ') 123 self.position_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 132 self.position_unit_tcl = wx.TextCtrl(self, -1, 133 size=(_BOX_WIDTH,20), style=0) 124 134 self.position_sizer.AddMany([(position_txt, 0, wx.LEFT|wx.RIGHT, 10), 125 135 (x_position_txt, 0, wx.LEFT, 14), … … 138 148 orientation_txt = wx.StaticText(self, -1, 'Orientation:') 139 149 x_orientation_txt = wx.StaticText(self, -1, 'x = ') 140 self.x_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 150 self.x_orientation_tcl = wx.TextCtrl(self, -1, 151 size=(_BOX_WIDTH,20), style=0) 141 152 y_orientation_txt = wx.StaticText(self, -1, 'y = ') 142 self.y_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 153 self.y_orientation_tcl = wx.TextCtrl(self, -1, 154 size=(_BOX_WIDTH,20), style=0) 143 155 z_orientation_txt = wx.StaticText(self, -1, 'z = ') 144 self.z_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 156 self.z_orientation_tcl = wx.TextCtrl(self, -1, 157 size=(_BOX_WIDTH,20), style=0) 145 158 orientation_unit_txt = wx.StaticText(self, -1, 'Unit: ') 146 self.orientation_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 147 self.orientation_sizer.AddMany([(orientation_txt, 0, wx.LEFT|wx.RIGHT, 10), 159 self.orientation_unit_tcl = wx.TextCtrl(self, -1, 160 size=(_BOX_WIDTH,20), style=0) 161 self.orientation_sizer.AddMany([(orientation_txt, 0, 162 wx.LEFT|wx.RIGHT, 10), 148 163 (x_orientation_txt, 0, wx.LEFT, 0), 149 164 (self.x_orientation_tcl, 0, wx.RIGHT, 10), … … 153 168 (self.z_orientation_tcl, 0, wx.RIGHT, 10), 154 169 (orientation_unit_txt, 0, wx.EXPAND), 155 170 (self.orientation_unit_tcl, 0, wx.RIGHT, 10)]) 156 171 157 172 def _layout_details(self): … … 275 290 self.position_unit_tcl.SetValue(str(sample.position_unit)) 276 291 #orientation 277 x, y, z = sample.orientation.x, sample.orientation.y , sample.orientation.z 292 x, y = sample.orientation.x, sample.orientation.y 293 z = sample.orientation.z 278 294 self.x_orientation_tcl.SetValue(str(x)) 279 295 self.y_orientation_tcl.SetValue(str(y)) … … 347 363 if self._sample.transmission != transmission: 348 364 self._notes += " Change transmission from" 349 self._notes += " %s to %s \n"%(self._sample.transmission, transmission) 365 self._notes += " %s to %s \n" % (self._sample.transmission, 366 transmission) 350 367 self._sample.transmission = transmission 351 368 … … 378 395 if self._sample.position.x != float(x_position) : 379 396 self._notes += "Change x of position from " 380 self._notes += "%s to %s \n"%(self._sample.position.x, x_position) 397 self._notes += "%s to %s \n" % (self._sample.position.x, 398 x_position) 381 399 self._sample.position.x = float(x_position) 382 400 else: … … 393 411 if self._sample.position.y != float(y_position): 394 412 self._notes += "Change y of position from " 395 self._notes += "%s to %s \n"%(self._sample.position.y, y_position) 413 self._notes += "%s to %s \n" % (self._sample.position.y, 414 y_position) 396 415 self._sample.position.y = float(y_position) 397 416 else: … … 408 427 if self._sample.position.z != float(z_position): 409 428 self._notes += "Change z of position from " 410 self._notes += "%s to %s \n"%(self._sample.position.z, z_position) 429 self._notes += "%s to %s \n" % (self._sample.position.z, 430 z_position) 411 431 self._sample.position.z = float(z_position) 412 432 else: … … 438 458 self._notes += "Error: Expected a float for orientation 's x " 439 459 self._notes += "won't changes x orientation from " 440 self._notes += "%s to %s"%(self._sample.orientation.x, x_orientation) 460 self._notes += "%s to %s" % (self._sample.orientation.x, 461 x_orientation) 441 462 #Change y coordinate 442 463 y_orientation = self.y_orientation_tcl.GetValue().lstrip().rstrip() … … 448 469 if self._sample.orientation.y != float(y_orientation): 449 470 self._notes += "Change y of orientation from " 450 self._notes += "%s to %s \n"%(self._sample.orientation.y, y_orientation) 471 self._notes += "%s to %s \n" % (self._sample.orientation.y, 472 y_orientation) 451 473 self._sample.orientation.y = float(y_orientation) 452 474 else: 453 475 self._notes += "Error: Expected a float for orientation's y " 454 476 self._notes += "won't changes y orientation from " 455 self._notes += "%s to %s"%(self._sample.orientation.y, y_orientation) 477 self._notes += "%s to %s" % (self._sample.orientation.y, 478 y_orientation) 456 479 #Change z coordinate 457 480 z_orientation = self.z_orientation_tcl.GetValue().lstrip().rstrip() … … 463 486 if self._sample.orientation.z != float(z_orientation): 464 487 self._notes += "Change z of orientation from " 465 self._notes += "%s to %s \n"%(self._sample.orientation.z, z_orientation) 466 self._sample.orientation.z = float(z_orientation) 488 self._notes += "%s to %s \n" % (self._sample.orientation.z, 489 z_orientation) 490 self._sample.orientation.z = float(z_orientation) 467 491 else: 468 492 self._notes += "Error: Expected a float for orientation 's x " 469 493 self._notes += "won't changes z orientation from " 470 self._notes += "%s to %s"%(self._sample.orientation.z, z_orientation) 494 self._notes += "%s to %s" % (self._sample.orientation.z, 495 z_orientation) 471 496 #change the beam center unit 472 497 unit = self.orientation_unit_tcl.GetValue().lstrip().rstrip() … … 505 530 if self.manager is not None: 506 531 self.manager.set_sample(self._sample) 507 532 if event is not None: 533 event.Skip() 534 508 535 def on_click_cancel(self, event): 509 536 """ … … 514 541 if self.manager is not None: 515 542 self.manager.set_sample(self._sample, self._notes) 543 if event is not None: 544 event.Skip() 516 545 517 if __name__ =="__main__": 518 519 app = wx.App() 546 if __name__ == "__main__": 547 app = wx.App() 520 548 from DataLoader.data_info import Sample 521 549 sample = Sample() -
calculatorview/perspectives/calculator/sld_panel.py
r855546d rb0ab6cb 1 1 """ 2 3 @author: Gervaise B. Alina 2 This module provide GUI for the neutron scattering length density calculator 3 4 4 """ 5 5 … … 8 8 import sys 9 9 10 from sans.guiframe.utils import format_number, check_float 10 from sans.guiframe.utils import format_number 11 from sans.guiframe.utils import check_float 11 12 from sans.guicomm.events import StatusEvent 12 13 13 14 # the calculator default value for wavelength is 6 14 import periodictable15 #import periodictable 15 16 from periodictable import formula 16 from periodictable.xsf import xray_energy, xray_sld_from_atoms 17 from periodictable.constants import avogadro_number 18 from periodictable.nsf import neutron_scattering 17 from periodictable.xsf import xray_energy 18 from periodictable.xsf import xray_sld_from_atoms 19 #rom periodictable.constants import avogadro_number 20 from periodictable.nsf import neutron_scattering 19 21 20 22 WAVELENGTH = 6.0 … … 24 26 25 27 #SLD panel size 26 if sys.platform.count("win32") >0:28 if sys.platform.count("win32") > 0: 27 29 _STATICBOX_WIDTH = 350 28 30 PANEL_SIZE = 400 … … 35 37 class SldPanel(wx.Panel): 36 38 """ 37 39 Provides the SLD calculator GUI. 38 40 """ 39 41 ## Internal nickname for the window, used by the AUI manager … … 43 45 ## Flag to tell the AUI manager to put this panel in the center pane 44 46 CENTER_PANE = True 45 def __init__(self, parent, base=None, id=-1): 46 wx.Panel.__init__(self, parent, id = id) 47 48 def __init__(self, parent, base=None): 49 """ 50 """ 51 wx.Panel.__init__(self, parent) 47 52 #Font size 48 53 self.SetWindowVariant(variant=FONT_VARIANT) … … 50 55 self.base = base 51 56 self.wavelength = WAVELENGTH 57 #layout attribute 58 self.compound_ctl = None 59 self.density_ctl = None 60 self.wavelength_ctl = None 61 self.neutron_sld_reel_ctl = None 62 self.neutron_sld_im_ctl = None 63 self.mo_ka_sld_reel_ctl = None 64 self.mo_ka_sld_im_ctl = None 65 self.cu_ka_sld_reel_ctl = None 66 self.cu_ka_sld_im_ctl = None 67 self.neutron_abs_ctl = None 68 self.neutron_inc_ctl = None 69 self.neutron_length_ctl = None 52 70 #Draw the panel 53 71 self._do_layout() … … 57 75 def _do_layout(self): 58 76 """ 59 77 Draw window content 60 78 """ 61 79 unit_a = '[A]' 62 80 unit_density = '[g/cm^(3)]' 63 81 unit_sld = '[1/A^(2)]' 64 unit_cm1 = '[1/cm]'65 unit_cm = '[cm]'66 sizer_input = wx.GridBagSizer(5, 5)67 sizer_output = wx.GridBagSizer(5, 5)82 unit_cm1 = '[1/cm]' 83 unit_cm = '[cm]' 84 sizer_input = wx.GridBagSizer(5, 5) 85 sizer_output = wx.GridBagSizer(5, 5) 68 86 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 69 87 sizer1 = wx.BoxSizer(wx.HORIZONTAL) … … 73 91 inputbox = wx.StaticBox(self, -1, "Input") 74 92 boxsizer1 = wx.StaticBoxSizer(inputbox, wx.VERTICAL) 75 boxsizer1.SetMinSize((_STATICBOX_WIDTH, -1))93 boxsizer1.SetMinSize((_STATICBOX_WIDTH, -1)) 76 94 77 95 compound_txt = wx.StaticText(self, -1, 'Compound ') 78 self.compound_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1))96 self.compound_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 79 97 density_txt = wx.StaticText(self, -1, 'Density ') 80 self.density_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1))98 self.density_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 81 99 unit_density_txt = wx.StaticText(self, -1, unit_density) 82 100 wavelength_txt = wx.StaticText(self, -1, 'Wavelength ') 83 self.wavelength_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1))101 self.wavelength_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 84 102 self.wavelength_ctl.SetValue(str(self.wavelength)) 85 103 unit_a_txt = wx.StaticText(self, -1, unit_a) 86 104 iy = 0 87 105 ix = 0 88 sizer_input.Add(compound_txt,(iy, ix),(1,1),\ 89 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 106 sizer_input.Add(compound_txt, (iy, ix), (1, 1), 107 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 108 ix += 1 109 sizer_input.Add(self.compound_ctl, (iy, ix), (1, 1), 110 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 111 iy += 1 112 ix = 0 113 sizer_input.Add(density_txt, (iy, ix), (1, 1), 114 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 115 ix += 1 116 sizer_input.Add(self.density_ctl, (iy, ix), (1, 1), 117 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 90 118 ix +=1 91 sizer_input.Add(self.compound_ctl,(iy, ix),(1,1),\ 92 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 93 iy += 1 94 ix = 0 95 sizer_input.Add(density_txt,(iy, ix),(1,1),\ 96 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 97 ix += 1 98 sizer_input.Add(self.density_ctl, (iy, ix), (1,1),\ 99 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 100 ix +=1 101 sizer_input.Add(unit_density_txt,(iy, ix),(1,1),\ 102 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 103 iy += 1 104 ix = 0 105 sizer_input.Add(wavelength_txt, (iy, ix),(1,1),\ 106 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 107 ix += 1 108 sizer_input.Add(self.wavelength_ctl,(iy, ix),(1,1),\ 109 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 110 ix += 1 111 sizer_input.Add(unit_a_txt,(iy, ix),(1,1),\ 112 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 113 boxsizer1.Add( sizer_input ) 114 sizer1.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) 119 sizer_input.Add(unit_density_txt,(iy, ix), (1, 1), 120 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 121 iy += 1 122 ix = 0 123 sizer_input.Add(wavelength_txt, (iy, ix), (1, 1), 124 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 125 ix += 1 126 sizer_input.Add(self.wavelength_ctl, (iy, ix), (1, 1), 127 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 128 ix += 1 129 sizer_input.Add(unit_a_txt, (iy, ix), (1, 1), 130 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 131 boxsizer1.Add(sizer_input) 132 sizer1.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 115 133 #---------Outputs sizer-------- 116 134 outputbox = wx.StaticBox(self, -1, "Output") 117 135 boxsizer2 = wx.StaticBoxSizer(outputbox, wx.VERTICAL) 118 boxsizer2.SetMinSize((_STATICBOX_WIDTH, -1))136 boxsizer2.SetMinSize((_STATICBOX_WIDTH, -1)) 119 137 120 138 i_complex = '- i' 121 139 neutron_sld_txt = wx.StaticText(self, -1, 'Neutron SLD') 122 self.neutron_sld_reel_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 140 self.neutron_sld_reel_ctl = wx.TextCtrl(self, -1, 141 size=(_BOX_WIDTH, -1)) 123 142 self.neutron_sld_reel_ctl.SetEditable(False) 124 143 self.neutron_sld_reel_ctl.SetToolTipString("Neutron SLD real.") 125 self.neutron_sld_im_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 144 self.neutron_sld_im_ctl = wx.TextCtrl(self, -1, 145 size=(_BOX_WIDTH, -1)) 126 146 self.neutron_sld_im_ctl.SetEditable(False) 127 147 self.neutron_sld_im_ctl.SetToolTipString("Neutron SLD imaginary.") … … 129 149 130 150 cu_ka_sld_txt = wx.StaticText(self, -1, 'Cu Ka SLD') 131 self.cu_ka_sld_reel_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 151 self.cu_ka_sld_reel_ctl = wx.TextCtrl(self, -1, 152 size=(_BOX_WIDTH, -1)) 132 153 self.cu_ka_sld_reel_ctl.SetEditable(False) 133 154 self.cu_ka_sld_reel_ctl.SetToolTipString("Cu Ka SLD real.") 134 self.cu_ka_sld_im_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 155 self.cu_ka_sld_im_ctl = wx.TextCtrl(self, -1, 156 size=(_BOX_WIDTH, -1)) 135 157 self.cu_ka_sld_im_ctl.SetEditable(False) 136 158 self.cu_ka_sld_im_ctl.SetToolTipString("Cu Ka SLD imaginary.") … … 138 160 139 161 mo_ka_sld_txt = wx.StaticText(self, -1, 'Mo Ka SLD') 140 self.mo_ka_sld_reel_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 162 self.mo_ka_sld_reel_ctl = wx.TextCtrl(self, -1, 163 size=(_BOX_WIDTH, -1)) 141 164 self.mo_ka_sld_reel_ctl.SetEditable(False) 142 165 self.mo_ka_sld_reel_ctl.SetToolTipString("Mo Ka SLD real.") 143 self.mo_ka_sld_im_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 166 self.mo_ka_sld_im_ctl = wx.TextCtrl(self, -1, 167 size=(_BOX_WIDTH, -1)) 144 168 self.mo_ka_sld_im_ctl.SetEditable(False) 145 169 self.mo_ka_sld_im_ctl.SetToolTipString("Mo Ka SLD imaginary.") … … 147 171 148 172 neutron_inc_txt = wx.StaticText(self, -1, 'Neutron Inc. Xs') 149 self.neutron_inc_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 173 self.neutron_inc_ctl = wx.TextCtrl(self, -1, 174 size=(_BOX_WIDTH, -1)) 150 175 self.neutron_inc_ctl.SetEditable(False) 151 176 self.neutron_inc_ctl.SetToolTipString("Neutron Inc. Xs") … … 153 178 154 179 neutron_abs_txt = wx.StaticText(self, -1, 'Neutron Abs. Xs') 155 self.neutron_abs_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 180 self.neutron_abs_ctl = wx.TextCtrl(self, -1, 181 size=(_BOX_WIDTH, -1)) 156 182 self.neutron_abs_ctl.SetEditable(False) 157 183 self.neutron_abs_ctl.SetToolTipString("Neutron Abs. Xs") … … 159 185 160 186 neutron_length_txt = wx.StaticText(self, -1, 'Neutron 1/e length') 161 self.neutron_length_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 187 self.neutron_length_ctl = wx.TextCtrl(self, -1, 188 size=(_BOX_WIDTH, -1)) 162 189 self.neutron_length_ctl.SetEditable(False) 163 190 self.neutron_length_ctl.SetToolTipString("Neutron 1/e length") … … 166 193 iy = 0 167 194 ix = 0 168 sizer_output.Add(neutron_sld_txt, (iy, ix),(1,1),169 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 170 ix += 1 171 sizer_output.Add(self.neutron_sld_reel_ctl, (iy, ix),(1,1),172 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 173 ix += 1 174 sizer_output.Add(wx.StaticText(self, -1, i_complex) 175 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)176 ix += 1177 sizer_output.Add(self.neutron_sld_im_ctl 178 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)179 ix += 1180 sizer_output.Add(neutron_sld_units_txt 181 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)182 iy += 1 183 ix = 0 184 sizer_output.Add(cu_ka_sld_txt, (iy, ix),(1,1),185 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 186 ix += 1187 sizer_output.Add(self.cu_ka_sld_reel_ctl, (iy, ix),(1,1),188 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 189 ix += 1190 sizer_output.Add(wx.StaticText(self, -1, i_complex) 191 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)192 ix += 1 193 sizer_output.Add(self.cu_ka_sld_im_ctl 194 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)195 ix += 1 196 sizer_output.Add(cu_ka_sld_units_txt 197 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)198 iy += 1 199 ix = 0 200 sizer_output.Add(mo_ka_sld_txt,(iy, ix), (1,1),201 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 202 ix += 1203 sizer_output.Add(self.mo_ka_sld_reel_ctl,(iy, ix), (1,1),204 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 205 ix += 1206 sizer_output.Add(wx.StaticText(self, -1, i_complex) 207 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)208 ix += 1 209 sizer_output.Add(self.mo_ka_sld_im_ctl 210 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)211 ix += 1212 sizer_output.Add(mo_ka_sld_units_txt 213 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)214 iy += 1 215 ix = 0 216 sizer_output.Add(neutron_inc_txt, (iy, ix),(1,1),217 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 218 ix += 1 219 sizer_output.Add(self.neutron_inc_ctl, (iy, ix),(1,1),195 sizer_output.Add(neutron_sld_txt, (iy, ix), (1, 1), 196 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 197 ix += 1 198 sizer_output.Add(self.neutron_sld_reel_ctl, (iy, ix), (1, 1), 199 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 200 ix += 1 201 sizer_output.Add(wx.StaticText(self, -1, i_complex), 202 (iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 203 ix += 1 204 sizer_output.Add(self.neutron_sld_im_ctl, 205 (iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 206 ix += 1 207 sizer_output.Add(neutron_sld_units_txt, 208 (iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 209 iy += 1 210 ix = 0 211 sizer_output.Add(cu_ka_sld_txt, (iy, ix), (1, 1), 212 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 213 ix += 1 214 sizer_output.Add(self.cu_ka_sld_reel_ctl, (iy, ix), (1, 1), 215 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 216 ix += 1 217 sizer_output.Add(wx.StaticText(self, -1, i_complex), 218 (iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 219 ix += 1 220 sizer_output.Add(self.cu_ka_sld_im_ctl, 221 (iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 222 ix += 1 223 sizer_output.Add(cu_ka_sld_units_txt, 224 (iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 225 iy += 1 226 ix = 0 227 sizer_output.Add(mo_ka_sld_txt,(iy, ix), (1, 1), 228 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 229 ix += 1 230 sizer_output.Add(self.mo_ka_sld_reel_ctl,(iy, ix), (1, 1), 231 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 232 ix += 1 233 sizer_output.Add(wx.StaticText(self, -1, i_complex), 234 (iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 235 ix += 1 236 sizer_output.Add(self.mo_ka_sld_im_ctl, 237 (iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 238 ix += 1 239 sizer_output.Add(mo_ka_sld_units_txt, 240 (iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 241 iy += 1 242 ix = 0 243 sizer_output.Add(neutron_inc_txt, (iy, ix), (1, 1), 244 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 245 ix += 1 246 sizer_output.Add(self.neutron_inc_ctl, (iy, ix), (1, 1), 220 247 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 221 248 ix += 2 222 sizer_output.Add(neutron_inc_units_txt,(iy, ix), (1,1),223 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 224 iy += 1 225 ix = 0 226 sizer_output.Add(neutron_abs_txt, (iy, ix), (1, 1),227 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 228 ix += 1 229 sizer_output.Add(self.neutron_abs_ctl, (iy, ix), (1, 1),230 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 231 ix += 2232 sizer_output.Add(neutron_abs_units_txt, (iy, ix), (1, 1),233 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 234 iy += 1 235 ix = 0 236 sizer_output.Add(neutron_length_txt, (iy, ix), (1, 1),237 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 238 ix += 1239 sizer_output.Add(self.neutron_length_ctl, (iy, ix), (1, 1),249 sizer_output.Add(neutron_inc_units_txt,(iy, ix), (1, 1), 250 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 251 iy += 1 252 ix = 0 253 sizer_output.Add(neutron_abs_txt, (iy, ix), (1, 1), 254 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 255 ix += 1 256 sizer_output.Add(self.neutron_abs_ctl, (iy, ix), (1, 1), 257 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 258 ix += 2 259 sizer_output.Add(neutron_abs_units_txt, (iy, ix), (1, 1), 260 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 261 iy += 1 262 ix = 0 263 sizer_output.Add(neutron_length_txt, (iy, ix), (1, 1), 264 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 265 ix += 1 266 sizer_output.Add(self.neutron_length_ctl, (iy, ix), (1, 1), 240 267 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 241 268 ix += 2 242 sizer_output.Add(neutron_length_units_txt, (iy, ix), (1, 1),269 sizer_output.Add(neutron_length_units_txt, (iy, ix), (1, 1), 243 270 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 244 boxsizer2.Add( sizer_output)245 sizer2.Add(boxsizer2, 0, wx.EXPAND|wx.ALL, 10)271 boxsizer2.Add(sizer_output) 272 sizer2.Add(boxsizer2, 0, wx.EXPAND|wx.ALL, 10) 246 273 #-----Button sizer------------ 247 274 … … 249 276 button_calculate = wx.Button(self, id, "Calculate") 250 277 button_calculate.SetToolTipString("Calculate SLD.") 251 self.Bind(wx.EVT_BUTTON, self.calculateSld, id =id)278 self.Bind(wx.EVT_BUTTON, self.calculateSld, id=id) 252 279 253 280 sizer_button.Add((250, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 254 sizer_button.Add(button_calculate, 0, wx.RIGHT|wx.ADJUST_MINSIZE, 20)281 sizer_button.Add(button_calculate, 0, wx.RIGHT|wx.ADJUST_MINSIZE, 20) 255 282 sizer3.Add(sizer_button) 256 283 #---------layout---------------- … … 297 324 else: 298 325 flag = False 299 raise ValueError, "Error for wavelength value :expect float"326 raise ValueError, "Error for wavelength value :expect float" 300 327 301 328 self.compound = self.compound_ctl.GetValue().lstrip().rstrip() … … 335 362 #get ready to compute 336 363 try: 337 self.sld_formula = formula(self.compound, density=self.density) 364 self.sld_formula = formula(self.compound, 365 density=self.density) 338 366 except: 339 367 if self.base is not None: 340 msg = "SLD Calculator: %s" %(sys.exc_value)368 msg = "SLD Calculator: %s" % (sys.exc_value) 341 369 wx.PostEvent(self.base, StatusEvent(status=msg)) 342 370 else: … … 345 373 346 374 347 (sld_real, sld_im, sld_inc), (coh,absorp,incoh), \375 (sld_real, sld_im, _), (_, absorp, incoh), \ 348 376 length = neutron_scattering(self.compound, 349 377 self.density, self.wavelength) … … 355 383 molecule_formula=self.sld_formula) 356 384 # set neutron sld values 357 self.neutron_sld_reel_ctl.SetValue(format_number(sld_real * _SCALE)) 358 self.neutron_sld_im_ctl.SetValue(format_number(math.fabs(sld_im) * _SCALE)) 385 val = format_number(sld_real * _SCALE) 386 self.neutron_sld_reel_ctl.SetValue(val) 387 val = format_number(math.fabs(sld_im) * _SCALE) 388 self.neutron_sld_im_ctl.SetValue(val) 359 389 # Compute the Cu SLD 360 390 self.cu_ka_sld_reel_ctl.SetValue(format_number(cu_real *_SCALE)) 361 self.cu_ka_sld_im_ctl.SetValue(format_number(math.fabs(cu_im )* _SCALE)) 391 val = format_number(math.fabs(cu_im )* _SCALE) 392 self.cu_ka_sld_im_ctl.SetValue(val) 362 393 # Compute the Mo SLD 363 394 self.mo_ka_sld_reel_ctl.SetValue(format_number(mo_real *_SCALE)) 364 self.mo_ka_sld_im_ctl.SetValue(format_number(math.fabs(mo_im)* _SCALE)) 395 val = format_number(math.fabs(mo_im)* _SCALE) 396 self.mo_ka_sld_im_ctl.SetValue(val) 365 397 # set incoherence and absorption 366 398 self.neutron_inc_ctl.SetValue(format_number(incoh)) … … 372 404 except: 373 405 if self.base is not None: 374 375 406 msg = "SLD Calculator: %s"%(sys.exc_value) 407 wx.PostEvent(self.base, StatusEvent(status=msg)) 376 408 else: 377 409 raise 378 410 return 379 411 if event is not None: 412 event.Skip() 380 413 381 414 class SldWindow(wx.Frame): 382 def __init__(self, parent=None, id=1, title="SLD Calculator",base=None): 383 wx.Frame.__init__(self, parent, id, title, size=( PANEL_SIZE, PANEL_SIZE)) 384 415 """ 416 """ 417 def __init__(self, parent=None, title="SLD Calculator", base=None): 418 """ 419 """ 420 wx.Frame.__init__(self, parent, title, 421 size=(PANEL_SIZE, PANEL_SIZE)) 422 """ 423 """ 385 424 self.panel = SldPanel(self, base=base) 386 425 self.Centre() … … 388 427 389 428 class ViewApp(wx.App): 429 """ 430 """ 390 431 def OnInit(self): 432 """ 433 """ 391 434 frame = SldWindow(None, -1, 'SLD Calculator') 392 435 frame.Show(True) 393 436 self.SetTopWindow(frame) 394 395 437 return True 396 438 -
calculatorview/perspectives/calculator/slit_length_calculator_panel.py
r74b1770 rb0ab6cb 13 13 import os 14 14 15 from DataLoader.readers.ascii_reader import Reader15 #from DataLoader.readers.ascii_reader import Reader 16 16 from sans.guicomm.events import StatusEvent 17 17 from sans.calculator.slit_length_calculator import SlitlengthCalculator 18 from calculator_widgets import OutputTextCtrl, InterActiveOutputTextCtrl 18 from calculator_widgets import OutputTextCtrl 19 from calculator_widgets import InterActiveOutputTextCtrl 19 20 20 21 _BOX_WIDTH = 76 … … 40 41 CENTER_PANE = True 41 42 42 def __init__(self, parent, id=-1,*args, **kwds):43 wx.Panel.__init__(self, parent, id=id,*args, **kwds)43 def __init__(self, parent, *args, **kwds): 44 wx.Panel.__init__(self, parent, *args, **kwds) 44 45 #Font size 45 46 self.SetWindowVariant(variant=FONT_VARIANT) … … 70 71 """ 71 72 data_name_txt = wx.StaticText(self, -1, 'Data: ') 72 self.data_name_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH*4,-1)) 73 self.data_name_tcl = OutputTextCtrl(self, -1, 74 size=(_BOX_WIDTH*4, -1)) 73 75 data_hint = "Loaded data" 74 76 self.data_name_tcl.SetToolTipString(data_hint) … … 87 89 """ 88 90 slit_size_txt = wx.StaticText(self, -1, 'Slit Size (FWHM/2): ') 89 self.slit_size_tcl = InterActiveOutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 91 self.slit_size_tcl = InterActiveOutputTextCtrl(self, -1, 92 size=(_BOX_WIDTH, -1)) 90 93 slit_size_hint = " Estimated full slit size" 91 94 self.slit_size_tcl.SetToolTipString(slit_size_hint) 92 95 slit_size_unit_txt = wx.StaticText(self, -1, 'Unit: ') 93 self.slit_size_unit_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 96 self.slit_size_unit_tcl = OutputTextCtrl(self, -1, 97 size=(_BOX_WIDTH, -1)) 94 98 slit_size_unit_hint = "Full slit size's unit" 95 99 self.slit_size_unit_tcl.SetToolTipString(slit_size_unit_hint) … … 97 101 (self.slit_size_tcl, 0, wx.LEFT, 10), 98 102 (slit_size_unit_txt, 0, wx.LEFT, 10), 99 103 (self.slit_size_unit_tcl, 0, wx.LEFT, 10)]) 100 104 101 105 def _layout_hint(self): … … 145 149 wildcard = "SAXSess Data 1D (*.DAT, *.dat)|*.DAT" 146 150 147 dlg = wx.FileDialog(self, "Choose a file", location,"", wildcard, wx.OPEN) 151 dlg = wx.FileDialog(self, "Choose a file", location, 152 "", wildcard, wx.OPEN) 148 153 if dlg.ShowModal() == wx.ID_OK: 149 154 path = dlg.GetPath() … … 177 182 self.reader.stop() 178 183 if self.parent.parent is not None: 179 wx.PostEvent(self.parent.parent, StatusEvent(status="Loading...", 184 wx.PostEvent(self.parent.parent, 185 StatusEvent(status="Loading...", 180 186 type="progress")) 181 187 self.reader = DataReader(path=path, … … 186 192 if self.parent.parent is None: 187 193 return 188 msg = "Slit Length Calculator: %s"%(sys.exc_value) 189 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, type='stop')) 194 msg = "Slit Length Calculator: %s" % (sys.exc_value) 195 wx.PostEvent(self.parent.parent, 196 StatusEvent(status=msg, type='stop')) 190 197 return 191 198 … … 198 205 return 199 206 msg = "Slit Length cannot be computed for 2D Data" 200 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, type='stop')) 207 wx.PostEvent(self.parent.parent, 208 StatusEvent(status=msg, type='stop')) 201 209 return 202 210 self.data_name_tcl.SetValue(str(data.filename)) … … 206 214 y = data.y 207 215 if x == [] or x is None or y == [] or y is None: 208 209 216 msg = "The current data is empty please check x and y" 217 raise ValueError, msg 210 218 slit_length_calculator = SlitlengthCalculator() 211 219 slit_length_calculator.set_data(x=x, y=y) … … 214 222 if self.parent.parent is None: 215 223 return 216 msg = "Slit Size Calculator: %s"%(sys.exc_value) 217 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, type='stop')) 224 msg = "Slit Size Calculator: %s" % (sys.exc_value) 225 wx.PostEvent(self.parent.parent, 226 StatusEvent(status=msg, type='stop')) 218 227 return 219 228 self.slit_size_tcl.SetValue(str(slit_length)) … … 225 234 wx.PostEvent(self.parent.parent, StatusEvent(status=msg, type='stop')) 226 235 236 227 237 class SlitLengthCalculatorWindow(wx.Frame): 228 def __init__(self, parent=None, id=1, title="Slit Size Calculator"): 229 wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH,PANEL_HEIGHT)) 238 """ 239 """ 240 def __init__(self, parent=None, title="Slit Size Calculator"): 241 """ 242 """ 243 wx.Frame.__init__(self, parent, title, 244 size=(PANEL_WIDTH,PANEL_HEIGHT)) 230 245 self.parent = parent 231 246 self.panel = SlitLengthCalculatorPanel(parent=self) -
calculatorview/perspectives/calculator/source_editor.py
rad6f597 rb0ab6cb 1 1 """ 2 """ 2 3 import wx 3 4 import sys 4 5 from copy import deepcopy 5 6 from sans.guiframe.utils import check_float 7 6 8 _BOX_WIDTH = 60 7 8 if sys.platform.count("win32")>0: 9 if sys.platform.count("win32") > 0: 9 10 _STATICBOX_WIDTH = 450 10 11 PANEL_WIDTH = 500 … … 37 38 """ 38 39 self.main_sizer = wx.BoxSizer(wx.VERTICAL) 39 self.box_source = wx.StaticBox(self, -1, str("source"))40 self.box_source = wx.StaticBox(self, -1, str("source")) 40 41 self.boxsizer_source = wx.StaticBoxSizer(self.box_source, 41 42 wx.VERTICAL) … … 57 58 # Sample name [string] 58 59 sample_name_txt = wx.StaticText(self, -1, 'Sample Name : ') 59 self.sample_name_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0) 60 self.sample_name_tcl = wx.TextCtrl(self, -1, 61 size=(_BOX_WIDTH*5, 20), style=0) 60 62 self.name_sizer.AddMany([(sample_name_txt, 0, wx.LEFT|wx.RIGHT, 10), 61 63 (self.sample_name_tcl, 0, wx.EXPAND)]) … … 66 68 #Radiation type [string] 67 69 radiation_txt = wx.StaticText(self, -1, 'Radiation: ') 68 self.radiation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 70 self.radiation_tcl = wx.TextCtrl(self, -1, 71 size=(_BOX_WIDTH, 20), style=0) 69 72 self.radiation_sizer.AddMany([(radiation_txt, 0, wx.LEFT|wx.RIGHT, 10), 70 73 (self.radiation_tcl, 0, wx.LEFT, 20)]) … … 76 79 #Beam shape [string] 77 80 beam_shape_txt = wx.StaticText(self, -1, 'Beam shape:') 78 self.beam_shape_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 79 self.beam_shape_sizer.AddMany([(beam_shape_txt, 0, wx.LEFT|wx.RIGHT, 10), 81 self.beam_shape_tcl = wx.TextCtrl(self, -1, 82 size=(_BOX_WIDTH, 20), style=0) 83 self.beam_shape_sizer.AddMany([(beam_shape_txt, 0, 84 wx.LEFT|wx.RIGHT, 10), 80 85 (self.beam_shape_tcl, 0, wx.LEFT, 10)]) 81 86 … … 86 91 #Wavelength [float] [Angstrom] 87 92 wavelength_txt = wx.StaticText(self, -1, 'wavelength:') 88 self.wavelength_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 93 self.wavelength_tcl = wx.TextCtrl(self, -1, 94 size=(_BOX_WIDTH, 20), style=0) 89 95 wavelength_unit_txt = wx.StaticText(self, -1, 'Unit: ') 90 self.wavelength_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) 91 self.wavelength_sizer.AddMany([(wavelength_txt, 0, wx.LEFT|wx.RIGHT, 10), 96 self.wavelength_unit_tcl = wx.TextCtrl(self, -1, 97 size=(_BOX_WIDTH, 20),style=0) 98 self.wavelength_sizer.AddMany([(wavelength_txt, 99 0, wx.LEFT|wx.RIGHT, 10), 92 100 (self.wavelength_tcl, 0, wx.LEFT, 12), 93 101 (wavelength_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), 94 102 (self.wavelength_unit_tcl, 0, wx.EXPAND)]) 95 103 … … 100 108 #Minimum wavelength [float] [Angstrom] 101 109 wavelength_min_txt = wx.StaticText(self, -1, 'Wavelength min:') 102 self.wavelength_min_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 110 self.wavelength_min_tcl = wx.TextCtrl(self, -1, 111 size=(_BOX_WIDTH, 20), style=0) 103 112 wavelength_min_unit_txt = wx.StaticText(self, -1, 'Unit: ') 104 self.wavelength_min_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) 105 self.wavelength_min_sizer.AddMany([(wavelength_min_txt, 0, wx.LEFT|wx.RIGHT, 10), 113 self.wavelength_min_unit_tcl = wx.TextCtrl(self, -1, 114 size=(_BOX_WIDTH, 20), style=0) 115 self.wavelength_min_sizer.AddMany([(wavelength_min_txt, 116 0, wx.LEFT|wx.RIGHT, 10), 106 117 (self.wavelength_min_tcl, 0, wx.LEFT, 10), 107 108 118 (wavelength_min_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), 119 (self.wavelength_min_unit_tcl, 0, wx.EXPAND)]) 109 120 110 121 def _layout_wavelength_max(self): … … 114 125 #Maximum wavelength [float] [Angstrom] 115 126 wavelength_max_txt = wx.StaticText(self, -1, 'Wavelength max:') 116 self.wavelength_max_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 127 self.wavelength_max_tcl = wx.TextCtrl(self, -1, 128 size=(_BOX_WIDTH, 20), style=0) 117 129 wavelength_max_unit_txt = wx.StaticText(self, -1, 'Unit: ') 118 self.wavelength_max_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) 119 self.wavelength_max_sizer.AddMany([(wavelength_max_txt, 0, wx.LEFT|wx.RIGHT, 10), 130 self.wavelength_max_unit_tcl = wx.TextCtrl(self, -1, 131 size=(_BOX_WIDTH, 20), style=0) 132 self.wavelength_max_sizer.AddMany([(wavelength_max_txt, 0, 133 wx.LEFT|wx.RIGHT, 10), 120 134 (self.wavelength_max_tcl, 0, wx.LEFT, 7), 121 (wavelength_max_unit_txt, 0,wx.LEFT|wx.RIGHT, 10),122 135 (wavelength_max_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), 136 (self.wavelength_max_unit_tcl, 0, wx.EXPAND)]) 123 137 124 138 def _layout_wavelength_spread(self): … … 130 144 wavelength_spread_unit = 'percent' 131 145 wavelength_spread_txt = wx.StaticText(self, -1, 'Wavelength spread:') 132 self.wavelength_spread_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 146 self.wavelength_spread_tcl = wx.TextCtrl(self, -1, 147 size=(_BOX_WIDTH, 20), style=0) 133 148 wavelength_spread_unit_txt = wx.StaticText(self, -1, 'Unit: ') 134 self.wavelength_spread_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) 135 self.wavelength_spread_sizer.AddMany([(wavelength_spread_txt, 0, wx.LEFT, 10), 136 (self.wavelength_spread_tcl, 0, wx.LEFT, 5), 137 (wavelength_spread_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), 138 (self.wavelength_spread_unit_tcl, 0, wx.EXPAND)]) 149 self.wavelength_spread_unit_tcl = wx.TextCtrl(self, -1, 150 size=(_BOX_WIDTH, 20), style=0) 151 self.wavelength_spread_sizer.AddMany([(wavelength_spread_txt, 152 0, wx.LEFT, 10), 153 (self.wavelength_spread_tcl, 0, wx.LEFT, 5), 154 (wavelength_spread_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), 155 (self.wavelength_spread_unit_tcl, 0, wx.EXPAND)]) 139 156 def _layout_beam_size_name(self): 140 157 """ … … 143 160 # Beam size name [string] 144 161 beam_size_name_txt = wx.StaticText(self, -1, 'Beam size name : ') 145 self.beam_size_name_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0) 146 self.beam_size_name_sizer.AddMany([(beam_size_name_txt, 0, wx.LEFT|wx.RIGHT, 10), 162 self.beam_size_name_tcl = wx.TextCtrl(self, -1, 163 size=(_BOX_WIDTH*5, 20), style=0) 164 self.beam_size_name_sizer.AddMany([(beam_size_name_txt, 165 0, wx.LEFT|wx.RIGHT, 10), 147 166 (self.beam_size_name_tcl, 0, wx.EXPAND)]) 148 167 … … 157 176 beam_size_txt = wx.StaticText(self, -1, 'Beam size:') 158 177 x_beam_size_txt = wx.StaticText(self, -1, 'x = ') 159 self.x_beam_size_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 178 self.x_beam_size_tcl = wx.TextCtrl(self, -1, 179 size=(_BOX_WIDTH, 20), style=0) 160 180 y_beam_size_txt = wx.StaticText(self, -1, 'y = ') 161 self.y_beam_size_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 181 self.y_beam_size_tcl = wx.TextCtrl(self, -1, 182 size=(_BOX_WIDTH, 20), style=0) 162 183 z_beam_size_txt = wx.StaticText(self, -1, 'z = ') 163 self.z_beam_size_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 184 self.z_beam_size_tcl = wx.TextCtrl(self, -1, 185 size=(_BOX_WIDTH, 20), style=0) 164 186 beam_size_unit_txt = wx.StaticText(self, -1, 'Unit: ') 165 self.beam_size_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 187 self.beam_size_unit_tcl = wx.TextCtrl(self, -1, 188 size=(_BOX_WIDTH, 20), style=0) 166 189 self.beam_size_sizer.AddMany([(beam_size_txt, 0, wx.LEFT|wx.RIGHT, 10), 167 190 (x_beam_size_txt, 0, wx.LEFT, 17), … … 172 195 (self.z_beam_size_tcl, 0, wx.RIGHT, 10), 173 196 (beam_size_unit_txt, 0, wx.EXPAND), 174 197 (self.beam_size_unit_tcl, 0, wx.RIGHT, 10)]) 175 198 176 199 def _layout_button(self): … … 363 386 self._source.wavelength_min = wavelength_min 364 387 self._notes += " Change wavelength min from" 365 self._notes += " %s to %s \n"%(self._source.wavelength_min, wavelength_min) 388 self._notes += " %s to %s \n" % (self._source.wavelength_min, 389 wavelength_min) 366 390 #change the wavelength min unit 367 391 unit = self.wavelength_min_unit_tcl.GetValue().lstrip().rstrip() 368 392 if self._source.wavelength_min_unit != unit: 369 393 self._notes += " Change wavelength min's unit from " 370 self._notes += "%s to %s" %(self._source.wavelength_min_unit, unit)394 self._notes += "%s to %s" % (self._source.wavelength_min_unit, unit) 371 395 372 396 def on_change_wavelength_max(self): … … 378 402 self._source.wavelength_max = wavelength_max 379 403 self._notes += " Change wavelength max from" 380 self._notes += " %s to %s \n"%(self._source.wavelength_max, wavelength_max) 404 self._notes += " %s to %s \n" % (self._source.wavelength_max, 405 wavelength_max) 381 406 #change the wavelength max unit 382 407 unit = self.wavelength_max_unit_tcl.GetValue().lstrip().rstrip() … … 392 417 wavelength_spread = self.wavelength_spread_tcl.GetValue().lstrip().rstrip() 393 418 self._notes += " Change wavelength spread from" 394 self._notes += " %s to %s \n"%(self._source.wavelength_spread, wavelength_spread) 419 self._notes += " %s to %s \n" % (self._source.wavelength_spread, 420 wavelength_spread) 395 421 self._source.wavelength_spread = wavelength_spread 396 422 #change the wavelength spread unit … … 398 424 if self._source.wavelength_spread_unit != unit: 399 425 self._notes += " Change wavelength spread's unit from " 400 self._notes += "%s to %s"%(self._source.wavelength_spread_unit, unit) 426 self._notes += "%s to %s" % (self._source.wavelength_spread_unit, 427 unit) 401 428 self._source.wavelength_spread_unit = unit 402 429 … … 411 438 if self._source.beam_size_name != name: 412 439 self._notes += "Change beam size 's " 413 self._notes += "name from %s to %s \n"%(self._source.beam_size_name, name) 440 self._notes += "name from %s to %s \n" % (self._source.beam_size_name, 441 name) 414 442 self._source.name = name 415 443 … … 426 454 if self._source.beam_size.x != float(x_beam_size) : 427 455 self._notes += "Change x of beam size from " 428 self._notes += "%s to %s \n"%(self._source.beam_size.x, x_beam_size) 456 self._notes += "%s to %s \n" % (self._source.beam_size.x, 457 x_beam_size) 429 458 self._source.beam_size.x = float(x_beam_size) 430 459 else: 431 460 self._notes += "Error: Expected a float for the beam size 's x " 432 461 self._notes += "won't changes x beam size from " 433 self._notes += "%s to %s"%(self._source.beam_size.x, x_beam_size) 462 self._notes += "%s to %s" % (self._source.beam_size.x, 463 x_beam_size) 434 464 #Change y coordinate 435 465 y_beam_size = self.y_beam_size_tcl.GetValue().lstrip().rstrip() … … 441 471 if self._source.beam_size.y != float(y_beam_size): 442 472 self._notes += "Change y of beam size from " 443 self._notes += "%s to %s \n"%(self._source.beam_size.y, y_beam_size) 473 self._notes += "%s to %s \n" % (self._source.beam_size.y, 474 y_beam_size) 444 475 self._source.beam_size.y = float(y_beam_size) 445 476 else: 446 477 self._notes += "Error: Expected a float for the beam size's y " 447 478 self._notes += "won't changes y beam size from " 448 self._notes += "%s to %s"%(self._source.beam_size.y, y_beam_size) 479 self._notes += "%s to %s" % (self._source.beam_size.y, 480 y_beam_size) 449 481 #Change z coordinate 450 482 z_beam_size = self.z_beam_size_tcl.GetValue().lstrip().rstrip() … … 456 488 if self._source.beam_size.z != float(z_beam_size): 457 489 self._notes += "Change z of beam size from " 458 self._notes += "%s to %s \n"%(self._source.beam_size.z, z_beam_size) 490 self._notes += "%s to %s \n" % (self._source.beam_size.z, 491 z_beam_size) 459 492 self._source.beam_size.z = float(z_beam_size) 460 493 else: 461 494 self._notes += "Error: Expected a float for the beam size 's z " 462 495 self._notes += "won't changes z beam size from " 463 self._notes += "%s to %s"%(self._source.beam_size.z, z_beam_size) 496 self._notes += "%s to %s" % (self._source.beam_size.z, 497 z_beam_size) 464 498 #change the beam center unit 465 499 unit = self.beam_size_unit_tcl.GetValue().lstrip().rstrip() … … 471 505 def on_click_apply(self, event): 472 506 """ 473 507 Apply user values to the source 474 508 """ 475 509 self.on_change_name() … … 484 518 if self.manager is not None: 485 519 self.manager.set_source(self._source, self._notes) 520 if event is not None: 521 event.Skip() 486 522 487 523 def on_click_cancel(self, event): 488 524 """ 489 525 reset the current source 490 526 """ 491 527 self.reset_source() 492 528 self.set_values() 493 529 if self.manager is not None: 494 self.manager.set_source(self._source) 530 self.manager.set_source(self._source) 531 if event is not None: 532 event.Skip() 495 533 496 534 if __name__ =="__main__":
Note: See TracChangeset
for help on using the changeset viewer.