Changeset e767897 in sasview
- Timestamp:
- Aug 16, 2016 6:11:39 AM (8 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:
- a674d0b
- Parents:
- fa1cbee
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/data_panel.py
rb5c44f0 re767897 2 2 #This software was developed by the University of Tennessee as part of the 3 3 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 #project funded by the US National Science Foundation. 4 #project funded by the US National Science Foundation. 5 5 # 6 6 #See the license text in license.txt … … 41 41 as QucikPlotDialog 42 42 import sas.sasgui.guiframe.config as config 43 43 44 44 extension_list = [] 45 45 if config.APPLICATION_STATE_EXTENSION is not None: 46 46 extension_list.append(config.APPLICATION_STATE_EXTENSION) 47 EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS + extension_list 47 EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS + extension_list 48 48 PLUGINS_WLIST = config.PLUGINS_WLIST 49 49 APPLICATION_WLIST = config.APPLICATION_WLIST 50 50 51 #Control panel width 51 #Control panel width 52 52 if sys.platform.count("win32") > 0: 53 53 PANEL_WIDTH = 235 … … 67 67 STYLE_FLAG = wx.RAISED_BORDER|CT.TR_HAS_BUTTONS| CT.TR_HIDE_ROOT|\ 68 68 wx.WANTS_CHARS|CT.TR_HAS_VARIABLE_ROW_HEIGHT 69 70 69 70 71 71 class DataTreeCtrl(CT.CustomTreeCtrl): 72 72 """ … … 97 97 CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds) 98 98 self.root = self.AddRoot("Available Data") 99 99 100 100 def OnCompareItems(self, item1, item2): 101 """ 102 Overrides OnCompareItems in wx.TreeCtrl. 103 Used by the SortChildren method. 101 """ 102 Overrides OnCompareItems in wx.TreeCtrl. 103 Used by the SortChildren method. 104 104 """ 105 105 # Get the item data … … 113 113 else: 114 114 return 0 115 115 116 116 class DataPanel(ScrolledPanel, PanelBase): 117 117 """ 118 This panel displays data available in the application and widgets to 118 This panel displays data available in the application and widgets to 119 119 interact with data. 120 120 """ … … 123 123 ## Title to appear on top of the window 124 124 window_caption = "Data Explorer" 125 #type of window 125 #type of window 126 126 window_type = "Data Panel" 127 127 ## Flag to tell the GUI manager that this panel is not 128 128 # tied to any perspective 129 129 #ALWAYS_ON = True 130 def __init__(self, parent, 130 def __init__(self, parent, 131 131 list=None, 132 132 size=(PANEL_WIDTH, PANEL_HEIGHT), … … 138 138 PanelBase.__init__(self, parent) 139 139 self.SetupScrolling() 140 #Set window's font size 140 #Set window's font size 141 141 self.SetWindowVariant(variant=FONT_VARIANT) 142 self.loader = Loader() 142 self.loader = Loader() 143 143 #Default location 144 self._default_save_location = None 144 self._default_save_location = None 145 145 self.all_data1d = True 146 146 self.parent = parent.parent … … 188 188 if self.parent is not None: 189 189 self.parent.Bind(EVT_DELETE_PLOTPANEL, self._on_delete_plot_panel) 190 190 191 191 def do_layout(self): 192 192 """ … … 198 198 self.layout_batch() 199 199 self.layout_button() 200 200 201 201 def disable_app_combo(self, enable): 202 202 """ … … 204 204 """ 205 205 self.perspective_cbox.Enable(enable) 206 206 207 207 def define_panel_structure(self): 208 208 """ … … 213 213 self.sizer1 = wx.BoxSizer(wx.VERTICAL) 214 214 self.sizer1.SetMinSize(wx.Size(w/13, h*2/5)) 215 215 216 216 self.sizer2 = wx.BoxSizer(wx.VERTICAL) 217 217 self.sizer3 = wx.FlexGridSizer(9, 2, 4, 1) 218 218 self.sizer4 = wx.BoxSizer(wx.VERTICAL) 219 219 self.sizer5 = wx.BoxSizer(wx.VERTICAL) 220 220 221 221 self.vbox.Add(self.sizer5, 0, wx.EXPAND|wx.ALL, 1) 222 222 self.vbox.Add(self.sizer1, 1, wx.EXPAND|wx.ALL, 0) … … 224 224 self.vbox.Add(self.sizer3, 0, wx.EXPAND|wx.ALL, 10) 225 225 #self.vbox.Add(self.sizer4, 0, wx.EXPAND|wx.ALL,5) 226 226 227 227 self.SetSizer(self.vbox) 228 228 229 229 def layout_selection(self): 230 230 """ … … 244 244 self.selection_cbox.SetValue('Select all Data') 245 245 wx.EVT_COMBOBOX(self.selection_cbox, -1, self._on_selection_type) 246 self.sizer5.AddMany([(select_txt, 0, wx.ALL, 5), 246 self.sizer5.AddMany([(select_txt, 0, wx.ALL, 5), 247 247 (self.selection_cbox, 0, wx.ALL,5)]) 248 248 self.enable_selection() 249 250 249 250 251 251 def _on_selection_type(self, event): 252 252 """ … … 254 254 :param event: UI event 255 255 """ 256 def check_item_and_children(control, check_value=True): 257 self.tree_ctrl.CheckItem(data_ctrl, check_value) 258 if data_ctrl.HasChildren(): 259 if check_value == True and not control.IsExpanded(): 260 # Only select children if control is expanded 261 # Always deselect children, regardless (see ticket #259) 262 return 263 for child_ctrl in data_ctrl.GetChildren(): 264 self.tree_ctrl.CheckItem(child_ctrl, check_value) 265 256 266 option = self.selection_cbox.GetValue() 257 267 258 268 pos = self.selection_cbox.GetSelection() 259 269 if pos == wx.NOT_FOUND: 260 return 270 return 261 271 option = self.selection_cbox.GetString(pos) 262 272 for item in self.list_cb_data.values(): 263 273 data_ctrl, _, _, _, _, _, _, _ = item 264 _, data_class, _ = self.tree_ctrl.GetItemPyData(data_ctrl) 274 _, data_class, _ = self.tree_ctrl.GetItemPyData(data_ctrl) 265 275 if option == 'Select all Data': 266 self.tree_ctrl.CheckItem(data_ctrl, True)276 check_item_and_children(data_ctrl, check_value=True) 267 277 elif option == 'Unselect all Data': 268 self.tree_ctrl.CheckItem(data_ctrl,False)278 check_item_and_children(data_ctrl, check_value=False) 269 279 elif option == 'Select all Data 1D': 270 280 if data_class == 'Data1D': 271 self.tree_ctrl.CheckItem(data_ctrl, True)281 check_item_and_children(data_ctrl, check_value=True) 272 282 elif option == 'Unselect all Data 1D': 273 283 if data_class == 'Data1D': 274 self.tree_ctrl.CheckItem(data_ctrl, False) 275 elif option == 'Select all Data 1D': 276 if data_class == 'Data1D': 277 self.tree_ctrl.CheckItem(data_ctrl, True) 284 check_item_and_children(data_ctrl, check_value=False) 278 285 elif option == 'Select all Data 2D': 279 286 if data_class == 'Data2D': 280 self.tree_ctrl.CheckItem(data_ctrl, True)287 check_item_and_children(data_ctrl, check_value=True) 281 288 elif option == 'Unselect all Data 2D': 282 289 if data_class == 'Data2D': 283 self.tree_ctrl.CheckItem(data_ctrl, False)290 check_item_and_children(data_ctrl, check_value=False) 284 291 self.enable_append() 285 292 self.enable_freeze() … … 287 294 self.enable_import() 288 295 self.enable_remove() 289 296 290 297 def layout_button(self): 291 298 """ … … 293 300 """ 294 301 #Load Data Button 295 self.bt_add = wx.Button(self, wx.NewId(), "Load Data", 302 self.bt_add = wx.Button(self, wx.NewId(), "Load Data", 296 303 size=(BUTTON_WIDTH, -1)) 297 304 self.bt_add.SetToolTipString("Load data files") 298 305 wx.EVT_BUTTON(self, self.bt_add.GetId(), self._load_data) 299 306 300 307 #Delete Data Button 301 308 self.bt_remove = wx.Button(self, wx.NewId(), "Delete Data", … … 303 310 self.bt_remove.SetToolTipString("Delete data from the application") 304 311 wx.EVT_BUTTON(self, self.bt_remove.GetId(), self.on_remove) 305 312 306 313 #Send data to perspective button 307 314 self.bt_import = wx.Button(self, wx.NewId(), "Send To", … … 309 316 self.bt_import.SetToolTipString("Send Data set to active perspective") 310 317 wx.EVT_BUTTON(self, self.bt_import.GetId(), self.on_import) 311 318 312 319 #Choose perspective to be send data to combo box 313 320 self.perspective_cbox = wx.ComboBox(self, -1, … … 315 322 if not IS_MAC: 316 323 self.perspective_cbox.SetMinSize((BUTTON_WIDTH*1.6, -1)) 317 wx.EVT_COMBOBOX(self.perspective_cbox, -1, 324 wx.EVT_COMBOBOX(self.perspective_cbox, -1, 318 325 self._on_perspective_selection) 319 326 320 327 #Append data to current Graph Button 321 328 self.bt_append_plot = wx.Button(self, wx.NewId(), "Append Plot To", … … 324 331 "Plot the selected data in the active panel") 325 332 wx.EVT_BUTTON(self, self.bt_append_plot.GetId(), self.on_append_plot) 326 333 327 334 #Create a new graph and send data to that new graph button 328 self.bt_plot = wx.Button(self, wx.NewId(), "New Plot", 335 self.bt_plot = wx.Button(self, wx.NewId(), "New Plot", 329 336 size=(BUTTON_WIDTH, -1)) 330 337 self.bt_plot.SetToolTipString("To trigger plotting") 331 338 wx.EVT_BUTTON(self, self.bt_plot.GetId(), self.on_plot) 332 339 333 340 #Freeze current theory button - becomes a data set and stays on graph 334 self.bt_freeze = wx.Button(self, wx.NewId(), "Freeze Theory", 341 self.bt_freeze = wx.Button(self, wx.NewId(), "Freeze Theory", 335 342 size=(BUTTON_WIDTH, -1)) 336 343 freeze_tip = "To trigger freeze a theory: making a copy\n" … … 339 346 self.bt_freeze.SetToolTipString(freeze_tip) 340 347 wx.EVT_BUTTON(self, self.bt_freeze.GetId(), self.on_freeze) 341 348 342 349 #select plot to send to combo box (blank if no data) 343 350 if sys.platform == 'darwin': 344 self.cb_plotpanel = wx.ComboBox(self, -1, 351 self.cb_plotpanel = wx.ComboBox(self, -1, 345 352 style=wx.CB_READONLY) 346 353 else: 347 self.cb_plotpanel = wx.ComboBox(self, -1, 354 self.cb_plotpanel = wx.ComboBox(self, -1, 348 355 style=wx.CB_READONLY|wx.CB_SORT) 349 356 wx.EVT_COMBOBOX(self.cb_plotpanel, -1, self._on_plot_selection) 350 357 self.cb_plotpanel.Disable() 351 358 352 359 #Help button 353 360 self.bt_help = wx.Button(self, wx.NewId(), "HELP", … … 365 372 ((10, 10)), 366 373 (self.bt_append_plot), 367 (self.cb_plotpanel, 374 (self.cb_plotpanel, 368 375 wx.EXPAND|wx.ADJUST_MINSIZE, 5), 369 376 ((5, 5)), 370 377 ((5, 5)), 371 378 (self.bt_import, 0, wx.EXPAND|wx.RIGHT, 5), 372 (self.perspective_cbox, 379 (self.perspective_cbox, 373 380 wx.EXPAND|wx.ADJUST_MINSIZE, 5), 374 381 ((10, 10)), … … 385 392 self.enable_freeze() 386 393 self.enable_remove_plot() 387 394 388 395 def layout_batch(self): 389 396 """ … … 397 404 self.Bind(wx.EVT_RADIOBUTTON, self.on_batch_mode, 398 405 id=self.rb_batch_mode.GetId()) 399 406 400 407 self.rb_single_mode.SetValue(not self.parent.batch_on) 401 408 self.rb_batch_mode.SetValue(self.parent.batch_on) 402 409 self.sizer4.AddMany([(self.rb_single_mode, 0, wx.ALL, 4), 403 410 (self.rb_batch_mode, 0, wx.ALL, 4)]) 404 411 405 412 def on_single_mode(self, event): 406 413 """ … … 410 417 if self.parent is not None: 411 418 wx.PostEvent(self.parent, NewBatchEvent(enable=False)) 412 419 413 420 def on_batch_mode(self, event): 414 421 """ … … 417 424 """ 418 425 if self.parent is not None: 419 wx.PostEvent(self.parent, 426 wx.PostEvent(self.parent, 420 427 NewBatchEvent(enable=True)) 421 422 def _get_data_selection(self, event): 428 429 def _get_data_selection(self, event): 423 430 """ 424 431 Get data selection from the right click … … 435 442 data = theory_list.values()[0][0] 436 443 return data 437 444 438 445 def on_edit_data(self, event): 439 446 """ … … 443 450 from sas.sasgui.guiframe.local_perspectives.plotting.masking \ 444 451 import MaskPanel as MaskDialog 445 446 panel = MaskDialog(parent=self.parent, base=self, 452 453 panel = MaskDialog(parent=self.parent, base=self, 447 454 data=data, id=wx.NewId()) 448 455 panel.ShowModal() 449 456 450 457 def on_plot_3d(self, event): 451 458 """ … … 455 462 from sas.sasgui.guiframe.local_perspectives.plotting.masking \ 456 463 import FloatPanel as Float3dDialog 457 458 panel = Float3dDialog(base=self, data=data, 464 465 panel = Float3dDialog(base=self, data=data, 459 466 dimension=3, id=wx.NewId()) 460 panel.ShowModal() 461 467 panel.ShowModal() 468 462 469 def on_quick_plot(self, event): 463 470 """ … … 468 475 dimension = 2 469 476 else: 470 dimension = 1 471 #panel = QucikPlotDialog(base=self, data=data, 477 dimension = 1 478 #panel = QucikPlotDialog(base=self, data=data, 472 479 # dimension=dimension, id=wx.NewId()) 473 480 frame = QucikPlotDialog(self, -1, "Plot " + data.name, 'log_{10}') … … 477 484 frame.Show(True) 478 485 frame.SetFocus() 479 #panel.ShowModal() 480 486 #panel.ShowModal() 487 481 488 def on_data_info(self, event): 482 489 """ … … 488 495 else: 489 496 self.parent.show_data1d(data, data.name) 490 497 491 498 def on_save_as(self, event): 492 499 """ … … 506 513 else: 507 514 print "unable to save this type of data" 508 515 509 516 def layout_data_list(self): 510 517 """ … … 523 530 self.data_menu.Append(id, name, msg) 524 531 wx.EVT_MENU(self, id, self.on_data_info) 525 532 526 533 id = wx.NewId() 527 534 name = "Save As" … … 529 536 self.data_menu.Append(id, name, msg) 530 537 wx.EVT_MENU(self, id, self.on_save_as) 531 538 532 539 quickplot_id = wx.NewId() 533 540 name = "Quick Plot" … … 535 542 self.data_menu.Append(quickplot_id, name, msg) 536 543 wx.EVT_MENU(self, quickplot_id, self.on_quick_plot) 537 544 538 545 self.plot3d_id = wx.NewId() 539 546 name = "Quick 3DPlot (Slow)" … … 541 548 self.data_menu.Append(self.plot3d_id, name, msg) 542 549 wx.EVT_MENU(self, self.plot3d_id, self.on_plot_3d) 543 550 544 551 self.editmask_id = wx.NewId() 545 552 name = "Edit Mask" … … 547 554 self.data_menu.Append(self.editmask_id, name, msg) 548 555 wx.EVT_MENU(self, self.editmask_id, self.on_edit_data) 549 556 550 557 tree_ctrl_theory_label = wx.StaticText(self, -1, "Theory") 551 558 tree_ctrl_theory_label.SetForegroundColour('blue') 552 self.tree_ctrl_theory = DataTreeCtrl(parent=self, 559 self.tree_ctrl_theory = DataTreeCtrl(parent=self, 553 560 style=wx.SUNKEN_BORDER) 554 self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_CHECKING, 561 self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_CHECKING, 555 562 self.on_check_item) 556 self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_MENU, 563 self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_MENU, 557 564 self.on_right_click_theory) 558 565 self.sizer1.Add(tree_ctrl_label, 0, wx.LEFT, 10) … … 560 567 self.sizer1.Add(tree_ctrl_theory_label, 0, wx.LEFT, 10) 561 568 self.sizer1.Add(self.tree_ctrl_theory, 1, wx.EXPAND|wx.ALL, 10) 562 569 563 570 def on_right_click_theory(self, event): 564 571 """ … … 575 582 self.data_menu.Enable(self.editmask_id, False) 576 583 self.data_menu.Enable(self.plot3d_id, menu_enable) 577 self.PopupMenu(self.data_menu) 578 584 self.PopupMenu(self.data_menu) 585 579 586 def on_right_click_data(self, event): 580 587 """ … … 596 603 self.data_menu.Enable(self.editmask_id, maskmenu_enable) 597 604 self.data_menu.Enable(self.plot3d_id, menu_enable) 598 self.PopupMenu(self.data_menu) 599 600 def onContextMenu(self, event): 605 self.PopupMenu(self.data_menu) 606 607 def onContextMenu(self, event): 601 608 """ 602 609 Retrieve the state selected state … … 606 613 pos = event.GetPosition() 607 614 pos = self.ScreenToClient(pos) 608 self.PopupMenu(self.popUpMenu, pos) 609 610 615 self.PopupMenu(self.popUpMenu, pos) 616 617 611 618 def on_check_item(self, event): 612 619 """ … … 614 621 """ 615 622 item = event.GetItem() 616 item.Check(not item.IsChecked()) 623 item.Check(not item.IsChecked()) 617 624 self.enable_append() 618 625 self.enable_freeze() … … 621 628 self.enable_remove() 622 629 event.Skip() 623 630 624 631 def fill_cbox_analysis(self, plugin): 625 632 """ … … 635 642 if plug.get_perspective(): 636 643 self.perspective_cbox.Append(plug.sub_menu, plug) 637 644 638 645 curr_pers = self.parent.get_current_perspective() 639 646 if curr_pers: 640 647 self.perspective_cbox.SetStringSelection(curr_pers.sub_menu) 641 648 self.enable_import() 642 649 643 650 def load_data_list(self, list): 644 651 """ … … 654 661 data_run = str(data.run) 655 662 data_class = data.__class__.__name__ 656 path = dstate.get_path() 663 path = dstate.get_path() 657 664 process_list = data.process 658 665 data_id = data.id … … 661 668 #new state 662 669 data_c = self.tree_ctrl.InsertItem(self.tree_ctrl.root, 663 0, data_name, ct_type=1, 670 0, data_name, ct_type=1, 664 671 data=(data_id, data_class, state_id)) 665 672 data_c.Check(True) 666 673 d_i_c = self.tree_ctrl.AppendItem(data_c, 'Info') 667 d_t_c = self.tree_ctrl.AppendItem(d_i_c, 674 d_t_c = self.tree_ctrl.AppendItem(d_i_c, 668 675 'Title: %s' % data_title) 669 r_n_c = self.tree_ctrl.AppendItem(d_i_c, 676 r_n_c = self.tree_ctrl.AppendItem(d_i_c, 670 677 'Run: %s' % data_run) 671 i_c_c = self.tree_ctrl.AppendItem(d_i_c, 678 i_c_c = self.tree_ctrl.AppendItem(d_i_c, 672 679 'Type: %s' % data_class) 673 680 p_c_c = self.tree_ctrl.AppendItem(d_i_c, 674 681 "Path: '%s'" % s_path) 675 682 d_p_c = self.tree_ctrl.AppendItem(d_i_c, 'Process') 676 683 677 684 for process in process_list: 678 685 process_str = str(process).replace('\n',' ') … … 680 687 process_str = process_str[:20]+' [...]' 681 688 self.tree_ctrl.AppendItem(d_p_c, process_str) 682 theory_child = self.tree_ctrl.AppendItem(data_c, 689 theory_child = self.tree_ctrl.AppendItem(data_c, 683 690 "THEORIES") 684 self.list_cb_data[state_id] = [data_c, 691 self.list_cb_data[state_id] = [data_c, 685 692 d_i_c, 686 693 d_t_c, … … 695 702 data_c, d_i_c, d_t_c, r_n_c, i_c_c, p_c_c, d_p_c, _ \ 696 703 = data_ctrl_list 697 self.tree_ctrl.SetItemText(data_c, data_name) 704 self.tree_ctrl.SetItemText(data_c, data_name) 698 705 temp = (data_id, data_class, state_id) 699 self.tree_ctrl.SetItemPyData(data_c, temp) 700 self.tree_ctrl.SetItemText(i_c_c, 706 self.tree_ctrl.SetItemPyData(data_c, temp) 707 self.tree_ctrl.SetItemText(i_c_c, 701 708 'Type: %s' % data_class) 702 self.tree_ctrl.SetItemText(p_c_c, 703 'Path: %s' % s_path) 704 self.tree_ctrl.DeleteChildren(d_p_c) 709 self.tree_ctrl.SetItemText(p_c_c, 710 'Path: %s' % s_path) 711 self.tree_ctrl.DeleteChildren(d_p_c) 705 712 for process in process_list: 706 713 if not process.is_empty(): … … 710 717 # Sort by data name 711 718 if self.tree_ctrl.root: 712 self.tree_ctrl.SortChildren(self.tree_ctrl.root) 719 self.tree_ctrl.SortChildren(self.tree_ctrl.root) 713 720 self.enable_remove() 714 721 self.enable_import() … … 716 723 self.enable_freeze() 717 724 self.enable_selection() 718 725 719 726 def _uncheck_all(self): 720 727 """ … … 723 730 for item in self.list_cb_data.values(): 724 731 data_ctrl, _, _, _, _, _, _, _ = item 725 self.tree_ctrl.CheckItem(data_ctrl, False) 732 self.tree_ctrl.CheckItem(data_ctrl, False) 726 733 self.enable_append() 727 734 self.enable_freeze() … … 729 736 self.enable_import() 730 737 self.enable_remove() 731 738 732 739 def append_theory(self, state_id, theory_list): 733 740 """ … … 736 743 """ 737 744 if not theory_list: 738 return 745 return 739 746 if state_id not in self.list_cb_data.keys(): 740 747 root = self.tree_ctrl_theory.root … … 746 753 tree = self.tree_ctrl 747 754 if root is not None: 748 wx.CallAfter(self.append_theory_helper, tree=tree, root=root, 749 state_id=state_id, 755 wx.CallAfter(self.append_theory_helper, tree=tree, root=root, 756 state_id=state_id, 750 757 theory_list=theory_list) 751 752 758 759 753 760 def append_theory_helper(self, tree, root, state_id, theory_list): 754 761 """ … … 778 785 name, ct_type=1, data=temp) 779 786 t_i_c = tree.AppendItem(t_child, 'Info') 780 i_c_c = tree.AppendItem(t_i_c, 787 i_c_c = tree.AppendItem(t_i_c, 781 788 'Type: %s' % theory_class) 782 789 t_p_c = tree.AppendItem(t_i_c, 'Process') 783 790 784 791 for process in theory_data.process: 785 792 tree.AppendItem(t_p_c, process.__str__()) 786 theory_list_ctrl[theory_id] = [t_child, 787 i_c_c, 793 theory_list_ctrl[theory_id] = [t_child, 794 i_c_c, 788 795 t_p_c] 789 796 else: 790 797 #replace theory 791 798 t_child, i_c_c, t_p_c = theory_list_ctrl[theory_id] 792 tree.SetItemText(t_child, name) 793 tree.SetItemPyData(t_child, temp) 794 tree.SetItemText(i_c_c, 'Type: %s' % theory_class) 795 tree.DeleteChildren(t_p_c) 799 tree.SetItemText(t_child, name) 800 tree.SetItemPyData(t_child, temp) 801 tree.SetItemText(i_c_c, 'Type: %s' % theory_class) 802 tree.DeleteChildren(t_p_c) 796 803 for process in theory_data.process: 797 804 tree.AppendItem(t_p_c, process.__str__()) 798 805 799 806 else: 800 807 #data didn't have a theory associated it before … … 807 814 theory_id = theory_data.id 808 815 #if theory_state is not None: 809 # name = theory_state.model.name 816 # name = theory_state.model.name 810 817 temp = (theory_id, theory_class, state_id) 811 818 t_child = tree.AppendItem(root, 812 name, ct_type=1, 819 name, ct_type=1, 813 820 data=(theory_data.id, theory_class, state_id)) 814 821 t_i_c = tree.AppendItem(t_child, 'Info') 815 i_c_c = tree.AppendItem(t_i_c, 822 i_c_c = tree.AppendItem(t_i_c, 816 823 'Type: %s' % theory_class) 817 824 t_p_c = tree.AppendItem(t_i_c, 'Process') 818 825 819 826 for process in theory_data.process: 820 827 tree.AppendItem(t_p_c, process.__str__()) 821 828 822 829 theory_list_ctrl[theory_id] = [t_child, i_c_c, t_p_c] 823 830 #self.list_cb_theory[data_id] = theory_list_ctrl 824 831 self.list_cb_theory[state_id] = theory_list_ctrl 825 826 827 832 833 834 828 835 def set_data_helper(self): 829 836 """ … … 840 847 if state_id not in state_to_plot: 841 848 state_to_plot.append(state_id) 842 849 843 850 for theory_dict in self.list_cb_theory.values(): 844 851 for _, value in theory_dict.iteritems(): … … 850 857 state_to_plot.append(state_id) 851 858 return data_to_plot, theory_to_plot, state_to_plot 852 859 853 860 def remove_by_id(self, id): 854 861 """ … … 857 864 for item in self.list_cb_data.values(): 858 865 data_c, _, _, _, _, _, _, _ = item 859 data_id, _, state_id = self.tree_ctrl.GetItemPyData(data_c) 866 data_id, _, state_id = self.tree_ctrl.GetItemPyData(data_c) 860 867 if id == data_id: 861 868 self.tree_ctrl.Delete(data_c) 862 869 del self.list_cb_data[state_id] 863 870 del self.list_cb_theory[data_id] 864 871 865 872 def load_error(self, error=None): 866 873 """ 867 874 Pop up an error message. 868 875 869 876 :param error: details error message to be displayed 870 877 """ 871 878 if error is not None or str(error).strip() != "": 872 dial = wx.MessageDialog(self.parent, str(error), 879 dial = wx.MessageDialog(self.parent, str(error), 873 880 'Error Loading File', 874 881 wx.OK | wx.ICON_EXCLAMATION) 875 dial.ShowModal() 876 882 dial.ShowModal() 883 877 884 def _load_data(self, event): 878 885 """ … … 881 888 if self.parent is not None: 882 889 wx.PostEvent(self.parent, NewLoadDataEvent()) 883 890 884 891 885 892 def on_remove(self, event): 886 893 """ 887 894 Get a list of item checked and remove them from the treectrl 888 Ask the parent to remove reference to this item 895 Ask the parent to remove reference to this item 889 896 """ 890 897 msg = "This operation will delete the data sets checked " … … 893 900 if msg_box.ShowModal() != wx.ID_OK: 894 901 return 895 902 896 903 data_to_remove, theory_to_remove, _ = self.set_data_helper() 897 904 data_key = [] … … 906 913 theory_list_ctrl = self.list_cb_theory[d_key] 907 914 theory_to_remove += theory_list_ctrl.keys() 908 # Remove theory from treectrl 915 # Remove theory from treectrl 909 916 for _, theory_dict in self.list_cb_theory.iteritems(): 910 917 for key, value in theory_dict.iteritems(): … … 916 923 pass 917 924 theory_key.append(key) 918 925 919 926 #Remove data and related theory references 920 927 for key in data_key: … … 934 941 pass 935 942 del theory_dict[key] 936 937 943 944 938 945 self.parent.remove_data(data_id=data_to_remove, 939 946 theory_id=theory_to_remove) … … 941 948 self.enable_freeze() 942 949 self.enable_remove_plot() 943 950 944 951 def on_import(self, event=None): 945 952 """ … … 951 958 temp = data_id + state_id 952 959 self.parent.set_data(data_id=temp, theory_id=theory_id) 953 960 954 961 def on_append_plot(self, event=None): 955 962 """ … … 958 965 self._on_plot_selection() 959 966 data_id, theory_id, state_id = self.set_data_helper() 960 self.parent.plot_data(data_id=data_id, 967 self.parent.plot_data(data_id=data_id, 961 968 state_id=state_id, 962 969 theory_id=theory_id, 963 970 append=True) 964 971 965 972 def on_plot(self, event=None): 966 973 """ … … 968 975 """ 969 976 data_id, theory_id, state_id = self.set_data_helper() 970 self.parent.plot_data(data_id=data_id, 977 self.parent.plot_data(data_id=data_id, 971 978 state_id=state_id, 972 979 theory_id=theory_id, 973 980 append=False) 974 981 self.enable_remove_plot() 975 982 976 983 def on_close_page(self, event=None): 977 984 """ … … 982 989 # send parent to update menu with no show nor hide action 983 990 self.parent.show_data_panel(action=False) 984 991 985 992 def on_freeze(self, event): 986 993 """ … … 995 1002 msg = "Freeze Theory: Requires at least one theory checked." 996 1003 wx.PostEvent(self.parent, StatusEvent(status=msg)) 997 1004 998 1005 def set_active_perspective(self, name): 999 1006 """ … … 1002 1009 self.perspective_cbox.SetStringSelection(name) 1003 1010 self.enable_import() 1004 1011 1005 1012 def _on_delete_plot_panel(self, event): 1006 1013 """ 1007 get an event with attribute name and caption to delete existing name 1014 get an event with attribute name and caption to delete existing name 1008 1015 from the combobox of the current panel 1009 1016 """ … … 1011 1018 caption = event.caption 1012 1019 if self.cb_plotpanel is not None: 1013 pos = self.cb_plotpanel.FindString(str(caption)) 1020 pos = self.cb_plotpanel.FindString(str(caption)) 1014 1021 if pos != wx.NOT_FOUND: 1015 1022 self.cb_plotpanel.Delete(pos) 1016 1023 self.enable_append() 1017 1024 1018 1025 def set_panel_on_focus(self, name=None): 1019 1026 """ … … 1031 1038 self.enable_append() 1032 1039 self.enable_remove_plot() 1033 1040 1034 1041 def set_plot_unfocus(self): 1035 1042 """ … … 1037 1044 """ 1038 1045 return 1039 1046 1040 1047 def _on_perspective_selection(self, event=None): 1041 1048 """ … … 1047 1054 perspective.on_perspective(event=None) 1048 1055 self.parent.check_multimode(perspective=perspective) 1049 1056 1050 1057 def _on_plot_selection(self, event=None): 1051 1058 """ … … 1061 1068 if combo.GetValue() != 'None': 1062 1069 panel = combo.GetClientData(selection) 1063 self.parent.on_set_plot_focus(panel) 1064 1070 self.parent.on_set_plot_focus(panel) 1071 1065 1072 def on_close_plot(self, event): 1066 1073 """ 1067 1074 clseo the panel on focus 1068 """ 1075 """ 1069 1076 self.enable_append() 1070 1077 selection = self.cb_plotpanel.GetSelection() … … 1072 1079 panel = self.cb_plotpanel.GetClientData(selection) 1073 1080 if self.parent is not None and panel is not None: 1074 wx.PostEvent(self.parent, 1081 wx.PostEvent(self.parent, 1075 1082 NewPlotEvent(group_id=panel.group_id, 1076 1083 action="delete")) 1077 1084 self.enable_remove_plot() 1078 1085 1079 1086 def set_frame(self, frame): 1080 1087 """ 1081 1088 """ 1082 1089 self.frame = frame 1083 1090 1084 1091 def get_frame(self): 1085 1092 """ 1086 1093 """ 1087 return self.frame 1088 1094 return self.frame 1095 1089 1096 def on_help(self, event): 1090 1097 """ … … 1115 1122 """ 1116 1123 self.parent.show_data_panel(event) 1117 1124 1118 1125 def set_schedule_full_draw(self, panel=None, func='del'): 1119 1126 """ … … 1121 1128 """ 1122 1129 self.parent.set_schedule_full_draw(panel, func) 1123 1130 1124 1131 def enable_remove_plot(self): 1125 1132 """ … … 1131 1138 #else: 1132 1139 # self.bt_close_plot.Enable() 1133 1140 1134 1141 def enable_remove(self): 1135 1142 """ … … 1142 1149 else: 1143 1150 self.bt_remove.Enable() 1144 1151 1145 1152 def enable_import(self): 1146 1153 """ … … 1160 1167 else: 1161 1168 self.perspective_cbox.Enable() 1162 1169 1163 1170 def enable_plot(self): 1164 1171 """ 1165 1172 enable or disable plot button 1166 1173 """ 1167 n_t = 0 1174 n_t = 0 1168 1175 n_t_t = 0 1169 1176 if self.tree_ctrl != None: … … 1176 1183 self.bt_plot.Enable() 1177 1184 self.enable_append() 1178 1185 1179 1186 def enable_append(self): 1180 1187 """ 1181 1188 enable or disable append button 1182 1189 """ 1183 n_t = 0 1190 n_t = 0 1184 1191 n_t_t = 0 1185 1192 if self.tree_ctrl != None: … … 1187 1194 if self.tree_ctrl_theory != None: 1188 1195 n_t_t = self.tree_ctrl_theory.GetCount() 1189 if n_t + n_t_t <= 0: 1196 if n_t + n_t_t <= 0: 1190 1197 self.bt_append_plot.Disable() 1191 1198 self.cb_plotpanel.Disable() … … 1196 1203 self.bt_append_plot.Enable() 1197 1204 self.cb_plotpanel.Enable() 1198 1205 1199 1206 def check_theory_to_freeze(self): 1200 1207 """ … … 1214 1221 else: 1215 1222 self.bt_freeze.Disable() 1216 1223 1217 1224 def enable_selection(self): 1218 1225 """ … … 1229 1236 else: 1230 1237 self.selection_cbox.Disable() 1231 1238 1232 1239 def show_data_button(self): 1233 1240 """ 1234 show load data and remove data button if 1241 show load data and remove data button if 1235 1242 dataloader on else hide them 1236 1243 """ … … 1238 1245 gui_style = self.parent.get_style() 1239 1246 style = gui_style & GUIFRAME.DATALOADER_ON 1240 if style == GUIFRAME.DATALOADER_ON: 1247 if style == GUIFRAME.DATALOADER_ON: 1241 1248 #self.bt_remove.Show(True) 1242 self.bt_add.Show(True) 1249 self.bt_add.Show(True) 1243 1250 else: 1244 1251 #self.bt_remove.Hide() 1245 1252 self.bt_add.Hide() 1246 except: 1253 except: 1247 1254 #self.bt_remove.Hide() 1248 self.bt_add.Hide() 1249 1255 self.bt_add.Hide() 1256 1250 1257 1251 1258 … … 1264 1271 self.list_of_ctrl = [] 1265 1272 if not data_list: 1266 return 1273 return 1267 1274 self._sizer_main = wx.BoxSizer(wx.VERTICAL) 1268 1275 self._sizer_txt = wx.BoxSizer(wx.VERTICAL) … … 1273 1280 self._panel.SetupScrolling() 1274 1281 self.__do_layout(data_list, text=text) 1275 1282 1276 1283 def __do_layout(self, data_list, text=''): 1277 1284 """ … … 1279 1286 """ 1280 1287 if not data_list or len(data_list) <= 1: 1281 return 1288 return 1282 1289 #add text 1283 1290 1284 1291 text = "Deleting these file reset some panels.\n" 1285 1292 text += "Do you want to proceed?\n" … … 1315 1322 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 1316 1323 static_line = wx.StaticLine(self, -1) 1317 1324 1318 1325 self._sizer_txt.Add(self._panel, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 5) 1319 1326 self._sizer_main.Add(self._sizer_txt, 1, wx.EXPAND|wx.ALL, 10) 1320 #self._sizer_main.Add(self._data_text_ctrl, 0, 1327 #self._sizer_main.Add(self._data_text_ctrl, 0, 1321 1328 # wx.EXPAND|wx.LEFT|wx.RIGHT, 10) 1322 1329 self._sizer_main.Add(static_line, 0, wx.EXPAND, 0) … … 1324 1331 self.SetSizer(self._sizer_main) 1325 1332 self.Layout() 1326 1333 1327 1334 def get_data(self): 1328 1335 """ … … 1335 1342 temp.append(data) 1336 1343 return temp 1337 1344 1338 1345 class DataFrame(wx.Frame): 1339 1346 """ … … 1347 1354 # tied to any perspective 1348 1355 ALWAYS_ON = True 1349 1356 1350 1357 def __init__(self, parent=None, owner=None, manager=None, size=(300, 800), 1351 1358 list_of_perspective=[], list=[], *args, **kwds): … … 1357 1364 self.owner = owner 1358 1365 self._manager = manager 1359 self.panel = DataPanel(parent=self, 1366 self.panel = DataPanel(parent=self, 1360 1367 manager=manager, 1361 1368 list_of_perspective=list_of_perspective) 1362 1369 1363 1370 def load_data_list(self, list=[]): 1364 1371 """ … … 1366 1373 """ 1367 1374 self.panel.load_data_list(list=list) 1368 1369 1370 1375 1376 1377 1371 1378 from sas.sasgui.guiframe.dataFitting import Theory1D 1372 1379 from sas.sasgui.guiframe.data_state import DataState … … 1383 1390 self.msg += "name value\n" 1384 1391 return self.msg 1385 1392 1386 1393 def set_data_state(data=None, path=None, theory=None, state=None): 1387 1394 """ … … 1391 1398 dstate.set_path(path=path) 1392 1399 dstate.set_theory(theory, state) 1393 1400 1394 1401 return dstate 1395 1402 1396 1403 if __name__ == "__main__": 1397 1404 1398 1405 app = wx.App() 1399 1406 try: … … 1477 1484 #raise 1478 1485 print "error", sys.exc_value 1479 1480 app.MainLoop() 1481 1482 1486 1487 app.MainLoop()
Note: See TracChangeset
for help on using the changeset viewer.