Changeset 94ee68c in sasview for src/sas/sasgui/guiframe
- Timestamp:
- Oct 7, 2016 5:25:17 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:
- 1efba268
- Parents:
- 1f648cf8 (diff), 212bfc2 (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/guiframe
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/CategoryInstaller.py
r50008e3 r212bfc2 11 11 import os 12 12 import sys 13 import shutil14 13 import json 15 from collections import defaultdict 14 import logging 15 from collections import defaultdict, OrderedDict 16 16 17 17 USER_FILE = 'categories.json' … … 23 23 Note - class is entirely static! 24 24 """ 25 26 25 27 26 def __init__(self): … … 43 42 import sas.sasgui.perspectives.fitting.models 44 43 return sas.sasgui.perspectives.fitting.models.get_model_python_path() 45 44 46 45 @staticmethod 47 46 def _get_default_cat_file_dir(): … … 54 53 import sas.sasview 55 54 cat_file = "default_categories.json" 56 55 57 56 possible_cat_file_paths = [ 58 57 os.path.join(os.path.split(sas.sasview.__file__)[0], cat_file), # Source … … 64 63 if os.path.isfile(path): 65 64 return os.path.dirname(path) 66 65 67 66 raise RuntimeError('CategoryInstaller: Could not find folder containing default categories') 68 67 … … 89 88 by_model_dict[model].append(category) 90 89 model_enabled_dict[model] = enabled 91 90 92 91 return (by_model_dict, model_enabled_dict) 93 94 92 95 93 @staticmethod … … 105 103 master_category_dict[category].append(\ 106 104 (model, model_enabled_dict[model])) 107 108 return master_category_dict 105 return OrderedDict(sorted(master_category_dict.items(), key=lambda t: t[0])) 109 106 110 107 @staticmethod … … 113 110 returns the user data file, eg .sasview/categories.json.json 114 111 """ 115 return os.path.join(CategoryInstaller._get_home_dir(), 116 USER_FILE) 112 return os.path.join(CategoryInstaller._get_home_dir(), USER_FILE) 117 113 118 114 @staticmethod 119 115 def get_default_file(): 120 """ 121 returns the path of the default file 122 e.g. blahblah/default_categories.json 123 """ 124 return os.path.join(\ 125 CategoryInstaller._get_default_cat_file_dir(), "default_categories.json") 126 116 logging.warning("CategoryInstaller.get_default_file is deprecated.") 117 127 118 @staticmethod 128 119 def check_install(homedir = None, model_list=None): … … 134 125 :param model_list: List of model names except customized models 135 126 """ 136 #model_list = [] 137 default_file = CategoryInstaller.get_default_file() 127 _model_dict = { model.name: model for model in model_list} 128 _model_list = _model_dict.keys() 129 138 130 serialized_file = None 139 master_category_dict = defaultdict(list)140 131 if homedir == None: 141 132 serialized_file = CategoryInstaller.get_user_file() … … 143 134 serialized_file = os.path.join(homedir, USER_FILE) 144 135 if os.path.isfile(serialized_file): 145 cat_file = open(serialized_file, 'rb') 136 with open(serialized_file, 'rb') as f: 137 master_category_dict = json.load(f) 146 138 else: 147 cat_file = open(default_file, 'rb') 148 master_category_dict = json.load(cat_file) 149 # master_category_dict = pickle.Unpickler(cat_file).load() 139 master_category_dict = defaultdict(list) 140 150 141 (by_model_dict, model_enabled_dict) = \ 151 142 CategoryInstaller._regenerate_model_dict(master_category_dict) 152 cat_file.close() 153 add_list = model_list 143 add_list = _model_list 154 144 del_name = False 155 145 for cat in master_category_dict.keys(): 156 146 for ind in range(len(master_category_dict[cat])): 157 147 model_name, enabled = master_category_dict[cat][ind] 158 if model_name not in model_list:148 if model_name not in _model_list: 159 149 del_name = True 160 150 try: … … 162 152 model_enabled_dict.pop(model_name) 163 153 except: 164 pass154 logging.error("CategoryInstaller: %s", sys.exc_value) 165 155 else: 166 156 add_list.remove(model_name) … … 168 158 for model in add_list: 169 159 model_enabled_dict[model]= True 170 by_model_dict[model].append('Uncategorized') 171 160 if _model_dict[model].category is None or len(str(_model_dict[model].category.capitalize())) == 0: 161 by_model_dict[model].append('Uncategorized') 162 else: 163 category = _model_dict[model].category 164 toks = category.split(':') 165 category = toks[-1] 166 toks = category.split('-') 167 capitalized_words = [t.capitalize() for t in toks] 168 category = ' '.join(capitalized_words) 169 170 by_model_dict[model].append(category) 171 172 172 master_category_dict = \ 173 173 CategoryInstaller._regenerate_master_dict(by_model_dict, 174 174 model_enabled_dict) 175 176 json.dump( master_category_dict, 177 open(serialized_file, 'wb') ) 175 176 json.dump(master_category_dict, open(serialized_file, 'wb')) -
src/sas/sasgui/guiframe/CategoryManager.py
r80b1df3 r212bfc2 13 13 import sys 14 14 import os 15 import logging 15 16 from wx.lib.mixins.listctrl import CheckListCtrlMixin, ListCtrlAutoWidthMixin 16 17 from collections import defaultdict … … 366 367 """ 367 368 try: 368 file = CategoryInstaller.get_user_file() 369 if os.path.isfile(file): 370 cat_file = open(file, 'rb') 371 # self.master_category_dict = pickle.load(cat_file) 372 self.master_category_dict = json.load(cat_file) 373 else: 374 cat_file = open(CategoryInstaller.get_default_file(), 'rb') 375 # self.master_category_dict = pickle.load(cat_file) 376 self.master_category_dict = json.load(cat_file) 377 cat_file.close() 369 cat_file = CategoryInstaller.get_user_file() 370 self.master_category_dict = {} 371 if os.path.isfile(cat_file): 372 with open(cat_file, 'rb') as f: 373 self.master_category_dict = json.load(f) 378 374 except IOError: 379 print 'Problem reading in category file. Please review' 380 375 logging.error('Problem reading in category file.') 381 376 382 377 self._regenerate_model_dict() -
src/sas/sasgui/guiframe/customdir.py
rd85c194 r212bfc2 1 1 # Setup and find Custom config dir 2 import sys3 2 import os.path 4 3 import shutil 5 from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller6 4 7 5 CONF_DIR = 'config' … … 12 10 Find and return user/.sasview dir 13 11 """ 14 dir = os.path.join(os.path.expanduser("~"), 15 ("." + APPLICATION_NAME)) 16 return dir 12 return os.path.join(os.path.expanduser("~"), ("." + APPLICATION_NAME)) 17 13 18 14 def _find_customconf_dir(): … … 22 18 """ 23 19 u_dir = _find_usersasview_dir() 24 dir = os.path.join(u_dir, CONF_DIR) 25 26 return dir 20 return os.path.join(u_dir, CONF_DIR) 27 21 28 22 def _setup_conf_dir(path): … … 30 24 Setup the custom config dir and cat file 31 25 """ 32 dir = _find_customconf_dir()26 conf_dir = _find_customconf_dir() 33 27 # 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") 37 cat_file = CategoryInstaller.get_user_file() 38 # If the user category file doesn't exist copy the default to 39 # the user directory 40 if not os.path.isfile(cat_file): 41 try: 42 default_cat_file = CategoryInstaller.get_default_file() 43 if os.path.isfile(default_cat_file): 44 shutil.copyfile(default_cat_file, cat_file) 45 else: 46 print "Unable to find/copy default cat file" 47 except: 48 print "Unable to copy default cat file to the user dir." 28 if not os.path.isdir(conf_dir): 29 os.makedirs(conf_dir) 30 config_file = os.path.join(conf_dir, "custom_config.py") 49 31 50 32 # Place example user models as needed 51 33 try: 52 if not os.path.isfile( file):53 shutil.copyfile(os.path.join(path, "custom_config.py"),file)34 if not os.path.isfile(config_file): 35 shutil.copyfile(os.path.join(path, "custom_config.py"), config_file) 54 36 except: 55 37 # Check for data path next to exe/zip file. … … 63 45 temp_path = os.path.join(f_dir, "custom_config.py") 64 46 if os.path.isfile(temp_path): 65 shutil.copyfile(temp_path, file)47 shutil.copyfile(temp_path, config_file) 66 48 is_dir = True 67 49 break 68 50 if not is_dir: 69 51 raise 70 71 return dir 72 73 52 return conf_dir 53 54 74 55 class SetupCustom(object): 75 56 """ … … 81 62 def setup_dir(self, path): 82 63 return _setup_conf_dir(path) 83 84 85 86 87 -
src/sas/sasgui/guiframe/data_panel.py
re767897 r998ca90 890 890 891 891 892 def on_remove(self, event ):892 def on_remove(self, event, msg=""): 893 893 """ 894 894 Get a list of item checked and remove them from the treectrl 895 895 Ask the parent to remove reference to this item 896 896 """ 897 msg = "This operation will delete the data sets checked " 898 msg += "and all the dependents." 897 if msg == "": 898 msg = "This operation will delete the data sets checked " 899 msg += "and all the dependents." 899 900 msg_box = wx.MessageDialog(None, msg, 'Warning', wx.OK|wx.CANCEL) 900 901 if msg_box.ShowModal() != wx.ID_OK: 901 return 902 return True 902 903 903 904 data_to_remove, theory_to_remove, _ = self.set_data_helper() -
src/sas/sasgui/guiframe/gui_manager.py
radb0851 r95eef00 1152 1152 self.delete_panel(ID) 1153 1153 break 1154 self.cpanel_on_focus.SetFocus() 1154 if self.cpanel_on_focus is not None: 1155 self.cpanel_on_focus.SetFocus() 1155 1156 1156 1157 … … 1907 1908 if self._default_save_location == None: 1908 1909 self._default_save_location = os.getcwd() 1909 wx.PostEvent(self, StatusEvent(status="Loading Project file...")) 1910 dlg = wx.FileDialog(self, 1910 msg = "This operation will set SasView to its freshly opened state " 1911 msg += "before loading the project. Do you wish to continue?" 1912 if not self._data_panel.on_remove(None, msg): 1913 wx.PostEvent(self, StatusEvent(status="Loading Project file...")) 1914 dlg = wx.FileDialog(self, 1911 1915 "Choose a file", 1912 1916 self._default_save_location, "", 1913 1917 APPLICATION_WLIST) 1914 if dlg.ShowModal() == wx.ID_OK:1915 path = dlg.GetPath()1918 if dlg.ShowModal() == wx.ID_OK: 1919 path = dlg.GetPath() 1916 1920 if path is not None: 1917 1921 self._default_save_location = os.path.dirname(path) 1918 dlg.Destroy() 1919 1920 self.load_state(path=path, is_project=True) 1922 dlg.Destroy() 1923 # Reset to a base state 1924 self._on_reset_state() 1925 # Load the project file 1926 self.load_state(path=path, is_project=True) 1927 1928 def _on_reset_state(self): 1929 """ 1930 Resets SasView to its freshly opened state. 1931 :return: None 1932 """ 1933 # Reset all plugins to their base state 1934 self._data_panel.set_panel_on_focus() 1935 # Remove all loaded data 1936 self._data_panel.selection_cbox.SetValue('Select all Data') 1937 self._data_panel._on_selection_type(None) 1938 for plugin in self.plugins: 1939 plugin.clear_panel() 1940 # Reset plot number to 0 1941 self.graph_num = 0 1921 1942 1922 1943 def _on_save_application(self, event): … … 2066 2087 except: 2067 2088 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) 2089 self._process_version(version_info, standalone=event == None) 2084 2090 2085 2091 def _process_version(self, version_info, standalone=True):
Note: See TracChangeset
for help on using the changeset viewer.