Changes in src/sas/sasgui/guiframe/gui_manager.py [b963b20:2f22db9] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/gui_manager.py
rb963b20 r2f22db9 22 22 import re 23 23 import logging 24 import httplib 24 25 import traceback 25 26 import urllib 27 import urllib2 26 28 import json 27 29 28 from matplotlib import _pylab_helpers29 30 from sas import get_local_config, get_custom_config, get_app_dir, get_user_dir31 30 from sas.sasgui.guiframe.events import EVT_CATEGORY 32 31 from sas.sasgui.guiframe.events import EVT_STATUS … … 47 46 from sas.sascalc.dataloader.loader import Loader 48 47 from sas.sasgui.guiframe.proxy import Connection 48 from matplotlib import _pylab_helpers 49 49 50 50 logger = logging.getLogger(__name__) 51 51 52 warnings.simplefilter("ignore") 52 53 53 config = get_local_config() 54 custom_config = get_custom_config() 54 def get_app_dir(): 55 """ 56 The application directory is the one where the default custom_config.py 57 file resides. 58 59 :returns: app_path - the path to the applicatin directory 60 """ 61 # First, try the directory of the executable we are running 62 app_path = sys.path[0] 63 if os.path.isfile(app_path): 64 app_path = os.path.dirname(app_path) 65 if os.path.isfile(os.path.join(app_path, "custom_config.py")): 66 app_path = os.path.abspath(app_path) 67 logger.info("Using application path: %s", app_path) 68 return app_path 69 70 # Next, try the current working directory 71 if os.path.isfile(os.path.join(os.getcwd(), "custom_config.py")): 72 logger.info("Using application path: %s", os.getcwd()) 73 return os.path.abspath(os.getcwd()) 74 75 # Finally, try the directory of the sasview module 76 # TODO: gui_manager will have to know about sasview until we 77 # clean all these module variables and put them into a config class 78 # that can be passed by sasview.py. 79 logger.debug(sys.executable) 80 logger.debug(str(sys.argv)) 81 from sas import sasview as sasview 82 app_path = os.path.dirname(sasview.__file__) 83 logger.debug("Using application path: %s", app_path) 84 return app_path 85 86 87 def get_user_directory(): 88 """ 89 Returns the user's home directory 90 """ 91 userdir = os.path.join(os.path.expanduser("~"), ".sasview") 92 if not os.path.isdir(userdir): 93 os.makedirs(userdir) 94 return userdir 95 96 97 def _find_local_config(file, path): 98 """ 99 Find configuration file for the current application 100 """ 101 config_module = None 102 fObj = None 103 try: 104 fObj, path_config, descr = imp.find_module(file, [path]) 105 config_module = imp.load_module(file, fObj, path_config, descr) 106 except: 107 logger.error("Error loading %s/%s: %s" % (path, file, sys.exc_value)) 108 finally: 109 if fObj is not None: 110 fObj.close() 111 logger.debug("GuiManager loaded %s/%s" % (path, file)) 112 return config_module 113 114 # Get APP folder 115 PATH_APP = get_app_dir() 116 DATAPATH = PATH_APP 117 118 # GUI always starts from the App folder 119 # os.chdir(PATH_APP) 120 # Read in the local config, which can either be with the main 121 # application or in the installation directory 122 config = _find_local_config('local_config', PATH_APP) 123 if config is None: 124 config = _find_local_config('local_config', os.getcwd()) 125 if config is None: 126 # Didn't find local config, load the default 127 import sas.sasgui.guiframe.config as config 128 logger.debug("using default local_config") 129 else: 130 logger.debug("found local_config in %s" % os.getcwd()) 131 else: 132 logger.debug("found local_config in %s" % PATH_APP) 133 134 from sas.sasgui.guiframe.customdir import SetupCustom 135 c_conf_dir = SetupCustom().setup_dir(PATH_APP) 136 custom_config = _find_local_config('custom_config', c_conf_dir) 137 if custom_config is None: 138 custom_config = _find_local_config('custom_config', os.getcwd()) 139 if custom_config is None: 140 msgConfig = "Custom_config file was not imported" 141 logger.debug(msgConfig) 142 else: 143 logger.debug("using custom_config in %s" % os.getcwd()) 144 else: 145 logger.debug("using custom_config from %s" % c_conf_dir) 55 146 56 147 # read some constants from config … … 62 153 SPLASH_SCREEN_HEIGHT = config.SPLASH_SCREEN_HEIGHT 63 154 SS_MAX_DISPLAY_TIME = config.SS_MAX_DISPLAY_TIME 155 SAS_OPENCL = config.SAS_OPENCL 64 156 if not WELCOME_PANEL_ON: 65 157 WELCOME_PANEL_SHOW = False … … 85 177 DEFAULT_OPEN_FOLDER = os.path.abspath(open_folder) 86 178 else: 87 DEFAULT_OPEN_FOLDER = get_app_dir()179 DEFAULT_OPEN_FOLDER = PATH_APP 88 180 SAS_OPENCL = custom_config.SAS_OPENCL 89 181 except: … … 100 192 DEFAULT_PERSPECTIVE = None 101 193 CLEANUP_PLOT = False 102 DEFAULT_OPEN_FOLDER = get_app_dir()103 194 DEFAULT_OPEN_FOLDER = PATH_APP 104 195 SAS_OPENCL = None … … 137 228 CHILD_FRAME = wx.Frame 138 229 230 #Initiliaze enviromental variable with custom setting but only if variable not set 231 if SAS_OPENCL and not "SAS_OPENCL" in os.environ: 232 os.environ["SAS_OPENCL"] = SAS_OPENCL 233 139 234 class ViewerFrame(PARENT_FRAME): 140 235 """ … … 170 265 if os.path.isfile(ico_file): 171 266 self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) 172 self.path = get_app_dir()267 self.path = PATH_APP 173 268 self.application_name = APPLICATION_NAME 174 269 # Application manager … … 445 540 try: 446 541 fd = open(file_name, 'w') 447 except Exception:542 except: 448 543 # On Permission denied: IOError 449 temp_dir = get_user_dir ()544 temp_dir = get_user_directory() 450 545 temp_file_name = os.path.join(temp_dir, name) 451 546 fd = open(temp_file_name, 'w') … … 1437 1532 # want Analysis. This is NOT an issue on the Mac which does not 1438 1533 # have the extra Window menu item. 1439 # March 2016 Code Camp -- PDB 1534 # March 2016 Code Camp -- PDB 1440 1535 Tools_pos = self._menubar.FindMenu("Tools") 1441 1536 self._menubar.Insert(Tools_pos+1, self._applications_menu, … … 2068 2163 logger.info("Failed to connect to www.sasview.org") 2069 2164 self._process_version(version_info, standalone=event is None) 2070 2071 2165 2072 2166 def _process_version(self, version_info, standalone=True): … … 3257 3351 if basename.lower() in [app_py, app_exe, app_app, app_base]: 3258 3352 data_base = sys.argv[1] 3259 input_file = os.path.normpath(os.path.join( get_app_dir(),3353 input_file = os.path.normpath(os.path.join(DATAPATH, 3260 3354 data_base)) 3261 3355 if input_file is None: … … 3272 3366 # do it only the first time app loaded 3273 3367 # delete unused model folder 3274 model_folder = os.path.join( get_app_dir(), path)3368 model_folder = os.path.join(PATH_APP, path) 3275 3369 if os.path.exists(model_folder) and os.path.isdir(model_folder): 3276 3370 if len(os.listdir(model_folder)) > 0:
Note: See TracChangeset
for help on using the changeset viewer.