Changeset c8e1996 in sasview for src/sas/sasgui/guiframe/gui_manager.py
- Timestamp:
- Oct 20, 2016 3:54:06 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, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 880e845, cf1910f
- Parents:
- 8b645cc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/gui_manager.py
ra4c2445 rc8e1996 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 httplib … … 49 48 from matplotlib import _pylab_helpers 50 49 50 warnings.simplefilter("ignore") 51 51 52 52 53 def get_app_dir(): … … 82 83 return app_path 83 84 85 84 86 def get_user_directory(): 85 87 """ … … 90 92 os.makedirs(userdir) 91 93 return userdir 94 92 95 93 96 def _find_local_config(file, path): … … 113 116 114 117 # GUI always starts from the App folder 115 # os.chdir(PATH_APP)118 # os.chdir(PATH_APP) 116 119 # Read in the local config, which can either be with the main 117 120 # application or in the installation directory … … 128 131 logging.info("found local_config in %s" % PATH_APP) 129 132 130 from sas.sasgui.guiframe.customdir 133 from sas.sasgui.guiframe.customdir import SetupCustom 131 134 c_conf_dir = SetupCustom().setup_dir(PATH_APP) 132 135 custom_config = _find_local_config('custom_config', c_conf_dir) … … 141 144 logging.info("using custom_config from %s" % c_conf_dir) 142 145 143 # read some constants from config146 # read some constants from config 144 147 APPLICATION_STATE_EXTENSION = config.APPLICATION_STATE_EXTENSION 145 148 APPLICATION_NAME = config.__appname__ … … 169 172 # custom open_path 170 173 open_folder = custom_config.DEFAULT_OPEN_FOLDER 171 if open_folder !=None and os.path.isdir(open_folder):174 if open_folder is not None and os.path.isdir(open_folder): 172 175 DEFAULT_OPEN_FOLDER = os.path.abspath(open_folder) 173 176 else: … … 222 225 CHILD_FRAME = wx.Frame 223 226 227 224 228 class ViewerFrame(PARENT_FRAME): 225 229 """ … … 235 239 Initialize the Frame object 236 240 """ 237 PARENT_FRAME.__init__(self, parent=parent, title=title, pos=pos, size=size) 241 PARENT_FRAME.__init__(self, parent=parent, title=title, 242 pos=pos, size=size) 238 243 # title 239 244 self.title = title … … 256 261 self.path = PATH_APP 257 262 self.application_name = APPLICATION_NAME 258 # #Application manager263 # Application manager 259 264 self._input_file = None 260 265 self.app_manager = None 261 266 self._mgr = None 262 # add current perpsective267 # add current perpsective 263 268 self._current_perspective = None 264 269 self._plotting_plugin = None 265 270 self._data_plugin = None 266 # Menu bar and item271 # Menu bar and item 267 272 self._menubar = None 268 273 self._file_menu = None … … 278 283 self._toolbar_menu = None 279 284 self._save_appl_menu = None 280 # tool bar285 # tool bar 281 286 self._toolbar = None 282 287 # Status bar … … 286 291 # plot duck cleanup option 287 292 self.cleanup_plots = CLEANUP_PLOT 288 # #Find plug-ins293 # Find plug-ins 289 294 # Modify this so that we can specify the directory to look into 290 295 self.plugins = [] 291 # add local plugin296 # add local plugin 292 297 self.plugins += self._get_local_plugins() 293 298 self.plugins += self._find_plugins() 294 # #List of panels299 # List of panels 295 300 self.panels = {} 296 301 # List of plot panels … … 304 309 self.defaultPanel = None 305 310 self.welcome_panel_class = None 306 # panel on focus311 # panel on focus 307 312 self.panel_on_focus = None 308 # control_panel on focus313 # control_panel on focus 309 314 self.cpanel_on_focus = None 310 315 311 316 self.loader = Loader() 312 # data manager317 # data manager 313 318 self.batch_on = False 314 319 from sas.sasgui.guiframe.data_manager import DataManager 315 320 self._data_manager = DataManager() 316 self._data_panel = None #DataPanel(parent=self)321 self._data_panel = None # DataPanel(parent=self) 317 322 if self.panel_on_focus is not None: 318 self._data_panel.set_panel_on_focus(self.panel_on_focus.window_caption) 323 self._data_panel.set_panel_on_focus( 324 self.panel_on_focus.window_caption) 319 325 # list of plot panels in schedule to full redraw 320 326 self.schedule = False 321 # self.callback = True327 # self.callback = True 322 328 self._idle_count = 0 323 329 self.schedule_full_draw_list = [] … … 333 339 # Register to status events 334 340 self.Bind(EVT_STATUS, self._on_status_event) 335 # Register add extra data on the same panel event on load341 # Register add extra data on the same panel event on load 336 342 self.Bind(EVT_PANEL_ON_FOCUS, self.set_panel_on_focus) 337 343 self.Bind(EVT_APPEND_BOOKMARK, self.append_bookmark) … … 373 379 # Adjust toolbar height 374 380 toolbar = self.GetToolBar() 375 if toolbar !=None:381 if toolbar is not None: 376 382 _, tb_h = toolbar.GetSizeTuple() 377 383 height -= tb_h … … 386 392 fitpanel = item.fit_panel 387 393 388 if fitpanel !=None:394 if fitpanel is not None: 389 395 for i in range(0, fitpanel.GetPageCount()): 390 396 fitpanel.GetPage(i)._populate_listbox() … … 413 419 """ 414 420 Display value of data into the application grid 415 :param data: dictionary of string and list of items 421 :param data_inputs: dictionary of string and list of items 422 :param details: descriptive string 423 :param file_name: file name 424 :param data_outputs: Data outputs 416 425 """ 417 426 self.batch_frame.set_data(data_inputs=data_inputs, … … 427 436 """ 428 437 path = None 429 if self._default_save_location ==None:438 if self._default_save_location is None: 430 439 self._default_save_location = os.getcwd() 431 440 wildcard = "(*.csv; *.txt)|*.csv; *.txt" … … 469 478 line.strip() 470 479 count = 0 471 if separator ==None:480 if separator is None: 472 481 line.replace('\t', ' ') 473 # found the first line containing the label482 # found the first line containing the label 474 483 col_name_toks = line.split() 475 484 for item in col_name_toks: … … 480 489 elif line.find(separator) != -1: 481 490 if line.count(separator) >= 2: 482 # found the first line containing the label491 # found the first line containing the label 483 492 col_name_toks = line.split(separator) 484 493 for item in col_name_toks: … … 534 543 separator = "," 535 544 fd.write(str(details)) 536 for col_name 545 for col_name in data.keys(): 537 546 fd.write(str(col_name)) 538 547 fd.write(separator) … … 597 606 Set up custom configuration if exists 598 607 """ 599 if custom_config ==None:608 if custom_config is None: 600 609 return 601 610 … … 617 626 Set default starting perspective 618 627 """ 619 if custom_config ==None:628 if custom_config is None: 620 629 return 621 630 for plugin in self.plugins: … … 626 635 frame = plugin.get_frame() 627 636 frame.Show(True) 628 # break637 # break 629 638 else: 630 639 frame = plugin.get_frame() … … 683 692 try: 684 693 flag = self.panel_on_focus.get_save_flag() 685 if self._save_appl_menu !=None:694 if self._save_appl_menu is not None: 686 695 self._save_appl_menu.Enable(flag) 687 696 … … 694 703 self.panel_on_focus is not None: 695 704 self.set_panel_on_focus_helper() 696 # update toolbar705 # update toolbar 697 706 self._update_toolbar_helper() 698 # update edit menu707 # update edit menu 699 708 self.enable_edit_menu() 700 709 except wx._core.PyDeadObjectError: … … 711 720 Send focusing on ID to data explorer 712 721 """ 713 if self._data_panel !=None:722 if self._data_panel is not None: 714 723 self._data_panel.set_panel_on_focus(name) 715 724 … … 720 729 caption = self.panel_on_focus.window_caption 721 730 self.send_focus_to_datapanel(caption) 722 # update combo731 # update combo 723 732 if self.panel_on_focus in self.plot_panels.values(): 724 733 combo = self._data_panel.cb_plotpanel … … 739 748 """ 740 749 cpanel = panel 741 if self._toolbar !=None and cpanel._bookmark_flag:742 for item in 750 if self._toolbar is not None and cpanel._bookmark_flag: 751 for item in self._toolbar.get_bookmark_items(): 743 752 self._toolbar.remove_bookmark_item(item) 744 753 self._toolbar.add_bookmark_default() … … 841 850 field = self.sb.get_msg_position() 842 851 wx.Frame.PushStatusText(self, field=field, 843 string="FIXME - PushStatusText called without text") 852 string= 853 "FIXME - PushStatusText called without text") 844 854 845 855 def add_perspective(self, plugin): … … 866 876 """ 867 877 plugins = [] 868 # import guiframe local plugins869 # check if the style contain guiframe.dataloader878 # import guiframe local plugins 879 # check if the style contain guiframe.dataloader 870 880 style1 = self.__gui_style & GUIFRAME.DATALOADER_ON 871 881 style2 = self.__gui_style & GUIFRAME.PLOTTING_ON 872 882 if style1 == GUIFRAME.DATALOADER_ON: 873 883 try: 874 from sas.sasgui.guiframe.local_perspectives.data_loader import data_loader 884 from sas.sasgui.guiframe.local_perspectives.data_loader \ 885 import data_loader 875 886 self._data_plugin = data_loader.Plugin() 876 887 plugins.append(self._data_plugin) … … 881 892 if style2 == GUIFRAME.PLOTTING_ON: 882 893 try: 883 from sas.sasgui.guiframe.local_perspectives.plotting import plotting 894 from sas.sasgui.guiframe.local_perspectives.plotting \ 895 import plotting 884 896 self._plotting_plugin = plotting.Plugin() 885 897 plugins.append(self._plotting_plugin) … … 907 919 else: 908 920 file_list = [] 909 # #the default panel is the panel is the last plugin added921 # the default panel is the panel is the last plugin added 910 922 for item in file_list: 911 923 toks = os.path.splitext(os.path.basename(item)) … … 914 926 if toks[1] == '.py' or toks[1] == '': 915 927 name = toks[0] 916 # check the validity of the module name parsed917 # before trying to import it928 # check the validity of the module name parsed 929 # before trying to import it 918 930 if name is None or name.strip() == '': 919 931 continue … … 941 953 logging.error(msg) 942 954 finally: 943 if not file ==None:955 if file is not None: 944 956 file.close() 945 957 except: … … 956 968 """ 957 969 self._window_width, self._window_height = self.get_client_size() 958 # #Default size970 # Default size 959 971 if DATAPANEL_WIDTH < 0: 960 972 panel_width = int(self._window_width * 0.25) … … 962 974 panel_width = DATAPANEL_WIDTH 963 975 panel_height = int(self._window_height) 964 if self._data_panel is not None 976 if self._data_panel is not None and (p == self._data_panel): 965 977 return panel_width, panel_height 966 978 if hasattr(p, "CENTER_PANE") and p.CENTER_PANE: … … 994 1006 if self.welcome_panel_class is not None: 995 1007 welcome_panel = MDIFrame(self, None, 'None', (100, 200)) 996 self.defaultPanel = self.welcome_panel_class(welcome_panel, -1, style=wx.RAISED_BORDER) 1008 self.defaultPanel = self.welcome_panel_class(welcome_panel, -1, 1009 style=wx.RAISED_BORDER) 997 1010 welcome_panel.set_panel(self.defaultPanel) 998 1011 self.defaultPanel.set_frame(welcome_panel) … … 1010 1023 frame.SetPosition((0, mac_pos_y + size_t_bar)) 1011 1024 frame.Show(True) 1012 # add data panel1025 # add data panel 1013 1026 win = MDIFrame(self, None, 'None', (100, 200)) 1014 1027 data_panel = DataPanel(parent=win, id=-1) … … 1018 1031 d_panel_width, h = self._get_panels_size(self._data_panel) 1019 1032 win.SetSize((d_panel_width, h)) 1020 is_visible = self.__gui_style & GUIFRAME.MANAGER_ON == GUIFRAME.MANAGER_ON 1033 is_visible = self.__gui_style & \ 1034 GUIFRAME.MANAGER_ON == GUIFRAME.MANAGER_ON 1021 1035 if IS_WIN: 1022 1036 win.SetPosition((0, 0)) … … 1064 1078 Update the data. 1065 1079 """ 1066 prev_id, data_state = self._data_manager.update_data( \1080 prev_id, data_state = self._data_manager.update_data( 1067 1081 prev_data=prev_data, new_data=new_data) 1068 1082 … … 1115 1129 self._current_perspective.delete_data(data) 1116 1130 1117 1118 1131 def get_context_menu(self, plotpanel=None): 1119 1132 """ … … 1139 1152 menu_list = [] 1140 1153 item = self._current_perspective 1141 if item !=None:1154 if item is not None: 1142 1155 menu_list.extend(item.get_context_menu(plotpanel=plotpanel)) 1143 1156 return menu_list … … 1158 1171 self.cpanel_on_focus.SetFocus() 1159 1172 1160 1161 1173 def popup_panel(self, p): 1162 1174 """ … … 1170 1182 ID = wx.NewId() 1171 1183 self.panels[str(ID)] = p 1172 # #Check and set the size1184 # Check and set the size 1173 1185 if PLOPANEL_WIDTH < 0: 1174 1186 p_panel_width = int(self._window_width * 0.45) … … 1209 1221 # Register for showing/hiding the panel 1210 1222 wx.EVT_MENU(self, ID, self.on_view) 1211 if p not in self.plot_panels.values() and p.group_id !=None:1223 if p not in self.plot_panels.values() and p.group_id is not None: 1212 1224 self.plot_panels[ID] = p 1213 1225 if len(self.plot_panels) == 1: … … 1215 1227 self.set_panel_on_focus(None) 1216 1228 if self._data_panel is not None and \ 1217 self._plotting_plugin is not None:1229 self._plotting_plugin is not None: 1218 1230 ind = self._data_panel.cb_plotpanel.FindString('None') 1219 1231 if ind != wx.NOT_FOUND: … … 1258 1270 panel_name = 'No Panel on Focus' 1259 1271 c_panel = self.cpanel_on_focus 1260 if self._toolbar is 1272 if self._toolbar is None: 1261 1273 return 1262 1274 if c_panel is not None: … … 1303 1315 """ 1304 1316 if self._menubar is None or self._current_perspective is None \ 1305 or self._menubar.GetMenuCount() == 0:1317 or self._menubar.GetMenuCount() == 0: 1306 1318 return 1307 # replace or add a new menu for the current plugin1319 # replace or add a new menu for the current plugin 1308 1320 pos = self._menubar.FindMenu(str(self._applications_menu_name)) 1309 1321 if pos == -1 and self._applications_menu_pos > 0: … … 1325 1337 for (menu, name) in menu_list: 1326 1338 if self._applications_menu_pos == -1: 1327 # Find the Analysis position and insert just after it if possible1339 # Find the Analysis position and insert just after it 1328 1340 analysis_pos = self._menubar.FindMenu("Analysis") 1329 1341 if analysis_pos == -1: … … 1334 1346 self._applications_menu_pos = analysis_pos + 1 1335 1347 else: 1336 self._menubar.Insert(self._applications_menu_pos, menu, name) 1348 self._menubar.Insert(self._applications_menu_pos, 1349 menu, name) 1337 1350 self._applications_menu_name = name 1338 1351 … … 1362 1375 if config._do_acknowledge: 1363 1376 wx_id = wx.NewId() 1364 self._help_menu.Append(wx_id, '&Acknowledge', 'Acknowledging SasView') 1377 self._help_menu.Append(wx_id, '&Acknowledge', 1378 'Acknowledging SasView') 1365 1379 wx.EVT_MENU(self, wx_id, self._onAcknowledge) 1366 1380 … … 1379 1393 wx_id = wx.NewId() 1380 1394 self._help_menu.Append(wx_id, '&Check for update', 1381 'Check for the latest version of %s' % config.__appname__) 1395 'Check for the latest version of %s' % 1396 config.__appname__) 1382 1397 wx.EVT_MENU(self, wx_id, self._check_update) 1383 1398 self._menubar.Append(self._help_menu, '&Help') … … 1400 1415 wx_id = wx.NewId() 1401 1416 self._data_panel_menu = self._view_menu.Append(wx_id, 1402 '&Show Data Explorer', '') 1417 '&Show Data Explorer', 1418 '') 1403 1419 wx.EVT_MENU(self, wx_id, self.show_data_panel) 1404 1420 if style == GUIFRAME.MANAGER_ON: … … 1411 1427 style1 = self.__gui_style & GUIFRAME.TOOLBAR_ON 1412 1428 if style1 == GUIFRAME.TOOLBAR_ON: 1413 self._toolbar_menu = self._view_menu.Append(wx_id, '&Hide Toolbar', '') 1429 self._toolbar_menu = self._view_menu.Append(wx_id, '&Hide Toolbar', 1430 '') 1414 1431 else: 1415 self._toolbar_menu = self._view_menu.Append(wx_id, '&Show Toolbar', '') 1432 self._toolbar_menu = self._view_menu.Append(wx_id, '&Show Toolbar', 1433 '') 1416 1434 wx.EVT_MENU(self, wx_id, self._on_toggle_toolbar) 1417 1435 1418 if custom_config !=None:1436 if custom_config is not None: 1419 1437 self._view_menu.AppendSeparator() 1420 1438 wx_id = wx.NewId() … … 1427 1445 wx_id = wx.NewId() 1428 1446 self._view_menu.AppendSeparator() 1429 self._view_menu.Append(wx_id, 'Category Manager', 'Edit model categories') 1447 self._view_menu.Append(wx_id, 'Category Manager', 1448 'Edit model categories') 1430 1449 wx.EVT_MENU(self, wx_id, self._on_category_manager) 1431 1450 … … 1440 1459 self.batch_frame.Show(True) 1441 1460 1442 def 1461 def on_category_panel(self, event): 1443 1462 """ 1444 1463 On cat panel … … 1459 1478 """ 1460 1479 from sas.sasgui.guiframe.startup_configuration \ 1461 import StartupConfiguration as ConfDialog1480 import StartupConfiguration as ConfDialog 1462 1481 1463 1482 dialog = ConfDialog(parent=self, gui=self.__gui_style) … … 1466 1485 dialog.write_custom_config() 1467 1486 # post event for info 1468 wx.PostEvent(self, StatusEvent(status="Wrote custom configuration", info='info')) 1487 wx.PostEvent(self, StatusEvent(status="Wrote custom configuration", 1488 info='info')) 1469 1489 dialog.Destroy() 1470 1490 … … 1485 1505 id = wx.NewId() 1486 1506 if plug.use_data(): 1487 self._applications_menu.InsertCheckItem(pos, id, plug.sub_menu, \ 1488 "Switch to analysis: %s" % plug.sub_menu) 1507 self._applications_menu.InsertCheckItem(pos, id, 1508 plug.sub_menu, 1509 "Switch to analysis: %s" % plug.sub_menu) 1489 1510 plug_data_count = True 1490 1511 pos += 1 1491 1512 else: 1492 1513 plug_no_data_count = True 1493 self._applications_menu.AppendCheckItem(id, plug.sub_menu, \ 1514 self._applications_menu.AppendCheckItem(id, 1515 plug.sub_menu, 1494 1516 "Switch to analysis: %s" % plug.sub_menu) 1495 1517 wx.EVT_MENU(self, id, plug.on_perspective) … … 1497 1519 if not plug_data_count or not plug_no_data_count: 1498 1520 self._applications_menu.RemoveItem(separator) 1499 # Windows introduces a "Window" menu item during the layout process1500 # somehow. We want it to be next to the last item with Help as1501 # last. However Analysis gets stuck after Window in normal ordering1502 # so force it to be next after the Tools menu item. Should we add1503 # another menu item will need to check if this is still where we1504 # want Analysis. This is NOT an issue on the Mac which does not1505 # have the extra Window menu item.1521 # Windows introduces a "Window" menu item during the layout process 1522 # somehow. We want it to be next to the last item with Help as 1523 # last. However Analysis gets stuck after Window in normal ordering 1524 # so force it to be next after the Tools menu item. Should we add 1525 # another menu item will need to check if this is still where we 1526 # want Analysis. This is NOT an issue on the Mac which does not 1527 # have the extra Window menu item. 1506 1528 # March 2016 Code Camp -- PDB 1507 1529 Tools_pos = self._menubar.FindMenu("Tools") 1508 self._menubar.Insert(Tools_pos+1, self._applications_menu,1530 self._menubar.Insert(Tools_pos+1, self._applications_menu, 1509 1531 '&Analysis') 1510 1532 self._check_applications_menu() … … 1527 1549 wx_id = wx.NewId() 1528 1550 hint_load_file = "read all analysis states saved previously" 1529 self._save_appl_menu = self._file_menu.Append(wx_id, '&Open Project', hint_load_file) 1551 self._save_appl_menu = self._file_menu.Append(wx_id, 1552 '&Open Project', 1553 hint_load_file) 1530 1554 wx.EVT_MENU(self, wx_id, self._on_open_state_project) 1531 1555 … … 1536 1560 wx_id = wx.NewId() 1537 1561 self._save_appl_menu = self._file_menu.Append(wx_id, 1538 '&Open Analysis', hint_load_file) 1562 '&Open Analysis', 1563 hint_load_file) 1539 1564 wx.EVT_MENU(self, wx_id, self._on_open_state_application) 1540 1565 if OPEN_SAVE_MENU: … … 1546 1571 if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: 1547 1572 wx_id = wx.NewId() 1548 self._save_appl_menu = self._file_menu.Append(wx_id, \ 1549 '&Save Analysis', 'Save state of the current active analysis panel') 1573 txt = '&Save Analysis' 1574 txt2 = 'Save state of the current active analysis panel' 1575 self._save_appl_menu = self._file_menu.Append(wx_id, txt, txt2) 1550 1576 wx.EVT_MENU(self, wx_id, self._on_save_application) 1551 1577 if not sys.platform == 'darwin': … … 1589 1615 1590 1616 self._edit_menu_copyas = wx.Menu() 1591 #Sub menu for Copy As... 1592 self._edit_menu_copyas.Append(GUIFRAME_ID.COPYEX_ID, 'Copy current tab to Excel', 1617 # Sub menu for Copy As... 1618 self._edit_menu_copyas.Append(GUIFRAME_ID.COPYEX_ID, 1619 'Copy current tab to Excel', 1593 1620 'Copy parameter values in tabular format') 1594 1621 wx.EVT_MENU(self, GUIFRAME_ID.COPYEX_ID, self.on_copy_panel) 1595 1622 1596 self._edit_menu_copyas.Append(GUIFRAME_ID.COPYLAT_ID, 'Copy current tab to LaTeX', 1623 self._edit_menu_copyas.Append(GUIFRAME_ID.COPYLAT_ID, 1624 'Copy current tab to LaTeX', 1597 1625 'Copy parameter values in tabular format') 1598 1626 wx.EVT_MENU(self, GUIFRAME_ID.COPYLAT_ID, self.on_copy_panel) 1599 1600 1627 1601 1628 self._edit_menu.AppendMenu(GUIFRAME_ID.COPYAS_ID, 'Copy Params as...', … … 1620 1647 Return the gui style 1621 1648 """ 1622 return 1649 return self.__gui_style 1623 1650 1624 1651 def _add_menu_data(self): … … 1675 1702 return 1676 1703 frame = self.panels['default'].get_frame() 1677 if frame ==None:1704 if frame is None: 1678 1705 return 1679 1706 # Show default panel … … 1708 1735 self.schedule_full_draw_list.remove(panel) 1709 1736 1710 # delete uid number not str(uid)1737 # delete uid number not str(uid) 1711 1738 if ID in self.plot_panels.keys(): 1712 1739 del self.plot_panels[ID] … … 1734 1761 return 1735 1762 1736 # reading a state file1763 # reading a state file 1737 1764 for plug in self.plugins: 1738 1765 reader, ext = plug.get_extensions() 1739 1766 if reader is not None: 1740 # read the state of the single plugin1767 # read the state of the single plugin 1741 1768 if extension == ext: 1742 1769 reader.read(path) … … 1749 1776 msg += "\n(%s)" % sys.exc_value 1750 1777 wx.PostEvent(self, StatusEvent(status=msg, 1751 info="error", type="stop")) 1778 info="error", 1779 type="stop")) 1752 1780 return 1753 1781 … … 1788 1816 basename = os.path.basename(path) 1789 1817 if APPLICATION_STATE_EXTENSION is not None \ 1790 and basename.endswith(APPLICATION_STATE_EXTENSION):1818 and basename.endswith(APPLICATION_STATE_EXTENSION): 1791 1819 if is_project: 1792 1820 for ID in self.plot_panels.keys(): … … 1858 1886 """ 1859 1887 path = None 1860 if self._default_save_location ==None:1888 if self._default_save_location is None: 1861 1889 self._default_save_location = os.getcwd() 1862 1890 wx.PostEvent(self, StatusEvent(status="Loading Analysis file...")) … … 1892 1920 break 1893 1921 # Found the extension 1894 if ind !=None:1922 if ind is not None: 1895 1923 plug_wlist.remove(ind) 1896 1924 plug_wlist.insert(0, ind) … … 1910 1938 """ 1911 1939 path = None 1912 if self._default_save_location ==None:1940 if self._default_save_location is None: 1913 1941 self._default_save_location = os.getcwd() 1914 1942 msg = "This operation will set remove all data, plots and analyses from" 1915 1943 msg += " SasView before loading the project. Do you wish to continue?" 1916 self._data_panel.selection_cbox.SetValue('Select all Data') 1917 self._data_panel._on_selection_type(None) 1918 for _, theory_dict in self._data_panel.list_cb_theory.iteritems(): 1919 for key, value in theory_dict.iteritems(): 1920 item, _, _ = value 1921 item.Check(True) 1922 if not self._data_panel.on_remove(None, msg): 1944 msg_box = wx.MessageDialog(None, msg, 'Warning', wx.OK | wx.CANCEL) 1945 if msg_box.ShowModal() == wx.ID_OK: 1946 self._data_panel.selection_cbox.SetValue('Select all Data') 1947 self._data_panel._on_selection_type(None) 1948 for _, theory_dict in self._data_panel.list_cb_theory.iteritems(): 1949 for key, value in theory_dict.iteritems(): 1950 item, _, _ = value 1951 item.Check(True) 1952 self._data_panel.on_remove(None, False) 1953 1923 1954 wx.PostEvent(self, StatusEvent(status="Loading Project file...")) 1924 dlg = wx.FileDialog(self, 1925 "Choose a file", 1926 self._default_save_location, "", 1927 APPLICATION_WLIST) 1955 dlg = wx.FileDialog(self, "Choose a file", 1956 self._default_save_location, "", 1957 APPLICATION_WLIST) 1928 1958 if dlg.ShowModal() == wx.ID_OK: 1929 1959 path = dlg.GetPath() … … 1969 1999 save the state of the SasView as *.svs 1970 2000 """ 1971 if self._current_perspective is 2001 if self._current_perspective is None: 1972 2002 return 1973 2003 wx.PostEvent(self, StatusEvent(status="Saving Project file...")) … … 1997 2027 extens = APPLICATION_STATE_EXTENSION 1998 2028 fName = os.path.splitext(path)[0] + extens 1999 if doc !=None:2029 if doc is not None: 2000 2030 fd = open(fName, 'w') 2001 2031 fd.write(doc.toprettyxml()) … … 2029 2059 if data is not None: 2030 2060 new_doc = reader.write_toXML(data, state) 2031 if doc !=None and hasattr(doc, "firstChild"):2061 if doc is not None and hasattr(doc, "firstChild"): 2032 2062 child = new_doc.firstChild.firstChild 2033 2063 doc.firstChild.appendChild(child) … … 2040 2070 if data is not None: 2041 2071 new_doc = reader.write_toXML(data, state) 2042 if doc !=None and hasattr(doc, "firstChild"):2072 if doc is not None and hasattr(doc, "firstChild"): 2043 2073 child = new_doc.firstChild.firstChild 2044 2074 doc.firstChild.appendChild(child) … … 2095 2125 except: 2096 2126 logging.info("Failed to connect to www.sasview.org") 2097 self._process_version(version_info, standalone=event ==None)2127 self._process_version(version_info, standalone=event is None) 2098 2128 2099 2129 def _process_version(self, version_info, standalone=True): … … 2184 2214 try: 2185 2215 # Try an alternate method 2186 logging.error("Could not open the tutorial pdf, trying xhtml2pdf") 2216 logging.error( 2217 "Could not open the tutorial pdf, trying xhtml2pdf") 2187 2218 from xhtml2pdf import pisa 2188 2219 pisa.startViewer(path) 2189 2220 except: 2190 logging.error("Could not open the tutorial pdf with xhtml2pdf") 2221 logging.error( 2222 "Could not open the tutorial pdf with xhtml2pdf") 2191 2223 msg = "This feature requires 'PDF Viewer'\n" 2192 2224 wx.MessageBox(msg, 'Error') … … 2198 2230 try: 2199 2231 # Try an alternate method 2200 logging.error("Could not open the tutorial pdf, trying xhtml2pdf") 2232 logging.error( 2233 "Could not open the tutorial pdf, trying xhtml2pdf") 2201 2234 from xhtml2pdf import pisa 2202 2235 pisa.startViewer(path) 2203 2236 except: 2204 logging.error("Could not open the tutorial pdf with xhtml2pdf") 2205 msg = "This feature requires the 'Preview' application\n" 2237 logging.error( 2238 "Could not open the tutorial pdf with xhtml2pdf") 2239 msg = "This feature requires the Preview application\n" 2206 2240 wx.MessageBox(msg, 'Error') 2207 2241 … … 2218 2252 from documentation_window import DocumentationWindow 2219 2253 _TreeLocation = "user/user.html" 2220 DocumentationWindow(self, -1, _TreeLocation, "", "SasView Documentation") 2254 DocumentationWindow(self, -1, _TreeLocation, "", 2255 "SasView Documentation") 2221 2256 2222 2257 def set_manager(self, manager): … … 2252 2287 if self.panels[item].ALWAYS_ON: 2253 2288 continue 2254 if self.panels[item] ==None:2289 if self.panels[item] is None: 2255 2290 continue 2256 2291 if self.panels[item].window_name in panels: … … 2261 2296 # always show the data panel if enable 2262 2297 style = self.__gui_style & GUIFRAME.MANAGER_ON 2263 if (style == GUIFRAME.MANAGER_ON) and self.panels[item] == self._data_panel: 2298 if (style == GUIFRAME.MANAGER_ON) \ 2299 and self.panels[item] == self._data_panel: 2264 2300 if 'data_panel' in self.panels.keys(): 2265 2301 frame = self.panels['data_panel'].get_frame() 2266 if frame ==None:2302 if frame is None: 2267 2303 continue 2268 2304 flag = frame.IsShown() … … 2270 2306 else: 2271 2307 frame = self.panels[item].get_frame() 2272 if frame ==None:2308 if frame is None: 2273 2309 continue 2274 2310 … … 2280 2316 show the data panel 2281 2317 """ 2282 if self._data_panel_menu ==None:2318 if self._data_panel_menu is None: 2283 2319 return 2284 2320 label = self._data_panel_menu.GetText() … … 2310 2346 :param data_list: dictionary of data's ID and value Data 2311 2347 """ 2312 # Store data into manager2348 # Store data into manager 2313 2349 self.add_data_helper(data_list) 2314 2350 # set data in the data panel … … 2316 2352 data_state = self._data_manager.get_data_state(data_list.keys()) 2317 2353 self._data_panel.load_data_list(data_state) 2318 # if the data panel is shown wait for the user to press a button2319 # to send data to the current perspective. if the panel is not2320 # show automatically send the data to the current perspective2354 # if the data panel is shown wait for the user to press a button 2355 # to send data to the current perspective. if the panel is not 2356 # show automatically send the data to the current perspective 2321 2357 style = self.__gui_style & GUIFRAME.MANAGER_ON 2322 2358 if style == GUIFRAME.MANAGER_ON: 2323 # wait for button press from the data panel to set_data2359 # wait for button press from the data panel to set_data 2324 2360 if self._data_panel is not None: 2325 2361 self._data_panel.frame.Show(True) 2326 2362 else: 2327 # automatically send that to the current perspective2363 # automatically send that to the current perspective 2328 2364 self.set_data(data_id=data_list.keys()) 2329 2365 … … 2386 2422 info='warning')) 2387 2423 else: 2388 # if not append then new plot2424 # if not append then new plot 2389 2425 from sas.sasgui.guiframe.dataFitting import Data2D 2390 2426 if issubclass(Data2D, new_plot.__class__): 2391 # for 2 D always plot in a separated new plot2427 # for 2 D always plot in a separated new plot 2392 2428 new_plot.group_id = wx.NewId() 2393 2429 else: … … 2420 2456 group_id=group_id, 2421 2457 action='remove')) 2422 # remove res plot: Todo: improve2458 # remove res plot: Todo: improve 2423 2459 wx.CallAfter(self._remove_res_plot, new_plot.id) 2424 2460 self._data_manager.delete_data(data_id=data_id, … … 2462 2498 mypath = os.path.basename(path) 2463 2499 2464 # Instantiate a loader2500 # Instantiate a loader 2465 2501 loader = Loader() 2466 2502 ext_format = ".txt" … … 2482 2518 dlg.Destroy() 2483 2519 2484 2485 2520 def _onsaveTXT(self, data, path): 2486 2521 """ … … 2489 2524 .. todo:: Refactor and remove this method. See 'TODO' in _onSave. 2490 2525 """ 2491 if not path ==None:2526 if path is not None: 2492 2527 out = open(path, 'w') 2493 2528 has_errors = True 2494 if data.dy ==None or data.dy == []:2529 if data.dy is None or data.dy == []: 2495 2530 has_errors = False 2496 2531 # Sanity check … … 2502 2537 has_errors = False 2503 2538 if has_errors: 2504 if data.dx !=None and data.dx != []:2539 if data.dx is not None and data.dx != []: 2505 2540 out.write("<X> <Y> <dY> <dX>\n") 2506 2541 else: … … 2511 2546 for i in range(len(data.x)): 2512 2547 if has_errors: 2513 if data.dx !=None and data.dx != []:2514 if data.dx[i] !=None:2548 if data.dx is not None and data.dx != []: 2549 if data.dx[i] is not None: 2515 2550 out.write("%g %g %g %g\n" % (data.x[i], 2516 2551 data.y[i], … … 2543 2578 info="error")) 2544 2579 raise ValueError, msg 2545 # #text = str(data)2580 # text = str(data) 2546 2581 text = data.__str__() 2547 2582 text += 'Data Min Max:\n' 2548 2583 text += 'X_min = %s: X_max = %s\n' % (xmin, max(data.x)) 2549 2584 text += 'Y_min = %s: Y_max = %s\n' % (ymin, max(data.y)) 2550 if data.dy !=None:2585 if data.dy is not None: 2551 2586 text += 'dY_min = %s: dY_max = %s\n' % (min(data.dy), max(data.dy)) 2552 2587 text += '\nData Points:\n' 2553 2588 x_st = "X" 2554 2589 for index in range(len(data.x)): 2555 if data.dy !=None and len(data.dy) > index:2590 if data.dy is not None and len(data.dy) > index: 2556 2591 dy_val = data.dy[index] 2557 2592 else: 2558 2593 dy_val = 0.0 2559 if data.dx !=None and len(data.dx) > index:2594 if data.dx is not None and len(data.dx) > index: 2560 2595 dx_val = data.dx[index] 2561 2596 else: 2562 2597 dx_val = 0.0 2563 if data.dxl !=None and len(data.dxl) > index:2598 if data.dxl is not None and len(data.dxl) > index: 2564 2599 if index == 0: 2565 2600 x_st = "Xl" 2566 2601 dx_val = data.dxl[index] 2567 elif data.dxw !=None and len(data.dxw) > index:2602 elif data.dxw is not None and len(data.dxw) > index: 2568 2603 if index == 0: 2569 2604 x_st = "Xw" … … 2605 2640 mypath = os.path.basename(path) 2606 2641 2607 # Instantiate a loader2642 # Instantiate a loader 2608 2643 loader = Loader() 2609 2644 … … 2642 2677 y_val = data.qy_data[index] 2643 2678 i_val = data.data[index] 2644 if data.err_data !=None:2679 if data.err_data is not None: 2645 2680 di_val = data.err_data[index] 2646 if data.dqx_data !=None:2681 if data.dqx_data is not None: 2647 2682 dx_val = data.dqx_data[index] 2648 if data.dqy_data !=None:2683 if data.dqy_data is not None: 2649 2684 dy_val = data.dqy_data[index] 2650 2685 … … 2681 2716 for name in self._current_perspective.get_perspective(): 2682 2717 frame = panel.get_frame() 2683 if frame !=None:2718 if frame is not None: 2684 2719 if name == panel.window_name: 2685 2720 panel.on_set_focus(event=None) … … 2691 2726 self._data_panel.set_active_perspective(name) 2692 2727 self._check_applications_menu() 2693 # Set the SasView title2728 # Set the SasView title 2694 2729 self._set_title_name(name) 2695 2730 … … 2723 2758 """ 2724 2759 2725 if self.panel_on_focus not in self._plotting_plugin.plot_panels.values(): 2760 if self.panel_on_focus \ 2761 not in self._plotting_plugin.plot_panels.values(): 2726 2762 return 2763 check = "Theory1D" 2727 2764 is_theory = len(self.panel_on_focus.plots) <= 1 and \ 2728 self.panel_on_focus.plots.values()[0].__class__.__name__ == "Theory1D"2765 self.panel_on_focus.plots.values()[0].__class__.__name__ == check 2729 2766 2730 2767 is_data2d = hasattr(new_plot, 'data') … … 2734 2771 has_meta_data = hasattr(new_plot, 'meta_data') 2735 2772 2736 # disable_add_data if the data is being recovered from a saved state file.2773 # disable_add_data if the data is being recovered from a saved state 2737 2774 is_state_data = False 2738 2775 if has_meta_data: 2739 2776 if 'invstate' in new_plot.meta_data: 2740 2777 is_state_data = True 2741 if 2778 if 'prstate' in new_plot.meta_data: 2742 2779 is_state_data = True 2743 if 2780 if 'fitstate' in new_plot.meta_data: 2744 2781 is_state_data = True 2745 2782 2746 return is_data1d and not is_data2d and not is_theory and not is_state_data 2783 return is_data1d and not is_data2d and not is_theory \ 2784 and not is_state_data 2747 2785 2748 2786 def check_multimode(self, perspective=None): … … 2750 2788 Check the perspective have batch mode capablitity 2751 2789 """ 2752 if perspective == None or self._data_panel ==None:2790 if perspective is None or self._data_panel is None: 2753 2791 return 2754 2792 flag = perspective.get_batch_capable() … … 2777 2815 self._edit_menu.Enable(GUIFRAME_ID.PASTE_ID, flag) 2778 2816 2779 # Copy menu2817 # Copy menu 2780 2818 flag = self.cpanel_on_focus.get_copy_flag() 2781 2819 self._edit_menu_copyas.Enable(GUIFRAME_ID.COPYEX_ID, flag) … … 2908 2946 if data_panel.cb_plotpanel is not None: 2909 2947 # Check if any panel has the same caption 2910 has_newstring = data_panel.cb_plotpanel.FindString \2911 (str(new_caption))2948 has_newstring = data_panel.cb_plotpanel.FindString( 2949 str(new_caption)) 2912 2950 caption = new_caption 2913 2951 if has_newstring != wx.NOT_FOUND: … … 3026 3064 drag 3027 3065 """ 3028 # Not implemeted3066 # Not implemeted 3029 3067 3030 3068 def enable_reset(self): … … 3039 3077 """ 3040 3078 size_y = 0 3041 if self.GetToolBar() !=None and self.GetToolBar().IsShown():3079 if self.GetToolBar() is not None and self.GetToolBar().IsShown(): 3042 3080 if not IS_LINUX: 3043 3081 _, size_y = self.GetToolBar().GetSizeTuple() … … 3054 3092 # append this panel in the schedule list if not in yet 3055 3093 if func == 'append': 3056 if not panelin self.schedule_full_draw_list:3094 if panel not in self.schedule_full_draw_list: 3057 3095 self.schedule_full_draw_list.append(panel) 3058 3096 # remove this panel from schedule list … … 3074 3112 3075 3113 count = len(self.schedule_full_draw_list) 3076 # if not self.schedule:3114 # if not self.schedule: 3077 3115 if count < 1: 3078 3116 self.set_schedule(False) … … 3089 3127 if ind == count: 3090 3128 return 3091 #Simple redraw only for a panel shown 3129 # Simple redraw only for a panel shown 3130 3092 3131 def f_draw(panel): 3093 3132 """ … … 3102 3141 # draw if possible 3103 3142 panel.set_resizing(False) 3104 # panel.Show(True)3143 # panel.Show(True) 3105 3144 panel.draw_plot() 3106 3145 # Check if the panel is not shown … … 3137 3176 Set focus on a plot panel 3138 3177 """ 3139 if panel ==None:3178 if panel is None: 3140 3179 return 3141 # self.set_plot_unfocus()3180 # self.set_plot_unfocus() 3142 3181 panel.on_set_focus(None) 3143 3182 # set focusing panel … … 3172 3211 try: 3173 3212 # check if it is time to redraw 3174 if self.GetCapture() ==None:3213 if self.GetCapture() is None: 3175 3214 # Draw plot, changes resizing too 3176 3215 self.full_draw() … … 3180 3219 # restart idle 3181 3220 self._redraw_idle(*args, **kwargs) 3182 3183 3221 3184 3222 def _redraw_idle(self, *args, **kwargs): … … 3195 3233 the GUI manager 3196 3234 """ 3197 # #Internal nickname for the window, used by the AUI manager3235 # Internal nickname for the window, used by the AUI manager 3198 3236 window_name = "default" 3199 # #Name to appear on the window title bar3237 # Name to appear on the window title bar 3200 3238 window_caption = "Welcome panel" 3201 # #Flag to tell the AUI manager to put this panel in the center pane3239 # Flag to tell the AUI manager to put this panel in the center pane 3202 3240 CENTER_PANE = True 3241 3203 3242 def __init__(self, parent, *args, **kwds): 3204 3243 wx.Panel.__init__(self, parent, *args, **kwds) 3205 3244 PanelBase.__init__(self, parent) 3206 3207 3245 3208 3246 … … 3236 3274 try: 3237 3275 if os.path.isfile(SPLASH_SCREEN_PATH): 3238 self.s_screen = self.display_splash_screen(parent=self.frame, 3239 path=SPLASH_SCREEN_PATH) 3276 self.s_screen = \ 3277 self.display_splash_screen(parent=self.frame, 3278 path=SPLASH_SCREEN_PATH) 3240 3279 else: 3241 3280 self.frame.Show() … … 3300 3339 os.remove(file_path) 3301 3340 except: 3302 logging.error("gui_manager.clean_plugin_models:\n %s" \3341 logging.error("gui_manager.clean_plugin_models:\n %s" 3303 3342 % sys.exc_value) 3304 3343 … … 3314 3353 Build the GUI 3315 3354 """ 3316 # try to load file at the start3355 # try to load file at the start 3317 3356 self.open_file() 3318 3357 self.frame.build_gui() … … 3390 3429 # Return the suggested position and size for the application frame. 3391 3430 return (posX, posY), (customWidth, customHeight), is_maximized 3392 3393 3431 3394 3432 def display_splash_screen(self, parent, … … 3427 3465 return s_screen 3428 3466 3429 3430 3467 def on_close_splash_screen(self, event): 3431 3468 """ … … 3447 3484 """ 3448 3485 # Initialize the Frame object 3449 CHILD_FRAME.__init__(self, parent=parent, id=wx.ID_ANY, title=title, size=size) 3486 CHILD_FRAME.__init__(self, parent=parent, id=wx.ID_ANY, 3487 title=title, size=size) 3450 3488 self.parent = parent 3451 3489 self.name = "Untitled" 3452 3490 self.batch_on = self.parent.batch_on 3453 3491 self.panel = panel 3454 if panel !=None:3492 if panel is not None: 3455 3493 self.set_panel(panel) 3456 3494 self.Show(False)
Note: See TracChangeset
for help on using the changeset viewer.