Changeset 49ab5d7 in sasview for src/sas/perspectives/calculator/source_editor.py
- Timestamp:
- Mar 4, 2015 3:28:39 PM (10 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 2f732b0
- Parents:
- 76aed53
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/perspectives/calculator/source_editor.py
r79492222 r49ab5d7 17 17 PANEL_HEIGHT = 430 18 18 FONT_VARIANT = 1 19 19 20 20 class SourceDialog(wx.Dialog): 21 21 def __init__(self, parent=None, manager=None, source=None, *args, **kwds): … … 23 23 kwds['size'] = (PANEL_WIDTH, PANEL_HEIGHT) 24 24 wx.Dialog.__init__(self, parent=parent, *args, **kwds) 25 25 26 26 self.parent = parent 27 27 self.manager = manager … … 32 32 self._do_layout() 33 33 self.set_values() 34 34 35 35 def _define_structure(self): 36 36 """ 37 define initial sizer 37 define initial sizer 38 38 """ 39 39 self.main_sizer = wx.BoxSizer(wx.VERTICAL) … … 51 51 self.beam_size_sizer = wx.BoxSizer(wx.HORIZONTAL) 52 52 self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) 53 53 54 54 def _layout_name(self): 55 55 """ … … 57 57 """ 58 58 # Sample name [string] 59 sample_name_txt = wx.StaticText(self, -1, 'Sample Name : ') 59 sample_name_txt = wx.StaticText(self, -1, 'Sample Name : ') 60 60 self.sample_name_tcl = wx.TextCtrl(self, -1, 61 size=(_BOX_WIDTH *5, 20), style=0)62 self.name_sizer.AddMany([(sample_name_txt, 0, wx.LEFT |wx.RIGHT, 10),61 size=(_BOX_WIDTH * 5, 20), style=0) 62 self.name_sizer.AddMany([(sample_name_txt, 0, wx.LEFT | wx.RIGHT, 10), 63 63 (self.sample_name_tcl, 0, wx.EXPAND)]) 64 64 def _layout_radiation(self): … … 67 67 """ 68 68 #Radiation type [string] 69 radiation_txt = wx.StaticText(self, -1, 'Radiation: ') 70 self.radiation_tcl = wx.TextCtrl(self, -1, 69 radiation_txt = wx.StaticText(self, -1, 'Radiation: ') 70 self.radiation_tcl = wx.TextCtrl(self, -1, 71 71 size=(_BOX_WIDTH, 20), style=0) 72 self.radiation_sizer.AddMany([(radiation_txt, 0, wx.LEFT |wx.RIGHT, 10),72 self.radiation_sizer.AddMany([(radiation_txt, 0, wx.LEFT | wx.RIGHT, 10), 73 73 (self.radiation_tcl, 0, wx.LEFT, 20)]) 74 74 75 75 def _layout_beam_shape(self): 76 76 """ … … 78 78 """ 79 79 #Beam shape [string] 80 beam_shape_txt = wx.StaticText(self, -1, 'Beam shape:') 80 beam_shape_txt = wx.StaticText(self, -1, 'Beam shape:') 81 81 self.beam_shape_tcl = wx.TextCtrl(self, -1, 82 size=(_BOX_WIDTH, 20), style=0) 82 size=(_BOX_WIDTH, 20), style=0) 83 83 self.beam_shape_sizer.AddMany([(beam_shape_txt, 0, 84 wx.LEFT |wx.RIGHT, 10),84 wx.LEFT | wx.RIGHT, 10), 85 85 (self.beam_shape_tcl, 0, wx.LEFT, 10)]) 86 86 87 87 def _layout_wavelength(self): 88 88 """ … … 90 90 """ 91 91 #Wavelength [float] [Angstrom] 92 wavelength_txt = wx.StaticText(self, -1, 'wavelength:') 92 wavelength_txt = wx.StaticText(self, -1, 'wavelength:') 93 93 self.wavelength_tcl = wx.TextCtrl(self, -1, 94 size=(_BOX_WIDTH, 20), style=0) 95 wavelength_unit_txt = wx.StaticText(self, -1, 'Unit: ') 94 size=(_BOX_WIDTH, 20), style=0) 95 wavelength_unit_txt = wx.StaticText(self, -1, 'Unit: ') 96 96 self.wavelength_unit_tcl = wx.TextCtrl(self, -1, 97 size=(_BOX_WIDTH, 20), style=0)97 size=(_BOX_WIDTH, 20), style=0) 98 98 self.wavelength_sizer.AddMany([(wavelength_txt, 99 0, wx.LEFT |wx.RIGHT, 10),99 0, wx.LEFT | wx.RIGHT, 10), 100 100 (self.wavelength_tcl, 0, wx.LEFT, 12), 101 (wavelength_unit_txt, 0, wx.LEFT |wx.RIGHT, 10),102 (self.wavelength_unit_tcl, 0, wx.EXPAND)]) 103 101 (wavelength_unit_txt, 0, wx.LEFT | wx.RIGHT, 10), 102 (self.wavelength_unit_tcl, 0, wx.EXPAND)]) 103 104 104 def _layout_wavelength_min(self): 105 105 """ … … 107 107 """ 108 108 #Minimum wavelength [float] [Angstrom] 109 wavelength_min_txt = wx.StaticText(self, -1, 'Wavelength min:') 109 wavelength_min_txt = wx.StaticText(self, -1, 'Wavelength min:') 110 110 self.wavelength_min_tcl = wx.TextCtrl(self, -1, 111 size=(_BOX_WIDTH, 20), style=0) 112 wavelength_min_unit_txt = wx.StaticText(self, -1, 'Unit: ') 111 size=(_BOX_WIDTH, 20), style=0) 112 wavelength_min_unit_txt = wx.StaticText(self, -1, 'Unit: ') 113 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),114 size=(_BOX_WIDTH, 20), style=0) 115 self.wavelength_min_sizer.AddMany([(wavelength_min_txt, 116 0, wx.LEFT | wx.RIGHT, 10), 117 117 (self.wavelength_min_tcl, 0, wx.LEFT, 10), 118 (wavelength_min_unit_txt, 0, wx.LEFT |wx.RIGHT, 10),119 (self.wavelength_min_unit_tcl, 0, wx.EXPAND)]) 120 118 (wavelength_min_unit_txt, 0, wx.LEFT | wx.RIGHT, 10), 119 (self.wavelength_min_unit_tcl, 0, wx.EXPAND)]) 120 121 121 def _layout_wavelength_max(self): 122 122 """ … … 124 124 """ 125 125 #Maximum wavelength [float] [Angstrom] 126 wavelength_max_txt = wx.StaticText(self, -1, 'Wavelength max:') 126 wavelength_max_txt = wx.StaticText(self, -1, 'Wavelength max:') 127 127 self.wavelength_max_tcl = wx.TextCtrl(self, -1, 128 size=(_BOX_WIDTH, 20), style=0) 129 wavelength_max_unit_txt = wx.StaticText(self, -1, 'Unit: ') 128 size=(_BOX_WIDTH, 20), style=0) 129 wavelength_max_unit_txt = wx.StaticText(self, -1, 'Unit: ') 130 130 self.wavelength_max_unit_tcl = wx.TextCtrl(self, -1, 131 size=(_BOX_WIDTH, 20), style=0) 131 size=(_BOX_WIDTH, 20), style=0) 132 132 self.wavelength_max_sizer.AddMany([(wavelength_max_txt, 0, 133 wx.LEFT |wx.RIGHT, 10),133 wx.LEFT | wx.RIGHT, 10), 134 134 (self.wavelength_max_tcl, 0, wx.LEFT, 7), 135 (wavelength_max_unit_txt, 0, wx.LEFT |wx.RIGHT, 10),136 (self.wavelength_max_unit_tcl, 0, wx.EXPAND)]) 137 135 (wavelength_max_unit_txt, 0, wx.LEFT | wx.RIGHT, 10), 136 (self.wavelength_max_unit_tcl, 0, wx.EXPAND)]) 137 138 138 def _layout_wavelength_spread(self): 139 139 """ … … 143 143 wavelength_spread = None 144 144 wavelength_spread_unit = 'percent' 145 wavelength_spread_txt = wx.StaticText(self, -1, 'Wavelength spread:') 145 wavelength_spread_txt = wx.StaticText(self, -1, 'Wavelength spread:') 146 146 self.wavelength_spread_tcl = wx.TextCtrl(self, -1, 147 size=(_BOX_WIDTH, 20), style=0) 148 wavelength_spread_unit_txt = wx.StaticText(self, -1, 'Unit: ') 147 size=(_BOX_WIDTH, 20), style=0) 148 wavelength_spread_unit_txt = wx.StaticText(self, -1, 'Unit: ') 149 149 self.wavelength_spread_unit_tcl = wx.TextCtrl(self, -1, 150 size=(_BOX_WIDTH, 20), style=0) 150 size=(_BOX_WIDTH, 20), style=0) 151 151 self.wavelength_spread_sizer.AddMany([(wavelength_spread_txt, 152 152 0, wx.LEFT, 10), 153 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)]) 154 (wavelength_spread_unit_txt, 0, wx.LEFT | wx.RIGHT, 10), 155 (self.wavelength_spread_unit_tcl, 0, wx.EXPAND)]) 156 156 def _layout_beam_size_name(self): 157 157 """ … … 159 159 """ 160 160 # Beam size name [string] 161 beam_size_name_txt = wx.StaticText(self, -1, 'Beam size name : ') 161 beam_size_name_txt = wx.StaticText(self, -1, 'Beam size name : ') 162 162 self.beam_size_name_tcl = wx.TextCtrl(self, -1, 163 size=(_BOX_WIDTH *5, 20), style=0)163 size=(_BOX_WIDTH * 5, 20), style=0) 164 164 self.beam_size_name_sizer.AddMany([(beam_size_name_txt, 165 0, wx.LEFT |wx.RIGHT, 10),165 0, wx.LEFT | wx.RIGHT, 10), 166 166 (self.beam_size_name_tcl, 0, wx.EXPAND)]) 167 167 168 168 def _layout_beam_size(self): 169 169 """ … … 173 173 beam_size = None 174 174 beam_size_unit = 'mm' 175 176 beam_size_txt = wx.StaticText(self, -1, 'Beam size:') 177 x_beam_size_txt = wx.StaticText(self, -1, 'x = ') 175 176 beam_size_txt = wx.StaticText(self, -1, 'Beam size:') 177 x_beam_size_txt = wx.StaticText(self, -1, 'x = ') 178 178 self.x_beam_size_tcl = wx.TextCtrl(self, -1, 179 size=(_BOX_WIDTH, 20), style=0) 180 y_beam_size_txt = wx.StaticText(self, -1, 'y = ') 179 size=(_BOX_WIDTH, 20), style=0) 180 y_beam_size_txt = wx.StaticText(self, -1, 'y = ') 181 181 self.y_beam_size_tcl = wx.TextCtrl(self, -1, 182 size=(_BOX_WIDTH, 20), style=0) 183 z_beam_size_txt = wx.StaticText(self, -1, 'z = ') 184 self.z_beam_size_tcl = wx.TextCtrl(self, -1, 185 size=(_BOX_WIDTH, 20), style=0) 186 beam_size_unit_txt = wx.StaticText(self, -1, 'Unit: ') 187 self.beam_size_unit_tcl = wx.TextCtrl(self, -1, 188 size=(_BOX_WIDTH, 20), style=0) 189 self.beam_size_sizer.AddMany([(beam_size_txt, 0, wx.LEFT |wx.RIGHT, 10),182 size=(_BOX_WIDTH, 20), style=0) 183 z_beam_size_txt = wx.StaticText(self, -1, 'z = ') 184 self.z_beam_size_tcl = wx.TextCtrl(self, -1, 185 size=(_BOX_WIDTH, 20), style=0) 186 beam_size_unit_txt = wx.StaticText(self, -1, 'Unit: ') 187 self.beam_size_unit_tcl = wx.TextCtrl(self, -1, 188 size=(_BOX_WIDTH, 20), style=0) 189 self.beam_size_sizer.AddMany([(beam_size_txt, 0, wx.LEFT | wx.RIGHT, 10), 190 190 (x_beam_size_txt, 0, wx.LEFT, 17), 191 191 (self.x_beam_size_tcl, 0, wx.RIGHT, 10), … … 196 196 (beam_size_unit_txt, 0, wx.EXPAND), 197 197 (self.beam_size_unit_tcl, 0, wx.RIGHT, 10)]) 198 199 def _layout_button(self): 198 199 def _layout_button(self): 200 200 """ 201 201 Do the layout for the button widgets 202 """ 203 self.bt_apply = wx.Button(self, -1, 'Apply')202 """ 203 self.bt_apply = wx.Button(self, -1, 'Apply') 204 204 self.bt_apply.Bind(wx.EVT_BUTTON, self.on_click_apply) 205 205 self.bt_apply.SetToolTipString("Apply current changes to the source.") 206 self.bt_cancel = wx.Button(self, -1, 'Cancel')206 self.bt_cancel = wx.Button(self, -1, 'Cancel') 207 207 self.bt_cancel.SetToolTipString("Cancel current changes.") 208 208 self.bt_cancel.Bind(wx.EVT_BUTTON, self.on_click_cancel) 209 self.bt_close = wx.Button(self, wx.ID_CANCEL, 'Close')209 self.bt_close = wx.Button(self, wx.ID_CANCEL, 'Close') 210 210 self.bt_close.SetToolTipString("Close window.") 211 211 self.button_sizer.AddMany([(self.bt_apply, 0, wx.LEFT, 200), 212 212 (self.bt_cancel, 0, wx.LEFT, 10), 213 213 (self.bt_close, 0, wx.LEFT, 10)]) 214 214 215 215 def _do_layout(self, data=None): 216 216 """ … … 228 228 self._layout_beam_size() 229 229 self._layout_button() 230 230 231 231 self.boxsizer_source.AddMany([(self.name_sizer, 0, 232 wx.EXPAND |wx.TOP|wx.BOTTOM, 5),232 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 233 233 (self.radiation_sizer, 0, 234 wx.EXPAND |wx.TOP|wx.BOTTOM, 5),234 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 235 235 (self.beam_shape_sizer, 0, 236 wx.EXPAND |wx.TOP|wx.BOTTOM, 5),236 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 237 237 (self.wavelength_sizer, 0, 238 wx.EXPAND |wx.TOP|wx.BOTTOM, 5),238 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 239 239 (self.wavelength_min_sizer, 0, 240 wx.EXPAND |wx.TOP|wx.BOTTOM, 5),240 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 241 241 (self.wavelength_max_sizer, 0, 242 wx.EXPAND |wx.TOP|wx.BOTTOM, 5),242 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 243 243 (self.wavelength_spread_sizer, 0, 244 wx.EXPAND |wx.TOP|wx.BOTTOM, 5),244 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 245 245 (self.beam_size_name_sizer, 0, 246 wx.EXPAND |wx.TOP|wx.BOTTOM, 5),246 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 247 247 (self.beam_size_sizer, 0, 248 wx.EXPAND |wx.TOP|wx.BOTTOM, 5)])248 wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) 249 249 self.main_sizer.AddMany([(self.boxsizer_source, 0, wx.ALL, 10), 250 250 (self.button_sizer, 0, 251 wx.EXPAND |wx.TOP|wx.BOTTOM, 5)])252 251 wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) 252 253 253 self.SetSizer(self.main_sizer) 254 254 self.SetAutoLayout(True) 255 255 256 256 def set_manager(self, manager): 257 """ 257 """ 258 258 Set manager of this window 259 259 """ 260 260 self.manager = manager 261 261 262 262 def reset_source(self): 263 263 """ … … 267 267 self._source.radiation = self._reset_source.radiation 268 268 self._source.beam_size_name = self._reset_source.beam_size_name 269 270 self._source.beam_size.x = 271 self._source.beam_size.y = 272 self._source.beam_size.z = 269 270 self._source.beam_size.x = self._reset_source.beam_size.x 271 self._source.beam_size.y = self._reset_source.beam_size.y 272 self._source.beam_size.z = self._reset_source.beam_size.z 273 273 self._source.beam_size_unit = self._reset_source.beam_size_unit 274 274 275 275 self._source.beam_shape = self._reset_source.beam_shape 276 276 self._source.wavelength = self._reset_source.wavelength … … 279 279 self._source.wavelength_min = self._reset_source.wavelength_min 280 280 self._source.wavelength_min_unit = self._reset_source.wavelength_min_unit 281 281 282 282 self._source.wavelength_max = self._reset_source.wavelength_max 283 283 self._source.wavelength_max_unit = self._reset_source.wavelength_max_unit 284 284 285 285 self._source.wavelength_spread = self._reset_source.wavelength_spread 286 286 self._source.wavelength_spread_unit = self._reset_source.wavelength_spread_unit 287 287 288 288 def set_values(self): 289 289 """ … … 313 313 self.beam_size_name_tcl.SetValue(str(source.beam_size_name)) 314 314 x, y, z = source.beam_size.x, source.beam_size.y , source.beam_size.z 315 self.x_beam_size_tcl.SetValue(str(x)) 316 self.y_beam_size_tcl.SetValue(str(y)) 317 self.z_beam_size_tcl.SetValue(str(z)) 315 self.x_beam_size_tcl.SetValue(str(x)) 316 self.y_beam_size_tcl.SetValue(str(y)) 317 self.z_beam_size_tcl.SetValue(str(z)) 318 318 self.beam_size_unit_tcl.SetValue(str(source.beam_size_unit)) 319 319 320 320 def get_source(self): 321 321 """ … … 323 323 """ 324 324 return self._source 325 325 326 326 def get_notes(self): 327 327 """ … … 329 329 """ 330 330 return self._notes 331 331 332 332 def on_change_name(self): 333 333 """ … … 340 340 if self._source.name != name: 341 341 self._notes += "Change sample 's " 342 self._notes += "name from %s to %s \n" %(self._source.name, name)342 self._notes += "name from %s to %s \n" % (self._source.name, name) 343 343 self._source.name = name 344 344 345 345 def on_change_radiation(self): 346 346 """ 347 Change radiation of the sample 347 Change radiation of the sample 348 348 """ 349 349 #Change radiation … … 351 351 self._source.radiation = radiation 352 352 self._notes += " Change radiation from" 353 self._notes += " %s to %s \n" %(self._source.radiation, radiation)354 353 self._notes += " %s to %s \n" % (self._source.radiation, radiation) 354 355 355 def on_change_beam_shape(self): 356 356 """ … … 361 361 self._source.beam_shape = beam_shape 362 362 self._notes += " Change beam shape from" 363 self._notes += " %s to %s \n" %(self._source.beam_shape, beam_shape)364 363 self._notes += " %s to %s \n" % (self._source.beam_shape, beam_shape) 364 365 365 def on_change_wavelength(self): 366 366 """ … … 371 371 self._source.wavelength = wavelength 372 372 self._notes += " Change wavelength from" 373 self._notes += " %s to %s \n" %(self._source.wavelength, wavelength)373 self._notes += " %s to %s \n" % (self._source.wavelength, wavelength) 374 374 #change the wavelength unit 375 375 unit = self.wavelength_unit_tcl.GetValue().lstrip().rstrip() 376 376 if self._source.wavelength_unit != unit: 377 377 self._notes += " Change wavelength's unit from " 378 self._notes += "%s to %s" %(self._source.wavelength_unit, unit)379 378 self._notes += "%s to %s" % (self._source.wavelength_unit, unit) 379 380 380 def on_change_wavelength_min(self): 381 381 """ … … 393 393 self._notes += " Change wavelength min's unit from " 394 394 self._notes += "%s to %s" % (self._source.wavelength_min_unit, unit) 395 395 396 396 def on_change_wavelength_max(self): 397 397 """ … … 408 408 if self._source.wavelength_max_unit != unit: 409 409 self._notes += " Change wavelength max's unit from " 410 self._notes += "%s to %s" %(self._source.wavelength_max_unit, unit)411 410 self._notes += "%s to %s" % (self._source.wavelength_max_unit, unit) 411 412 412 def on_change_wavelength_spread(self): 413 413 """ … … 417 417 wavelength_spread = self.wavelength_spread_tcl.GetValue().lstrip().rstrip() 418 418 self._notes += " Change wavelength spread from" 419 self._notes += " %s to %s \n" % (self._source.wavelength_spread, 419 self._notes += " %s to %s \n" % (self._source.wavelength_spread, 420 420 wavelength_spread) 421 421 self._source.wavelength_spread = wavelength_spread … … 424 424 if self._source.wavelength_spread_unit != unit: 425 425 self._notes += " Change wavelength spread's unit from " 426 self._notes += "%s to %s" % (self._source.wavelength_spread_unit, 426 self._notes += "%s to %s" % (self._source.wavelength_spread_unit, 427 427 unit) 428 428 self._source.wavelength_spread_unit = unit 429 429 430 430 def on_change_beam_size_name(self): 431 431 """ … … 441 441 name) 442 442 self._source.name = name 443 443 444 444 def on_change_beam_size(self): 445 445 """ … … 456 456 self._notes += "%s to %s \n" % (self._source.beam_size.x, 457 457 x_beam_size) 458 self._source.beam_size.x 458 self._source.beam_size.x = float(x_beam_size) 459 459 else: 460 460 self._notes += "Error: Expected a float for the beam size 's x " … … 473 473 self._notes += "%s to %s \n" % (self._source.beam_size.y, 474 474 y_beam_size) 475 self._source.beam_size.y 475 self._source.beam_size.y = float(y_beam_size) 476 476 else: 477 477 self._notes += "Error: Expected a float for the beam size's y " … … 490 490 self._notes += "%s to %s \n" % (self._source.beam_size.z, 491 491 z_beam_size) 492 self._source.beam_size.z 492 self._source.beam_size.z = float(z_beam_size) 493 493 else: 494 494 self._notes += "Error: Expected a float for the beam size 's z " … … 500 500 if self._source.beam_size_unit != unit: 501 501 self._notes += " Change beam size's unit from " 502 self._notes += "%s to %s" %(self._source.beam_size_unit, unit)502 self._notes += "%s to %s" % (self._source.beam_size_unit, unit) 503 503 self._source.beam_size_unit = unit 504 504 505 505 def on_click_apply(self, event): 506 506 """ … … 520 520 if event is not None: 521 521 event.Skip() 522 522 523 523 def on_click_cancel(self, event): 524 524 """ … … 531 531 if event is not None: 532 532 event.Skip() 533 534 if __name__ == "__main__":535 app 533 534 if __name__ == "__main__": 535 app = wx.App() 536 536 from sas.dataloader.data_info import Source 537 537 source = Source() … … 539 539 dlg.ShowModal() 540 540 app.MainLoop() 541
Note: See TracChangeset
for help on using the changeset viewer.