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