Changes in src/sas/guiframe/gui_manager.py [78f75d02:957af0d] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/guiframe/gui_manager.py
r78f75d02 r957af0d 27 27 import urllib 28 28 import urllib2 29 29 import json 30 30 31 31 from sas.guiframe.events import EVT_CATEGORY … … 46 46 from sas.guiframe.CategoryManager import CategoryManager 47 47 from sas.dataloader.loader import Loader 48 from sas.guiframe.proxy import Connection 48 49 from matplotlib import _pylab_helpers 50 49 51 50 52 def get_app_dir(): … … 52 54 The application directory is the one where the default custom_config.py 53 55 file resides. 56 57 :returns: app_path - the path to the applicatin directory 54 58 """ 55 59 # First, try the directory of the executable we are running … … 68 72 69 73 # Finally, try the directory of the sasview module 70 # TODO: gui_manager will have to know about sasview until we74 # TODO: gui_manager will have to know about sasview until we 71 75 # clean all these module variables and put them into a config class 72 76 # that can be passed by sasview.py. … … 231 235 Initialize the Frame object 232 236 """ 237 233 238 PARENT_FRAME.__init__(self, parent=parent, title=title, pos=pos, size=size) 234 239 # title … … 359 364 frame.SetIcon(icon) 360 365 except: 361 logging.error("ViewerFrame.put_icon: could not set icon")366 pass 362 367 363 368 def get_client_size(self): … … 747 752 self._toolbar.Realize() 748 753 754 749 755 def build_gui(self): 750 756 """ … … 772 778 # Append item from plugin under menu file if necessary 773 779 self._populate_file_menu() 780 774 781 775 782 if not wx.VERSION_STRING >= '3.0.0.0': … … 815 822 # Load panels 816 823 self._load_panels() 824 self.set_default_perspective() 817 825 818 826 def SetStatusText(self, *args, **kwds): … … 830 838 def PushStatusText(self, *args, **kwds): 831 839 """ 832 FIXME: No message is passed. What is this supposed to do?840 .. todo:: No message is passed. What is this supposed to do? 833 841 """ 834 842 field = self.sb.get_msg_position() 835 843 wx.Frame.PushStatusText(self, field=field, 836 string="FIXME :PushStatusText called without text")844 string="FIXME - PushStatusText called without text") 837 845 838 846 def add_perspective(self, plugin): … … 890 898 :param dir: directory in which to look for plug-ins 891 899 892 :return : list of plug-ins900 :returns: list of plug-ins 893 901 894 902 """ … … 923 931 if hasattr(module, "PLUGIN_ID"): 924 932 try: 925 plugins.append(module.Plugin()) 933 plug = module.Plugin() 934 if plug.set_default_perspective(): 935 self._current_perspective = plug 936 plugins.append(plug) 937 926 938 msg = "Found plug-in: %s" % module.PLUGIN_ID 927 939 logging.info(msg) … … 937 949 file.close() 938 950 except: 939 # Should raise and catch at a higher level and 951 # Should raise and catch at a higher level and 940 952 # display error on status bar 941 953 logging.error(sys.exc_value) … … 984 996 985 997 # Set up welcome panel 986 # TODO: this needs serious simplification998 # TODO: this needs serious simplification 987 999 if self.welcome_panel_class is not None: 988 1000 welcome_panel = MDIFrame(self, None, 'None', (100, 200)) … … 1074 1086 def onfreeze(self, theory_id): 1075 1087 """ 1088 Saves theory/model and passes to data loader. 1089 1090 ..warning:: This seems to be the exact same code as the next 1091 function called simply freeze. This probably needs fixing 1076 1092 """ 1077 1093 data_state_list = self._data_manager.freeze(theory_id) … … 1085 1101 def freeze(self, data_id, theory_id): 1086 1102 """ 1103 Saves theory/model and passes to data loader. 1104 1105 ..warning:: This seems to be the exact same code as the next 1106 function called simply freeze. This probably needs fixing 1087 1107 """ 1088 1108 data_state_list = self._data_manager.freeze_theory(data_id=data_id, … … 1149 1169 :param p: panel object to add to the AUI manager 1150 1170 1151 :return : ID of the event associated with the new panel [int]1171 :returns: ID of the event associated with the new panel [int] 1152 1172 1153 1173 """ … … 1170 1190 # Append nummber 1171 1191 captions = self._get_plotpanel_captions() 1172 # FIXME: Fix this aweful loop1192 # FIXME: Fix this awful loop 1173 1193 while (1): 1174 1194 caption = windowcaption + '%s' % str(self.graph_num) … … 1491 1511 for item in plugin.populate_file_menu(): 1492 1512 m_name, m_hint, m_handler = item 1493 wx_id = wx.NewId()1494 self._file_menu.Append( wx_id, m_name, m_hint)1495 wx.EVT_MENU(self, wx_id, m_handler)1513 id = wx.NewId() 1514 self._file_menu.Append(id, m_name, m_hint) 1515 wx.EVT_MENU(self, id, m_handler) 1496 1516 self._file_menu.AppendSeparator() 1497 1517 1498 1518 style1 = self.__gui_style & GUIFRAME.MULTIPLE_APPLICATIONS 1499 1519 if OPEN_SAVE_MENU: 1500 wx_id = wx.NewId()1520 id = wx.NewId() 1501 1521 hint_load_file = "read all analysis states saved previously" 1502 self._save_appl_menu = self._file_menu.Append( wx_id, '&Open Project', hint_load_file)1503 wx.EVT_MENU(self, wx_id, self._on_open_state_project)1522 self._save_appl_menu = self._file_menu.Append(id, '&Open Project', hint_load_file) 1523 wx.EVT_MENU(self, id, self._on_open_state_project) 1504 1524 1505 1525 if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: … … 1507 1527 hint_load_file = "Read a status files and load" 1508 1528 hint_load_file += " them into the analysis" 1509 wx_id = wx.NewId()1510 self._save_appl_menu = self._file_menu.Append( wx_id,1529 id = wx.NewId() 1530 self._save_appl_menu = self._file_menu.Append(id, 1511 1531 '&Open Analysis', hint_load_file) 1512 wx.EVT_MENU(self, wx_id, self._on_open_state_application)1532 wx.EVT_MENU(self, id, self._on_open_state_application) 1513 1533 if OPEN_SAVE_MENU: 1514 1534 self._file_menu.AppendSeparator() 1515 wx_id = wx.NewId()1516 self._file_menu.Append( wx_id, '&Save Project',1535 id = wx.NewId() 1536 self._file_menu.Append(id, '&Save Project', 1517 1537 'Save the state of the whole analysis') 1518 wx.EVT_MENU(self, wx_id, self._on_save_project)1538 wx.EVT_MENU(self, id, self._on_save_project) 1519 1539 if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: 1520 wx_id = wx.NewId()1521 self._save_appl_menu = self._file_menu.Append( wx_id, \1540 id = wx.NewId() 1541 self._save_appl_menu = self._file_menu.Append(id, \ 1522 1542 '&Save Analysis', 'Save state of the current active analysis panel') 1523 wx.EVT_MENU(self, wx_id, self._on_save_application)1543 wx.EVT_MENU(self, id, self._on_save_application) 1524 1544 if not sys.platform == 'darwin': 1525 1545 self._file_menu.AppendSeparator() 1526 wx_id = wx.NewId()1527 self._file_menu.Append( wx_id, '&Quit', 'Exit')1528 wx.EVT_MENU(self, wx_id, self.Close)1546 id = wx.NewId() 1547 self._file_menu.Append(id, '&Quit', 'Exit') 1548 wx.EVT_MENU(self, id, self.Close) 1529 1549 1530 1550 def _add_menu_file(self): … … 1697 1717 """ 1698 1718 """ 1719 message = "" 1699 1720 log_msg = '' 1721 output = [] 1722 error_message = "" 1700 1723 basename = os.path.basename(path) 1701 _, extension = os.path.splitext(basename)1724 root, extension = os.path.splitext(basename) 1702 1725 if extension.lower() not in EXTENSIONS: 1703 1726 log_msg = "File Loader cannot " … … 2031 2054 a call-back method when the current version number has been obtained. 2032 2055 """ 2033 try: 2034 req = urllib2.Request('https://github.com/SasView/sasview/releases/latest') 2035 res = urllib2.urlopen(req) 2036 get_url= res.geturl() 2037 content = get_url.partition('/v')[2] 2038 logging.info("connected to GitHub. sasview.latestversion = %s" 2039 % (content)) 2040 except: 2041 msg = traceback.format_exc() 2042 logging.info(msg) 2043 logging.info("failed to connect to GitHub") 2044 content = "0.0.0" 2045 2046 version = content.strip() 2047 logging.info("Latest SasView version number: %s" % (version)) 2048 if len(re.findall('\d+\.\d+\.\d+$', version)) < 0: 2049 content = "0.0.0" 2050 self._process_version(content, standalone=event == None) 2051 2052 def _process_version(self, version, standalone=True): 2056 version_info = {"version": "0.0.0"} 2057 c = Connection(config.__update_URL__, config.UPDATE_TIMEOUT) 2058 response = c.connect() 2059 if response is not None: 2060 try: 2061 # 2062 content = response.read().strip() 2063 logging.info("Connected to www.sasview.org. Latest version: %s" 2064 % (content)) 2065 version_info = json.loads(content) 2066 except: 2067 logging.info("Failed to connect to www.sasview.org") 2068 self._process_version(version_info, standalone=event == None) 2069 2070 2071 2072 # 2073 # try: 2074 # req = urllib2.Request(config.__update_URL__) 2075 # res = urllib2.urlopen(req) 2076 # content = res.read().strip() 2077 # logging.info("Connected to www.sasview.org. Latest version: %s" 2078 # % (content)) 2079 # version_info = json.loads(content) 2080 # except: 2081 # logging.info("Failed to connect to www.sasview.org") 2082 # version_info = {"version": "0.0.0"} 2083 # self._process_version(version_info, standalone=event == None) 2084 2085 def _process_version(self, version_info, standalone=True): 2053 2086 """ 2054 2087 Call-back method for the process of checking for updates. … … 2063 2096 """ 2064 2097 try: 2098 version = version_info["version"] 2065 2099 if version == "0.0.0": 2066 2100 msg = "Could not connect to the application server." … … 2071 2105 if not standalone: 2072 2106 import webbrowser 2073 webbrowser.open(config.__download_page__) 2107 if "download_url" in version_info: 2108 webbrowser.open(version_info["download_url"]) 2109 else: 2110 webbrowser.open(config.__download_page__) 2074 2111 else: 2075 2112 msg += "See the help menu to download it." … … 2187 2224 if hasattr(item, "post_init"): 2188 2225 item.post_init() 2226 2227 def set_default_perspective(self): 2228 """ 2229 Choose among the plugin the first plug-in that has 2230 "set_default_perspective" method and its return value is True will be 2231 as a default perspective when the welcome page is closed 2232 """ 2233 for item in self.plugins: 2234 if hasattr(item, "set_default_perspective"): 2235 if item.set_default_perspective(): 2236 item.on_perspective(event=None) 2237 return 2189 2238 2190 2239 def set_perspective(self, panels): … … 2365 2414 total_plot_list.append(theory_data) 2366 2415 for new_plot in total_plot_list: 2416 id = new_plot.id 2367 2417 for group_id in new_plot.list_group_id: 2368 wx.PostEvent(self, NewPlotEvent(id= new_plot.id,2418 wx.PostEvent(self, NewPlotEvent(id=id, 2369 2419 group_id=group_id, 2370 2420 action='remove')) 2371 2421 #remove res plot: Todo: improve 2372 wx.CallAfter(self._remove_res_plot, new_plot.id)2422 wx.CallAfter(self._remove_res_plot, id) 2373 2423 self._data_manager.delete_data(data_id=data_id, 2374 2424 theory_id=theory_id) … … 2405 2455 ext_num = dlg.GetFilterIndex() 2406 2456 if ext_num == 0: 2407 ext_format = '.txt'2457 format = '.txt' 2408 2458 else: 2409 ext_format = '.xml'2410 path = os.path.splitext(path)[0] + ext_format2459 format = '.xml' 2460 path = os.path.splitext(path)[0] + format 2411 2461 mypath = os.path.basename(path) 2412 2462 2413 2463 #Instantiate a loader 2414 2464 loader = Loader() 2415 ext_format = ".txt"2416 if os.path.splitext(mypath)[1].lower() == ext_format:2465 format = ".txt" 2466 if os.path.splitext(mypath)[1].lower() == format: 2417 2467 # Make sure the ext included in the file name 2418 2468 # especially on MAC 2419 fName = os.path.splitext(path)[0] + ext_format2469 fName = os.path.splitext(path)[0] + format 2420 2470 self._onsaveTXT(data, fName) 2421 ext_format = ".xml"2422 if os.path.splitext(mypath)[1].lower() == ext_format:2471 format = ".xml" 2472 if os.path.splitext(mypath)[1].lower() == format: 2423 2473 # Make sure the ext included in the file name 2424 2474 # especially on MAC 2425 fName = os.path.splitext(path)[0] + ext_format2426 loader.save(fName, data, ext_format)2475 fName = os.path.splitext(path)[0] + format 2476 loader.save(fName, data, format) 2427 2477 try: 2428 2478 self._default_save_location = os.path.dirname(path) … … 2435 2485 """ 2436 2486 Save file as txt 2437 :TODO: Refactor and remove this method. See TODO in _onSave. 2487 2488 .. todo:: Refactor and remove this method. See 'TODO' in _onSave. 2438 2489 """ 2439 2490 if not path == None: … … 2547 2598 ext_num = dlg.GetFilterIndex() 2548 2599 if ext_num == 0: 2549 ext_format = '.dat'2600 format = '.dat' 2550 2601 else: 2551 ext_format = ''2552 path = os.path.splitext(path)[0] + ext_format2602 format = '' 2603 path = os.path.splitext(path)[0] + format 2553 2604 mypath = os.path.basename(path) 2554 2605 … … 2556 2607 loader = Loader() 2557 2608 2558 ext_format = ".dat"2559 if os.path.splitext(mypath)[1].lower() == ext_format:2609 format = ".dat" 2610 if os.path.splitext(mypath)[1].lower() == format: 2560 2611 # Make sure the ext included in the file name 2561 2612 # especially on MAC 2562 fileName = os.path.splitext(path)[0] + ext_format2563 loader.save(fileName, data, ext_format)2613 fileName = os.path.splitext(path)[0] + format 2614 loader.save(fileName, data, format) 2564 2615 try: 2565 2616 self._default_save_location = os.path.dirname(path) … … 2863 2914 # Append nummber 2864 2915 inc = 1 2865 # FIXME: fix this terrible loop2916 # FIXME: fix this terrible loop 2866 2917 while (1): 2867 2918 caption = new_caption + '_%s' % str(inc) … … 2886 2937 2887 2938 :param name: window_name in AuiPaneInfo 2888 :return : AuiPaneInfo of the name2939 :returns: AuiPaneInfo of the name 2889 2940 """ 2890 2941 for panel in self.plot_panels.values(): … … 3058 3109 pass 3059 3110 3060 # Draw all panels 3111 # Draw all panels 3061 3112 if count == 1: 3062 3113 f_draw(self.schedule_full_draw_list[0]) 3063 3114 else: 3064 3115 map(f_draw, self.schedule_full_draw_list) 3065 # Reset the attr 3116 # Reset the attr 3066 3117 if len(self.schedule_full_draw_list) == 0: 3067 3118 self.set_schedule(False) … … 3104 3155 Get window size 3105 3156 3106 :return size: tuple 3157 :returns: size 3158 :rtype: tuple 3107 3159 """ 3108 3160 width, height = self.GetSizeTuple() … … 3125 3177 pass 3126 3178 3127 # restart idle 3179 # restart idle 3128 3180 self._redraw_idle(*args, **kwargs) 3129 3181 … … 3133 3185 Restart Idle 3134 3186 """ 3135 # restart idle 3187 # restart idle 3136 3188 self.idletimer.Restart(100 * TIME_FACTOR, *args, **kwargs) 3137 3189 … … 3154 3206 3155 3207 3156 class SasViewApp(wx.App):3208 class ViewApp(wx.App): 3157 3209 """ 3158 SasView application3210 Toy application to test this Frame 3159 3211 """ 3160 3212 def OnInit(self): … … 3242 3294 if len(os.listdir(model_folder)) > 0: 3243 3295 try: 3244 for file namein os.listdir(model_folder):3245 file_path = os.path.join(model_folder, file name)3296 for file in os.listdir(model_folder): 3297 file_path = os.path.join(model_folder, file) 3246 3298 if os.path.isfile(file_path): 3247 3299 os.remove(file_path) … … 3262 3314 """ 3263 3315 #try to load file at the start 3264 self.open_file() 3316 try: 3317 self.open_file() 3318 except: 3319 raise 3265 3320 self.frame.build_gui() 3266 3321 … … 3290 3345 """ 3291 3346 is_maximized = False 3292 # Get size of screen without 3347 # Get size of screen without 3293 3348 for screenCount in range(wx.Display().GetCount()): 3294 3349 screen = wx.Display(screenCount) … … 3307 3362 customHeight = displayHeight * 0.9 3308 3363 else: 3309 # If the custom screen is bigger than the 3364 # If the custom screen is bigger than the 3310 3365 # window screen than make maximum size 3311 3366 if customWidth > displayWidth: … … 3405 3460 def show_data_panel(self, action): 3406 3461 """ 3462 Turns on the data panel 3463 3464 The the data panel is optional. Most of its functions can be 3465 performed from the menu bar and from the plots. 3407 3466 """ 3408 3467 self.parent.show_data_panel(action)
Note: See TracChangeset
for help on using the changeset viewer.