Changeset 80c2c85 in sasview for src/sas/sasgui
- Timestamp:
- Jun 28, 2016 5:10:33 PM (9 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:
- 3aa2f3c
- Parents:
- 899e084 (diff), 5552396 (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. - Location:
- src/sas/sasgui
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/basepage.py
r7673ecd r6ed67db 202 202 self.state_change = False 203 203 ## save customized array 204 self.values = []205 self.weights = []204 self.values = {} # type: Dict[str, List[float, ...]] 205 self.weights = {} # type: Dict[str, List[float, ...]] 206 206 ## retrieve saved state 207 207 self.number_saved_state = 0 … … 2588 2588 self._draw_model() 2589 2589 self.Refresh() 2590 except: 2590 except Exception: 2591 logging.error(traceback.format_exc()) 2591 2592 # Error msg 2592 2593 msg = "Error occurred:" … … 2680 2681 # Try to delete values and weight of the names array dic if exists 2681 2682 try: 2682 del self.values[name] 2683 del self.weights[name] 2684 # delete all other dic 2685 del self.state.values[name] 2686 del self.state.weights[name] 2687 del self.model._persistency_dict[name.split('.')[0]] 2688 del self.state.model._persistency_dict[name.split('.')[0]] 2683 if name in self.values: 2684 del self.values[name] 2685 del self.weights[name] 2686 # delete all other dic 2687 del self.state.values[name] 2688 del self.state.weights[name] 2689 del self.model._persistency_dict[name.split('.')[0]] 2690 del self.state.model._persistency_dict[name.split('.')[0]] 2689 2691 except Exception: 2690 2692 logging.error(traceback.format_exc()) -
src/sas/sasgui/__init__.py
rd7bb526 refe730d 1 import os 2 3 # Set up config directories 4 def make_user_folder(): 5 path = os.path.join(os.path.expanduser("~"),'.sasview') 6 if not os.path.exists(path): 7 os.mkdir(path) 8 return path 9 10 def find_app_folder(): 11 # If the directory containing sasview.py exists, then we are not running 12 # frozen and the current path is the app path. 13 root = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 14 path = os.path.join(root, 'sasview') 15 if os.path.exists(path): 16 return path 17 18 # If we are running frozen, then skip from: 19 # library.zip/sas/sasview 20 path = os.path.dirname(os.path.dirname(root)) 21 return path 22 23 USER_FOLDER = make_user_folder() 24 APP_FOLDER = find_app_folder() 25 26 27 28 def get_app_dir(): 29 if APP_FOLDER is None: 30 raise RuntimeError("Need to initialize sas.sasgui.USER_FOLDER") 31 return APP_FOLDER 32 33 def get_user_dir(): 34 if USER_FOLDER is None: 35 raise RuntimeError("Need to initialize sas.sasgui.USER_FOLDER") 36 return USER_FOLDER 37 38 _config_cache = None 39 def get_local_config(): 40 global _config_cache 41 if not _config_cache: 42 _config_cache = _load_config() 43 return _config_cache 44 45 def _load_config(): 46 import os 47 import sys 48 import imp 49 import logging 50 51 dirname = get_app_dir() 52 filename = 'local_config.py' 53 path = os.path.join(dirname, filename) 54 if os.path.exists(path): 55 try: 56 fObj = None 57 fObj, config_path, descr = imp.find_module('local_config', [APP_FOLDER]) 58 config = imp.load_module('local_config', fObj, config_path, descr) 59 logging.info("GuiManager loaded %s" % config_path) 60 return config 61 except Exception: 62 import traceback; logging.error(traceback.format_exc()) 63 logging.error("Error loading %s: %s" % (path, sys.exc_value)) 64 finally: 65 if fObj is not None: 66 fObj.close() 67 from sas.sasgui.guiframe import config 68 logging.info("GuiManager config defaults to sas.sasgui.guiframe") 69 return config -
src/sas/sasgui/guiframe/CategoryInstaller.py
r50008e3 refe730d 11 11 import os 12 12 import sys 13 import shutil14 13 import json 15 14 from collections import defaultdict 15 16 from sas.sasgui import get_user_dir 16 17 17 18 USER_FILE = 'categories.json' … … 68 69 69 70 @staticmethod 70 def _get_home_dir():71 """72 returns the users sasview config dir73 """74 return os.path.join(os.path.expanduser("~"), ".sasview")75 76 @staticmethod77 71 def _regenerate_model_dict(master_category_dict): 78 72 """ … … 113 107 returns the user data file, eg .sasview/categories.json.json 114 108 """ 115 return os.path.join(CategoryInstaller._get_home_dir(), 116 USER_FILE) 109 return os.path.join(get_user_dir(), USER_FILE) 117 110 118 111 @staticmethod -
src/sas/sasgui/guiframe/aboutbox.py
rd85c194 refe730d 24 24 import os.path 25 25 import os 26 try: 27 # Try to find a local config 28 import imp 29 path = os.getcwd() 30 if(os.path.isfile("%s/%s.py" % (path, 'local_config'))) or \ 31 (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))): 32 fObj, path, descr = imp.find_module('local_config', [path]) 33 config = imp.load_module('local_config', fObj, path, descr) 34 else: 35 # Try simply importing local_config 36 import local_config as config 37 except: 38 # Didn't find local config, load the default 39 import config 26 27 from sas.sasgui import get_local_config 28 config = get_local_config() 40 29 41 30 def launchBrowser(url): -
src/sas/sasgui/guiframe/acknowledgebox.py
rd85c194 refe730d 8 8 __revision__ = "$Revision: 1193 $" 9 9 10 import os 11 10 12 import wx 11 13 import wx.richtext 12 14 import wx.lib.hyperlink 13 import random14 import os.path15 import os16 try:17 # Try to find a local config18 import imp19 path = os.getcwd()20 if(os.path.isfile("%s/%s.py" % (path, 'local_config'))) or \21 (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))):22 fObj, path, descr = imp.find_module('local_config', [path])23 config = imp.load_module('local_config', fObj, path, descr)24 else:25 # Try simply importing local_config26 import local_config as config27 except:28 # Didn't find local config, load the default29 import config30 15 16 from sas.sasgui import get_local_config 17 config = get_local_config() 31 18 32 19 class DialogAcknowledge(wx.Dialog): -
src/sas/sasgui/guiframe/config.py
rd85c194 refe730d 125 125 (StatusBarEvent, EVT_STATUS) = wx.lib.newevent.NewEvent() 126 126 127 # Time out for updating sasview 128 UPDATE_TIMEOUT = 2 129 127 130 def printEVT(message): 128 131 """ -
src/sas/sasgui/guiframe/customdir.py
rd85c194 refe730d 1 1 # Setup and find Custom config dir 2 2 import sys 3 import imp 3 4 import os.path 5 import logging 4 6 import shutil 7 5 8 from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller 9 from sas.sasgui import get_user_dir, get_app_dir 6 10 7 CONF_DIR = 'config' 8 APPLICATION_NAME = 'sasview' 11 def get_custom_config_path(): 12 dirname = os.path.join(get_user_dir(), 'config') 13 # If the directory doesn't exist, create it 14 if not os.path.exists(dirname): 15 os.makedirs(dirname) 16 path = os.path.join(dirname, "custom_config.py") 17 return path 9 18 10 def _find_usersasview_dir():11 """12 Find and return user/.sasview dir13 """14 dir = os.path.join(os.path.expanduser("~"),15 ("." + APPLICATION_NAME))16 return dir17 19 18 def _find_customconf_dir(): 19 """ 20 Find path of the config directory. 21 The plugin directory is located in the user's home directory. 22 """ 23 u_dir = _find_usersasview_dir() 24 dir = os.path.join(u_dir, CONF_DIR) 25 26 return dir 27 28 def _setup_conf_dir(path): 20 _config_cache = None 21 def setup_custom_config(): 29 22 """ 30 23 Setup the custom config dir and cat file 31 24 """ 32 dir = _find_customconf_dir() 33 # If the plugin directory doesn't exist, create it 34 if not os.path.isdir(dir): 35 os.makedirs(dir) 36 file = os.path.join(dir, "custom_config.py") 25 global _config_cache 26 if not _config_cache: 27 _config_cache = _setup_custom_config() 28 return _config_cache 29 30 31 def _setup_custom_config(): 32 path = get_custom_config_path() 33 if not os.path.isfile(path): 34 # if the custom config file does not exist, copy the default from 35 # the app dir 36 try: 37 shutil.copyfile(os.path.join(get_app_dir(), "custom_config.py"), 38 path) 39 except Exception: 40 #import traceback; logging.error(traceback.format_exc()) 41 logging.error("Could not copy default custom config.") 42 43 custom_config = _load_config(path) 44 37 45 cat_file = CategoryInstaller.get_user_file() 38 46 # If the user category file doesn't exist copy the default to … … 44 52 shutil.copyfile(default_cat_file, cat_file) 45 53 else: 46 print "Unable to find/copy default cat file"47 except :48 print "Unable to copy default cat file to the user dir."54 logging.error("Unable to find/copy default cat file") 55 except Exception: 56 logging.error("Unable to copy default cat file to the user dir.") 49 57 50 # Place example user models as needed 51 try: 52 if not os.path.isfile(file): 53 shutil.copyfile(os.path.join(path, "custom_config.py"), file) 54 except: 55 # Check for data path next to exe/zip file. 56 #Look for maximum n_dir up of the current dir to find plugins dir 57 n_dir = 12 58 is_dir = False 59 f_dir = path 60 for i in range(n_dir): 61 if i > 1: 62 f_dir, _ = os.path.split(f_dir) 63 temp_path = os.path.join(f_dir, "custom_config.py") 64 if os.path.isfile(temp_path): 65 shutil.copyfile(temp_path, file) 66 is_dir = True 67 break 68 if not is_dir: 69 raise 70 71 return dir 72 73 74 class SetupCustom(object): 75 """ 76 implement custom config dir 77 """ 78 def find_dir(self): 79 return _find_customconf_dir() 80 81 def setup_dir(self, path): 82 return _setup_conf_dir(path) 83 58 return custom_config 84 59 85 86 87 60 61 def _load_config(path): 62 if os.path.exists(path): 63 try: 64 fObj = None 65 fObj, config_path, descr = imp.find_module('custom_config', [os.path.dirname(path)]) 66 custom_config = imp.load_module('custom_config', fObj, config_path, descr) 67 logging.info("GuiManager loaded %s" % config_path) 68 return custom_config 69 except Exception: 70 logging.error("Error loading %s: %s" % (path, sys.exc_value)) 71 finally: 72 if fObj is not None: 73 fObj.close() 74 from sas.sasview import custom_config 75 logging.info("GuiManager custom_config defaults to sas.sasview.custom_config") 76 return custom_config -
src/sas/sasgui/guiframe/documentation_window.py
rd85c194 refe730d 16 16 import os 17 17 import logging 18 import urllib 19 20 import webbrowser 18 21 import wx 19 import webbrowser 20 import urllib 21 import sys 22 23 from sas.sasgui import get_app_dir 22 24 23 25 SPHINX_DOC_ENV = "SASVIEW_DOC_PATH" … … 27 29 except: 28 30 WX_SUPPORTS_HTML2 = False 29 30 31 from gui_manager import get_app_dir32 31 33 32 -
src/sas/sasgui/guiframe/gui_manager.py
rc8a641e8 refe730d 23 23 warnings.simplefilter("ignore") 24 24 import logging 25 import httplib26 25 import traceback 27 26 import urllib 28 import urllib229 27 import json 30 28 29 from matplotlib import _pylab_helpers 30 31 from sas.sasgui import get_local_config, get_app_dir, get_user_dir 31 32 from sas.sasgui.guiframe.events import EVT_CATEGORY 32 33 from sas.sasgui.guiframe.events import EVT_STATUS … … 47 48 from sas.sascalc.dataloader.loader import Loader 48 49 from sas.sasgui.guiframe.proxy import Connection 49 from matplotlib import _pylab_helpers 50 51 52 def get_app_dir(): 53 """ 54 The application directory is the one where the default custom_config.py 55 file resides. 56 57 :returns: app_path - the path to the applicatin directory 58 """ 59 # First, try the directory of the executable we are running 60 app_path = sys.path[0] 61 if os.path.isfile(app_path): 62 app_path = os.path.dirname(app_path) 63 if os.path.isfile(os.path.join(app_path, "custom_config.py")): 64 app_path = os.path.abspath(app_path) 65 logging.info("Using application path: %s", app_path) 66 return app_path 67 68 # Next, try the current working directory 69 if os.path.isfile(os.path.join(os.getcwd(), "custom_config.py")): 70 logging.info("Using application path: %s", os.getcwd()) 71 return os.path.abspath(os.getcwd()) 72 73 # Finally, try the directory of the sasview module 74 # TODO: gui_manager will have to know about sasview until we 75 # clean all these module variables and put them into a config class 76 # that can be passed by sasview.py. 77 logging.info(sys.executable) 78 logging.info(str(sys.argv)) 79 from sas import sasview as sasview 80 app_path = os.path.dirname(sasview.__file__) 81 logging.info("Using application path: %s", app_path) 82 return app_path 83 84 def get_user_directory(): 85 """ 86 Returns the user's home directory 87 """ 88 userdir = os.path.join(os.path.expanduser("~"), ".sasview") 89 if not os.path.isdir(userdir): 90 os.makedirs(userdir) 91 return userdir 92 93 def _find_local_config(file, path): 94 """ 95 Find configuration file for the current application 96 """ 97 config_module = None 98 fObj = None 99 try: 100 fObj, path_config, descr = imp.find_module(file, [path]) 101 config_module = imp.load_module(file, fObj, path_config, descr) 102 except: 103 logging.error("Error loading %s/%s: %s" % (path, file, sys.exc_value)) 104 finally: 105 if fObj is not None: 106 fObj.close() 107 logging.info("GuiManager loaded %s/%s" % (path, file)) 108 return config_module 109 110 # Get APP folder 111 PATH_APP = get_app_dir() 112 DATAPATH = PATH_APP 113 114 # GUI always starts from the App folder 115 #os.chdir(PATH_APP) 116 # Read in the local config, which can either be with the main 117 # application or in the installation directory 118 config = _find_local_config('local_config', PATH_APP) 119 if config is None: 120 config = _find_local_config('local_config', os.getcwd()) 121 if config is None: 122 # Didn't find local config, load the default 123 import sas.sasgui.guiframe.config as config 124 logging.info("using default local_config") 125 else: 126 logging.info("found local_config in %s" % os.getcwd()) 127 else: 128 logging.info("found local_config in %s" % PATH_APP) 129 130 from sas.sasgui.guiframe.customdir import SetupCustom 131 c_conf_dir = SetupCustom().setup_dir(PATH_APP) 132 custom_config = _find_local_config('custom_config', c_conf_dir) 133 if custom_config is None: 134 custom_config = _find_local_config('custom_config', os.getcwd()) 135 if custom_config is None: 136 msgConfig = "Custom_config file was not imported" 137 logging.info(msgConfig) 138 else: 139 logging.info("using custom_config in %s" % os.getcwd()) 140 else: 141 logging.info("using custom_config from %s" % c_conf_dir) 50 from sas.sasgui.guiframe.customdir import setup_custom_config 51 52 config = get_local_config() 53 custom_config = setup_custom_config() 142 54 143 55 #read some constants from config … … 172 84 DEFAULT_OPEN_FOLDER = os.path.abspath(open_folder) 173 85 else: 174 DEFAULT_OPEN_FOLDER = PATH_APP86 DEFAULT_OPEN_FOLDER = get_app_dir() 175 87 except: 176 88 DATALOADER_SHOW = True … … 186 98 DEFAULT_PERSPECTIVE = None 187 99 CLEANUP_PLOT = False 188 DEFAULT_OPEN_FOLDER = PATH_APP100 DEFAULT_OPEN_FOLDER = get_app_dir() 189 101 190 102 DEFAULT_STYLE = config.DEFAULT_STYLE … … 254 166 if os.path.isfile(ico_file): 255 167 self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) 256 self.path = PATH_APP168 self.path = get_app_dir() 257 169 self.application_name = APPLICATION_NAME 258 170 ## Application manager … … 525 437 try: 526 438 fd = open(file_name, 'w') 527 except :439 except Exception: 528 440 # On Permission denied: IOError 529 temp_dir = get_user_dir ectory()441 temp_dir = get_user_dir() 530 442 temp_file_name = os.path.join(temp_dir, name) 531 443 fd = open(temp_file_name, 'w') … … 2061 1973 2062 1974 2063 # 1975 # import urllib2 2064 1976 # try: 2065 1977 # req = urllib2.Request(config.__update_URL__) … … 3253 3165 if basename.lower() in [app_py, app_exe, app_app, app_base]: 3254 3166 data_base = sys.argv[1] 3255 input_file = os.path.normpath(os.path.join( DATAPATH,3167 input_file = os.path.normpath(os.path.join(get_app_dir(), 3256 3168 data_base)) 3257 3169 if input_file is None: … … 3268 3180 # do it only the first time app loaded 3269 3181 # delete unused model folder 3270 model_folder = os.path.join( PATH_APP, path)3182 model_folder = os.path.join(get_app_dir(), path) 3271 3183 if os.path.exists(model_folder) and os.path.isdir(model_folder): 3272 3184 if len(os.listdir(model_folder)) > 0: -
src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py
rfaa3ae7 refe730d 9 9 10 10 from sas.sascalc.dataloader.loader import Loader 11 12 from sas.sasgui import get_local_config 11 13 from sas.sasgui.guiframe.plugin_base import PluginBase 12 14 from sas.sasgui.guiframe.events import StatusEvent 13 15 from sas.sasgui.guiframe.gui_style import GUIFRAME 14 16 from sas.sasgui.guiframe.gui_manager import DEFAULT_OPEN_FOLDER 15 try: 16 # Try to find a local config 17 import imp 18 path = os.getcwd() 19 if(os.path.isfile("%s/%s.py" % (path, 'local_config'))) or \ 20 (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))): 21 fObj, path, descr = imp.find_module('local_config', [path]) 22 config = imp.load_module('local_config', fObj, path, descr) 23 else: 24 # Try simply importing local_config 25 import local_config as config 26 except: 27 # Didn't find local config, load the default 28 import sas.sasgui.guiframe.config as config 29 30 if config is None: 31 import sas.sasgui.guiframe.config as config 32 33 17 18 config = get_local_config() 34 19 extension_list = [] 35 20 if config.APPLICATION_STATE_EXTENSION is not None: -
src/sas/sasgui/guiframe/startup_configuration.py
rd85c194 refe730d 9 9 #copyright 2009, University of Tennessee 10 10 ################################################################################ 11 import os 12 import copy 13 11 14 import wx 12 import os 13 import sys 14 import copy 15 #import sas.sasgui.guiframe.gui_manager as gui 16 from sas.sasgui.guiframe.events import StatusEvent 15 16 from sas.sasgui.customdir import get_custom_config_path 17 17 from sas.sasgui.guiframe.gui_style import GUIFRAME 18 18 from sas.sasgui.guiframe import gui_manager as CURRENT 19 from sas.sasgui.guiframe.customdir import SetupCustom 19 20 20 21 # default configuration 21 22 DEFAULT_STRINGS = {'GUIFRAME_WIDTH':-1, … … 64 65 # parent 65 66 self.parent = parent 66 self.path = SetupCustom().find_dir()67 67 self._gui = gui 68 68 # font size … … 189 189 def write_custom_config(self): 190 190 """ 191 Write custom configuration 192 """ 193 fname = os.path.join(self.path, 'custom_config.py') 194 self.write_string(fname, self.return_string) 195 196 def write_string(self, fname, strings): 197 """ 198 Write and Save file 199 """ 200 201 try: 202 out_f = open(fname,'w') 203 except : 204 raise #RuntimeError, "Error: Can not change the configuration..." 205 out_f.write("#Application appearance custom configuration\n" ) 206 for key, item in strings.iteritems(): 207 if (key == 'DEFAULT_PERSPECTIVE') or \ 208 (key == 'DEFAULT_OPEN_FOLDER' and item != None): 209 out_f.write("%s = \"%s\"\n" % (key,str(item))) 210 else: 211 out_f.write("%s = %s\n" % (key,str(item))) 212 213 out_f.close() 214 191 Write custom configuration 192 """ 193 path = get_custom_config_path() 194 with open(path, 'w') as out_f: 195 out_f.write("#Application appearance custom configuration\n" ) 196 for key, item in self.return_string.iteritems(): 197 if (key == 'DEFAULT_PERSPECTIVE') or \ 198 (key == 'DEFAULT_OPEN_FOLDER' and item != None): 199 out_f.write("%s = \"%s\"\n" % (key,str(item))) 200 else: 201 out_f.write("%s = %s\n" % (key,str(item))) -
src/sas/sasgui/perspectives/fitting/models.py
r7673ecd refe730d 12 12 import py_compile 13 13 import shutil 14 from sasmodels.sasview_model import load_custom_model, load_standard_models 14 15 # Explicitly import from the pluginmodel module so that py2exe 15 16 # places it in the distribution. The Model1DPlugin class is used 16 17 # as the base class of plug-in models. 18 from sas.sasgui import get_user_dir 17 19 from sas.sascalc.fit.pluginmodel import Model1DPlugin 18 20 from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller 19 from sasmodels.sasview_model import load_custom_model, load_standard_models20 21 21 22 22 23 PLUGIN_DIR = 'plugin_models' 23 PLUGIN_LOG = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR, 24 "plugins.log") 24 PLUGIN_LOG = os.path.join(get_user_dir(), PLUGIN_DIR, "plugins.log") 25 25 26 26 def get_model_python_path(): -
src/sas/sasgui/plottools/__init__.py
rd7bb526 refe730d 1 import config2 1 from PlotPanel import PlotPanel 3 2 from plottables import Data1D, Theory1D
Note: See TracChangeset
for help on using the changeset viewer.