Changeset 914ba0a in sasview for src/sas/sasgui/guiframe/gui_manager.py
- Timestamp:
- May 2, 2017 3:58:01 PM (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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- d66dbcc
- Parents:
- 74d9780 (diff), 658dd57 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/gui_manager.py
refe730d r914ba0a 3 3 """ 4 4 ################################################################################ 5 # This software was developed by the University of Tennessee as part of the6 # Distributed Data Analysis of Neutron Scattering Experiments (DANSE)7 # project funded by the US National Science Foundation.5 # This software was developed by the University of Tennessee as part of the 6 # Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 7 # project funded by the US National Science Foundation. 8 8 # 9 # See the license text in license.txtz9 # See the license text in license.txtz 10 10 # 11 # copyright 2008, University of Tennessee11 # copyright 2008, University of Tennessee 12 12 ################################################################################ 13 13 … … 21 21 import warnings 22 22 import re 23 warnings.simplefilter("ignore")24 23 import logging 25 24 import traceback … … 50 49 from sas.sasgui.guiframe.customdir import setup_custom_config 51 50 51 logger = logging.getLogger(__name__) 52 warnings.simplefilter("ignore") 53 52 54 config = get_local_config() 53 55 custom_config = setup_custom_config() 54 56 55 # read some constants from config57 # read some constants from config 56 58 APPLICATION_STATE_EXTENSION = config.APPLICATION_STATE_EXTENSION 57 59 APPLICATION_NAME = config.__appname__ … … 61 63 SPLASH_SCREEN_HEIGHT = config.SPLASH_SCREEN_HEIGHT 62 64 SS_MAX_DISPLAY_TIME = config.SS_MAX_DISPLAY_TIME 65 SAS_OPENCL = config.SAS_OPENCL 63 66 if not WELCOME_PANEL_ON: 64 67 WELCOME_PANEL_SHOW = False … … 81 84 # custom open_path 82 85 open_folder = custom_config.DEFAULT_OPEN_FOLDER 83 if open_folder !=None and os.path.isdir(open_folder):86 if open_folder is not None and os.path.isdir(open_folder): 84 87 DEFAULT_OPEN_FOLDER = os.path.abspath(open_folder) 85 88 else: 86 89 DEFAULT_OPEN_FOLDER = get_app_dir() 90 SAS_OPENCL = custom_config.SAS_OPENCL 87 91 except: 88 92 DATALOADER_SHOW = True … … 99 103 CLEANUP_PLOT = False 100 104 DEFAULT_OPEN_FOLDER = get_app_dir() 101 105 DEFAULT_OPEN_FOLDER = PATH_APP 106 SAS_OPENCL = None 102 107 DEFAULT_STYLE = config.DEFAULT_STYLE 103 108 … … 134 139 CHILD_FRAME = wx.Frame 135 140 141 #Initiliaze enviromental variable with custom setting but only if variable not set 142 if SAS_OPENCL and not "SAS_OPENCL" in os.environ: 143 os.environ["SAS_OPENCL"] = SAS_OPENCL 144 136 145 class ViewerFrame(PARENT_FRAME): 137 146 """ … … 147 156 Initialize the Frame object 148 157 """ 149 PARENT_FRAME.__init__(self, parent=parent, title=title, pos=pos, size=size) 158 PARENT_FRAME.__init__(self, parent=parent, title=title, 159 pos=pos, size=size) 150 160 # title 151 161 self.title = title … … 168 178 self.path = get_app_dir() 169 179 self.application_name = APPLICATION_NAME 170 # #Application manager180 # Application manager 171 181 self._input_file = None 172 182 self.app_manager = None 173 183 self._mgr = None 174 # add current perpsective184 # add current perpsective 175 185 self._current_perspective = None 176 186 self._plotting_plugin = None 177 187 self._data_plugin = None 178 # Menu bar and item188 # Menu bar and item 179 189 self._menubar = None 180 190 self._file_menu = None … … 190 200 self._toolbar_menu = None 191 201 self._save_appl_menu = None 192 # tool bar202 # tool bar 193 203 self._toolbar = None 194 204 # Status bar … … 198 208 # plot duck cleanup option 199 209 self.cleanup_plots = CLEANUP_PLOT 200 # #Find plug-ins210 # Find plug-ins 201 211 # Modify this so that we can specify the directory to look into 202 212 self.plugins = [] 203 # add local plugin213 # add local plugin 204 214 self.plugins += self._get_local_plugins() 205 215 self.plugins += self._find_plugins() 206 # #List of panels216 # List of panels 207 217 self.panels = {} 208 218 # List of plot panels … … 216 226 self.defaultPanel = None 217 227 self.welcome_panel_class = None 218 # panel on focus228 # panel on focus 219 229 self.panel_on_focus = None 220 # control_panel on focus230 # control_panel on focus 221 231 self.cpanel_on_focus = None 222 232 223 233 self.loader = Loader() 224 # data manager234 # data manager 225 235 self.batch_on = False 226 236 from sas.sasgui.guiframe.data_manager import DataManager 227 237 self._data_manager = DataManager() 228 self._data_panel = None #DataPanel(parent=self)238 self._data_panel = None # DataPanel(parent=self) 229 239 if self.panel_on_focus is not None: 230 self._data_panel.set_panel_on_focus(self.panel_on_focus.window_caption) 240 self._data_panel.set_panel_on_focus( 241 self.panel_on_focus.window_caption) 231 242 # list of plot panels in schedule to full redraw 232 243 self.schedule = False 233 # self.callback = True244 # self.callback = True 234 245 self._idle_count = 0 235 246 self.schedule_full_draw_list = [] … … 245 256 # Register to status events 246 257 self.Bind(EVT_STATUS, self._on_status_event) 247 # Register add extra data on the same panel event on load258 # Register add extra data on the same panel event on load 248 259 self.Bind(EVT_PANEL_ON_FOCUS, self.set_panel_on_focus) 249 260 self.Bind(EVT_APPEND_BOOKMARK, self.append_bookmark) … … 275 286 frame.SetIcon(icon) 276 287 except: 277 logg ing.error("ViewerFrame.put_icon: could not set icon")288 logger.error("ViewerFrame.put_icon: could not set icon") 278 289 279 290 def get_client_size(self): … … 285 296 # Adjust toolbar height 286 297 toolbar = self.GetToolBar() 287 if toolbar !=None:298 if toolbar is not None: 288 299 _, tb_h = toolbar.GetSizeTuple() 289 300 height -= tb_h … … 298 309 fitpanel = item.fit_panel 299 310 300 if fitpanel !=None:311 if fitpanel is not None: 301 312 for i in range(0, fitpanel.GetPageCount()): 302 313 fitpanel.GetPage(i)._populate_listbox() … … 325 336 """ 326 337 Display value of data into the application grid 327 :param data: dictionary of string and list of items 338 :param data_inputs: dictionary of string and list of items 339 :param details: descriptive string 340 :param file_name: file name 341 :param data_outputs: Data outputs 328 342 """ 329 343 self.batch_frame.set_data(data_inputs=data_inputs, … … 339 353 """ 340 354 path = None 341 if self._default_save_location ==None:355 if self._default_save_location is None: 342 356 self._default_save_location = os.getcwd() 343 357 wildcard = "(*.csv; *.txt)|*.csv; *.txt" … … 381 395 line.strip() 382 396 count = 0 383 if separator ==None:397 if separator is None: 384 398 line.replace('\t', ' ') 385 # found the first line containing the label399 # found the first line containing the label 386 400 col_name_toks = line.split() 387 401 for item in col_name_toks: … … 392 406 elif line.find(separator) != -1: 393 407 if line.count(separator) >= 2: 394 # found the first line containing the label408 # found the first line containing the label 395 409 col_name_toks = line.split(separator) 396 410 for item in col_name_toks: … … 446 460 separator = "," 447 461 fd.write(str(details)) 448 for col_name 462 for col_name in data.keys(): 449 463 fd.write(str(col_name)) 450 464 fd.write(separator) … … 509 523 Set up custom configuration if exists 510 524 """ 511 if custom_config ==None:525 if custom_config is None: 512 526 return 513 527 … … 529 543 Set default starting perspective 530 544 """ 531 if custom_config ==None:545 if custom_config is None: 532 546 return 533 547 for plugin in self.plugins: … … 538 552 frame = plugin.get_frame() 539 553 frame.Show(True) 540 # break554 # break 541 555 else: 542 556 frame = plugin.get_frame() … … 589 603 update edit menu if available 590 604 """ 591 if event !=None:605 if event is not None: 592 606 self.panel_on_focus = event.panel 593 607 if self.panel_on_focus is not None: 594 #Disable save application if the current panel is in batch mode 595 flag = self.panel_on_focus.get_save_flag() 596 if self._save_appl_menu != None: 597 self._save_appl_menu.Enable(flag) 598 599 if self.panel_on_focus not in self.plot_panels.values(): 600 for ID in self.panels.keys(): 601 if self.panel_on_focus != self.panels[ID]: 602 self.panels[ID].on_kill_focus(None) 603 604 if self._data_panel is not None and \ 605 self.panel_on_focus is not None: 606 self.set_panel_on_focus_helper() 607 #update toolbar 608 self._update_toolbar_helper() 609 #update edit menu 610 self.enable_edit_menu() 608 # Disable save application if the current panel is in batch mode 609 try: 610 flag = self.panel_on_focus.get_save_flag() 611 if self._save_appl_menu is not None: 612 self._save_appl_menu.Enable(flag) 613 614 if self.panel_on_focus not in self.plot_panels.values(): 615 for ID in self.panels.keys(): 616 if self.panel_on_focus != self.panels[ID]: 617 self.panels[ID].on_kill_focus(None) 618 619 if self._data_panel is not None and \ 620 self.panel_on_focus is not None: 621 self.set_panel_on_focus_helper() 622 # update toolbar 623 self._update_toolbar_helper() 624 # update edit menu 625 self.enable_edit_menu() 626 except wx._core.PyDeadObjectError: 627 pass 611 628 612 629 def disable_app_menu(self, p_panel=None): … … 620 637 Send focusing on ID to data explorer 621 638 """ 622 if self._data_panel !=None:639 if self._data_panel is not None: 623 640 self._data_panel.set_panel_on_focus(name) 624 641 … … 629 646 caption = self.panel_on_focus.window_caption 630 647 self.send_focus_to_datapanel(caption) 631 # update combo648 # update combo 632 649 if self.panel_on_focus in self.plot_panels.values(): 633 650 combo = self._data_panel.cb_plotpanel … … 648 665 """ 649 666 cpanel = panel 650 if self._toolbar !=None and cpanel._bookmark_flag:651 for item in 667 if self._toolbar is not None and cpanel._bookmark_flag: 668 for item in self._toolbar.get_bookmark_items(): 652 669 self._toolbar.remove_bookmark_item(item) 653 670 self._toolbar.add_bookmark_default() … … 698 715 str(self._input_file)) 699 716 msg += str(sys.exc_value) + '\n' 700 logg ing.error(msg)717 logger.error(msg) 701 718 if self._data_panel is not None and len(self.plugins) > 0: 702 719 self._data_panel.fill_cbox_analysis(self.plugins) … … 750 767 field = self.sb.get_msg_position() 751 768 wx.Frame.PushStatusText(self, field=field, 752 string="FIXME - PushStatusText called without text") 769 string= 770 "FIXME - PushStatusText called without text") 753 771 754 772 def add_perspective(self, plugin): … … 763 781 if plugin.__class__ == item.__class__: 764 782 msg = "Plugin %s already loaded" % plugin.sub_menu 765 logg ing.info(msg)783 logger.info(msg) 766 784 is_loaded = True 767 785 if not is_loaded: 768 786 self.plugins.append(plugin) 769 787 msg = "Plugin %s appended" % plugin.sub_menu 770 logg ing.info(msg)788 logger.info(msg) 771 789 772 790 def _get_local_plugins(self): … … 775 793 """ 776 794 plugins = [] 777 # import guiframe local plugins778 # check if the style contain guiframe.dataloader795 # import guiframe local plugins 796 # check if the style contain guiframe.dataloader 779 797 style1 = self.__gui_style & GUIFRAME.DATALOADER_ON 780 798 style2 = self.__gui_style & GUIFRAME.PLOTTING_ON 781 799 if style1 == GUIFRAME.DATALOADER_ON: 782 800 try: 783 from sas.sasgui.guiframe.local_perspectives.data_loader import data_loader 801 from sas.sasgui.guiframe.local_perspectives.data_loader \ 802 import data_loader 784 803 self._data_plugin = data_loader.Plugin() 785 804 plugins.append(self._data_plugin) … … 787 806 msg = "ViewerFrame._get_local_plugins:" 788 807 msg += "cannot import dataloader plugin.\n %s" % sys.exc_value 789 logg ing.error(msg)808 logger.error(msg) 790 809 if style2 == GUIFRAME.PLOTTING_ON: 791 810 try: 792 from sas.sasgui.guiframe.local_perspectives.plotting import plotting 811 from sas.sasgui.guiframe.local_perspectives.plotting \ 812 import plotting 793 813 self._plotting_plugin = plotting.Plugin() 794 814 plugins.append(self._plotting_plugin) … … 796 816 msg = "ViewerFrame._get_local_plugins:" 797 817 msg += "cannot import plotting plugin.\n %s" % sys.exc_value 798 logg ing.error(msg)818 logger.error(msg) 799 819 800 820 return plugins … … 816 836 else: 817 837 file_list = [] 818 # #the default panel is the panel is the last plugin added838 # the default panel is the panel is the last plugin added 819 839 for item in file_list: 820 840 toks = os.path.splitext(os.path.basename(item)) … … 823 843 if toks[1] == '.py' or toks[1] == '': 824 844 name = toks[0] 825 # check the validity of the module name parsed826 # before trying to import it845 # check the validity of the module name parsed 846 # before trying to import it 827 847 if name is None or name.strip() == '': 828 848 continue … … 841 861 plugins.append(module.Plugin()) 842 862 msg = "Found plug-in: %s" % module.PLUGIN_ID 843 logg ing.info(msg)863 logger.info(msg) 844 864 except: 845 865 msg = "Error accessing PluginPanel" … … 848 868 except: 849 869 msg = "ViewerFrame._find_plugins: %s" % sys.exc_value 850 logg ing.error(msg)870 logger.error(msg) 851 871 finally: 852 if not file ==None:872 if file is not None: 853 873 file.close() 854 874 except: 855 875 # Should raise and catch at a higher level and 856 876 # display error on status bar 857 logg ing.error(sys.exc_value)877 logger.error(sys.exc_value) 858 878 859 879 return plugins … … 865 885 """ 866 886 self._window_width, self._window_height = self.get_client_size() 867 # #Default size887 # Default size 868 888 if DATAPANEL_WIDTH < 0: 869 889 panel_width = int(self._window_width * 0.25) … … 871 891 panel_width = DATAPANEL_WIDTH 872 892 panel_height = int(self._window_height) 873 if self._data_panel is not None 893 if self._data_panel is not None and (p == self._data_panel): 874 894 return panel_width, panel_height 875 895 if hasattr(p, "CENTER_PANE") and p.CENTER_PANE: … … 903 923 if self.welcome_panel_class is not None: 904 924 welcome_panel = MDIFrame(self, None, 'None', (100, 200)) 905 self.defaultPanel = self.welcome_panel_class(welcome_panel, -1, style=wx.RAISED_BORDER) 925 self.defaultPanel = self.welcome_panel_class(welcome_panel, -1, 926 style=wx.RAISED_BORDER) 906 927 welcome_panel.set_panel(self.defaultPanel) 907 928 self.defaultPanel.set_frame(welcome_panel) … … 919 940 frame.SetPosition((0, mac_pos_y + size_t_bar)) 920 941 frame.Show(True) 921 # add data panel942 # add data panel 922 943 win = MDIFrame(self, None, 'None', (100, 200)) 923 944 data_panel = DataPanel(parent=win, id=-1) … … 927 948 d_panel_width, h = self._get_panels_size(self._data_panel) 928 949 win.SetSize((d_panel_width, h)) 929 is_visible = self.__gui_style & GUIFRAME.MANAGER_ON == GUIFRAME.MANAGER_ON 950 is_visible = self.__gui_style & \ 951 GUIFRAME.MANAGER_ON == GUIFRAME.MANAGER_ON 930 952 if IS_WIN: 931 953 win.SetPosition((0, 0)) … … 973 995 Update the data. 974 996 """ 975 prev_id, data_state = self._data_manager.update_data( \997 prev_id, data_state = self._data_manager.update_data( 976 998 prev_data=prev_data, new_data=new_data) 977 999 … … 1024 1046 self._current_perspective.delete_data(data) 1025 1047 1026 1027 1048 def get_context_menu(self, plotpanel=None): 1028 1049 """ … … 1048 1069 menu_list = [] 1049 1070 item = self._current_perspective 1050 if item !=None:1071 if item is not None: 1051 1072 menu_list.extend(item.get_context_menu(plotpanel=plotpanel)) 1052 1073 return menu_list … … 1064 1085 self.delete_panel(ID) 1065 1086 break 1066 self.cpanel_on_focus.SetFocus()1067 1087 if self.cpanel_on_focus is not None: 1088 self.cpanel_on_focus.SetFocus() 1068 1089 1069 1090 def popup_panel(self, p): … … 1078 1099 ID = wx.NewId() 1079 1100 self.panels[str(ID)] = p 1080 # #Check and set the size1101 # Check and set the size 1081 1102 if PLOPANEL_WIDTH < 0: 1082 1103 p_panel_width = int(self._window_width * 0.45) … … 1117 1138 # Register for showing/hiding the panel 1118 1139 wx.EVT_MENU(self, ID, self.on_view) 1119 if p not in self.plot_panels.values() and p.group_id !=None:1140 if p not in self.plot_panels.values() and p.group_id is not None: 1120 1141 self.plot_panels[ID] = p 1121 1142 if len(self.plot_panels) == 1: … … 1123 1144 self.set_panel_on_focus(None) 1124 1145 if self._data_panel is not None and \ 1125 self._plotting_plugin is not None:1146 self._plotting_plugin is not None: 1126 1147 ind = self._data_panel.cb_plotpanel.FindString('None') 1127 1148 if ind != wx.NOT_FOUND: … … 1166 1187 panel_name = 'No Panel on Focus' 1167 1188 c_panel = self.cpanel_on_focus 1168 if self._toolbar is 1189 if self._toolbar is None: 1169 1190 return 1170 1191 if c_panel is not None: … … 1211 1232 """ 1212 1233 if self._menubar is None or self._current_perspective is None \ 1213 or self._menubar.GetMenuCount() == 0:1234 or self._menubar.GetMenuCount() == 0: 1214 1235 return 1215 # replace or add a new menu for the current plugin1236 # replace or add a new menu for the current plugin 1216 1237 pos = self._menubar.FindMenu(str(self._applications_menu_name)) 1217 1238 if pos == -1 and self._applications_menu_pos > 0: … … 1233 1254 for (menu, name) in menu_list: 1234 1255 if self._applications_menu_pos == -1: 1235 # Find the Analysis position and insert just after it if possible1256 # Find the Analysis position and insert just after it 1236 1257 analysis_pos = self._menubar.FindMenu("Analysis") 1237 1258 if analysis_pos == -1: … … 1242 1263 self._applications_menu_pos = analysis_pos + 1 1243 1264 else: 1244 self._menubar.Insert(self._applications_menu_pos, menu, name) 1265 self._menubar.Insert(self._applications_menu_pos, 1266 menu, name) 1245 1267 self._applications_menu_name = name 1268 1269 def _on_marketplace_click(self, event): 1270 """ 1271 Click event for the help menu item linking to the Marketplace. 1272 """ 1273 import webbrowser 1274 webbrowser.open_new(config.marketplace_url) 1246 1275 1247 1276 def _add_help_menu(self): … … 1250 1279 tutorial PDF and documentation pages. 1251 1280 """ 1252 # Help menu1253 1281 self._help_menu = wx.Menu() 1254 style = self.__gui_style & GUIFRAME.WELCOME_PANEL_ON1255 1282 1256 1283 wx_id = wx.NewId() … … 1259 1286 1260 1287 if config._do_tutorial and (IS_WIN or sys.platform == 'darwin'): 1261 self._help_menu.AppendSeparator()1262 1288 wx_id = wx.NewId() 1263 1289 self._help_menu.Append(wx_id, '&Tutorial', 'Software tutorial') … … 1265 1291 1266 1292 if config._do_acknowledge: 1267 self._help_menu.AppendSeparator()1268 1293 wx_id = wx.NewId() 1269 self._help_menu.Append(wx_id, '&Acknowledge', 'Acknowledging SasView') 1294 self._help_menu.Append(wx_id, '&Acknowledge', 1295 'Acknowledging SasView') 1270 1296 wx.EVT_MENU(self, wx_id, self._onAcknowledge) 1271 1297 1272 1298 if config._do_aboutbox: 1273 self._help_menu.AppendSeparator() 1274 self._help_menu.Append(wx.ID_ABOUT, '&About', 'Software information') 1275 wx.EVT_MENU(self, wx.ID_ABOUT, self._onAbout) 1299 logger.info("Doing help menu") 1300 wx_id = wx.NewId() 1301 self._help_menu.Append(wx_id, '&About', 'Software information') 1302 wx.EVT_MENU(self, wx_id, self._onAbout) 1303 1304 if config.marketplace_url: 1305 wx_id = wx.NewId() 1306 self._help_menu.Append(wx_id, '&Model marketplace', '') 1307 wx.EVT_MENU(self, wx_id, self._on_marketplace_click) 1276 1308 1277 1309 # Checking for updates 1278 1310 wx_id = wx.NewId() 1279 1311 self._help_menu.Append(wx_id, '&Check for update', 1280 'Check for the latest version of %s' % config.__appname__) 1312 'Check for the latest version of %s' % 1313 config.__appname__) 1281 1314 wx.EVT_MENU(self, wx_id, self._check_update) 1282 1315 self._menubar.Append(self._help_menu, '&Help') … … 1299 1332 wx_id = wx.NewId() 1300 1333 self._data_panel_menu = self._view_menu.Append(wx_id, 1301 '&Show Data Explorer', '') 1334 '&Show Data Explorer', 1335 '') 1302 1336 wx.EVT_MENU(self, wx_id, self.show_data_panel) 1303 1337 if style == GUIFRAME.MANAGER_ON: … … 1310 1344 style1 = self.__gui_style & GUIFRAME.TOOLBAR_ON 1311 1345 if style1 == GUIFRAME.TOOLBAR_ON: 1312 self._toolbar_menu = self._view_menu.Append(wx_id, '&Hide Toolbar', '') 1346 self._toolbar_menu = self._view_menu.Append(wx_id, '&Hide Toolbar', 1347 '') 1313 1348 else: 1314 self._toolbar_menu = self._view_menu.Append(wx_id, '&Show Toolbar', '') 1349 self._toolbar_menu = self._view_menu.Append(wx_id, '&Show Toolbar', 1350 '') 1315 1351 wx.EVT_MENU(self, wx_id, self._on_toggle_toolbar) 1316 1352 1317 if custom_config !=None:1353 if custom_config is not None: 1318 1354 self._view_menu.AppendSeparator() 1319 1355 wx_id = wx.NewId() … … 1326 1362 wx_id = wx.NewId() 1327 1363 self._view_menu.AppendSeparator() 1328 self._view_menu.Append(wx_id, 'Category Manager', 'Edit model categories') 1364 self._view_menu.Append(wx_id, 'Category Manager', 1365 'Edit model categories') 1329 1366 wx.EVT_MENU(self, wx_id, self._on_category_manager) 1330 1367 … … 1339 1376 self.batch_frame.Show(True) 1340 1377 1341 def 1378 def on_category_panel(self, event): 1342 1379 """ 1343 1380 On cat panel … … 1358 1395 """ 1359 1396 from sas.sasgui.guiframe.startup_configuration \ 1360 import StartupConfiguration as ConfDialog1397 import StartupConfiguration as ConfDialog 1361 1398 1362 1399 dialog = ConfDialog(parent=self, gui=self.__gui_style) … … 1365 1402 dialog.write_custom_config() 1366 1403 # post event for info 1367 wx.PostEvent(self, StatusEvent(status="Wrote custom configuration", info='info')) 1404 wx.PostEvent(self, StatusEvent(status="Wrote custom configuration", 1405 info='info')) 1368 1406 dialog.Destroy() 1369 1407 … … 1384 1422 id = wx.NewId() 1385 1423 if plug.use_data(): 1386 self._applications_menu.InsertCheckItem(pos, id, plug.sub_menu, \ 1387 "Switch to analysis: %s" % plug.sub_menu) 1424 self._applications_menu.InsertCheckItem(pos, id, 1425 plug.sub_menu, 1426 "Switch to analysis: %s" % plug.sub_menu) 1388 1427 plug_data_count = True 1389 1428 pos += 1 1390 1429 else: 1391 1430 plug_no_data_count = True 1392 self._applications_menu.AppendCheckItem(id, plug.sub_menu, \ 1431 self._applications_menu.AppendCheckItem(id, 1432 plug.sub_menu, 1393 1433 "Switch to analysis: %s" % plug.sub_menu) 1394 1434 wx.EVT_MENU(self, id, plug.on_perspective) … … 1396 1436 if not plug_data_count or not plug_no_data_count: 1397 1437 self._applications_menu.RemoveItem(separator) 1398 # Windows introduces a "Window" menu item during the layout process1399 # somehow. We want it to be next to the last item with Help as1400 # last. However Analysis gets stuck after Window in normal ordering1401 # so force it to be next after the Tools menu item. Should we add1402 # another menu item will need to check if this is still where we1403 # want Analysis. This is NOT an issue on the Mac which does not1404 # have the extra Window menu item.1405 # March 2016 Code Camp -- PDB 1438 # Windows introduces a "Window" menu item during the layout process 1439 # somehow. We want it to be next to the last item with Help as 1440 # last. However Analysis gets stuck after Window in normal ordering 1441 # so force it to be next after the Tools menu item. Should we add 1442 # another menu item will need to check if this is still where we 1443 # want Analysis. This is NOT an issue on the Mac which does not 1444 # have the extra Window menu item. 1445 # March 2016 Code Camp -- PDB 1406 1446 Tools_pos = self._menubar.FindMenu("Tools") 1407 self._menubar.Insert(Tools_pos+1, self._applications_menu,1447 self._menubar.Insert(Tools_pos+1, self._applications_menu, 1408 1448 '&Analysis') 1409 1449 self._check_applications_menu() … … 1426 1466 wx_id = wx.NewId() 1427 1467 hint_load_file = "read all analysis states saved previously" 1428 self._save_appl_menu = self._file_menu.Append(wx_id, '&Open Project', hint_load_file) 1468 self._save_appl_menu = self._file_menu.Append(wx_id, 1469 '&Open Project', 1470 hint_load_file) 1429 1471 wx.EVT_MENU(self, wx_id, self._on_open_state_project) 1430 1472 … … 1435 1477 wx_id = wx.NewId() 1436 1478 self._save_appl_menu = self._file_menu.Append(wx_id, 1437 '&Open Analysis', hint_load_file) 1479 '&Open Analysis', 1480 hint_load_file) 1438 1481 wx.EVT_MENU(self, wx_id, self._on_open_state_application) 1439 1482 if OPEN_SAVE_MENU: … … 1445 1488 if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: 1446 1489 wx_id = wx.NewId() 1447 self._save_appl_menu = self._file_menu.Append(wx_id, \ 1448 '&Save Analysis', 'Save state of the current active analysis panel') 1490 txt = '&Save Analysis' 1491 txt2 = 'Save state of the current active analysis panel' 1492 self._save_appl_menu = self._file_menu.Append(wx_id, txt, txt2) 1449 1493 wx.EVT_MENU(self, wx_id, self._on_save_application) 1450 1494 if not sys.platform == 'darwin': … … 1488 1532 1489 1533 self._edit_menu_copyas = wx.Menu() 1490 #Sub menu for Copy As... 1491 self._edit_menu_copyas.Append(GUIFRAME_ID.COPYEX_ID, 'Copy current tab to Excel', 1534 # Sub menu for Copy As... 1535 self._edit_menu_copyas.Append(GUIFRAME_ID.COPYEX_ID, 1536 'Copy current tab to Excel', 1492 1537 'Copy parameter values in tabular format') 1493 1538 wx.EVT_MENU(self, GUIFRAME_ID.COPYEX_ID, self.on_copy_panel) 1494 1539 1495 self._edit_menu_copyas.Append(GUIFRAME_ID.COPYLAT_ID, 'Copy current tab to LaTeX', 1540 self._edit_menu_copyas.Append(GUIFRAME_ID.COPYLAT_ID, 1541 'Copy current tab to LaTeX', 1496 1542 'Copy parameter values in tabular format') 1497 1543 wx.EVT_MENU(self, GUIFRAME_ID.COPYLAT_ID, self.on_copy_panel) 1498 1499 1544 1500 1545 self._edit_menu.AppendMenu(GUIFRAME_ID.COPYAS_ID, 'Copy Params as...', … … 1519 1564 Return the gui style 1520 1565 """ 1521 return 1566 return self.__gui_style 1522 1567 1523 1568 def _add_menu_data(self): … … 1574 1619 return 1575 1620 frame = self.panels['default'].get_frame() 1576 if frame ==None:1621 if frame is None: 1577 1622 return 1578 1623 # Show default panel … … 1607 1652 self.schedule_full_draw_list.remove(panel) 1608 1653 1609 # delete uid number not str(uid)1654 # delete uid number not str(uid) 1610 1655 if ID in self.plot_panels.keys(): 1611 1656 del self.plot_panels[ID] … … 1613 1658 del self.panels[ID] 1614 1659 else: 1615 logg ing.error("delete_panel: No such plot id as %s" % ID)1660 logger.error("delete_panel: No such plot id as %s" % ID) 1616 1661 1617 1662 def create_gui_data(self, data, path=None): … … 1630 1675 log_msg += "load: %s\n" % str(basename) 1631 1676 log_msg += "Try Data opening...." 1632 logg ing.error(log_msg)1677 logger.error(log_msg) 1633 1678 return 1634 1679 1635 # reading a state file1680 # reading a state file 1636 1681 for plug in self.plugins: 1637 1682 reader, ext = plug.get_extensions() 1638 1683 if reader is not None: 1639 # read the state of the single plugin1684 # read the state of the single plugin 1640 1685 if extension == ext: 1641 1686 reader.read(path) … … 1648 1693 msg += "\n(%s)" % sys.exc_value 1649 1694 wx.PostEvent(self, StatusEvent(status=msg, 1650 info="error", type="stop")) 1695 info="error", 1696 type="stop")) 1651 1697 return 1652 1698 … … 1687 1733 basename = os.path.basename(path) 1688 1734 if APPLICATION_STATE_EXTENSION is not None \ 1689 and basename.endswith(APPLICATION_STATE_EXTENSION):1735 and basename.endswith(APPLICATION_STATE_EXTENSION): 1690 1736 if is_project: 1691 1737 for ID in self.plot_panels.keys(): … … 1709 1755 log_msg += "load: %s\n" % str(path) 1710 1756 log_msg += "Try File opening ...." 1711 logg ing.error(log_msg)1757 logger.error(log_msg) 1712 1758 return 1713 1759 log_msg = '' … … 1715 1761 error_message = "" 1716 1762 try: 1717 logg ing.info("Loading Data...:\n" + str(path) + "\n")1763 logger.info("Loading Data...:\n" + str(path) + "\n") 1718 1764 temp = self.loader.load(path) 1719 1765 if temp.__class__.__name__ == "list": … … 1730 1776 error_message += " Data from cmd:\n %s\n" % str(path) 1731 1777 error_message += str(sys.exc_value) + "\n" 1732 logg ing.error(error_message)1778 logger.error(error_message) 1733 1779 1734 1780 def load_folder(self, path): … … 1751 1797 error_message += " Data folder from cmd:\n %s\n" % str(path) 1752 1798 error_message += str(sys.exc_value) + "\n" 1753 logg ing.error(error_message)1799 logger.error(error_message) 1754 1800 1755 1801 def _on_open_state_application(self, event): … … 1757 1803 """ 1758 1804 path = None 1759 if self._default_save_location ==None:1805 if self._default_save_location is None: 1760 1806 self._default_save_location = os.getcwd() 1761 1807 wx.PostEvent(self, StatusEvent(status="Loading Analysis file...")) … … 1791 1837 break 1792 1838 # Found the extension 1793 if ind !=None:1839 if ind is not None: 1794 1840 plug_wlist.remove(ind) 1795 1841 plug_wlist.insert(0, ind) … … 1806 1852 def _on_open_state_project(self, event): 1807 1853 """ 1854 Load in a .svs project file after removing all data from SasView 1808 1855 """ 1809 1856 path = None 1810 if self._default_save_location ==None:1857 if self._default_save_location is None: 1811 1858 self._default_save_location = os.getcwd() 1812 wx.PostEvent(self, StatusEvent(status="Loading Project file...")) 1813 dlg = wx.FileDialog(self, 1814 "Choose a file", 1815 self._default_save_location, "", 1816 APPLICATION_WLIST) 1817 if dlg.ShowModal() == wx.ID_OK: 1818 path = dlg.GetPath() 1859 msg = "This operation will set remove all data, plots and analyses from" 1860 msg += " SasView before loading the project. Do you wish to continue?" 1861 msg_box = wx.MessageDialog(None, msg, 'Warning', wx.OK | wx.CANCEL) 1862 if msg_box.ShowModal() == wx.ID_OK: 1863 self._data_panel.selection_cbox.SetValue('Select all Data') 1864 self._data_panel._on_selection_type(None) 1865 for _, theory_dict in self._data_panel.list_cb_theory.iteritems(): 1866 for key, value in theory_dict.iteritems(): 1867 item, _, _ = value 1868 item.Check(True) 1869 1870 wx.PostEvent(self, StatusEvent(status="Loading Project file...")) 1871 dlg = wx.FileDialog(self, "Choose a file", 1872 self._default_save_location, "", 1873 APPLICATION_WLIST) 1874 if dlg.ShowModal() == wx.ID_OK: 1875 path = dlg.GetPath() 1819 1876 if path is not None: 1820 1877 self._default_save_location = os.path.dirname(path) 1821 dlg.Destroy() 1822 1823 self.load_state(path=path, is_project=True) 1878 dlg.Destroy() 1879 # Reset to a base state 1880 self._on_reset_state() 1881 self._data_panel.on_remove(None, False) 1882 # Load the project file 1883 self.load_state(path=path, is_project=True) 1884 1885 def _on_reset_state(self): 1886 """ 1887 Resets SasView to its freshly opened state. 1888 :return: None 1889 """ 1890 # Reset all plugins to their base state 1891 self._data_panel.set_panel_on_focus() 1892 # Remove all loaded data 1893 for plugin in self.plugins: 1894 plugin.clear_panel() 1895 # Reset plot number to 0 1896 self.graph_num = 0 1824 1897 1825 1898 def _on_save_application(self, event): … … 1834 1907 wx.PostEvent(self, 1835 1908 StatusEvent(status="Completed saving.")) 1836 except :1909 except Exception: 1837 1910 msg = "Error occurred while saving: " 1911 msg += traceback.format_exc() 1838 1912 msg += "To save, the application panel should have a data set.." 1839 1913 wx.PostEvent(self, StatusEvent(status=msg)) … … 1843 1917 save the state of the SasView as *.svs 1844 1918 """ 1845 if self._current_perspective is 1919 if self._current_perspective is None: 1846 1920 return 1847 1921 wx.PostEvent(self, StatusEvent(status="Saving Project file...")) … … 1871 1945 extens = APPLICATION_STATE_EXTENSION 1872 1946 fName = os.path.splitext(path)[0] + extens 1873 if doc !=None:1947 if doc is not None: 1874 1948 fd = open(fName, 'w') 1875 1949 fd.write(doc.toprettyxml()) … … 1882 1956 msg += "and model selected. " 1883 1957 msg += "No project was saved to %s" % (str(path)) 1884 logg ing.warning(msg)1958 logger.warning(msg) 1885 1959 wx.PostEvent(self, StatusEvent(status=msg, info="error")) 1886 except :1960 except Exception: 1887 1961 msg = "Error occurred while saving: " 1962 msg += traceback.format_exc() 1888 1963 msg += "To save, at least one application panel " 1889 1964 msg += "should have a data set.." … … 1903 1978 if data is not None: 1904 1979 new_doc = reader.write_toXML(data, state) 1905 if doc !=None and hasattr(doc, "firstChild"):1980 if doc is not None and hasattr(doc, "firstChild"): 1906 1981 child = new_doc.firstChild.firstChild 1907 1982 doc.firstChild.appendChild(child) … … 1914 1989 if data is not None: 1915 1990 new_doc = reader.write_toXML(data, state) 1916 if doc !=None and hasattr(doc, "firstChild"):1991 if doc is not None and hasattr(doc, "firstChild"): 1917 1992 child = new_doc.firstChild.firstChild 1918 1993 doc.firstChild.appendChild(child) … … 1946 2021 Quit the application 1947 2022 """ 1948 logging.info(" --- SasView session was closed --- \n") 2023 #IF SAS_OPENCL is set, settings are stored in the custom config file 2024 self._write_opencl_config_file() 2025 logger.info(" --- SasView session was closed --- \n") 1949 2026 wx.Exit() 1950 2027 sys.exit() 2028 2029 def _write_opencl_config_file(self): 2030 """ 2031 Writes OpenCL settings to custom config file, so they can be remmbered 2032 from session to session 2033 """ 2034 if custom_config is not None: 2035 sas_opencl = os.environ.get("SAS_OPENCL") 2036 new_config_lines = [] 2037 config_file = open(custom_config.__file__) 2038 config_lines = config_file.readlines() 2039 for line in config_lines: 2040 if "SAS_OPENCL" in line: 2041 if sas_opencl: 2042 new_config_lines.append("SAS_OPENCL = \"" + sas_opencl 2043 + "\"\n") 2044 else: 2045 new_config_lines.append("SAS_OPENCL = \"None\"\n") 2046 else: 2047 new_config_lines.append(line) 2048 config_file.close() 2049 2050 #If custom_config is None, settings will not be remmbered 2051 new_config_file = open(custom_config.__file__,"w") 2052 new_config_file.writelines(new_config_lines) 2053 new_config_file.close() 2054 else: 2055 logger.info("Failed to save OPENCL settings in custom config file") 2056 1951 2057 1952 2058 def _check_update(self, event=None): … … 1962 2068 if response is not None: 1963 2069 try: 1964 #1965 2070 content = response.read().strip() 1966 logging.info("Connected to www.sasview.org. Latest version: %s" 1967 % (content)) 2071 logger.info("Connected to www.sasview.org. Latest version: %s", content) 1968 2072 version_info = json.loads(content) 1969 2073 except: 1970 logging.info("Failed to connect to www.sasview.org") 1971 self._process_version(version_info, standalone=event == None) 1972 1973 1974 1975 # import urllib2 1976 # try: 1977 # req = urllib2.Request(config.__update_URL__) 1978 # res = urllib2.urlopen(req) 1979 # content = res.read().strip() 1980 # logging.info("Connected to www.sasview.org. Latest version: %s" 1981 # % (content)) 1982 # version_info = json.loads(content) 1983 # except: 1984 # logging.info("Failed to connect to www.sasview.org") 1985 # version_info = {"version": "0.0.0"} 1986 # self._process_version(version_info, standalone=event == None) 2074 logger.info("Failed to connect to www.sasview.org") 2075 self._process_version(version_info, standalone=event is None) 2076 1987 2077 1988 2078 def _process_version(self, version_info, standalone=True): … … 2023 2113 msg = "guiframe: could not get latest application" 2024 2114 msg += " version number\n %s" % sys.exc_value 2025 logg ing.error(msg)2115 logger.error(msg) 2026 2116 if not standalone: 2027 2117 msg = "Could not connect to the application server." … … 2070 2160 dialog.Show(True) 2071 2161 except: 2072 logg ing.error("Error in _onTutorial: %s" % sys.exc_value)2162 logger.error("Error in _onTutorial: %s" % sys.exc_value) 2073 2163 try: 2074 2164 # Try an alternate method 2075 logging.error("Could not open the tutorial pdf, trying xhtml2pdf") 2165 logger.error( 2166 "Could not open the tutorial pdf, trying xhtml2pdf") 2076 2167 from xhtml2pdf import pisa 2077 2168 pisa.startViewer(path) 2078 2169 except: 2079 logging.error("Could not open the tutorial pdf with xhtml2pdf") 2170 logger.error( 2171 "Could not open the tutorial pdf with xhtml2pdf") 2080 2172 msg = "This feature requires 'PDF Viewer'\n" 2081 2173 wx.MessageBox(msg, 'Error') … … 2087 2179 try: 2088 2180 # Try an alternate method 2089 logging.error("Could not open the tutorial pdf, trying xhtml2pdf") 2181 logger.error( 2182 "Could not open the tutorial pdf, trying xhtml2pdf") 2090 2183 from xhtml2pdf import pisa 2091 2184 pisa.startViewer(path) 2092 2185 except: 2093 logging.error("Could not open the tutorial pdf with xhtml2pdf") 2094 msg = "This feature requires the 'Preview' application\n" 2186 logger.error( 2187 "Could not open the tutorial pdf with xhtml2pdf") 2188 msg = "This feature requires the Preview application\n" 2095 2189 wx.MessageBox(msg, 'Error') 2096 2190 … … 2107 2201 from documentation_window import DocumentationWindow 2108 2202 _TreeLocation = "user/user.html" 2109 DocumentationWindow(self, -1, _TreeLocation, "", "SasView Documentation") 2203 DocumentationWindow(self, -1, _TreeLocation, "", 2204 "SasView Documentation") 2110 2205 2111 2206 def set_manager(self, manager): … … 2141 2236 if self.panels[item].ALWAYS_ON: 2142 2237 continue 2143 if self.panels[item] ==None:2238 if self.panels[item] is None: 2144 2239 continue 2145 2240 if self.panels[item].window_name in panels: … … 2150 2245 # always show the data panel if enable 2151 2246 style = self.__gui_style & GUIFRAME.MANAGER_ON 2152 if (style == GUIFRAME.MANAGER_ON) and self.panels[item] == self._data_panel: 2247 if (style == GUIFRAME.MANAGER_ON) \ 2248 and self.panels[item] == self._data_panel: 2153 2249 if 'data_panel' in self.panels.keys(): 2154 2250 frame = self.panels['data_panel'].get_frame() 2155 if frame ==None:2251 if frame is None: 2156 2252 continue 2157 2253 flag = frame.IsShown() … … 2159 2255 else: 2160 2256 frame = self.panels[item].get_frame() 2161 if frame ==None:2257 if frame is None: 2162 2258 continue 2163 2259 … … 2169 2265 show the data panel 2170 2266 """ 2171 if self._data_panel_menu ==None:2267 if self._data_panel_menu is None: 2172 2268 return 2173 2269 label = self._data_panel_menu.GetText() … … 2199 2295 :param data_list: dictionary of data's ID and value Data 2200 2296 """ 2201 # Store data into manager2297 # Store data into manager 2202 2298 self.add_data_helper(data_list) 2203 2299 # set data in the data panel … … 2205 2301 data_state = self._data_manager.get_data_state(data_list.keys()) 2206 2302 self._data_panel.load_data_list(data_state) 2207 # if the data panel is shown wait for the user to press a button2208 # to send data to the current perspective. if the panel is not2209 # show automatically send the data to the current perspective2303 # if the data panel is shown wait for the user to press a button 2304 # to send data to the current perspective. if the panel is not 2305 # show automatically send the data to the current perspective 2210 2306 style = self.__gui_style & GUIFRAME.MANAGER_ON 2211 2307 if style == GUIFRAME.MANAGER_ON: 2212 # wait for button press from the data panel to set_data2308 # wait for button press from the data panel to set_data 2213 2309 if self._data_panel is not None: 2214 2310 self._data_panel.frame.Show(True) 2215 2311 else: 2216 # automatically send that to the current perspective2312 # automatically send that to the current perspective 2217 2313 self.set_data(data_id=data_list.keys()) 2218 2314 … … 2227 2323 else: 2228 2324 msg = "Guiframe does not have a current perspective" 2229 logg ing.info(msg)2325 logger.info(msg) 2230 2326 2231 2327 def set_theory(self, state_id, theory_id=None): … … 2238 2334 except: 2239 2335 msg = "Guiframe set_theory: \n" + str(sys.exc_value) 2240 logg ing.info(msg)2336 logger.info(msg) 2241 2337 wx.PostEvent(self, StatusEvent(status=msg, info="error")) 2242 2338 else: 2243 2339 msg = "Guiframe does not have a current perspective" 2244 logg ing.info(msg)2340 logger.info(msg) 2245 2341 2246 2342 def plot_data(self, state_id, data_id=None, … … 2275 2371 info='warning')) 2276 2372 else: 2277 # if not append then new plot2373 # if not append then new plot 2278 2374 from sas.sasgui.guiframe.dataFitting import Data2D 2279 2375 if issubclass(Data2D, new_plot.__class__): 2280 # for 2 D always plot in a separated new plot2376 # for 2 D always plot in a separated new plot 2281 2377 new_plot.group_id = wx.NewId() 2282 2378 else: … … 2309 2405 group_id=group_id, 2310 2406 action='remove')) 2311 #remove res plot: Todo: improve2312 2407 wx.CallAfter(self._remove_res_plot, new_plot.id) 2313 2408 self._data_manager.delete_data(data_id=data_id, … … 2325 2420 action='remove')) 2326 2421 except: 2327 logg ing.error(sys.exc_value)2422 logger.error(sys.exc_value) 2328 2423 2329 2424 def save_data1d(self, data, fname): … … 2351 2446 mypath = os.path.basename(path) 2352 2447 2353 # Instantiate a loader2448 # Instantiate a loader 2354 2449 loader = Loader() 2355 2450 ext_format = ".txt" … … 2371 2466 dlg.Destroy() 2372 2467 2373 2374 2468 def _onsaveTXT(self, data, path): 2375 2469 """ … … 2378 2472 .. todo:: Refactor and remove this method. See 'TODO' in _onSave. 2379 2473 """ 2380 if not path ==None:2474 if path is not None: 2381 2475 out = open(path, 'w') 2382 2476 has_errors = True 2383 if data.dy ==None or data.dy == []:2477 if data.dy is None or data.dy == []: 2384 2478 has_errors = False 2385 2479 # Sanity check … … 2391 2485 has_errors = False 2392 2486 if has_errors: 2393 if data.dx !=None and data.dx != []:2487 if data.dx is not None and data.dx != []: 2394 2488 out.write("<X> <Y> <dY> <dX>\n") 2395 2489 else: … … 2400 2494 for i in range(len(data.x)): 2401 2495 if has_errors: 2402 if data.dx !=None and data.dx != []:2403 if data.dx[i] !=None:2496 if data.dx is not None and data.dx != []: 2497 if data.dx[i] is not None: 2404 2498 out.write("%g %g %g %g\n" % (data.x[i], 2405 2499 data.y[i], … … 2432 2526 info="error")) 2433 2527 raise ValueError, msg 2434 # #text = str(data)2528 # text = str(data) 2435 2529 text = data.__str__() 2436 2530 text += 'Data Min Max:\n' 2437 2531 text += 'X_min = %s: X_max = %s\n' % (xmin, max(data.x)) 2438 2532 text += 'Y_min = %s: Y_max = %s\n' % (ymin, max(data.y)) 2439 if data.dy !=None:2533 if data.dy is not None: 2440 2534 text += 'dY_min = %s: dY_max = %s\n' % (min(data.dy), max(data.dy)) 2441 2535 text += '\nData Points:\n' 2442 2536 x_st = "X" 2443 2537 for index in range(len(data.x)): 2444 if data.dy !=None and len(data.dy) > index:2538 if data.dy is not None and len(data.dy) > index: 2445 2539 dy_val = data.dy[index] 2446 2540 else: 2447 2541 dy_val = 0.0 2448 if data.dx !=None and len(data.dx) > index:2542 if data.dx is not None and len(data.dx) > index: 2449 2543 dx_val = data.dx[index] 2450 2544 else: 2451 2545 dx_val = 0.0 2452 if data.dxl !=None and len(data.dxl) > index:2546 if data.dxl is not None and len(data.dxl) > index: 2453 2547 if index == 0: 2454 2548 x_st = "Xl" 2455 2549 dx_val = data.dxl[index] 2456 elif data.dxw !=None and len(data.dxw) > index:2550 elif data.dxw is not None and len(data.dxw) > index: 2457 2551 if index == 0: 2458 2552 x_st = "Xw" … … 2494 2588 mypath = os.path.basename(path) 2495 2589 2496 # Instantiate a loader2590 # Instantiate a loader 2497 2591 loader = Loader() 2498 2592 … … 2531 2625 y_val = data.qy_data[index] 2532 2626 i_val = data.data[index] 2533 if data.err_data !=None:2627 if data.err_data is not None: 2534 2628 di_val = data.err_data[index] 2535 if data.dqx_data !=None:2629 if data.dqx_data is not None: 2536 2630 dx_val = data.dqx_data[index] 2537 if data.dqy_data !=None:2631 if data.dqy_data is not None: 2538 2632 dy_val = data.dqy_data[index] 2539 2633 … … 2570 2664 for name in self._current_perspective.get_perspective(): 2571 2665 frame = panel.get_frame() 2572 if frame !=None:2666 if frame is not None: 2573 2667 if name == panel.window_name: 2574 2668 panel.on_set_focus(event=None) … … 2580 2674 self._data_panel.set_active_perspective(name) 2581 2675 self._check_applications_menu() 2582 # Set the SasView title2676 # Set the SasView title 2583 2677 self._set_title_name(name) 2584 2678 … … 2612 2706 """ 2613 2707 2614 if self.panel_on_focus not in self._plotting_plugin.plot_panels.values(): 2708 if self.panel_on_focus \ 2709 not in self._plotting_plugin.plot_panels.values(): 2615 2710 return 2711 check = "Theory1D" 2616 2712 is_theory = len(self.panel_on_focus.plots) <= 1 and \ 2617 self.panel_on_focus.plots.values()[0].__class__.__name__ == "Theory1D"2713 self.panel_on_focus.plots.values()[0].__class__.__name__ == check 2618 2714 2619 2715 is_data2d = hasattr(new_plot, 'data') … … 2623 2719 has_meta_data = hasattr(new_plot, 'meta_data') 2624 2720 2625 # disable_add_data if the data is being recovered from a saved state file.2721 # disable_add_data if the data is being recovered from a saved state 2626 2722 is_state_data = False 2627 2723 if has_meta_data: 2628 2724 if 'invstate' in new_plot.meta_data: 2629 2725 is_state_data = True 2630 if 2726 if 'prstate' in new_plot.meta_data: 2631 2727 is_state_data = True 2632 if 2728 if 'fitstate' in new_plot.meta_data: 2633 2729 is_state_data = True 2634 2730 2635 return is_data1d and not is_data2d and not is_theory and not is_state_data 2731 return is_data1d and not is_data2d and not is_theory \ 2732 and not is_state_data 2636 2733 2637 2734 def check_multimode(self, perspective=None): … … 2639 2736 Check the perspective have batch mode capablitity 2640 2737 """ 2641 if perspective == None or self._data_panel ==None:2738 if perspective is None or self._data_panel is None: 2642 2739 return 2643 2740 flag = perspective.get_batch_capable() … … 2666 2763 self._edit_menu.Enable(GUIFRAME_ID.PASTE_ID, flag) 2667 2764 2668 # Copy menu2765 # Copy menu 2669 2766 flag = self.cpanel_on_focus.get_copy_flag() 2670 2767 self._edit_menu_copyas.Enable(GUIFRAME_ID.COPYEX_ID, flag) … … 2797 2894 if data_panel.cb_plotpanel is not None: 2798 2895 # Check if any panel has the same caption 2799 has_newstring = data_panel.cb_plotpanel.FindString \2800 (str(new_caption))2896 has_newstring = data_panel.cb_plotpanel.FindString( 2897 str(new_caption)) 2801 2898 caption = new_caption 2802 2899 if has_newstring != wx.NOT_FOUND: … … 2915 3012 drag 2916 3013 """ 2917 # Not implemeted3014 # Not implemeted 2918 3015 2919 3016 def enable_reset(self): … … 2928 3025 """ 2929 3026 size_y = 0 2930 if self.GetToolBar() !=None and self.GetToolBar().IsShown():3027 if self.GetToolBar() is not None and self.GetToolBar().IsShown(): 2931 3028 if not IS_LINUX: 2932 3029 _, size_y = self.GetToolBar().GetSizeTuple() … … 2943 3040 # append this panel in the schedule list if not in yet 2944 3041 if func == 'append': 2945 if not panelin self.schedule_full_draw_list:3042 if panel not in self.schedule_full_draw_list: 2946 3043 self.schedule_full_draw_list.append(panel) 2947 3044 # remove this panel from schedule list … … 2963 3060 2964 3061 count = len(self.schedule_full_draw_list) 2965 # if not self.schedule:3062 # if not self.schedule: 2966 3063 if count < 1: 2967 3064 self.set_schedule(False) … … 2978 3075 if ind == count: 2979 3076 return 2980 #Simple redraw only for a panel shown 3077 # Simple redraw only for a panel shown 3078 2981 3079 def f_draw(panel): 2982 3080 """ … … 2991 3089 # draw if possible 2992 3090 panel.set_resizing(False) 2993 # panel.Show(True)3091 # panel.Show(True) 2994 3092 panel.draw_plot() 2995 3093 # Check if the panel is not shown … … 3026 3124 Set focus on a plot panel 3027 3125 """ 3028 if panel ==None:3126 if panel is None: 3029 3127 return 3030 # self.set_plot_unfocus()3128 # self.set_plot_unfocus() 3031 3129 panel.on_set_focus(None) 3032 3130 # set focusing panel … … 3061 3159 try: 3062 3160 # check if it is time to redraw 3063 if self.GetCapture() ==None:3161 if self.GetCapture() is None: 3064 3162 # Draw plot, changes resizing too 3065 3163 self.full_draw() … … 3069 3167 # restart idle 3070 3168 self._redraw_idle(*args, **kwargs) 3071 3072 3169 3073 3170 def _redraw_idle(self, *args, **kwargs): … … 3084 3181 the GUI manager 3085 3182 """ 3086 # #Internal nickname for the window, used by the AUI manager3183 # Internal nickname for the window, used by the AUI manager 3087 3184 window_name = "default" 3088 # #Name to appear on the window title bar3185 # Name to appear on the window title bar 3089 3186 window_caption = "Welcome panel" 3090 # #Flag to tell the AUI manager to put this panel in the center pane3187 # Flag to tell the AUI manager to put this panel in the center pane 3091 3188 CENTER_PANE = True 3189 3092 3190 def __init__(self, parent, *args, **kwds): 3093 3191 wx.Panel.__init__(self, parent, *args, **kwds) 3094 3192 PanelBase.__init__(self, parent) 3095 3096 3193 3097 3194 … … 3121 3218 msg = "%s Could not load " % str(APPLICATION_NAME) 3122 3219 msg += "input file from command line.\n" 3123 logg ing.error(msg)3220 logger.error(msg) 3124 3221 # Display a splash screen on top of the frame. 3125 3222 try: 3126 3223 if os.path.isfile(SPLASH_SCREEN_PATH): 3127 self.s_screen = self.display_splash_screen(parent=self.frame, 3128 path=SPLASH_SCREEN_PATH) 3224 self.s_screen = \ 3225 self.display_splash_screen(parent=self.frame, 3226 path=SPLASH_SCREEN_PATH) 3129 3227 else: 3130 3228 self.frame.Show() … … 3134 3232 msg = "Cannot display splash screen\n" 3135 3233 msg += str(sys.exc_value) 3136 logg ing.error(msg)3234 logger.error(msg) 3137 3235 self.frame.Show() 3138 3236 … … 3189 3287 os.remove(file_path) 3190 3288 except: 3191 logg ing.error("gui_manager.clean_plugin_models:\n %s" \3289 logger.error("gui_manager.clean_plugin_models:\n %s" 3192 3290 % sys.exc_value) 3193 3291 … … 3203 3301 Build the GUI 3204 3302 """ 3205 # try to load file at the start3303 # try to load file at the start 3206 3304 self.open_file() 3207 3305 self.frame.build_gui() … … 3279 3377 # Return the suggested position and size for the application frame. 3280 3378 return (posX, posY), (customWidth, customHeight), is_maximized 3281 3282 3379 3283 3380 def display_splash_screen(self, parent, … … 3316 3413 return s_screen 3317 3414 3318 3319 3415 def on_close_splash_screen(self, event): 3320 3416 """ … … 3336 3432 """ 3337 3433 # Initialize the Frame object 3338 CHILD_FRAME.__init__(self, parent=parent, id=wx.ID_ANY, title=title, size=size) 3434 CHILD_FRAME.__init__(self, parent=parent, id=wx.ID_ANY, 3435 title=title, size=size) 3339 3436 self.parent = parent 3340 3437 self.name = "Untitled" 3341 3438 self.batch_on = self.parent.batch_on 3342 3439 self.panel = panel 3343 if panel !=None:3440 if panel is not None: 3344 3441 self.set_panel(panel) 3345 3442 self.Show(False)
Note: See TracChangeset
for help on using the changeset viewer.