Changeset 091e71a2 in sasview
- Timestamp:
- Mar 4, 2015 11:41:18 AM (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:
- 3350ad6
- Parents:
- 1128bd31
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/guiframe/gui_manager.py
r064723b r091e71a2 5 5 #This software was developed by the University of Tennessee as part of the 6 6 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 7 #project funded by the US National Science Foundation. 7 #project funded by the US National Science Foundation. 8 8 # 9 9 #See the license text in license.txtz … … 58 58 logging.info("Using application path: %s", app_path) 59 59 return app_path 60 60 61 61 # Next, try the current working directory 62 62 if os.path.isfile(os.path.join(os.getcwd(), "custom_config.py")): 63 63 logging.info("Using application path: %s", os.getcwd()) 64 64 return os.path.abspath(os.getcwd()) 65 65 66 66 # Finally, try the directory of the sasview module 67 67 #TODO: gui_manager will have to know about sasview until we … … 79 79 Returns the user's home directory 80 80 """ 81 userdir = os.path.join(os.path.expanduser("~"), ".sasview")81 userdir = os.path.join(os.path.expanduser("~"), ".sasview") 82 82 if not os.path.isdir(userdir): 83 83 os.makedirs(userdir) 84 84 return userdir 85 85 86 86 def _find_local_config(file, path): 87 87 """ 88 88 Find configuration file for the current application 89 """ 89 """ 90 90 config_module = None 91 91 fObj = None 92 92 try: 93 93 fObj, path_config, descr = imp.find_module(file, [path]) 94 config_module = imp.load_module(file, fObj, path_config, descr) 94 config_module = imp.load_module(file, fObj, path_config, descr) 95 95 except: 96 96 logging.error("Error loading %s/%s: %s" % (path, file, sys.exc_value)) … … 102 102 103 103 # Get APP folder 104 PATH_APP = get_app_dir() 104 PATH_APP = get_app_dir() 105 105 DATAPATH = PATH_APP 106 106 107 # GUI always starts from the App folder 107 # GUI always starts from the App folder 108 108 #os.chdir(PATH_APP) 109 109 # Read in the local config, which can either be with the main … … 113 113 config = _find_local_config('local_config', os.getcwd()) 114 114 if config is None: 115 # Didn't find local config, load the default 115 # Didn't find local config, load the default 116 116 import sas.guiframe.config as config 117 logging.info("using default local_config") 117 logging.info("using default local_config") 118 118 else: 119 logging.info("found local_config in %s" % os.getcwd()) 119 logging.info("found local_config in %s" % os.getcwd()) 120 120 else: 121 logging.info("found local_config in %s" % PATH_APP) 122 121 logging.info("found local_config in %s" % PATH_APP) 122 123 123 from sas.guiframe.customdir import SetupCustom 124 124 c_conf_dir = SetupCustom().setup_dir(PATH_APP) … … 154 154 PLOPANEL_WIDTH = custom_config.PLOPANEL_WIDTH 155 155 DATAPANEL_WIDTH = custom_config.DATAPANEL_WIDTH 156 GUIFRAME_WIDTH = custom_config.GUIFRAME_WIDTH 156 GUIFRAME_WIDTH = custom_config.GUIFRAME_WIDTH 157 157 GUIFRAME_HEIGHT = custom_config.GUIFRAME_HEIGHT 158 CONTROL_WIDTH = custom_config.CONTROL_WIDTH 158 CONTROL_WIDTH = custom_config.CONTROL_WIDTH 159 159 CONTROL_HEIGHT = custom_config.CONTROL_HEIGHT 160 160 DEFAULT_PERSPECTIVE = custom_config.DEFAULT_PERSPECTIVE … … 173 173 PLOPANEL_WIDTH = config.PLOPANEL_WIDTH 174 174 DATAPANEL_WIDTH = config.DATAPANEL_WIDTH 175 GUIFRAME_WIDTH = config.GUIFRAME_WIDTH 175 GUIFRAME_WIDTH = config.GUIFRAME_WIDTH 176 176 GUIFRAME_HEIGHT = config.GUIFRAME_HEIGHT 177 CONTROL_WIDTH = -1 177 CONTROL_WIDTH = -1 178 178 CONTROL_HEIGHT = -1 179 179 DEFAULT_PERSPECTIVE = None … … 183 183 DEFAULT_STYLE = config.DEFAULT_STYLE 184 184 185 PLUGIN_STATE_EXTENSIONS = 185 PLUGIN_STATE_EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS 186 186 OPEN_SAVE_MENU = config.OPEN_SAVE_PROJECT_MENU 187 187 VIEW_MENU = config.VIEW_MENU … … 214 214 PARENT_FRAME = wx.Frame 215 215 CHILD_FRAME = wx.Frame 216 216 217 217 class ViewerFrame(PARENT_FRAME): 218 218 """ 219 219 Main application frame 220 220 """ 221 222 def __init__(self, parent, title, 221 222 def __init__(self, parent, title, 223 223 size=(GUIFRAME_WIDTH, GUIFRAME_HEIGHT), 224 gui_style=DEFAULT_STYLE, 224 gui_style=DEFAULT_STYLE, 225 225 style=wx.DEFAULT_FRAME_STYLE, 226 226 pos=wx.DefaultPosition): … … 232 232 # title 233 233 self.title = title 234 self.__gui_style = gui_style 234 self.__gui_style = gui_style 235 235 path = os.path.dirname(__file__) 236 temp_path = os.path.join(path, 'images')237 ico_file = os.path.join(temp_path, 'ball.ico')236 temp_path = os.path.join(path, 'images') 237 ico_file = os.path.join(temp_path, 'ball.ico') 238 238 if os.path.isfile(ico_file): 239 239 self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) 240 240 else: 241 temp_path = os.path.join(os.getcwd(), 'images')242 ico_file = os.path.join(temp_path, 'ball.ico')241 temp_path = os.path.join(os.getcwd(), 'images') 242 ico_file = os.path.join(temp_path, 'ball.ico') 243 243 if os.path.isfile(ico_file): 244 244 self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) 245 245 else: 246 246 ico_file = os.path.join(os.path.dirname(os.path.sys.path[0]), 247 'images', 'ball.ico')247 'images', 'ball.ico') 248 248 if os.path.isfile(ico_file): 249 249 self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) 250 250 self.path = PATH_APP 251 self.application_name = APPLICATION_NAME 251 self.application_name = APPLICATION_NAME 252 252 ## Application manager 253 253 self._input_file = None … … 294 294 295 295 # Default locations 296 self._default_save_location = DEFAULT_OPEN_FOLDER 296 self._default_save_location = DEFAULT_OPEN_FOLDER 297 297 # Welcome panel 298 298 self.defaultPanel = None … … 303 303 self.cpanel_on_focus = None 304 304 305 self.loader = Loader() 305 self.loader = Loader() 306 306 #data manager 307 307 self.batch_on = False … … 310 310 self._data_panel = None#DataPanel(parent=self) 311 311 if self.panel_on_focus is not None: 312 self._data_panel.set_panel_on_focus( 313 self.panel_on_focus.window_caption) 312 self._data_panel.set_panel_on_focus(self.panel_on_focus.window_caption) 314 313 # list of plot panels in schedule to full redraw 315 314 self.schedule = False … … 318 317 self.schedule_full_draw_list = [] 319 318 self.idletimer = wx.CallLater(TIME_FACTOR, self._onDrawIdle) 320 319 321 320 self.batch_frame = GridFrame(parent=self) 322 321 self.batch_frame.Hide() 323 322 self.on_batch_selection(event=None) 324 323 self.add_icon() 325 324 326 325 # Register the close event so it calls our own method 327 326 wx.EVT_CLOSE(self, self.WindowClose) … … 338 337 # Preferred window size 339 338 self._window_width, self._window_height = size 340 339 341 340 def add_icon(self): 342 341 """ 343 get list of child and attempt to add the default icon 344 """ 345 346 list_children = self.GetChildren() 342 get list of child and attempt to add the default icon 343 """ 344 345 list_children = self.GetChildren() 347 346 for frame in list_children: 348 347 self.put_icon(frame) 349 350 def put_icon(self, frame): 348 349 def put_icon(self, frame): 351 350 """ 352 351 Put icon on the tap of a panel … … 358 357 frame.SetIcon(icon) 359 358 except: 360 pass 361 359 pass 360 362 361 def get_client_size(self): 363 362 """ … … 370 369 if toolbar != None: 371 370 _, tb_h = toolbar.GetSizeTuple() 372 height -= tb_h 371 height -= tb_h 373 372 return width, height 374 373 375 374 def on_change_categories(self, evt): 376 375 # ILL … … 382 381 383 382 if fitpanel != None: 384 for i in range(0, fitpanel.GetPageCount()):383 for i in range(0, fitpanel.GetPageCount()): 385 384 fitpanel.GetPage(i)._populate_listbox() 386 385 387 388 389 386 def on_set_batch_result(self, data_outputs, data_inputs=None, 390 387 plugin_name=""): 391 388 """ 392 389 Display data into a grid in batch mode and show the grid … … 395 392 time_str = time.strftime("%b %d %H;%M of %Y", t) 396 393 details = "File Generated by %s : %s" % (APPLICATION_NAME, 397 398 details += "on %s.\n" % time_str 394 str(plugin_name)) 395 details += "on %s.\n" % time_str 399 396 ext = ".csv" 400 file_name = "Batch_" + str(plugin_name) + "_" + time_str + ext397 file_name = "Batch_" + str(plugin_name) + "_" + time_str + ext 401 398 file_name = self._default_save_location + str(file_name) 402 399 403 400 self.open_with_localapp(file_name=file_name, 404 401 details=details, 405 402 data_inputs=data_inputs, 406 data_outputs=data_outputs) 407 408 403 data_outputs=data_outputs) 404 409 405 def open_with_localapp(self, data_inputs=None, details="", file_name=None, 410 406 data_outputs=None): … … 413 409 :param data: dictionary of string and list of items 414 410 """ 415 self.batch_frame.set_data(data_inputs=data_inputs, 411 self.batch_frame.set_data(data_inputs=data_inputs, 416 412 data_outputs=data_outputs, 417 413 details=details, 418 414 file_name=file_name) 419 415 self.show_batch_frame(None) 420 416 421 417 def on_read_batch_tofile(self, base): 422 418 """ … … 428 424 self._default_save_location = os.getcwd() 429 425 wildcard = "(*.csv; *.txt)|*.csv; *.txt" 430 dlg = wx.FileDialog(base, 431 "Choose a file", 426 dlg = wx.FileDialog(base, 427 "Choose a file", 432 428 self._default_save_location, "", 433 429 wildcard) 434 430 if dlg.ShowModal() == wx.ID_OK: 435 431 path = dlg.GetPath() … … 440 436 self.read_batch_tofile(file_name=path) 441 437 except: 442 msg = "Error occurred when reading the file; %s\n" % path443 msg += "%s\n" % sys.exc_value438 msg = "Error occurred when reading the file; %s\n" % path 439 msg += "%s\n" % sys.exc_value 444 440 wx.PostEvent(self, StatusEvent(status=msg, 445 446 441 info="error")) 442 447 443 def read_batch_tofile(self, file_name): 448 444 """ … … 457 453 if ext.lower() == ".csv": 458 454 separator = "," 459 buffer = fd.read()460 lines = buffer.split('\n')455 fd_buffer = fd.read() 456 lines = fd_buffer.split('\n') 461 457 fd.close() 462 column_names_line 458 column_names_line = "" 463 459 index = None 464 460 details = "" … … 487 483 if count >= 2: 488 484 column_names_line = line 489 break 490 485 break 486 491 487 if column_names_line.strip() == "" or index is None: 492 return 488 return 493 489 494 490 col_name_toks = column_names_line.split(separator) … … 500 496 try: 501 497 float(c_name) 502 col_name = "Column %s" % str(col_index + 1)498 col_name = "Column %s" % str(col_index + 1) 503 499 index_min = index 504 500 except: 505 501 col_name = c_name 506 502 index_min = index + 1 507 data[col_name] = [ 508 for row in range(index_min, len(lines)-1)]503 data[col_name] = [lines[row].split(separator)[c_index] 504 for row in range(index_min, len(lines) - 1)] 509 505 c_index += 1 510 506 511 507 self.open_with_localapp(data_outputs=data, data_inputs=None, 512 508 file_name=file_name, details=details) 513 509 514 510 def write_batch_tofile(self, data, file_name, details=""): 515 511 """ … … 541 537 max_index = max(max_list) 542 538 index = 0 543 while (index < max_index):539 while index < max_index: 544 540 for value_list in data.values(): 545 541 if index < len(value_list): … … 552 548 index += 1 553 549 fd.close() 554 550 555 551 def open_with_externalapp(self, data, file_name, details=""): 556 552 """ … … 559 555 if not os.path.exists(file_name): 560 556 self.write_batch_tofile(data=data, file_name=file_name, 561 557 details=details) 562 558 try: 563 559 from win32com.client import Dispatch 564 excel_app = Dispatch('Excel.Application') 565 wb = excel_app.Workbooks.Open(file_name)560 excel_app = Dispatch('Excel.Application') 561 excel_app.Workbooks.Open(file_name) 566 562 excel_app.Visible = 1 567 563 except: … … 570 566 msg += "check that %s really exists.\n" % str(file_name) 571 567 wx.PostEvent(self, StatusEvent(status=msg, 572 info="error")) 573 574 568 info="error")) 569 575 570 def on_batch_selection(self, event=None): 576 571 """ … … 583 578 for plug in self.plugins: 584 579 plug.set_batch_selection(self.batch_on) 585 580 586 581 def on_color_selection(self, event): 587 582 """ 588 583 :param event: contains parameters for id and color 589 """ 590 color, id = event.color, event.id584 """ 585 color, event_id = event.color, event.id 591 586 for plug in self.plugins: 592 plug.add_color(color, id) 593 594 587 plug.add_color(color, event_id) 588 595 589 def setup_custom_conf(self): 596 590 """ … … 599 593 if custom_config == None: 600 594 return 601 595 602 596 if not FIXED_PANEL: 603 597 self.__gui_style &= (~GUIFRAME.FIXED_PANEL) … … 611 605 612 606 if WELCOME_PANEL_SHOW: 613 self.__gui_style |= GUIFRAME.WELCOME_PANEL_ON 614 607 self.__gui_style |= GUIFRAME.WELCOME_PANEL_ON 608 615 609 def set_custom_default_perspective(self): 616 610 """ … … 622 616 try: 623 617 if plugin.sub_menu == DEFAULT_PERSPECTIVE: 624 618 625 619 plugin.on_perspective(event=None) 626 620 frame = plugin.get_frame() … … 629 623 else: 630 624 frame = plugin.get_frame() 631 frame.Show(False) 625 frame.Show(False) 632 626 except: 633 pass 634 return 635 627 pass 628 return 629 636 630 def on_load_data(self, event): 637 631 """ … … 640 634 if self._data_plugin is not None: 641 635 self._data_plugin.load_data(event) 642 636 643 637 def get_current_perspective(self): 644 638 """ … … 652 646 """ 653 647 return self._default_save_location 654 648 655 649 def set_input_file(self, input_file): 656 650 """ … … 658 652 """ 659 653 self._input_file = input_file 660 654 661 655 def get_data_manager(self): 662 656 """ … … 664 658 """ 665 659 return self._data_manager 666 660 667 661 def get_toolbar(self): 668 662 """ … … 670 664 """ 671 665 return self._toolbar 672 666 673 667 def set_panel_on_focus(self, event): 674 668 """ … … 698 692 self.enable_edit_menu() 699 693 700 def disable_app_menu(self, p_panel=None): 694 def disable_app_menu(self, p_panel=None): 701 695 """ 702 696 Disables all menus in the menubar 703 697 """ 704 698 return 705 706 def send_focus_to_datapanel(self, name): 699 700 def send_focus_to_datapanel(self, name): 707 701 """ 708 702 Send focusing on ID to data explorer … … 710 704 if self._data_panel != None: 711 705 self._data_panel.set_panel_on_focus(name) 712 706 713 707 def set_panel_on_focus_helper(self): 714 708 """ … … 722 716 combo_title = str(self.panel_on_focus.window_caption) 723 717 combo.SetStringSelection(combo_title) 724 combo.SetToolTip( wx.ToolTip(combo_title ))718 combo.SetToolTip(wx.ToolTip(combo_title)) 725 719 elif self.panel_on_focus != self._data_panel: 726 720 cpanel = self.panel_on_focus … … 728 722 cpanel.on_tap_focus() 729 723 self.cpanel_on_focus = self.panel_on_focus 730 724 731 725 def reset_bookmark_menu(self, panel): 732 726 """ 733 727 Reset Bookmark menu list 734 728 735 729 : param panel: a control panel or tap where the bookmark is 736 730 """ … … 745 739 if pos < 3: 746 740 continue 747 id = 741 id = bitem.GetId() 748 742 label = bitem.GetLabel() 749 743 self._toolbar.append_bookmark_item(id, label) 750 744 wx.EVT_MENU(self, id, cpanel._back_to_bookmark) 751 745 self._toolbar.Realize() 752 746 753 747 754 748 def build_gui(self): … … 771 765 self._setup_layout() 772 766 self._add_menu_application() 773 767 774 768 # Set up the menu 775 769 self._add_current_plugin_menu() … … 781 775 if not wx.VERSION_STRING >= '3.0.0.0': 782 776 self.SetMenuBar(self._menubar) 783 777 784 778 try: 785 779 self.load_from_cmd(self._input_file) 786 780 except: 787 msg = "%s Cannot load file %s\n" % (str(APPLICATION_NAME),788 str(self._input_file))781 msg = "%s Cannot load file %s\n" % (str(APPLICATION_NAME), 782 str(self._input_file)) 789 783 msg += str(sys.exc_value) + '\n' 790 784 logging.error(msg) … … 798 792 self._check_update(None) 799 793 800 def _setup_extra_custom(self): 794 def _setup_extra_custom(self): 801 795 """ 802 796 Set up toolbar and welcome view if needed … … 804 798 style = self.__gui_style & GUIFRAME.TOOLBAR_ON 805 799 if (style == GUIFRAME.TOOLBAR_ON) & (not self._toolbar.IsShown()): 806 self._on_toggle_toolbar() 807 800 self._on_toggle_toolbar() 801 808 802 # Set Custom deafult start page 809 803 welcome_style = self.__gui_style & GUIFRAME.WELCOME_PANEL_ON 810 804 if welcome_style == GUIFRAME.WELCOME_PANEL_ON: 811 805 self.show_welcome_panel(None) 812 806 813 807 def _setup_layout(self): 814 808 """ … … 822 816 self._load_panels() 823 817 self.set_default_perspective() 824 818 825 819 def SetStatusText(self, *args, **kwds): 826 820 """ … … 828 822 number = self.sb.get_msg_position() 829 823 wx.Frame.SetStatusText(self, number=number, *args, **kwds) 830 824 831 825 def PopStatusText(self, *args, **kwds): 832 826 """ … … 834 828 field = self.sb.get_msg_position() 835 829 wx.Frame.PopStatusText(self, field=field) 836 830 837 831 def PushStatusText(self, *args, **kwds): 838 832 """ 839 FIXME: No message is passed. What is this supposed to do? 833 FIXME: No message is passed. What is this supposed to do? 840 834 """ 841 835 field = self.sb.get_msg_position() 842 wx.Frame.PushStatusText(self, field=field, 843 string="FIXME: PushStatusText called without text")836 wx.Frame.PushStatusText(self, field=field, 837 string="FIXME: PushStatusText called without text") 844 838 845 839 def add_perspective(self, plugin): … … 855 849 msg = "Plugin %s already loaded" % plugin.sub_menu 856 850 logging.info(msg) 857 is_loaded = True 851 is_loaded = True 858 852 if not is_loaded: 859 self.plugins.append(plugin) 853 self.plugins.append(plugin) 860 854 msg = "Plugin %s appended" % plugin.sub_menu 861 855 logging.info(msg) 862 856 863 857 def _get_local_plugins(self): 864 858 """ 865 get plugins local to guiframe and others 859 get plugins local to guiframe and others 866 860 """ 867 861 plugins = [] … … 888 882 msg += "cannot import plotting plugin.\n %s" % sys.exc_value 889 883 logging.error(msg) 890 884 891 885 return plugins 892 886 893 887 def _find_plugins(self, dir="perspectives"): 894 888 """ 895 889 Find available perspective plug-ins 896 890 897 891 :param dir: directory in which to look for plug-ins 898 892 899 893 :return: list of plug-ins 900 894 901 895 """ 902 896 plugins = [] 903 897 # Go through files in panels directory 904 898 try: 905 list = os.listdir(dir)899 file_list = os.listdir(dir) 906 900 ## the default panel is the panel is the last plugin added 907 for item in list:901 for item in file_list: 908 902 toks = os.path.splitext(os.path.basename(item)) 909 903 name = '' … … 924 918 else: 925 919 (file, path, info) = imp.find_module(name, path) 926 module = imp.load_module( 920 module = imp.load_module(name, file, item, info) 927 921 if hasattr(module, "PLUGIN_ID"): 928 try: 922 try: 929 923 plug = module.Plugin() 930 924 if plug.set_default_perspective(): 931 925 self._current_perspective = plug 932 926 plugins.append(plug) 933 927 934 928 msg = "Found plug-in: %s" % module.PLUGIN_ID 935 929 logging.info(msg) … … 947 941 # Should raise and catch at a higher level and 948 942 # display error on status bar 949 pass943 logging.error(sys.exc_value) 950 944 951 945 return plugins … … 963 957 panel_width = DATAPANEL_WIDTH 964 958 panel_height = int(self._window_height) 965 style = self.__gui_style & (GUIFRAME.MANAGER_ON)966 959 if self._data_panel is not None and (p == self._data_panel): 967 960 return panel_width, panel_height … … 976 969 return self._window_width, panel_height 977 970 return panel_width, panel_height 978 971 979 972 def _load_panels(self): 980 973 """ … … 991 984 ps = item.get_panels(self) 992 985 panels.extend(ps) 993 986 994 987 # Set up welcome panel 995 988 #TODO: this needs serious simplification … … 1000 993 self.defaultPanel.set_frame(welcome_panel) 1001 994 welcome_panel.Show(False) 1002 995 1003 996 self.panels["default"] = self.defaultPanel 1004 997 size_t_bar = 70 … … 1012 1005 frame.SetPosition((0, mac_pos_y + size_t_bar)) 1013 1006 frame.Show(True) 1014 #add data panel 1007 #add data panel 1015 1008 win = MDIFrame(self, None, 'None', (100, 200)) 1016 data_panel = DataPanel(parent=win, 1009 data_panel = DataPanel(parent=win, id=-1) 1017 1010 win.set_panel(data_panel) 1018 1011 self.panels["data_panel"] = data_panel … … 1029 1022 for panel_class in panels: 1030 1023 frame = panel_class.get_frame() 1031 id = wx.NewId()1024 wx_id = wx.NewId() 1032 1025 # Check whether we need to put this panel in the center pane 1033 1026 if hasattr(panel_class, "CENTER_PANE") and panel_class.CENTER_PANE: 1034 1027 w, h = self._get_panels_size(panel_class) 1035 1028 if panel_class.CENTER_PANE: 1036 self.panels[str( id)] = panel_class1029 self.panels[str(wx_id)] = panel_class 1037 1030 _, pos_y = frame.GetPositionTuple() 1038 1031 frame.SetPosition((d_panel_width + 1, pos_y)) … … 1043 1036 continue 1044 1037 else: 1045 self.panels[str( id)] = panel_class1038 self.panels[str(wx_id)] = panel_class 1046 1039 frame.SetSize((w, h)) 1047 1040 frame.Show(False) … … 1061 1054 else: 1062 1055 self.SetSize((self._window_width, win_height)) 1063 1056 1064 1057 def update_data(self, prev_data, new_data): 1065 1058 """ 1066 1059 Update the data. 1067 1060 """ 1068 prev_id, data_state = self._data_manager.update_data( 1061 prev_id, data_state = self._data_manager.update_data( \ 1069 1062 prev_data=prev_data, new_data=new_data) 1070 1063 1071 1064 self._data_panel.remove_by_id(prev_id) 1072 1065 self._data_panel.load_data_list(data_state) 1073 1066 1074 1067 def update_theory(self, data_id, theory, state=None): 1075 1068 """ 1076 1069 Update the theory 1077 """ 1078 data_state = self._data_manager.update_theory(data_id=data_id, 1079 theory=theory,1080 state=state)1070 """ 1071 data_state = self._data_manager.update_theory(data_id=data_id, 1072 theory=theory, 1073 state=state) 1081 1074 wx.CallAfter(self._data_panel.load_data_list, data_state) 1082 1075 1083 1076 def onfreeze(self, theory_id): 1084 1077 """ … … 1088 1081 for data_state in data_state_list.values(): 1089 1082 new_plot = data_state.get_data() 1090 1083 1091 1084 wx.PostEvent(self, NewPlotEvent(plot=new_plot, 1092 1093 1085 title=new_plot.title)) 1086 1094 1087 def freeze(self, data_id, theory_id): 1095 1088 """ 1096 1089 """ 1097 data_state_list = self._data_manager.freeze_theory(data_id=data_id, 1098 theory_id=theory_id)1090 data_state_list = self._data_manager.freeze_theory(data_id=data_id, 1091 theory_id=theory_id) 1099 1092 self._data_panel.load_data_list(list=data_state_list) 1100 1093 for data_state in data_state_list.values(): 1101 1094 new_plot = data_state.get_data() 1102 1095 wx.PostEvent(self, NewPlotEvent(plot=new_plot, 1103 1104 1096 title=new_plot.title)) 1097 1105 1098 def delete_data(self, data): 1106 1099 """ … … 1108 1101 """ 1109 1102 self._current_perspective.delete_data(data) 1110 1111 1103 1104 1112 1105 def get_context_menu(self, plotpanel=None): 1113 1106 """ 1114 Get the context menu items made available 1115 by the different plug-ins. 1107 Get the context menu items made available 1108 by the different plug-ins. 1116 1109 This function is used by the plotting module 1117 1110 """ … … 1122 1115 menu_list.extend(item.get_context_menu(plotpanel=plotpanel)) 1123 1116 return menu_list 1124 1117 1125 1118 def get_current_context_menu(self, plotpanel=None): 1126 1119 """ 1127 Get the context menu items made available 1128 by the current plug-in. 1120 Get the context menu items made available 1121 by the current plug-in. 1129 1122 This function is used by the plotting module 1130 1123 """ … … 1136 1129 menu_list.extend(item.get_context_menu(plotpanel=plotpanel)) 1137 1130 return menu_list 1138 1131 1139 1132 def on_panel_close(self, event): 1140 1133 """ … … 1150 1143 break 1151 1144 self.cpanel_on_focus.SetFocus() 1152 1153 1145 1146 1154 1147 def popup_panel(self, p): 1155 1148 """ 1156 1149 Add a panel object to the AUI manager 1157 1150 1158 1151 :param p: panel object to add to the AUI manager 1159 1152 1160 1153 :return: ID of the event associated with the new panel [int] 1161 1154 1162 1155 """ 1163 1156 ID = wx.NewId() … … 1179 1172 # Append nummber 1180 1173 captions = self._get_plotpanel_captions() 1174 #FIXME: Fix this aweful loop 1181 1175 while (1): 1182 caption = windowcaption + '%s' % str(self.graph_num)1176 caption = windowcaption + '%s' % str(self.graph_num) 1183 1177 if caption not in captions: 1184 1178 break … … 1188 1182 break 1189 1183 if p.window_caption.split()[0] not in NOT_SO_GRAPH_LIST: 1190 p.window_caption = caption 1184 p.window_caption = caption 1191 1185 p.window_name = windowname + str(self.graph_num) 1192 1186 1193 1187 p.frame.SetTitle(p.window_caption) 1194 1188 p.frame.name = p.window_name … … 1214 1208 self._data_panel.cb_plotpanel.Append(str(caption), p) 1215 1209 return ID 1216 1210 1217 1211 def _get_plotpanel_captions(self): 1218 1212 """ 1219 1213 Get all the plotpanel cations 1220 1214 1221 1215 : return: list of captions 1222 1216 """ … … 1224 1218 for Id in self.plot_panels.keys(): 1225 1219 captions.append(self.plot_panels[Id].window_caption) 1226 1220 1227 1221 return captions 1228 1222 1229 1223 def _setup_tool_bar(self): 1230 1224 """ … … 1242 1236 self._update_toolbar_helper() 1243 1237 self._on_toggle_toolbar(event=None) 1244 1238 1245 1239 def _update_toolbar_helper(self): 1246 1240 """ … … 1249 1243 application_name = 'No Selected Analysis' 1250 1244 panel_name = 'No Panel on Focus' 1251 c_panel = self.cpanel_on_focus 1245 c_panel = self.cpanel_on_focus 1252 1246 if self._toolbar is None: 1253 1247 return … … 1262 1256 c_panel_state = None 1263 1257 self._toolbar.update_toolbar(c_panel_state) 1264 self._toolbar.update_button(application_name=application_name, 1265 1258 self._toolbar.update_button(application_name=application_name, 1259 panel_name=panel_name) 1266 1260 self._toolbar.Realize() 1267 1261 1268 1262 def _add_menu_tool(self): 1269 1263 """ … … 1287 1281 if self._tool_menu is not None: 1288 1282 self._menubar.Append(self._tool_menu, '&Tool') 1289 1283 1290 1284 def _add_current_plugin_menu(self): 1291 1285 """ 1292 1286 add current plugin menu 1293 1287 Look for plug-in menus 1294 Add available plug-in sub-menus. 1288 Add available plug-in sub-menus. 1295 1289 """ 1296 1290 if self._menubar is None or self._current_perspective is None \ 1297 or self._menubar.GetMenuCount() ==0:1291 or self._menubar.GetMenuCount() == 0: 1298 1292 return 1299 1293 #replace or add a new menu for the current plugin 1300 1294 1301 1295 pos = self._menubar.FindMenu(str(self._applications_menu_name)) 1302 1296 if pos != -1: … … 1304 1298 if menu_list: 1305 1299 for (menu, name) in menu_list: 1306 hidden_menu = self._menubar.Replace(pos, menu, name) 1307 self._applications_menu_name = name 1308 #self._applications_menu_pos = pos 1300 self._menubar.Replace(pos, menu, name) 1301 self._applications_menu_name = name 1309 1302 else: 1310 hidden_menu =self._menubar.Remove(pos)1303 self._menubar.Remove(pos) 1311 1304 self._applications_menu_name = None 1312 1305 #get the position of the menu when it first added 1313 self._applications_menu_pos = pos 1314 1306 self._applications_menu_pos = pos 1307 1315 1308 else: 1316 1309 menu_list = self._current_perspective.populate_menu(self) … … 1320 1313 self._menubar.Append(menu, name) 1321 1314 else: 1322 self._menubar.Insert(self._applications_menu_pos, 1315 self._menubar.Insert(self._applications_menu_pos, 1323 1316 menu, name) 1324 1317 self._applications_menu_name = name 1325 1318 1326 1319 def _add_help_menu(self): 1327 1320 """ 1328 1321 add help menu to menu bar. Includes welcome page, about page, 1329 tutorial PDF and documentation pages. 1322 tutorial PDF and documentation pages. 1330 1323 """ 1331 1324 # Help menu … … 1336 1329 # add the welcome panel menu item 1337 1330 if config.WELCOME_PANEL_ON and self.defaultPanel is not None: 1338 id = wx.NewId()1339 self._help_menu.Append( id, '&Welcome', '')1340 wx.EVT_MENU(self, id, self.show_welcome_panel)1331 wx_id = wx.NewId() 1332 self._help_menu.Append(wx_id, '&Welcome', '') 1333 wx.EVT_MENU(self, wx_id, self.show_welcome_panel) 1341 1334 1342 1335 self._help_menu.AppendSeparator() 1343 id = wx.NewId()1344 self._help_menu.Append( id, '&Documentation', '')1345 wx.EVT_MENU(self, id, self._onSphinxDocs)1346 1347 if config._do_tutorial and (IS_WIN or sys.platform == 'darwin'):1336 wx_id = wx.NewId() 1337 self._help_menu.Append(wx_id, '&Documentation', '') 1338 wx.EVT_MENU(self, wx_id, self._onSphinxDocs) 1339 1340 if config._do_tutorial and (IS_WIN or sys.platform == 'darwin'): 1348 1341 self._help_menu.AppendSeparator() 1349 id = wx.NewId()1350 self._help_menu.Append( id, '&Tutorial', 'Software tutorial')1351 wx.EVT_MENU(self, id, self._onTutorial)1352 1342 wx_id = wx.NewId() 1343 self._help_menu.Append(wx_id, '&Tutorial', 'Software tutorial') 1344 wx.EVT_MENU(self, wx_id, self._onTutorial) 1345 1353 1346 if config._do_acknowledge: 1354 1347 self._help_menu.AppendSeparator() 1355 id = wx.NewId()1356 self._help_menu.Append( id, '&Acknowledge', 'Acknowledging SasView')1357 wx.EVT_MENU(self, id, self._onAcknowledge)1358 1348 wx_id = wx.NewId() 1349 self._help_menu.Append(wx_id, '&Acknowledge', 'Acknowledging SasView') 1350 wx.EVT_MENU(self, wx_id, self._onAcknowledge) 1351 1359 1352 if config._do_aboutbox: 1360 1353 self._help_menu.AppendSeparator() 1361 1354 self._help_menu.Append(wx.ID_ABOUT, '&About', 'Software information') 1362 1355 wx.EVT_MENU(self, wx.ID_ABOUT, self._onAbout) 1363 1356 1364 1357 # Checking for updates 1365 id = wx.NewId()1366 self._help_menu.Append( id,'&Check for update',1367 'Check for the latest version of %s' % config.__appname__)1368 wx.EVT_MENU(self, id, self._check_update)1358 wx_id = wx.NewId() 1359 self._help_menu.Append(wx_id, '&Check for update', 1360 'Check for the latest version of %s' % config.__appname__) 1361 wx.EVT_MENU(self, wx_id, self._check_update) 1369 1362 self._menubar.Append(self._help_menu, '&Help') 1370 1363 1371 1364 def _add_menu_view(self): 1372 1365 """ … … 1376 1369 return 1377 1370 self._view_menu = wx.Menu() 1378 1379 id = wx.NewId()1371 1372 wx_id = wx.NewId() 1380 1373 hint = "Display the Grid Window for batch results etc." 1381 self._view_menu.Append( id, '&Show Grid Window', hint)1382 wx.EVT_MENU(self, id, self.show_batch_frame)1383 1374 self._view_menu.Append(wx_id, '&Show Grid Window', hint) 1375 wx.EVT_MENU(self, wx_id, self.show_batch_frame) 1376 1384 1377 self._view_menu.AppendSeparator() 1385 1378 style = self.__gui_style & GUIFRAME.MANAGER_ON 1386 id = wx.NewId()1387 self._data_panel_menu = self._view_menu.Append( id,1388 '&Show Data Explorer', '')1389 wx.EVT_MENU(self, id, self.show_data_panel)1379 wx_id = wx.NewId() 1380 self._data_panel_menu = self._view_menu.Append(wx_id, 1381 '&Show Data Explorer', '') 1382 wx.EVT_MENU(self, wx_id, self.show_data_panel) 1390 1383 if style == GUIFRAME.MANAGER_ON: 1391 1384 self._data_panel_menu.SetText('Hide Data Explorer') 1392 1385 else: 1393 1386 self._data_panel_menu.SetText('Show Data Explorer') 1394 1387 1395 1388 self._view_menu.AppendSeparator() 1396 id = wx.NewId()1389 wx_id = wx.NewId() 1397 1390 style1 = self.__gui_style & GUIFRAME.TOOLBAR_ON 1398 1391 if style1 == GUIFRAME.TOOLBAR_ON: 1399 self._toolbar_menu = self._view_menu.Append( id, '&Hide Toolbar', '')1392 self._toolbar_menu = self._view_menu.Append(wx_id, '&Hide Toolbar', '') 1400 1393 else: 1401 self._toolbar_menu = self._view_menu.Append( id, '&Show Toolbar', '')1402 wx.EVT_MENU(self, id, self._on_toggle_toolbar)1394 self._toolbar_menu = self._view_menu.Append(wx_id, '&Show Toolbar', '') 1395 wx.EVT_MENU(self, wx_id, self._on_toggle_toolbar) 1403 1396 1404 1397 if custom_config != None: 1405 1398 self._view_menu.AppendSeparator() 1406 id = wx.NewId()1399 wx_id = wx.NewId() 1407 1400 hint_ss = "Select the current/default configuration " 1408 1401 hint_ss += "as a startup setting" 1409 preference_menu = self._view_menu.Append( id, 'Startup Setting',1402 preference_menu = self._view_menu.Append(wx_id, 'Startup Setting', 1410 1403 hint_ss) 1411 wx.EVT_MENU(self, id, self._on_preference_menu)1412 1413 id = wx.NewId()1404 wx.EVT_MENU(self, wx_id, self._on_preference_menu) 1405 1406 wx_id = wx.NewId() 1414 1407 self._view_menu.AppendSeparator() 1415 self._view_menu.Append( id, 'Category Manager', 'Edit model categories')1416 wx.EVT_MENU(self, id, self._on_category_manager)1417 1418 self._menubar.Append(self._view_menu, '&View') 1419 1408 self._view_menu.Append(wx_id, 'Category Manager', 'Edit model categories') 1409 wx.EVT_MENU(self, wx_id, self._on_category_manager) 1410 1411 self._menubar.Append(self._view_menu, '&View') 1412 1420 1413 def show_batch_frame(self, event=None): 1421 1414 """ … … 1425 1418 self.batch_frame.Show(False) 1426 1419 self.batch_frame.Show(True) 1427 1428 def on_category_panel(self, event): 1420 1421 def on_category_panel(self, event): 1429 1422 """ 1430 1423 On cat panel 1431 1424 """ 1432 1425 self._on_category_manager(event) 1433 1426 1434 1427 def _on_category_manager(self, event): 1435 1428 """ … … 1440 1433 frame.SetIcon(icon) 1441 1434 1442 def _on_preference_menu(self, event): 1435 def _on_preference_menu(self, event): 1443 1436 """ 1444 1437 Build a panel to allow to edit Mask … … 1446 1439 from sas.guiframe.startup_configuration \ 1447 1440 import StartupConfiguration as ConfDialog 1448 1441 1449 1442 dialog = ConfDialog(parent=self, gui=self.__gui_style) 1450 1443 result = dialog.ShowModal() … … 1454 1447 wx.PostEvent(self, StatusEvent(status="Wrote custom configuration", info='info')) 1455 1448 dialog.Destroy() 1456 1449 1457 1450 def _add_menu_application(self): 1458 1451 """ … … 1461 1454 add menu application 1462 1455 """ 1463 if self._num_perspectives 1456 if self._num_perspectives > 1: 1464 1457 plug_data_count = False 1465 1458 plug_no_data_count = False … … 1471 1464 id = wx.NewId() 1472 1465 if plug.use_data(): 1473 1474 self._applications_menu.InsertCheckItem(pos, id, plug.sub_menu, 1475 "Switch to analysis: %s" % plug.sub_menu) 1466 self._applications_menu.InsertCheckItem(pos, id, plug.sub_menu, \ 1467 "Switch to analysis: %s" % plug.sub_menu) 1476 1468 plug_data_count = True 1477 1469 pos += 1 1478 1470 else: 1479 1471 plug_no_data_count = True 1480 self._applications_menu.AppendCheckItem(id, plug.sub_menu, 1481 1472 self._applications_menu.AppendCheckItem(id, plug.sub_menu, \ 1473 "Switch to analysis: %s" % plug.sub_menu) 1482 1474 wx.EVT_MENU(self, id, plug.on_perspective) 1483 1475 1484 if (not plug_data_count or not plug_no_data_count):1476 if not plug_data_count or not plug_no_data_count: 1485 1477 self._applications_menu.RemoveItem(separator) 1486 1478 self._menubar.Append(self._applications_menu, '&Analysis') 1487 1479 self._check_applications_menu() 1488 1480 1489 1481 def _populate_file_menu(self): 1490 1482 """ … … 1499 1491 wx.EVT_MENU(self, id, m_handler) 1500 1492 self._file_menu.AppendSeparator() 1501 1493 1502 1494 style1 = self.__gui_style & GUIFRAME.MULTIPLE_APPLICATIONS 1503 1495 if OPEN_SAVE_MENU: 1504 1496 id = wx.NewId() 1505 1497 hint_load_file = "read all analysis states saved previously" 1506 self._save_appl_menu = self._file_menu.Append(id, 1507 '&Open Project', hint_load_file) 1498 self._save_appl_menu = self._file_menu.Append(id, '&Open Project', hint_load_file) 1508 1499 wx.EVT_MENU(self, id, self._on_open_state_project) 1509 1500 1510 1501 if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: 1511 1502 # some menu of plugin to be seen under file menu … … 1513 1504 hint_load_file += " them into the analysis" 1514 1505 id = wx.NewId() 1515 self._save_appl_menu = self._file_menu.Append(id, 1516 '&Open Analysis', hint_load_file)1506 self._save_appl_menu = self._file_menu.Append(id, 1507 '&Open Analysis', hint_load_file) 1517 1508 wx.EVT_MENU(self, id, self._on_open_state_application) 1518 if OPEN_SAVE_MENU: 1509 if OPEN_SAVE_MENU: 1519 1510 self._file_menu.AppendSeparator() 1520 1511 id = wx.NewId() 1521 1512 self._file_menu.Append(id, '&Save Project', 1522 'Save the state of the whole analysis')1513 'Save the state of the whole analysis') 1523 1514 wx.EVT_MENU(self, id, self._on_save_project) 1524 1515 if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: 1525 1516 id = wx.NewId() 1526 self._save_appl_menu = self._file_menu.Append(id, 1527 '&Save Analysis', 1528 'Save state of the current active analysis panel') 1517 self._save_appl_menu = self._file_menu.Append(id, \ 1518 '&Save Analysis', 'Save state of the current active analysis panel') 1529 1519 wx.EVT_MENU(self, id, self._on_save_application) 1530 if not sys.platform == 'darwin':1520 if not sys.platform == 'darwin': 1531 1521 self._file_menu.AppendSeparator() 1532 1522 id = wx.NewId() 1533 self._file_menu.Append(id, '&Quit', 'Exit') 1523 self._file_menu.Append(id, '&Quit', 'Exit') 1534 1524 wx.EVT_MENU(self, id, self.Close) 1535 1525 1536 1526 def _add_menu_file(self): 1537 1527 """ … … 1542 1532 # Add sub menus 1543 1533 self._menubar.Append(self._file_menu, '&File') 1544 1534 1545 1535 def _add_menu_edit(self): 1546 1536 """ … … 1551 1541 # Edit Menu 1552 1542 self._edit_menu = wx.Menu() 1553 self._edit_menu.Append(GUIFRAME_ID.UNDO_ID, '&Undo', 1543 self._edit_menu.Append(GUIFRAME_ID.UNDO_ID, '&Undo', 1554 1544 'Undo the previous action') 1555 1545 wx.EVT_MENU(self, GUIFRAME_ID.UNDO_ID, self.on_undo_panel) 1556 self._edit_menu.Append(GUIFRAME_ID.REDO_ID, '&Redo', 1546 self._edit_menu.Append(GUIFRAME_ID.REDO_ID, '&Redo', 1557 1547 'Redo the previous action') 1558 1548 wx.EVT_MENU(self, GUIFRAME_ID.REDO_ID, self.on_redo_panel) 1559 1549 self._edit_menu.AppendSeparator() 1560 self._edit_menu.Append(GUIFRAME_ID.COPY_ID, '&Copy Params', 1550 self._edit_menu.Append(GUIFRAME_ID.COPY_ID, '&Copy Params', 1561 1551 'Copy parameter values') 1562 1552 wx.EVT_MENU(self, GUIFRAME_ID.COPY_ID, self.on_copy_panel) 1563 self._edit_menu.Append(GUIFRAME_ID.PASTE_ID, '&Paste Params', 1553 self._edit_menu.Append(GUIFRAME_ID.PASTE_ID, '&Paste Params', 1564 1554 'Paste parameter values') 1565 1555 wx.EVT_MENU(self, GUIFRAME_ID.PASTE_ID, self.on_paste_panel) … … 1570 1560 #Sub menu for Copy As... 1571 1561 self._edit_menu_copyas.Append(GUIFRAME_ID.COPYEX_ID, 'Copy current tab to Excel', 1572 'Copy parameter values in tabular format')1562 'Copy parameter values in tabular format') 1573 1563 wx.EVT_MENU(self, GUIFRAME_ID.COPYEX_ID, self.on_copy_panel) 1574 1564 1575 1565 self._edit_menu_copyas.Append(GUIFRAME_ID.COPYLAT_ID, 'Copy current tab to LaTeX', 1576 'Copy parameter values in tabular format')1566 'Copy parameter values in tabular format') 1577 1567 wx.EVT_MENU(self, GUIFRAME_ID.COPYLAT_ID, self.on_copy_panel) 1578 1568 1579 1569 1580 self._edit_menu.AppendMenu(GUIFRAME_ID.COPYAS_ID, 'Copy Params as...', self._edit_menu_copyas,1581 'Copy parameter values in various formats')1582 1570 self._edit_menu.AppendMenu(GUIFRAME_ID.COPYAS_ID, 'Copy Params as...', 1571 self._edit_menu_copyas, 1572 'Copy parameter values in various formats') 1583 1573 1584 1574 self._edit_menu.AppendSeparator() 1585 1575 1586 1576 self._edit_menu.Append(GUIFRAME_ID.PREVIEW_ID, '&Report Results', 1587 1577 'Preview current panel') 1588 1578 wx.EVT_MENU(self, GUIFRAME_ID.PREVIEW_ID, self.on_preview_panel) 1589 1579 1590 self._edit_menu.Append(GUIFRAME_ID.RESET_ID, '&Reset Page', 1580 self._edit_menu.Append(GUIFRAME_ID.RESET_ID, '&Reset Page', 1591 1581 'Reset current panel') 1592 1582 wx.EVT_MENU(self, GUIFRAME_ID.RESET_ID, self.on_reset_panel) 1593 1594 self._menubar.Append(self._edit_menu, 1583 1584 self._menubar.Append(self._edit_menu, '&Edit') 1595 1585 self.enable_edit_menu() 1596 1586 1597 1587 def get_style(self): 1598 1588 """ … … 1600 1590 """ 1601 1591 return self.__gui_style 1602 1592 1603 1593 def _add_menu_data(self): 1604 1594 """ … … 1610 1600 for (menu, name) in menu_list: 1611 1601 self._menubar.Append(menu, name) 1612 1613 1602 1614 1603 def _on_toggle_toolbar(self, event=None): 1615 1604 """ … … 1627 1616 self._toolbar.Show() 1628 1617 self._toolbar.Realize() 1629 1618 1630 1619 def _on_status_event(self, evt): 1631 1620 """ … … 1634 1623 # This CallAfter fixes many crashes on MAC. 1635 1624 wx.CallAfter(self.sb.set_status, evt) 1636 1625 1637 1626 def on_view(self, evt): 1638 1627 """ 1639 1628 A panel was selected to be shown. If it's not already 1640 1629 shown, display it. 1641 1630 1642 1631 :param evt: menu event 1643 1632 1644 1633 """ 1645 1634 panel_id = str(evt.GetId()) 1646 1635 self.on_set_plot_focus(self.panels[panel_id]) 1647 wx.CallLater(5 *TIME_FACTOR, self.set_schedule(True))1636 wx.CallLater(5 * TIME_FACTOR, self.set_schedule(True)) 1648 1637 self.set_plot_unfocus() 1649 1638 1650 1639 def show_welcome_panel(self, event): 1651 """ 1640 """ 1652 1641 Display the welcome panel 1653 1642 """ 1654 1643 if self.defaultPanel is None: 1655 return 1644 return 1656 1645 frame = self.panels['default'].get_frame() 1657 1646 if frame == None: … … 1660 1649 if not frame.IsShown(): 1661 1650 frame.Show(True) 1662 1651 1663 1652 def on_close_welcome_panel(self): 1664 1653 """ … … 1666 1655 """ 1667 1656 if self.defaultPanel is None: 1668 return 1657 return 1669 1658 default_panel = self.panels["default"].frame 1670 1659 if default_panel.IsShown(): 1671 default_panel.Show(False) 1672 1660 default_panel.Show(False) 1661 1673 1662 def delete_panel(self, uid): 1674 1663 """ … … 1677 1666 ID = str(uid) 1678 1667 config.printEVT("delete_panel: %s" % ID) 1679 try:1680 caption = self.panels[ID].window_caption1681 except:1682 logging.error("delete_panel: No such plot id as %s" % ID)1683 return1684 1668 if ID in self.panels.keys(): 1685 1669 self.panel_on_focus = None … … 1691 1675 1692 1676 if panel in self.schedule_full_draw_list: 1693 self.schedule_full_draw_list.remove(panel) 1694 1677 self.schedule_full_draw_list.remove(panel) 1678 1695 1679 #delete uid number not str(uid) 1696 1680 if ID in self.plot_panels.keys(): … … 1698 1682 if ID in self.panels.keys(): 1699 1683 del self.panels[ID] 1700 return 1701 1684 else: 1685 logging.error("delete_panel: No such plot id as %s" % ID) 1686 1702 1687 def create_gui_data(self, data, path=None): 1703 1688 """ 1704 1689 """ 1705 1690 return self._data_manager.create_gui_data(data, path) 1706 1691 1707 1692 def get_data(self, path): 1708 1693 """ … … 1712 1697 output = [] 1713 1698 error_message = "" 1714 basename 1699 basename = os.path.basename(path) 1715 1700 root, extension = os.path.splitext(basename) 1716 1701 if extension.lower() not in EXTENSIONS: … … 1720 1705 logging.error(log_msg) 1721 1706 return 1722 1707 1723 1708 #reading a state file 1724 1709 for plug in self.plugins: … … 1734 1719 except: 1735 1720 msg = "DataLoader Error: Encounted Non-ASCII character" 1736 msg += "\n(%s)" % sys.exc_value1737 wx.PostEvent(self, StatusEvent(status=msg, 1738 info="error", type="stop"))1721 msg += "\n(%s)" % sys.exc_value 1722 wx.PostEvent(self, StatusEvent(status=msg, 1723 info="error", type="stop")) 1739 1724 return 1740 1725 1741 1726 style = self.__gui_style & GUIFRAME.MANAGER_ON 1742 1727 if style == GUIFRAME.MANAGER_ON: 1743 1728 if self._data_panel is not None: 1744 1729 self._data_panel.frame.Show(True) 1745 1746 def load_from_cmd(self, path):1730 1731 def load_from_cmd(self, path): 1747 1732 """ 1748 1733 load data from cmd or application 1749 """ 1734 """ 1750 1735 if path is None: 1751 1736 return … … 1754 1739 if not os.path.isfile(path) and not os.path.isdir(path): 1755 1740 return 1756 1741 1757 1742 if os.path.isdir(path): 1758 1743 self.load_folder(path) 1759 1744 return 1760 1745 1761 basename 1762 root, extension = os.path.splitext(basename)1746 basename = os.path.basename(path) 1747 _, extension = os.path.splitext(basename) 1763 1748 if extension.lower() not in EXTENSIONS: 1764 1749 self.load_data(path) … … 1767 1752 1768 1753 self._default_save_location = os.path.dirname(path) 1769 1770 def load_state(self, path, is_project=False): 1754 1755 def load_state(self, path, is_project=False): 1771 1756 """ 1772 1757 load data from command line or application 1773 1758 """ 1774 1759 if path and (path is not None) and os.path.isfile(path): 1775 basename 1760 basename = os.path.basename(path) 1776 1761 if APPLICATION_STATE_EXTENSION is not None \ 1777 1762 and basename.endswith(APPLICATION_STATE_EXTENSION): … … 1784 1769 else: 1785 1770 wx.PostEvent(self, StatusEvent(status=" ")) 1786 1771 1787 1772 def load_data(self, path): 1788 1773 """ … … 1791 1776 if not os.path.isfile(path): 1792 1777 return 1793 basename 1794 root, extension = os.path.splitext(basename)1778 basename = os.path.basename(path) 1779 _, extension = os.path.splitext(basename) 1795 1780 if extension.lower() in EXTENSIONS: 1796 1781 log_msg = "Data Loader cannot " … … 1804 1789 try: 1805 1790 logging.info("Loading Data...:\n" + str(path) + "\n") 1806 temp = 1791 temp = self.loader.load(path) 1807 1792 if temp.__class__.__name__ == "list": 1808 1793 for item in temp: … … 1812 1797 data = self.create_gui_data(temp, path) 1813 1798 output[data.id] = data 1814 1799 1815 1800 self.add_data(data_list=output) 1816 1801 except: … … 1819 1804 error_message += str(sys.exc_value) + "\n" 1820 1805 logging.error(error_message) 1821 1806 1822 1807 def load_folder(self, path): 1823 1808 """ 1824 1809 Load entire folder 1825 """ 1810 """ 1826 1811 if not os.path.isdir(path): 1827 1812 return … … 1834 1819 self._data_plugin.get_data(file_list) 1835 1820 else: 1836 return 1821 return 1837 1822 except: 1838 1823 error_message = "Error while loading" … … 1840 1825 error_message += str(sys.exc_value) + "\n" 1841 1826 logging.error(error_message) 1842 1827 1843 1828 def _on_open_state_application(self, event): 1844 1829 """ … … 1849 1834 wx.PostEvent(self, StatusEvent(status="Loading Analysis file...")) 1850 1835 plug_wlist = self._on_open_state_app_helper() 1851 dlg = wx.FileDialog(self, 1852 "Choose a file", 1836 dlg = wx.FileDialog(self, 1837 "Choose a file", 1853 1838 self._default_save_location, "", 1854 1839 plug_wlist) … … 1858 1843 self._default_save_location = os.path.dirname(path) 1859 1844 dlg.Destroy() 1860 self.load_state(path=path) 1861 1845 self.load_state(path=path) 1846 1862 1847 def _on_open_state_app_helper(self): 1863 1848 """ 1864 Helps '_on_open_state_application()' to find the extension of 1849 Helps '_on_open_state_application()' to find the extension of 1865 1850 the current perspective/application 1866 1851 """ 1867 1852 # No current perspective or no extension attr 1868 1853 if self._current_perspective is None: 1869 return PLUGINS_WLIST 1854 return PLUGINS_WLIST 1870 1855 try: 1871 # Find the extension of the perspective 1856 # Find the extension of the perspective 1872 1857 # and get that as 1st item in list 1873 1858 ind = None … … 1888 1873 1889 1874 except: 1890 plug_wlist = PLUGINS_WLIST 1891 1875 plug_wlist = PLUGINS_WLIST 1876 1892 1877 return plug_wlist 1893 1878 1894 1879 def _on_open_state_project(self, event): 1895 1880 """ … … 1899 1884 self._default_save_location = os.getcwd() 1900 1885 wx.PostEvent(self, StatusEvent(status="Loading Project file...")) 1901 dlg = wx.FileDialog(self, 1902 "Choose a file", 1886 dlg = wx.FileDialog(self, 1887 "Choose a file", 1903 1888 self._default_save_location, "", 1904 1889 APPLICATION_WLIST) 1905 1890 if dlg.ShowModal() == wx.ID_OK: 1906 1891 path = dlg.GetPath() … … 1908 1893 self._default_save_location = os.path.dirname(path) 1909 1894 dlg.Destroy() 1910 1895 1911 1896 self.load_state(path=path, is_project=True) 1912 1897 1913 1898 def _on_save_application(self, event): 1914 1899 """ … … 1917 1902 if self.cpanel_on_focus is not None: 1918 1903 try: 1919 wx.PostEvent(self, 1904 wx.PostEvent(self, 1920 1905 StatusEvent(status="Saving Analysis file...")) 1921 1906 self.cpanel_on_focus.on_save(event) 1922 wx.PostEvent(self, 1907 wx.PostEvent(self, 1923 1908 StatusEvent(status="Completed saving.")) 1924 1909 except: 1925 1910 msg = "Error occurred while saving: " 1926 1911 msg += "To save, the application panel should have a data set.." 1927 wx.PostEvent(self, StatusEvent(status=msg)) 1928 1912 wx.PostEvent(self, StatusEvent(status=msg)) 1913 1929 1914 def _on_save_project(self, event): 1930 1915 """ … … 1934 1919 return 1935 1920 wx.PostEvent(self, StatusEvent(status="Saving Project file...")) 1936 reader, ext = self._current_perspective.get_extensions()1937 1921 path = None 1938 1922 extension = '*' + APPLICATION_STATE_EXTENSION 1939 1923 dlg = wx.FileDialog(self, "Save Project file", 1940 1924 self._default_save_location, "sasview_proj", 1941 extension,1942 1925 extension, 1926 wx.SAVE) 1943 1927 if dlg.ShowModal() == wx.ID_OK: 1944 1928 path = dlg.GetPath() … … 1956 1940 if temp is not None: 1957 1941 doc = temp 1958 1942 1959 1943 # Write the XML document 1960 1944 extens = APPLICATION_STATE_EXTENSION … … 1972 1956 msg += "No project was saved to %s" % (str(path)) 1973 1957 logging.error(msg) 1974 wx.PostEvent(self, StatusEvent(status=msg))1958 wx.PostEvent(self, StatusEvent(status=msg)) 1975 1959 except: 1976 1960 msg = "Error occurred while saving: " 1977 1961 msg += "To save, at least one application panel " 1978 1962 msg += "should have a data set.." 1979 wx.PostEvent(self, StatusEvent(status=msg)) 1980 1963 wx.PostEvent(self, StatusEvent(status=msg)) 1964 1981 1965 def on_save_helper(self, doc, reader, panel, path): 1982 1966 """ 1983 1967 Save state into a file 1984 1968 """ 1985 try: 1986 if reader is not None: 1987 # case of a panel with multi-pages 1988 if hasattr(panel, "opened_pages"): 1989 for uid, page in panel.opened_pages.iteritems(): 1990 data = page.get_data() 1991 # state must be cloned 1992 state = page.get_state().clone() 1993 if data is not None: 1994 new_doc = reader.write_toXML(data, state) 1995 if doc != None and hasattr(doc, "firstChild"): 1996 child = new_doc.firstChild.firstChild 1997 doc.firstChild.appendChild(child) 1998 else: 1999 doc = new_doc 2000 # case of only a panel 2001 else: 2002 data = panel.get_data() 2003 state = panel.get_state() 1969 if reader is not None: 1970 # case of a panel with multi-pages 1971 if hasattr(panel, "opened_pages"): 1972 for _, page in panel.opened_pages.iteritems(): 1973 data = page.get_data() 1974 # state must be cloned 1975 state = page.get_state().clone() 2004 1976 if data is not None: 2005 1977 new_doc = reader.write_toXML(data, state) 2006 1978 if doc != None and hasattr(doc, "firstChild"): 2007 1979 child = new_doc.firstChild.firstChild 2008 doc.firstChild.appendChild(child) 1980 doc.firstChild.appendChild(child) 2009 1981 else: 2010 doc = new_doc 2011 except: 2012 raise 2013 #pass 2014 1982 doc = new_doc 1983 # case of only a panel 1984 else: 1985 data = panel.get_data() 1986 state = panel.get_state() 1987 if data is not None: 1988 new_doc = reader.write_toXML(data, state) 1989 if doc != None and hasattr(doc, "firstChild"): 1990 child = new_doc.firstChild.firstChild 1991 doc.firstChild.appendChild(child) 1992 else: 1993 doc = new_doc 2015 1994 return doc 2016 1995 … … 2021 2000 message = "\nDo you really want to exit this application? \n\n" 2022 2001 dial = wx.MessageDialog(self, message, 'Confirm Exit', 2023 wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION)2002 wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION) 2024 2003 if dial.ShowModal() == wx.ID_YES: 2025 2004 return True 2026 2005 else: 2027 return False 2028 2006 return False 2007 2029 2008 def WindowClose(self, event=None): 2030 2009 """ … … 2035 2014 _pylab_helpers.Gcf.figs = {} 2036 2015 self.Close() 2037 2016 2038 2017 def Close(self, event=None): 2039 2018 """ … … 2042 2021 wx.Exit() 2043 2022 sys.exit() 2044 2045 def _check_update(self, event=None): 2023 2024 def _check_update(self, event=None): 2046 2025 """ 2047 2026 Check with the deployment server whether a new version … … 2051 2030 """ 2052 2031 try: 2053 conn = httplib.HTTPConnection(config.__update_URL__[0], 2054 timeout=3.0)2032 conn = httplib.HTTPConnection(config.__update_URL__[0], 2033 timeout=3.0) 2055 2034 conn.request("GET", config.__update_URL__[1]) 2056 2035 res = conn.getresponse() … … 2059 2038 except: 2060 2039 content = "0.0.0" 2061 2040 2062 2041 version = content.strip() 2063 2042 if len(re.findall('\d+\.\d+\.\d+$', version)) < 0: 2064 2043 content = "0.0.0" 2065 self._process_version(content, standalone=event ==None)2066 2044 self._process_version(content, standalone=event == None) 2045 2067 2046 def _process_version(self, version, standalone=True): 2068 2047 """ … … 2071 2050 version number has been obtained. If the check is being done in the 2072 2051 background, the user will not be notified unless there's an update. 2073 2052 2074 2053 :param version: version string 2075 :param standalone: True of the update is being checked in 2054 :param standalone: True of the update is being checked in 2076 2055 the background, False otherwise. 2077 2056 2078 2057 """ 2079 2058 try: … … 2088 2067 webbrowser.open(config.__download_page__) 2089 2068 else: 2090 msg += "See the help menu to download it."2069 msg += "See the help menu to download it." 2091 2070 self.SetStatusText(msg) 2092 2071 else: … … 2103 2082 msg += " Please try again later." 2104 2083 self.SetStatusText(msg) 2105 2084 2106 2085 def _onAcknowledge(self, evt): 2107 2086 """ 2108 2087 Pop up the acknowledge dialog 2109 2088 2110 2089 :param evt: menu event 2111 2090 2112 2091 """ 2113 2092 if config._do_acknowledge: … … 2115 2094 dialog = AcknowledgeBox.DialogAcknowledge(None, -1, "") 2116 2095 dialog.ShowModal() 2117 2096 2118 2097 def _onAbout(self, evt): 2119 2098 """ 2120 2099 Pop up the about dialog 2121 2100 2122 2101 :param evt: menu event 2123 2102 2124 2103 """ 2125 2104 if config._do_aboutbox: 2126 2105 import sas.guiframe.aboutbox as AboutBox 2127 2106 dialog = AboutBox.DialogAbout(None, -1, "") 2128 dialog.ShowModal() 2129 2107 dialog.ShowModal() 2108 2130 2109 def _onTutorial(self, evt): 2131 2110 """ 2132 2111 Pop up the tutorial dialog 2133 2112 2134 2113 :param evt: menu event 2135 2136 """ 2137 if config._do_tutorial: 2114 2115 """ 2116 if config._do_tutorial: 2138 2117 path = config.TUTORIAL_PATH 2139 2118 if IS_WIN: … … 2142 2121 dialog = PDFFrame(None, -1, "Tutorial", path) 2143 2122 # put icon 2144 self.put_icon(dialog) 2145 dialog.Show(True) 2123 self.put_icon(dialog) 2124 dialog.Show(True) 2146 2125 except: 2147 2126 logging.error("Error in _onTutorial: %s" % sys.exc_value) … … 2175 2154 'documentation' is clicked. Calls DocumentationWindow with the top 2176 2155 level path of "index.html" 2177 2156 2178 2157 :param evt: menu event 2179 2158 """ … … 2181 2160 # different place than they would otherwise. 2182 2161 from documentation_window import DocumentationWindow 2183 2184 sphinx_doc_viewer = DocumentationWindow(self, -1, "index.html", \ 2185 "General Help") 2162 DocumentationWindow(self, -1, "index.html", "General Help") 2186 2163 2187 2164 def set_manager(self, manager): 2188 2165 """ 2189 2166 Sets the application manager for this frame 2190 2167 2191 2168 :param manager: frame manager 2192 2169 """ 2193 2170 self.app_manager = manager 2194 2171 2195 2172 def post_init(self): 2196 2173 """ 2197 This initialization method is called after the GUI 2174 This initialization method is called after the GUI 2198 2175 has been created and all plug-ins loaded. It calls 2199 2176 the post_init() method of each plug-in (if it exists) … … 2203 2180 if hasattr(item, "post_init"): 2204 2181 item.post_init() 2205 2182 2206 2183 def set_default_perspective(self): 2207 2184 """ 2208 Choose among the plugin the first plug-in that has 2185 Choose among the plugin the first plug-in that has 2209 2186 "set_default_perspective" method and its return value is True will be 2210 2187 as a default perspective when the welcome page is closed … … 2214 2191 if item.set_default_perspective(): 2215 2192 item.on_perspective(event=None) 2216 return 2217 2193 return 2194 2218 2195 def set_perspective(self, panels): 2219 2196 """ … … 2221 2198 Opens all the panels in the list, and closes 2222 2199 all the others. 2223 2200 2224 2201 :param panels: list of panels 2225 2202 """ … … 2228 2205 if hasattr(self.panels[item], "ALWAYS_ON"): 2229 2206 if self.panels[item].ALWAYS_ON: 2230 continue 2207 continue 2231 2208 if self.panels[item] == None: 2232 2209 continue … … 2252 2229 if frame.IsShown(): 2253 2230 frame.Show(False) 2254 2231 2255 2232 def show_data_panel(self, event=None, action=True): 2256 2233 """ … … 2263 2240 frame = pane.get_frame() 2264 2241 if label == 'Show Data Explorer': 2265 if action: 2242 if action: 2266 2243 frame.Show(True) 2267 2244 self.__gui_style = self.__gui_style | GUIFRAME.MANAGER_ON … … 2278 2255 if self._data_manager is not None: 2279 2256 self._data_manager.add_data(data_list) 2280 2257 2281 2258 def add_data(self, data_list): 2282 2259 """ 2283 2260 receive a dictionary of data from loader 2284 2261 store them its data manager if possible 2285 send to data the current active perspective if the data panel 2286 is not active. 2262 send to data the current active perspective if the data panel 2263 is not active. 2287 2264 :param data_list: dictionary of data's ID and value Data 2288 2265 """ … … 2293 2270 data_state = self._data_manager.get_data_state(data_list.keys()) 2294 2271 self._data_panel.load_data_list(data_state) 2295 #if the data panel is shown wait for the user to press a button 2272 #if the data panel is shown wait for the user to press a button 2296 2273 #to send data to the current perspective. if the panel is not 2297 2274 #show automatically send the data to the current perspective 2298 2275 style = self.__gui_style & GUIFRAME.MANAGER_ON 2299 2276 if style == GUIFRAME.MANAGER_ON: 2300 #wait for button press from the data panel to set_data 2277 #wait for button press from the data panel to set_data 2301 2278 if self._data_panel is not None: 2302 2279 self._data_panel.frame.Show(True) … … 2304 2281 #automatically send that to the current perspective 2305 2282 self.set_data(data_id=data_list.keys()) 2306 2307 def set_data(self, data_id, theory_id=None): 2283 2284 def set_data(self, data_id, theory_id=None): 2308 2285 """ 2309 2286 set data to current perspective … … 2316 2293 msg = "Guiframe does not have a current perspective" 2317 2294 logging.info(msg) 2318 2295 2319 2296 def set_theory(self, state_id, theory_id=None): 2320 2297 """ … … 2331 2308 msg = "Guiframe does not have a current perspective" 2332 2309 logging.info(msg) 2333 2334 def plot_data(self, 2310 2311 def plot_data(self, state_id, data_id=None, 2335 2312 theory_id=None, append=False): 2336 2313 """ 2337 2314 send a list of data to plot 2338 2315 """ 2339 total_plot_list = []2340 2316 data_list, _ = self._data_manager.get_by_id(data_id) 2341 2317 _, temp_list_theory = self._data_manager.get_by_id(theory_id) … … 2350 2326 message = "cannot append plot. No plot panel on focus!" 2351 2327 message += "please click on any available plot to set focus" 2352 wx.PostEvent(self, StatusEvent(status=message, 2328 wx.PostEvent(self, StatusEvent(status=message, 2353 2329 info='warning')) 2354 return 2330 return 2355 2331 else: 2356 2332 if self.enable_add_data(new_plot): … … 2359 2335 message = "Only 1D Data can be append to" 2360 2336 message += " plot panel containing 1D data.\n" 2361 message += "%s not be appended.\n" % str(new_plot.name)2337 message += "%s not be appended.\n" % str(new_plot.name) 2362 2338 message += "try new plot option.\n" 2363 wx.PostEvent(self, StatusEvent(status=message, 2364 info='warning'))2339 wx.PostEvent(self, StatusEvent(status=message, 2340 info='warning')) 2365 2341 else: 2366 2342 #if not append then new plot … … 2374 2350 title = "PLOT " + str(new_plot.title) 2375 2351 wx.PostEvent(self, NewPlotEvent(plot=new_plot, 2376 2377 group_id =new_plot.group_id))2378 2352 title=title, 2353 group_id=new_plot.group_id)) 2354 2379 2355 def remove_data(self, data_id, theory_id=None): 2380 2356 """ … … 2387 2363 for plug in self.plugins: 2388 2364 plug.delete_data(temp) 2389 total_plot_list = []2390 2365 data_list, _ = self._data_manager.get_by_id(data_id) 2391 2366 _, temp_list_theory = self._data_manager.get_by_id(theory_id) … … 2398 2373 for group_id in new_plot.list_group_id: 2399 2374 wx.PostEvent(self, NewPlotEvent(id=id, 2400 2401 2375 group_id=group_id, 2376 action='remove')) 2402 2377 #remove res plot: Todo: improve 2403 2378 wx.CallAfter(self._remove_res_plot, id) 2404 self._data_manager.delete_data(data_id=data_id, 2379 self._data_manager.delete_data(data_id=data_id, 2405 2380 theory_id=theory_id) 2406 2381 2407 2382 def _remove_res_plot(self, id): 2408 2383 """ 2409 2384 Try to remove corresponding res plot 2410 2385 2411 2386 : param id: id of the data 2412 2387 """ 2413 2388 try: 2414 wx.PostEvent(self, NewPlotEvent(id=("res" +str(id)),2415 group_id=("res"+str(id)),2416 action='remove'))2389 wx.PostEvent(self, NewPlotEvent(id=("res" + str(id)), 2390 group_id=("res" + str(id)), 2391 action='remove')) 2417 2392 except: 2418 pass2419 2393 logging.error(sys.exc_value) 2394 2420 2395 def save_data1d(self, data, fname): 2421 2396 """ … … 2424 2399 default_name = fname 2425 2400 wildcard = "Text files (*.txt)|*.txt|"\ 2426 "CanSAS 1D files(*.xml)|*.xml" 2401 "CanSAS 1D files(*.xml)|*.xml" 2427 2402 path = None 2428 2403 dlg = wx.FileDialog(self, "Choose a file", 2429 2404 self._default_save_location, 2430 default_name, wildcard 2431 2405 default_name, wildcard, wx.SAVE) 2406 2432 2407 if dlg.ShowModal() == wx.ID_OK: 2433 2408 path = dlg.GetPath() … … 2441 2416 path = os.path.splitext(path)[0] + format 2442 2417 mypath = os.path.basename(path) 2443 2444 #TODO: This is bad design. The DataLoader is designed 2445 #to recognize extensions. 2446 # It should be a simple matter of calling the . 2447 #save(file, data, '.xml') method 2448 # of the sas.dataloader.loader.Loader class. 2449 from sas.dataloader.loader import Loader 2450 #Instantiate a loader 2451 loader = Loader() 2418 2419 #Instantiate a loader 2420 loader = Loader() 2452 2421 format = ".txt" 2453 2422 if os.path.splitext(mypath)[1].lower() == format: … … 2465 2434 self._default_save_location = os.path.dirname(path) 2466 2435 except: 2467 pass 2436 pass 2468 2437 dlg.Destroy() 2469 2470 2438 2439 2471 2440 def _onsaveTXT(self, data, path): 2472 2441 """ 2473 Save file as txt 2442 Save file as txt 2474 2443 :TODO: Refactor and remove this method. See TODO in _onSave. 2475 2444 """ … … 2493 2462 else: 2494 2463 out.write("<X> <Y>\n") 2495 2464 2496 2465 for i in range(len(data.x)): 2497 2466 if has_errors: 2498 2467 if data.dx != None and data.dx != []: 2499 2468 if data.dx[i] != None: 2500 out.write("%g %g %g %g\n" % (data.x[i], 2501 data.y[i],2502 data.dy[i],2503 data.dx[i]))2469 out.write("%g %g %g %g\n" % (data.x[i], 2470 data.y[i], 2471 data.dy[i], 2472 data.dx[i])) 2504 2473 else: 2505 out.write("%g %g %g\n" % (data.x[i], 2474 out.write("%g %g %g\n" % (data.x[i], 2506 2475 data.y[i], 2507 2476 data.dy[i])) 2508 2477 else: 2509 out.write("%g %g %g\n" % (data.x[i], 2478 out.write("%g %g %g\n" % (data.x[i], 2510 2479 data.y[i], 2511 2480 data.dy[i])) 2512 2481 else: 2513 out.write("%g %g\n" % (data.x[i], 2482 out.write("%g %g\n" % (data.x[i], 2514 2483 data.y[i])) 2515 out.close() 2516 2484 out.close() 2485 2517 2486 def show_data1d(self, data, name): 2518 2487 """ 2519 2488 Show data dialog 2520 """ 2489 """ 2521 2490 try: 2522 2491 xmin = min(data.x) 2523 2492 ymin = min(data.y) 2524 2493 except: 2525 msg = "Unable to find min/max of \n data named %s" % \2526 data.filename 2494 msg = "Unable to find min/max of \n data named %s" % \ 2495 data.filename 2527 2496 wx.PostEvent(self, StatusEvent(status=msg, 2528 info="error"))2497 info="error")) 2529 2498 raise ValueError, msg 2530 2499 ## text = str(data) 2531 2500 text = data.__str__() 2532 2501 text += 'Data Min Max:\n' 2533 text += 'X_min = %s: X_max = %s\n' % (xmin, max(data.x))2534 text += 'Y_min = %s: Y_max = %s\n' % (ymin, max(data.y))2502 text += 'X_min = %s: X_max = %s\n' % (xmin, max(data.x)) 2503 text += 'Y_min = %s: Y_max = %s\n' % (ymin, max(data.y)) 2535 2504 if data.dy != None: 2536 text += 'dY_min = %s: dY_max = %s\n' % (min(data.dy), max(data.dy))2505 text += 'dY_min = %s: dY_max = %s\n' % (min(data.dy), max(data.dy)) 2537 2506 text += '\nData Points:\n' 2538 2507 x_st = "X" … … 2547 2516 dx_val = 0.0 2548 2517 if data.dxl != None and len(data.dxl) > index: 2549 if index == 0: 2518 if index == 0: 2550 2519 x_st = "Xl" 2551 2520 dx_val = data.dxl[index] 2552 2521 elif data.dxw != None and len(data.dxw) > index: 2553 if index == 0: 2522 if index == 0: 2554 2523 x_st = "Xw" 2555 2524 dx_val = data.dxw[index] 2556 2525 2557 2526 if index == 0: 2558 text += "<index> \t<X> \t<Y> \t<dY> \t<d%s>\n" % x_st2527 text += "<index> \t<X> \t<Y> \t<dY> \t<d%s>\n" % x_st 2559 2528 text += "%s \t%s \t%s \t%s \t%s\n" % (index, 2560 data.x[index],2561 data.y[index],2562 dy_val,2563 dx_val)2529 data.x[index], 2530 data.y[index], 2531 dy_val, 2532 dx_val) 2564 2533 from pdfview import TextFrame 2565 frame = TextFrame(None, -1, "Data Info: %s" % data.name, text)2534 frame = TextFrame(None, -1, "Data Info: %s" % data.name, text) 2566 2535 # put icon 2567 self.put_icon(frame) 2568 frame.Show(True) 2569 2570 def save_data2d(self, data, fname): 2536 self.put_icon(frame) 2537 frame.Show(True) 2538 2539 def save_data2d(self, data, fname): 2571 2540 """ 2572 2541 Save data2d dialog … … 2576 2545 dlg = wx.FileDialog(self, "Choose a file", 2577 2546 self._default_save_location, 2578 default_name, wildcard 2579 2547 default_name, wildcard, wx.SAVE) 2548 2580 2549 if dlg.ShowModal() == wx.ID_OK: 2581 2550 path = dlg.GetPath() … … 2589 2558 path = os.path.splitext(path)[0] + format 2590 2559 mypath = os.path.basename(path) 2591 2592 #TODO: This is bad design. The DataLoader is designed 2593 #to recognize extensions. 2594 # It should be a simple matter of calling the . 2595 #save(file, data, '.xml') method 2596 # of the DataLoader.loader.Loader class. 2597 from sas.dataloader.loader import Loader 2598 #Instantiate a loader 2599 loader = Loader() 2560 2561 #Instantiate a loader 2562 loader = Loader() 2600 2563 2601 2564 format = ".dat" … … 2608 2571 self._default_save_location = os.path.dirname(path) 2609 2572 except: 2610 pass 2611 dlg.Destroy() 2612 2573 pass 2574 dlg.Destroy() 2575 2613 2576 def show_data2d(self, data, name): 2614 2577 """ 2615 2578 Show data dialog 2616 """ 2617 2618 wx.PostEvent(self, StatusEvent(status = "Gathering Data2D Info.", 2619 type = 'start' )) 2620 text = data.__str__() 2579 """ 2580 wx.PostEvent(self, StatusEvent(status="Gathering Data2D Info.", 2581 type='start')) 2582 text = data.__str__() 2621 2583 text += 'Data Min Max:\n' 2622 text += 'I_min = %s\n' % min(data.data)2623 text += 'I_max = %s\n\n' % max(data.data)2584 text += 'I_min = %s\n' % min(data.data) 2585 text += 'I_max = %s\n\n' % max(data.data) 2624 2586 text += 'Data (First 2501) Points:\n' 2625 2587 text += 'Data columns include err(I).\n' … … 2629 2591 dx_val = 0.0 2630 2592 dy_val = 0.0 2631 #mask_val = True2632 2593 len_data = len(data.qx_data) 2633 2594 for index in xrange(0, len_data): … … 2635 2596 y_val = data.qy_data[index] 2636 2597 i_val = data.data[index] 2637 if data.err_data != None: 2598 if data.err_data != None: 2638 2599 di_val = data.err_data[index] 2639 if data.dqx_data != None: 2600 if data.dqx_data != None: 2640 2601 dx_val = data.dqx_data[index] 2641 if data.dqy_data != None: 2602 if data.dqy_data != None: 2642 2603 dy_val = data.dqy_data[index] 2643 2604 2644 2605 text += "%s \t%s \t%s \t%s \t%s \t%s \t%s\n" % (index, 2645 x_val,2646 y_val,2647 i_val,2648 di_val,2649 dx_val,2650 dy_val)2606 x_val, 2607 y_val, 2608 i_val, 2609 di_val, 2610 dx_val, 2611 dy_val) 2651 2612 # Takes too long time for typical data2d: Break here 2652 2613 if index >= 2500: … … 2655 2616 2656 2617 from pdfview import TextFrame 2657 frame = TextFrame(None, -1, "Data Info: %s" % data.name, text)2618 frame = TextFrame(None, -1, "Data Info: %s" % data.name, text) 2658 2619 # put icon 2659 2620 self.put_icon(frame) 2660 frame.Show(True) 2661 wx.PostEvent(self, StatusEvent(status = "Data2D Info Displayed",2662 type = 'stop'))2663 2621 frame.Show(True) 2622 wx.PostEvent(self, StatusEvent(status="Data2D Info Displayed", 2623 type='stop')) 2624 2664 2625 def set_current_perspective(self, perspective): 2665 2626 """ 2666 set the current active perspective 2627 set the current active perspective 2667 2628 """ 2668 2629 self._current_perspective = perspective … … 2680 2641 else: 2681 2642 frame.Show(False) 2682 #break2683 2643 name = self._current_perspective.sub_menu 2684 2644 if self._data_panel is not None: … … 2687 2647 #Set the SasView title 2688 2648 self._set_title_name(name) 2689 2649 2690 2650 def _set_title_name(self, name): 2691 2651 """ 2692 2652 Set the SasView title w/ the current application name 2693 2653 2694 2654 : param name: application name [string] 2695 2655 """ … … 2697 2657 title = self.title + " - " + name + " -" 2698 2658 self.SetTitle(title) 2699 2659 2700 2660 def _check_applications_menu(self): 2701 2661 """ … … 2710 2670 menu.Check(True) 2711 2671 else: 2712 menu.Check(False) 2713 2672 menu.Check(False) 2673 2714 2674 def enable_add_data(self, new_plot): 2715 2675 """ … … 2721 2681 is_theory = len(self.panel_on_focus.plots) <= 1 and \ 2722 2682 self.panel_on_focus.plots.values()[0].__class__.__name__ == "Theory1D" 2723 2683 2724 2684 is_data2d = hasattr(new_plot, 'data') 2725 2685 2726 2686 is_data1d = self.panel_on_focus.__class__.__name__ == "ModelPanel1D"\ 2727 2687 and self.panel_on_focus.group_id is not None 2728 2688 has_meta_data = hasattr(new_plot, 'meta_data') 2729 2689 2730 2690 #disable_add_data if the data is being recovered from a saved state file. 2731 2691 is_state_data = False 2732 2692 if has_meta_data: 2733 if 'invstate' in new_plot.meta_data: 2693 if 'invstate' in new_plot.meta_data: 2734 2694 is_state_data = True 2735 if 'prstate' in new_plot.meta_data: 2695 if 'prstate' in new_plot.meta_data: 2736 2696 is_state_data = True 2737 if 'fitstate' in new_plot.meta_data: 2697 if 'fitstate' in new_plot.meta_data: 2738 2698 is_state_data = True 2739 2699 2740 2700 return is_data1d and not is_data2d and not is_theory and not is_state_data 2741 2701 2742 2702 def check_multimode(self, perspective=None): 2743 2703 """ … … 2756 2716 self._data_panel.rb_single_mode.Enable(flag) 2757 2717 self._data_panel.rb_batch_mode.Enable(flag) 2758 2759 2760 2718 2761 2719 def enable_edit_menu(self): 2762 2720 """ … … 2775 2733 #Copy menu 2776 2734 flag = self.cpanel_on_focus.get_copy_flag() 2777 #self._edit_menu.ENABLE(GUIFRAME_ID.COPYAS_ID,flag)2778 2735 self._edit_menu_copyas.Enable(GUIFRAME_ID.COPYEX_ID, flag) 2779 2736 self._edit_menu_copyas.Enable(GUIFRAME_ID.COPYLAT_ID, flag) … … 2789 2746 self._edit_menu.Enable(GUIFRAME_ID.COPY_ID, flag) 2790 2747 self._edit_menu.Enable(GUIFRAME_ID.PASTE_ID, flag) 2791 #self._edit_menu.Enable(GUIFRAME_ID.COPYEX_ID, flag)2792 #self._edit_menu.Enable(GUIFRAME_ID.COPYLAT_ID, flag)2793 #self._edit_menu.Enable(GUIFRAME_ID.COPYAS_ID, flag)2794 2748 self._edit_menu.Enable(GUIFRAME_ID.PREVIEW_ID, flag) 2795 2749 self._edit_menu.Enable(GUIFRAME_ID.RESET_ID, flag) 2796 2750 2797 2751 def on_undo_panel(self, event=None): 2798 2752 """ … … 2801 2755 if self.cpanel_on_focus is not None: 2802 2756 self.cpanel_on_focus.on_undo(event) 2803 2757 2804 2758 def on_redo_panel(self, event=None): 2805 2759 """ … … 2808 2762 if self.cpanel_on_focus is not None: 2809 2763 self.cpanel_on_focus.on_redo(event) 2810 2764 2811 2765 def on_copy_panel(self, event=None): 2812 2766 """ … … 2815 2769 if self.cpanel_on_focus is not None: 2816 2770 self.cpanel_on_focus.on_copy(event) 2817 2771 2818 2772 def on_paste_panel(self, event=None): 2819 2773 """ … … 2822 2776 if self.cpanel_on_focus is not None: 2823 2777 self.cpanel_on_focus.on_paste(event) 2824 2778 2825 2779 def on_bookmark_panel(self, event=None): 2826 2780 """ … … 2829 2783 if self.cpanel_on_focus is not None: 2830 2784 self.cpanel_on_focus.on_bookmark(event) 2831 2785 2832 2786 def append_bookmark(self, event=None): 2833 2787 """ … … 2835 2789 """ 2836 2790 self._toolbar.append_bookmark(event) 2837 2791 2838 2792 def on_save_panel(self, event=None): 2839 2793 """ … … 2842 2796 if self.cpanel_on_focus is not None: 2843 2797 self.cpanel_on_focus.on_save(event) 2844 2798 2845 2799 def on_preview_panel(self, event=None): 2846 2800 """ … … 2849 2803 if self.cpanel_on_focus is not None: 2850 2804 self.cpanel_on_focus.on_preview(event) 2851 2805 2852 2806 def on_print_panel(self, event=None): 2853 2807 """ … … 2856 2810 if self.cpanel_on_focus is not None: 2857 2811 self.cpanel_on_focus.on_print(event) 2858 2812 2859 2813 def on_zoom_panel(self, event=None): 2860 2814 """ … … 2863 2817 if self.cpanel_on_focus is not None: 2864 2818 self.cpanel_on_focus.on_zoom(event) 2865 2819 2866 2820 def on_zoom_in_panel(self, event=None): 2867 2821 """ … … 2870 2824 if self.cpanel_on_focus is not None: 2871 2825 self.cpanel_on_focus.on_zoom_in(event) 2872 2826 2873 2827 def on_zoom_out_panel(self, event=None): 2874 2828 """ … … 2877 2831 if self.cpanel_on_focus is not None: 2878 2832 self.cpanel_on_focus.on_zoom_out(event) 2879 2833 2880 2834 def on_drag_panel(self, event=None): 2881 2835 """ … … 2884 2838 if self.cpanel_on_focus is not None: 2885 2839 self.cpanel_on_focus.on_drag(event) 2886 2840 2887 2841 def on_reset_panel(self, event=None): 2888 2842 """ … … 2891 2845 if self.cpanel_on_focus is not None: 2892 2846 self.cpanel_on_focus.on_reset(event) 2893 2894 def on_change_caption(self, name, old_caption, new_caption): 2847 2848 def on_change_caption(self, name, old_caption, new_caption): 2895 2849 """ 2896 2850 Change the panel caption 2897 2851 2898 2852 :param name: window_name of the pane 2899 2853 :param old_caption: current caption [string] … … 2901 2855 """ 2902 2856 # wx.aui.AuiPaneInfo 2903 pane_info = self.get_paneinfo(old_caption) 2857 pane_info = self.get_paneinfo(old_caption) 2904 2858 # update the data_panel.cb_plotpanel 2905 2859 if 'data_panel' in self.panels.keys(): … … 2909 2863 # Check if any panel has the same caption 2910 2864 has_newstring = data_panel.cb_plotpanel.FindString\ 2911 (str(new_caption)) 2865 (str(new_caption)) 2912 2866 caption = new_caption 2913 2867 if has_newstring != wx.NOT_FOUND: … … 2915 2869 # Append nummber 2916 2870 inc = 1 2871 #FIXME: fix this terrible loop 2917 2872 while (1): 2918 caption = new_caption + '_%s' % str(inc)2873 caption = new_caption + '_%s' % str(inc) 2919 2874 if caption not in captions: 2920 2875 break 2921 2876 inc += 1 2922 2877 # notify to users 2923 msg = "Found Same Title: Added '_%s'" % str(inc)2878 msg = "Found Same Title: Added '_%s'" % str(inc) 2924 2879 wx.PostEvent(self, StatusEvent(status=msg)) 2925 2880 # update data_panel cb 2926 pos = data_panel.cb_plotpanel.FindString(str(old_caption)) 2881 pos = data_panel.cb_plotpanel.FindString(str(old_caption)) 2927 2882 if pos != wx.NOT_FOUND: 2928 2883 data_panel.cb_plotpanel.SetString(pos, caption) … … 2931 2886 pane_info.SetTitle(caption) 2932 2887 return caption 2933 2888 2934 2889 def get_paneinfo(self, name): 2935 2890 """ 2936 2891 Get pane Caption from window_name 2937 2892 2938 2893 :param name: window_name in AuiPaneInfo 2939 2894 : return: AuiPaneInfo of the name … … 2943 2898 return panel.frame 2944 2899 return None 2945 2900 2946 2901 def enable_undo(self): 2947 2902 """ … … 2950 2905 if self.cpanel_on_focus is not None: 2951 2906 self._toolbar.enable_undo(self.cpanel_on_focus) 2952 2907 2953 2908 def enable_redo(self): 2954 2909 """ 2955 enable redo 2910 enable redo 2956 2911 """ 2957 2912 if self.cpanel_on_focus is not None: 2958 2913 self._toolbar.enable_redo(self.cpanel_on_focus) 2959 2914 2960 2915 def enable_copy(self): 2961 2916 """ … … 2964 2919 if self.cpanel_on_focus is not None: 2965 2920 self._toolbar.enable_copy(self.cpanel_on_focus) 2966 2921 2967 2922 def enable_paste(self): 2968 2923 """ 2969 enable paste 2924 enable paste 2970 2925 """ 2971 2926 if self.cpanel_on_focus is not None: 2972 2927 self._toolbar.enable_paste(self.cpanel_on_focus) 2973 2928 2974 2929 def enable_bookmark(self): 2975 2930 """ 2976 Bookmark 2931 Bookmark 2977 2932 """ 2978 2933 if self.cpanel_on_focus is not None: 2979 2934 self._toolbar.enable_bookmark(self.cpanel_on_focus) 2980 2935 2981 2936 def enable_save(self): 2982 2937 """ 2983 save 2938 save 2984 2939 """ 2985 2940 if self.cpanel_on_focus is not None: 2986 2941 self._toolbar.enable_save(self.cpanel_on_focus) 2987 2942 2988 2943 def enable_preview(self): 2989 2944 """ 2990 preview 2945 preview 2991 2946 """ 2992 2947 if self.cpanel_on_focus is not None: 2993 2948 self._toolbar.enable_preview(self.cpanel_on_focus) 2994 2949 2995 2950 def enable_print(self): 2996 2951 """ 2997 print 2952 print 2998 2953 """ 2999 2954 if self.cpanel_on_focus is not None: 3000 2955 self._toolbar.enable_print(self.cpanel_on_focus) 3001 2956 3002 2957 def enable_zoom(self): 3003 2958 """ 3004 zoom 2959 zoom 3005 2960 """ 3006 2961 if self.cpanel_on_focus is not None: 3007 2962 self._toolbar.enable_zoom(self.panel_on_focus) 3008 2963 3009 2964 def enable_zoom_in(self): 3010 2965 """ 3011 zoom in 2966 zoom in 3012 2967 """ 3013 2968 if self.cpanel_on_focus is not None: 3014 2969 self._toolbar.enable_zoom_in(self.panel_on_focus) 3015 2970 3016 2971 def enable_zoom_out(self): 3017 2972 """ 3018 zoom out 2973 zoom out 3019 2974 """ 3020 2975 if self.cpanel_on_focus is not None: 3021 2976 self._toolbar.enable_zoom_out(self.panel_on_focus) 3022 2977 3023 2978 def enable_drag(self, event=None): 3024 2979 """ 3025 drag 2980 drag 3026 2981 """ 3027 2982 #Not implemeted 3028 2983 3029 2984 def enable_reset(self): 3030 2985 """ … … 3033 2988 if self.cpanel_on_focus is not None: 3034 2989 self._toolbar.enable_reset(self.panel_on_focus) 3035 2990 3036 2991 def get_toolbar_height(self): 3037 2992 """ … … 3042 2997 _, size_y = self.GetToolBar().GetSizeTuple() 3043 2998 return size_y 3044 2999 3045 3000 def set_schedule_full_draw(self, panel=None, func='del'): 3046 3001 """ 3047 3002 Add/subtract the schedule full draw list with the panel given 3048 3003 3049 3004 :param panel: plot panel 3050 3005 :param func: append or del [string] … … 3054 3009 if func == 'append': 3055 3010 if not panel in self.schedule_full_draw_list: 3056 self.schedule_full_draw_list.append(panel) 3011 self.schedule_full_draw_list.append(panel) 3057 3012 # remove this panel from schedule list 3058 3013 elif func == 'del': … … 3065 3020 self.schedule = False 3066 3021 else: 3067 self.schedule = True 3068 3022 self.schedule = True 3023 3069 3024 def full_draw(self): 3070 3025 """ 3071 3026 Draw the panels with axes in the schedule to full dwar list 3072 3027 """ 3073 3028 3074 3029 count = len(self.schedule_full_draw_list) 3075 3030 #if not self.schedule: … … 3097 3052 # while any panel is capture. 3098 3053 frame = panel.frame 3099 3054 3100 3055 if not frame.GetCapture(): 3101 3056 # draw if possible … … 3105 3060 # Check if the panel is not shown 3106 3061 flag = frame.IsShown() 3107 frame.Show(flag) 3062 frame.Show(flag) 3108 3063 except: 3109 3064 pass 3110 3065 3111 3066 # Draw all panels 3112 3067 if count == 1: 3113 f_draw(self.schedule_full_draw_list[0]) 3068 f_draw(self.schedule_full_draw_list[0]) 3114 3069 else: 3115 3070 map(f_draw, self.schedule_full_draw_list) … … 3119 3074 else: 3120 3075 self.set_schedule(True) 3121 3122 def set_schedule(self, schedule=False): 3076 3077 def set_schedule(self, schedule=False): 3123 3078 """ 3124 3079 Set schedule 3125 3080 """ 3126 3081 self.schedule = schedule 3127 3128 def get_schedule(self): 3082 3083 def get_schedule(self): 3129 3084 """ 3130 3085 Get schedule 3131 3086 """ 3132 3087 return self.schedule 3133 3088 3134 3089 def on_set_plot_focus(self, panel): 3135 3090 """ … … 3139 3094 return 3140 3095 #self.set_plot_unfocus() 3141 panel.on_set_focus(None) 3096 panel.on_set_focus(None) 3142 3097 # set focusing panel 3143 self.panel_on_focus = panel 3098 self.panel_on_focus = panel 3144 3099 self.set_panel_on_focus(None) 3145 3100 3146 def set_plot_unfocus(self): 3101 def set_plot_unfocus(self): 3147 3102 """ 3148 3103 Un focus all plot panels … … 3150 3105 for plot in self.plot_panels.values(): 3151 3106 plot.on_kill_focus(None) 3152 3107 3153 3108 def get_window_size(self): 3154 3109 """ 3155 Get window size 3156 3110 Get window size 3111 3157 3112 :return size: tuple 3158 3113 """ … … 3163 3118 height -= 45 3164 3119 return (width, height) 3165 3120 3166 3121 def _onDrawIdle(self, *args, **kwargs): 3167 3122 """ … … 3175 3130 except: 3176 3131 pass 3177 3132 3178 3133 # restart idle 3179 3134 self._redraw_idle(*args, **kwargs) 3180 3135 3181 3136 3182 3137 def _redraw_idle(self, *args, **kwargs): 3183 3138 """ … … 3185 3140 """ 3186 3141 # restart idle 3187 self.idletimer.Restart(100 *TIME_FACTOR, *args, **kwargs)3188 3189 3142 self.idletimer.Restart(100 * TIME_FACTOR, *args, **kwargs) 3143 3144 3190 3145 class DefaultPanel(wx.Panel, PanelBase): 3191 3146 """ … … 3202 3157 wx.Panel.__init__(self, parent, *args, **kwds) 3203 3158 PanelBase.__init__(self, parent) 3204 3159 3205 3160 3206 3161 … … 3213 3168 When initialised 3214 3169 """ 3215 pos, size, self.is_max = self.window_placement((GUIFRAME_WIDTH, 3216 GUIFRAME_HEIGHT))3217 self.frame = ViewerFrame(parent=None, 3218 title=APPLICATION_NAME,3219 pos=pos,3220 gui_style =DEFAULT_STYLE,3221 size=size)3170 pos, size, self.is_max = self.window_placement((GUIFRAME_WIDTH, 3171 GUIFRAME_HEIGHT)) 3172 self.frame = ViewerFrame(parent=None, 3173 title=APPLICATION_NAME, 3174 pos=pos, 3175 gui_style=DEFAULT_STYLE, 3176 size=size) 3222 3177 self.frame.Hide() 3223 3178 if not IS_WIN: … … 3234 3189 try: 3235 3190 if os.path.isfile(SPLASH_SCREEN_PATH): 3236 self.s_screen = self.display_splash_screen(parent=self.frame, 3237 path=SPLASH_SCREEN_PATH)3191 self.s_screen = self.display_splash_screen(parent=self.frame, 3192 path=SPLASH_SCREEN_PATH) 3238 3193 else: 3239 self.frame.Show() 3194 self.frame.Show() 3240 3195 except: 3241 3196 if self.s_screen is not None: 3242 3197 self.s_screen.Close() 3243 3198 msg = "Cannot display splash screen\n" 3244 msg += str 3199 msg += str(sys.exc_value) 3245 3200 logging.error(msg) 3246 3201 self.frame.Show() 3247 3202 3248 3203 self.SetTopWindow(self.frame) 3249 3204 3250 3205 return True 3251 3206 3252 3207 def maximize_win(self): 3253 3208 """ … … 3266 3221 if len(sys.argv) >= 2: 3267 3222 cmd = sys.argv[0].lower() 3268 basename 3223 basename = os.path.basename(cmd) 3269 3224 app_base = str(APPLICATION_NAME).lower() 3270 3225 if os.path.isfile(cmd) or basename.lower() == app_base: … … 3274 3229 if basename.lower() in [app_py, app_exe, app_app, app_base]: 3275 3230 data_base = sys.argv[1] 3276 input_file = os.path.normpath(os.path.join(DATAPATH, 3231 input_file = os.path.normpath(os.path.join(DATAPATH, 3277 3232 data_base)) 3278 3233 if input_file is None: … … 3280 3235 if self.frame is not None: 3281 3236 self.frame.set_input_file(input_file=input_file) 3282 3283 def clean_plugin_models(self, path): 3237 3238 def clean_plugin_models(self, path): 3284 3239 """ 3285 3240 Delete plugin models in app folder 3286 3241 3287 3242 :param path: path of the plugin_models folder in app 3288 3243 """ 3289 3244 # do it only the first time app loaded 3290 # delete unused model folder 3245 # delete unused model folder 3291 3246 model_folder = os.path.join(PATH_APP, path) 3292 3247 if os.path.exists(model_folder) and os.path.isdir(model_folder): … … 3300 3255 logging.error("gui_manager.clean_plugin_models:\n %s" \ 3301 3256 % sys.exc_value) 3302 3257 3303 3258 def set_manager(self, manager): 3304 3259 """ 3305 3260 Sets a reference to the application manager 3306 of the GUI manager (Frame) 3261 of the GUI manager (Frame) 3307 3262 """ 3308 3263 self.frame.set_manager(manager) 3309 3264 3310 3265 def build_gui(self): 3311 3266 """ … … 3318 3273 raise 3319 3274 self.frame.build_gui() 3320 3275 3321 3276 def set_welcome_panel(self, panel_class): 3322 3277 """ 3323 3278 Set the welcome panel 3324 3279 3325 3280 :param panel_class: class of the welcome panel to be instantiated 3326 3281 3327 3282 """ 3328 3283 self.frame.welcome_panel_class = panel_class 3329 3284 3330 3285 def add_perspective(self, perspective): 3331 3286 """ … … 3333 3288 """ 3334 3289 self.frame.add_perspective(perspective) 3335 3290 3336 3291 def window_placement(self, size): 3337 3292 """ … … 3350 3305 displayRect = screen.GetClientArea() 3351 3306 break 3352 3353 posX, posY, displayWidth, displayHeight = displayRect 3307 3308 posX, posY, displayWidth, displayHeight = displayRect 3354 3309 customWidth, customHeight = size 3355 3310 3356 3311 # If the custom size is default, set 90% of the screen size 3357 3312 if customWidth <= 0 and customHeight <= 0: … … 3367 3322 if customHeight > displayHeight: 3368 3323 customHeight = displayHeight 3369 3324 3370 3325 # Note that when running Linux and using an Xming (X11) server on a PC 3371 3326 # with a dual monitor configuration, the reported display size may be … … 3374 3329 # screen 'too big'. If so, we assume a smaller width which means the 3375 3330 # application will be placed towards the left hand side of the screen. 3376 3331 3377 3332 # If dual screen registered as 1 screen. Make width half. 3378 3333 # MAC just follows the default behavior of pos 3379 3334 if IS_WIN: 3380 if displayWidth > (displayHeight *2):3381 if (customWidth == displayWidth):3382 customWidth = displayWidth /23335 if displayWidth > (displayHeight * 2): 3336 if customWidth == displayWidth: 3337 customWidth = displayWidth / 2 3383 3338 # and set the position to be the corner of the screen. 3384 3339 posX = 0 3385 3340 posY = 0 3386 3341 3387 3342 # Make the position the middle of the screen. (Not 0,0) 3388 3343 else: 3389 posX = (displayWidth - customWidth) /23390 posY = (displayHeight - customHeight) /23391 # Return the suggested position and size for the application frame. 3344 posX = (displayWidth - customWidth) / 2 3345 posY = (displayHeight - customHeight) / 2 3346 # Return the suggested position and size for the application frame. 3392 3347 return (posX, posY), (customWidth, customHeight), is_maximized 3393 3348 3394 3395 def display_splash_screen(self, parent, 3349 3350 def display_splash_screen(self, parent, 3396 3351 path=SPLASH_SCREEN_PATH): 3397 3352 """Displays the splash screen. It will exactly cover the main frame.""" 3398 3353 3399 3354 # Prepare the picture. On a 2GHz intel cpu, this takes about a second. 3400 3355 image = wx.Image(path, wx.BITMAP_TYPE_PNG) 3401 image.Rescale(SPLASH_SCREEN_WIDTH, 3356 image.Rescale(SPLASH_SCREEN_WIDTH, 3402 3357 SPLASH_SCREEN_HEIGHT, wx.IMAGE_QUALITY_HIGH) 3403 3358 bm = image.ConvertToBitmap() … … 3413 3368 # case the splash screen disappears upon entering the event loop. 3414 3369 s_screen = wx.SplashScreen(bitmap=bm, 3415 splashStyle=(wx.SPLASH_TIMEOUT |3370 splashStyle=(wx.SPLASH_TIMEOUT | 3416 3371 wx.SPLASH_CENTRE_ON_SCREEN), 3417 style=(wx.SIMPLE_BORDER |3418 wx.FRAME_NO_TASKBAR |3372 style=(wx.SIMPLE_BORDER | 3373 wx.FRAME_NO_TASKBAR | 3419 3374 wx.FRAME_FLOAT_ON_PARENT), 3420 3375 milliseconds=SS_MAX_DISPLAY_TIME, … … 3427 3382 s_screen.Show() 3428 3383 return s_screen 3429 3430 3384 3385 3431 3386 def on_close_splash_screen(self, event): 3432 3387 """ … … 3442 3397 Frame for panels 3443 3398 """ 3444 def __init__(self, parent, panel, title="Untitled", size=(300, 200)):3399 def __init__(self, parent, panel, title="Untitled", size=(300, 200)): 3445 3400 """ 3446 3401 comment … … 3456 3411 self.set_panel(panel) 3457 3412 self.Show(False) 3458 3413 3459 3414 def show_data_panel(self, action): 3460 3415 """ 3461 3416 """ 3462 3417 self.parent.show_data_panel(action) 3463 3418 3464 3419 def set_panel(self, panel): 3465 3420 """ … … 3471 3426 width, height = self.parent._get_panels_size(panel) 3472 3427 if hasattr(panel, "CENTER_PANE") and panel.CENTER_PANE: 3473 width *= 0.6 3428 width *= 0.6 3474 3429 self.SetSize((width, height)) 3475 3430 self.parent.put_icon(self) … … 3477 3432 self.Bind(wx.EVT_CLOSE, self.OnClose) 3478 3433 self.Show(False) 3479 3434 3480 3435 def set_panel_focus(self, event): 3481 3436 """ … … 3484 3439 self.panel.SetFocus() 3485 3440 self.parent.panel_on_focus = self.panel 3486 3441 3487 3442 def OnClose(self, event): 3488 3443 """ … … 3490 3445 """ 3491 3446 self.panel.on_close(event) 3492 3493 if __name__ == "__main__": 3447 3448 if __name__ == "__main__": 3494 3449 app = ViewApp(0) 3495 3450 app.MainLoop()
Note: See TracChangeset
for help on using the changeset viewer.