Changeset 49ab5d7 in sasview for src/sas/perspectives/calculator/collimation_editor.py
- Timestamp:
- Mar 4, 2015 3:28:39 PM (9 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/collimation_editor.py
r79492222 r49ab5d7 11 11 _BOX_WIDTH = 60 12 12 13 if sys.platform.count("win32") >0:13 if sys.platform.count("win32") > 0: 14 14 _STATICBOX_WIDTH = 500 15 15 PANEL_WIDTH = 530 … … 21 21 PANEL_HEIGHT = 480 22 22 FONT_VARIANT = 1 23 23 24 24 class CollimationDialog(wx.Dialog): 25 25 """ … … 33 33 wx.Dialog.__init__(self, parent=parent, *args, **kwds) 34 34 self.parent = parent 35 self.manager = manager 35 self.manager = manager 36 36 self._collimation = collimation 37 37 self._reset_collimation = deepcopy(collimation) … … 42 42 self.box_collimation = None 43 43 self.boxsizer_collimation = None 44 45 44 45 46 46 self._do_layout() 47 47 self.set_values() 48 48 49 49 def _define_structure(self): 50 50 """ 51 define initial sizer 51 define initial sizer 52 52 """ 53 53 self.main_sizer = wx.BoxSizer(wx.VERTICAL) … … 56 56 self.boxsizer_collimation = wx.StaticBoxSizer(self.box_collimation, 57 57 wx.VERTICAL) 58 58 59 59 collimation_box = wx.StaticBox(self, -1, "Edit Number of Collimations") 60 60 self.collimation_sizer = wx.StaticBoxSizer(collimation_box, wx.VERTICAL) … … 62 62 self.collimation_button_sizer = wx.BoxSizer(wx.HORIZONTAL) 63 63 self.collimation_hint_sizer = wx.BoxSizer(wx.HORIZONTAL) 64 64 65 65 self.name_sizer = wx.BoxSizer(wx.HORIZONTAL) 66 66 self.length_sizer = wx.BoxSizer(wx.HORIZONTAL) 67 67 self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) 68 68 69 69 aperture_box = wx.StaticBox(self, -1, "Edit Aperture") 70 70 self.aperture_sizer = wx.StaticBoxSizer(aperture_box, wx.VERTICAL) 71 71 self.aperture_button_sizer = wx.BoxSizer(wx.HORIZONTAL) 72 72 self.aperture_hint_sizer = wx.BoxSizer(wx.HORIZONTAL) 73 73 74 74 def _layout_collimation(self): 75 75 """ 76 76 Do the layout for collimation related widgets 77 77 """ 78 collimation_name_txt = wx.StaticText(self, -1, "Collimation:") 78 collimation_name_txt = wx.StaticText(self, -1, "Collimation:") 79 79 hint_collimation_txt = 'Current available collimation.' 80 collimation_name_txt.SetToolTipString(hint_collimation_txt) 80 collimation_name_txt.SetToolTipString(hint_collimation_txt) 81 81 self.collimation_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 82 wx.EVT_COMBOBOX(self.collimation_cbox, -1, self.on_select_collimation) 82 wx.EVT_COMBOBOX(self.collimation_cbox, -1, self.on_select_collimation) 83 83 hint_collimation_name_txt = 'Name of collimations.' 84 self.collimation_cbox.SetToolTipString(hint_collimation_name_txt) 85 84 self.collimation_cbox.SetToolTipString(hint_collimation_name_txt) 85 86 86 self.bt_add_collimation = wx.Button(self, -1, "Add") 87 87 self.bt_add_collimation.SetToolTipString("Edit data's collimation.") 88 88 self.bt_add_collimation.Bind(wx.EVT_BUTTON, self.add_collimation) 89 89 90 90 self.bt_remove_collimation = wx.Button(self, -1, "Remove") 91 91 hint = "Remove data's collimation." 92 92 self.bt_remove_collimation.SetToolTipString(hint) 93 93 self.bt_remove_collimation.Bind(wx.EVT_BUTTON, self.remove_collimation) 94 94 95 95 self.collimation_button_sizer.AddMany([(collimation_name_txt, 0, 96 96 wx.LEFT, 15), … … 100 100 0, wx.LEFT, 5)]) 101 101 collimation_hint_txt = 'No collimation is available for this data.' 102 self.collimation_txt = wx.StaticText(self, -1, collimation_hint_txt) 102 self.collimation_txt = wx.StaticText(self, -1, collimation_hint_txt) 103 103 self.collimation_hint_sizer.Add(self.collimation_txt, 0, wx.LEFT, 10) 104 104 self.collimation_sizer.AddMany([(self.collimation_button_sizer, … … 106 106 (self.collimation_hint_sizer, 107 107 0, wx.ALL, 10)]) 108 108 109 109 self.fill_collimation_combox() 110 110 self.enable_collimation() 111 111 112 112 113 113 def _layout_name(self): … … 116 116 """ 117 117 #Collimation name [string] 118 name_txt = wx.StaticText(self, -1, 'Name : ') 119 self.name_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH *5, 20), style=0)120 self.name_sizer.AddMany([(name_txt, 0, wx.LEFT |wx.RIGHT, 10),118 name_txt = wx.StaticText(self, -1, 'Name : ') 119 self.name_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH * 5, 20), style=0) 120 self.name_sizer.AddMany([(name_txt, 0, wx.LEFT | wx.RIGHT, 10), 121 121 (self.name_tcl, 0, wx.EXPAND)]) 122 122 123 123 def _layout_length(self): 124 124 """ … … 126 126 """ 127 127 #Collimation length 128 length_txt = wx.StaticText(self, -1, 'Length:') 129 self.length_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 130 length_unit_txt = wx.StaticText(self, -1, 'Unit: ') 128 length_txt = wx.StaticText(self, -1, 'Length:') 129 self.length_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 130 length_unit_txt = wx.StaticText(self, -1, 'Unit: ') 131 131 self.length_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), 132 style=0) 133 self.length_sizer.AddMany([(length_txt, 0, wx.LEFT |wx.RIGHT, 10),132 style=0) 133 self.length_sizer.AddMany([(length_txt, 0, wx.LEFT | wx.RIGHT, 10), 134 134 (self.length_tcl, 0, wx.LEFT, 12), 135 (length_unit_txt, 0, wx.LEFT |wx.RIGHT, 10),136 (self.length_unit_tcl, 0, wx.EXPAND)]) 137 138 def _layout_button(self): 135 (length_unit_txt, 0, wx.LEFT | wx.RIGHT, 10), 136 (self.length_unit_tcl, 0, wx.EXPAND)]) 137 138 def _layout_button(self): 139 139 """ 140 140 Do the layout for the button widgets 141 """ 142 self.bt_apply = wx.Button(self, -1, 'Apply')141 """ 142 self.bt_apply = wx.Button(self, -1, 'Apply') 143 143 self.bt_apply.Bind(wx.EVT_BUTTON, self.on_click_apply) 144 144 self.bt_apply.SetToolTipString("Apply current changes to collimation.") 145 self.bt_cancel = wx.Button(self, -1, 'Cancel')145 self.bt_cancel = wx.Button(self, -1, 'Cancel') 146 146 self.bt_cancel.SetToolTipString("Cancel current changes.") 147 147 self.bt_cancel.Bind(wx.EVT_BUTTON, self.on_click_cancel) 148 self.bt_close = wx.Button(self, wx.ID_CANCEL, 'Close')148 self.bt_close = wx.Button(self, wx.ID_CANCEL, 'Close') 149 149 self.bt_close.SetToolTipString("Close window.") 150 150 self.button_sizer.AddMany([(self.bt_apply, 0, wx.LEFT, 200), … … 155 155 Do the layout for aperture related widgets 156 156 """ 157 aperture_name_txt = wx.StaticText(self, -1, "Aperture:") 157 aperture_name_txt = wx.StaticText(self, -1, "Aperture:") 158 158 hint_aperture_txt = 'Current available aperture.' 159 aperture_name_txt.SetToolTipString(hint_aperture_txt) 159 aperture_name_txt.SetToolTipString(hint_aperture_txt) 160 160 self.aperture_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 161 161 hint_aperture_name_txt = 'Name of apertures.' 162 self.aperture_cbox.SetToolTipString(hint_aperture_name_txt) 163 162 self.aperture_cbox.SetToolTipString(hint_aperture_name_txt) 163 164 164 self.bt_add_aperture = wx.Button(self, -1, "Add") 165 165 self.bt_add_aperture.SetToolTipString("Edit data's aperture.") … … 171 171 self.bt_remove_aperture.SetToolTipString("Remove data's aperture.") 172 172 self.bt_remove_aperture.Bind(wx.EVT_BUTTON, self.remove_aperture) 173 173 174 174 self.aperture_button_sizer.AddMany([(aperture_name_txt, 0, wx.LEFT, 15), 175 175 (self.aperture_cbox, 0, wx.LEFT, 5), … … 178 178 (self.bt_remove_aperture, 0, wx.LEFT, 5)]) 179 179 aperture_hint_txt = 'No aperture is available for this data.' 180 self.aperture_txt = wx.StaticText(self, -1, aperture_hint_txt) 180 self.aperture_txt = wx.StaticText(self, -1, aperture_hint_txt) 181 181 self.aperture_hint_sizer.Add(self.aperture_txt, 0, wx.LEFT, 10) 182 182 self.aperture_sizer.AddMany([(self.aperture_button_sizer, … … 185 185 self.fill_aperture_combox() 186 186 self.enable_aperture() 187 187 188 188 def _do_layout(self): 189 189 """ … … 196 196 self._layout_aperture() 197 197 self._layout_button() 198 198 199 199 self.boxsizer_collimation.AddMany([(self.name_sizer, 0, 200 wx.EXPAND |wx.TOP|wx.BOTTOM, 5),200 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 201 201 (self.length_sizer, 0, 202 wx.EXPAND |wx.TOP|wx.BOTTOM, 5),202 wx.EXPAND | wx.TOP | wx.BOTTOM, 5), 203 203 (self.aperture_sizer, 0, 204 wx.EXPAND |wx.ALL, 10)])204 wx.EXPAND | wx.ALL, 10)]) 205 205 self.main_sizer.AddMany([(self.collimation_sizer, 0, wx.ALL, 10), 206 206 (self.boxsizer_collimation, 0, wx.ALL, 10), 207 207 (self.button_sizer, 0, 208 wx.EXPAND |wx.TOP|wx.BOTTOM, 5)])208 wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) 209 209 self.SetSizer(self.main_sizer) 210 210 self.SetAutoLayout(True) 211 211 212 212 def get_current_collimation(self): 213 213 """ … … 215 215 if not self.collimation_cbox.IsEnabled(): 216 216 return None, None, None 217 position = self.collimation_cbox.GetSelection() 217 position = self.collimation_cbox.GetSelection() 218 218 if position == wx.NOT_FOUND: 219 219 return None, None, None 220 collimation_name = self.collimation_cbox.GetStringSelection() 220 collimation_name = self.collimation_cbox.GetStringSelection() 221 221 collimation = self.collimation_cbox.GetClientData(position) 222 222 return collimation, collimation_name, position 223 223 224 224 def fill_collimation_combox(self): 225 225 """ … … 232 232 self.collimation_cbox.SetClientData(pos, collimation) 233 233 self.collimation_cbox.SetSelection(pos) 234 self.collimation_cbox.SetStringSelection(str(collimation.name)) 235 234 self.collimation_cbox.SetStringSelection(str(collimation.name)) 235 236 236 def add_collimation(self, event): 237 237 """ 238 238 Append empty collimation to data's list of collimation 239 239 """ 240 240 241 241 if not self.collimation_cbox.IsEnabled(): 242 242 self.collimation_cbox.Enable() … … 245 245 position = self.collimation_cbox.Append(str(collimation.name)) 246 246 self.collimation_cbox.SetClientData(position, collimation) 247 self.collimation_cbox.SetSelection(position) 248 self.enable_collimation() 247 self.collimation_cbox.SetSelection(position) 248 self.enable_collimation() 249 249 self.bt_add_aperture.Enable() 250 250 self.fill_aperture_combox() 251 251 self.enable_aperture() 252 252 self.set_values() 253 253 254 254 def remove_collimation(self, event): 255 255 """ … … 262 262 if collimation in self._collimation: 263 263 self._collimation.remove(collimation) 264 self.collimation_cbox.Delete(position) 264 self.collimation_cbox.Delete(position) 265 265 #set the combo box box the next available item 266 266 position = self.collimation_cbox.GetCount() 267 267 if position > 0: 268 position -= 1 268 position -= 1 269 269 self.collimation_cbox.SetSelection(position) 270 if not self._collimation and self.collimation_cbox.GetCount() == 0: 271 self.bt_add_aperture.Disable() 270 if not self._collimation and self.collimation_cbox.GetCount() == 0: 271 self.bt_add_aperture.Disable() 272 272 self.name_tcl.Clear() 273 273 self.length_tcl.Clear() … … 278 278 self.enable_collimation() 279 279 self.enable_aperture() 280 280 281 281 def on_select_collimation(self, event): 282 282 """ 283 fill the control on the panel according to 284 the current selected collimation 283 fill the control on the panel according to 284 the current selected collimation 285 285 """ 286 286 self.set_values() 287 287 self.fill_aperture_combox() 288 288 self.enable_aperture() 289 289 290 290 def enable_collimation(self): 291 291 """ … … 298 298 n_collimation = self.collimation_cbox.GetCount() 299 299 collimation_hint_txt = "collimations" 300 collimation_hint_txt += " available: %s " % str(n_collimation)300 collimation_hint_txt += " available: %s " % str(n_collimation) 301 301 if len(self._collimation) > 0: 302 302 self.bt_remove_collimation.Enable() … … 308 308 collimation_hint_txt = 'No collimation is available for this data.' 309 309 self.collimation_txt.SetLabel(collimation_hint_txt) 310 311 310 311 312 312 def reset_collimation_combobox(self, edited_collimation): 313 313 """ … … 318 318 if collimation == edited_collimation: 319 319 collimation = edited_collimation 320 self.collimation_cbox.SetString(position, str(collimation.name)) 320 self.collimation_cbox.SetString(position, str(collimation.name)) 321 321 self.collimation_cbox.SetClientData(position, collimation) 322 self.collimation_cbox.SetStringSelection(str(collimation.name)) 323 322 self.collimation_cbox.SetStringSelection(str(collimation.name)) 323 324 324 def add_aperture(self, event): 325 325 """ … … 333 333 position = self.aperture_cbox.Append(str(aperture.name)) 334 334 self.aperture_cbox.SetClientData(position, aperture) 335 self.aperture_cbox.SetSelection(position) 335 self.aperture_cbox.SetSelection(position) 336 336 self.enable_aperture() 337 337 338 338 def edit_aperture(self, event): 339 339 """ … … 341 341 """ 342 342 if self._collimation is None or not self.aperture_cbox.IsEnabled(): 343 return 344 position = self.aperture_cbox.GetSelection() 343 return 344 position = self.aperture_cbox.GetSelection() 345 345 if position != wx.NOT_FOUND: 346 name = self.aperture_cbox.GetStringSelection() 346 name = self.aperture_cbox.GetStringSelection() 347 347 aperture = self.aperture_cbox.GetClientData(position) 348 348 dlg = ApertureDialog(parent=self, aperture=aperture) 349 349 dlg.set_manager(self) 350 350 dlg.ShowModal() 351 351 352 352 def remove_aperture(self, event): 353 353 """ … … 363 363 if aperture in collimation.aperture: 364 364 collimation.aperture.remove(aperture) 365 self.aperture_cbox.Delete(position) 365 self.aperture_cbox.Delete(position) 366 366 #set the combo box box the next available item 367 367 position = self.aperture_cbox.GetCount() 368 368 if position > 0: 369 position -= 1 369 position -= 1 370 370 self.aperture_cbox.SetSelection(position) 371 371 372 372 #disable or enable the combo box when necessary 373 373 self.enable_aperture() 374 374 375 375 def set_aperture(self, aperture): 376 376 """ … … 386 386 self.reset_aperture_combobox(edited_aperture=aperture) 387 387 return 388 388 389 389 def enable_aperture(self): 390 390 """ … … 397 397 self.bt_remove_aperture.Enable() 398 398 n_aperture = self.aperture_cbox.GetCount() 399 aperture_hint_txt = 'apertures available: %s ' %str(n_aperture)399 aperture_hint_txt = 'apertures available: %s ' % str(n_aperture) 400 400 if len(collimation.aperture) > 0: 401 401 self.bt_remove_aperture.Enable() … … 408 408 aperture_hint_txt = 'No aperture is available for this data.' 409 409 self.aperture_txt.SetLabel(aperture_hint_txt) 410 410 411 411 def reset_aperture_combobox(self, edited_aperture): 412 412 """ … … 417 417 if aperture == edited_aperture: 418 418 aperture = edited_aperture 419 self.aperture_cbox.SetString(position, str(aperture.name)) 419 self.aperture_cbox.SetString(position, str(aperture.name)) 420 420 self.aperture_cbox.SetClientData(position, aperture) 421 self.aperture_cbox.SetStringSelection(str(aperture.name)) 422 421 self.aperture_cbox.SetStringSelection(str(aperture.name)) 422 423 423 def fill_aperture_combox(self): 424 424 """ … … 433 433 self.aperture_cbox.SetClientData(pos, aperture) 434 434 self.aperture_cbox.SetSelection(pos) 435 self.aperture_cbox.SetStringSelection(str(aperture.name)) 436 435 self.aperture_cbox.SetStringSelection(str(aperture.name)) 436 437 437 def set_manager(self, manager): 438 """ 438 """ 439 439 Set manager of this window 440 440 """ 441 441 self.manager = manager 442 442 443 443 def set_values(self): 444 444 """ … … 459 459 #Length unit 460 460 self.length_unit_tcl.SetValue(str(collimation.length_unit)) 461 461 462 462 def get_collimation(self): 463 463 """ … … 465 465 """ 466 466 return self._collimation 467 467 468 468 def get_notes(self): 469 469 """ … … 471 471 """ 472 472 return self._notes 473 473 474 474 def on_change_name(self): 475 475 """ … … 477 477 """ 478 478 collimation, collimation_name, position = self.get_current_collimation() 479 if collimation is None: 479 if collimation is None: 480 480 return 481 481 #Change the name of the collimation … … 485 485 if collimation.name != name: 486 486 self._notes += "Change collimation 's " 487 self._notes += "name from %s to %s \n" %(collimation.name, name)487 self._notes += "name from %s to %s \n" % (collimation.name, name) 488 488 collimation.name = name 489 self.collimation_cbox.SetString(position, str(collimation.name)) 489 self.collimation_cbox.SetString(position, str(collimation.name)) 490 490 self.collimation_cbox.SetClientData(position, collimation) 491 self.collimation_cbox.SetStringSelection(str(collimation.name)) 492 491 self.collimation_cbox.SetStringSelection(str(collimation.name)) 492 493 493 def on_change_length(self): 494 494 """ … … 496 496 """ 497 497 collimation, collimation_name, position = self.get_current_collimation() 498 if collimation is None: 498 if collimation is None: 499 499 return 500 500 #Change length … … 507 507 if collimation.length != float(length): 508 508 self._notes += "Change Collimation length from " 509 self._notes += "%s to %s \n" %(collimation.length, length)510 collimation.length 509 self._notes += "%s to %s \n" % (collimation.length, length) 510 collimation.length = float(length) 511 511 else: 512 512 self._notes += "Error: Expected a float for collimation length" 513 513 self._notes += " won't changes length from " 514 self._notes += "%s to %s" %(collimation.length, length)514 self._notes += "%s to %s" % (collimation.length, length) 515 515 #change length unit 516 516 unit = self.length_unit_tcl.GetValue().lstrip().rstrip() 517 517 if collimation.length_unit != unit: 518 518 self._notes += " Change length's unit from " 519 self._notes += "%s to %s" %(collimation.length_unit, unit)519 self._notes += "%s to %s" % (collimation.length_unit, unit) 520 520 collimation.length_unit = unit 521 521 522 522 def on_click_apply(self, event): 523 523 """ … … 529 529 if self.manager is not None: 530 530 self.manager.set_collimation(self._collimation, self._notes) 531 531 532 532 def on_click_cancel(self, event): 533 533 """ … … 538 538 if self.manager is not None: 539 539 self.manager.set_collimation(self._collimation) 540 541 540 541 542 542 if __name__ == "__main__": 543 543 544 app 544 app = wx.App() 545 545 dlg = CollimationDialog(collimation=[Collimation()]) 546 546 dlg.ShowModal() 547 547 app.MainLoop() 548
Note: See TracChangeset
for help on using the changeset viewer.