Changeset b0ab6cb in sasview for calculatorview/perspectives/calculator/data_editor.py
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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()
Note: See TracChangeset
for help on using the changeset viewer.