Changeset 2f4b430 in sasview for src/sas/perspectives/fitting/models.py
- Timestamp:
- Mar 4, 2015 3:39:45 PM (10 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, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 74f419d
- Parents:
- 2f732b0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/perspectives/fitting/models.py
r6f82ba1 r2f4b430 20 20 from sas.models.BaseComponent import BaseComponent 21 21 from sas.guiframe.CategoryInstaller import CategoryInstaller 22 22 23 23 PLUGIN_DIR = 'plugin_models' 24 24 … … 40 40 """ 41 41 Do some checking before model adding plugins in the list 42 42 43 43 :param model: class model to add into the plugin list 44 44 :param name:name of the module plugin 45 45 46 46 :return model: model if valid model or None if not valid 47 47 48 48 """ 49 49 #Check if the plugin is of type Model1DPlugin … … 63 63 log(msg) 64 64 return None 65 65 66 66 if hasattr(new_instance, "function"): 67 67 try: … … 77 77 return None 78 78 return model 79 80 79 80 81 81 def find_plugins_dir(): 82 82 """ … … 85 85 """ 86 86 dir = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR) 87 87 88 88 # If the plugin directory doesn't exist, create it 89 89 if not os.path.isdir(dir): 90 90 os.makedirs(dir) 91 91 92 92 # Find paths needed 93 93 try: … … 132 132 raise type, value, traceback 133 133 return 1 134 134 135 135 report_problem = ReportProblem() 136 136 … … 173 173 if toks[1] == '.py' and not toks[0] == '__init__': 174 174 name = toks[0] 175 175 176 176 path = [os.path.abspath(dir)] 177 177 file = None … … 194 194 log(msg) 195 195 finally: 196 196 197 197 if not file == None: 198 198 file.close() … … 213 213 """ 214 214 self.mydict = {} 215 215 216 216 def set_list(self, name, mylist): 217 217 """ 218 218 :param name: the type of the list 219 219 :param mylist: the list to add 220 220 221 221 """ 222 222 if name not in self.mydict.keys(): 223 223 self.reset_list(name, mylist) 224 224 225 225 def reset_list(self, name, mylist): 226 226 """ … … 229 229 """ 230 230 self.mydict[name] = mylist 231 231 232 232 def get_list(self): 233 233 """ … … 235 235 """ 236 236 return self.mydict 237 238 237 238 239 239 class ModelManagerBase: 240 240 """ … … 262 262 event_owner = None 263 263 last_time_dir_modified = 0 264 264 265 265 def __init__(self): 266 266 """ … … 269 269 self.stored_plugins = {} 270 270 self._getModelList() 271 271 272 272 def findModels(self): 273 273 """ … … 280 280 logging.info("pluging model : %s\n" % str(temp)) 281 281 return temp 282 282 283 283 def _getModelList(self): 284 284 """ 285 285 List of models we want to make available by default 286 286 for this application 287 287 288 288 :return: the next free event ID following the new menu events 289 289 290 290 """ 291 291 … … 702 702 # self.shape_indep_list.append(BEPolyelectrolyte) 703 703 self.model_name_list.append(BEPolyelectrolyte.__name__) 704 self.form_factor_dict[str(wx.NewId())] = 704 self.form_factor_dict[str(wx.NewId())] = [SphereModel] 705 705 except: 706 706 pass … … 1013 1013 #self.shape_indep_list.append(FractalO_Z) 1014 1014 #self.model_name_list.append(FractalO_Z.__name__) 1015 1015 1016 1016 #Looking for plugins 1017 1017 self.stored_plugins = self.findModels() … … 1019 1019 for name, plug in self.stored_plugins.iteritems(): 1020 1020 self.model_dictionary[name] = plug 1021 1021 1022 1022 self._get_multifunc_models() 1023 1023 1024 1024 return 0 1025 1025 … … 1036 1036 is_modified = True 1037 1037 self.last_time_dir_modified = temp 1038 1038 1039 1039 return is_modified 1040 1040 1041 1041 def update(self): 1042 1042 """ … … 1055 1055 else: 1056 1056 return {} 1057 1057 1058 1058 def pulgins_reset(self): 1059 1059 """ … … 1074 1074 self.model_combobox.reset_list("Customized Models", self.plugins) 1075 1075 return self.model_combobox.get_list() 1076 1076 1077 1077 ## I believe the next four methods are for the old form factor GUI 1078 1078 ## where the dropdown showed a list of categories which then rolled out … … 1101 1101 ## guiframe reference 1102 1102 # self.event_owner = event_owner 1103 1103 1104 1104 # shape_submenu = wx.Menu() 1105 1105 # shape_indep_submenu = wx.Menu() … … 1112 1112 # " simple shape"], 1113 1113 # list1=self.shape_list) 1114 1114 1115 1115 # self._fill_simple_menu(menuinfo=["Shape-Independent", 1116 1116 # shape_indep_submenu, 1117 1117 # "List of shape-independent models"], 1118 1118 # list1=self.shape_indep_list) 1119 1119 1120 1120 # self._fill_simple_menu(menuinfo=["Structure Factors", 1121 1121 # structure_factor, 1122 1122 # "List of Structure factors models"], 1123 1123 # list1=self.struct_list) 1124 1124 1125 1125 # self._fill_plugin_menu(menuinfo=["Customized Models", added_models, 1126 1126 # "List of additional models"], 1127 1127 # list1=self.plugins) 1128 1128 1129 1129 # self._fill_menu(menuinfo=["P(Q)*S(Q)", multip_models, 1130 1130 # "mulplication of 2 models"], … … 1132 1132 # list2=self.struct_list) 1133 1133 # return 0 1134 1134 1135 1135 # def _fill_plugin_menu(self, menuinfo, list1): 1136 1136 # """ … … 1143 1143 # menuinfo[1].Append(int(id), "Empty", msg) 1144 1144 # self._fill_simple_menu(menuinfo, list1) 1145 1145 1146 1146 # def _fill_simple_menu(self, menuinfo, list1): 1147 1147 # """ … … 1157 1157 # if len(list1) > 0: 1158 1158 # self.model_combobox.set_list(menuinfo[0], list1) 1159 1159 1160 1160 # for item in list1: 1161 1161 # try: … … 1217 1217 # id = wx.NewId() 1218 1218 # self.modelmenu.AppendMenu(id, menuinfo[0], menuinfo[1], menuinfo[2]) 1219 1219 1220 1220 def _on_model(self, evt): 1221 1221 """ 1222 1222 React to a model menu event 1223 1223 1224 1224 :param event: wx menu event 1225 1225 1226 1226 """ 1227 1227 if int(evt.GetId()) in self.form_factor_dict.keys(): … … 1232 1232 else: 1233 1233 model = self.struct_factor_dict[str(evt.GetId())]() 1234 1234 1235 1235 #TODO: investigate why the following two lines were left in the code 1236 1236 # even though the ModelEvent class doesn't exist 1237 1237 #evt = ModelEvent(model=model) 1238 1238 #wx.PostEvent(self.event_owner, evt) 1239 1239 1240 1240 def _get_multifunc_models(self): 1241 1241 """ … … 1250 1250 # pass to other items 1251 1251 pass 1252 1252 1253 1253 def get_model_list(self): 1254 1254 """ 1255 1255 return dictionary of models for fitpanel use 1256 1256 1257 1257 """ 1258 1258 ## Model_list now only contains attribute lists not category list. … … 1263 1263 ## 1264 1264 ## -PDB April 26, 2014 1265 1265 1266 1266 # self.model_combobox.set_list("Shapes", self.shape_list) 1267 1267 # self.model_combobox.set_list("Shape-Independent", … … 1274 1274 self.model_combobox.set_list("Multi-Functions", self.multi_func_list) 1275 1275 return self.model_combobox.get_list() 1276 1276 1277 1277 def get_model_name_list(self): 1278 1278 """ … … 1286 1286 """ 1287 1287 return self.model_dictionary 1288 1289 1288 1289 1290 1290 class ModelManager(object): 1291 1291 """ … … 1300 1300 def findModels(self): 1301 1301 return self.__modelmanager.findModels() 1302 1302 1303 1303 def _getModelList(self): 1304 1304 return self.__modelmanager._getModelList() 1305 1305 1306 1306 def is_changed(self): 1307 1307 return self.__modelmanager.is_changed() 1308 1308 1309 1309 def update(self): 1310 1310 return self.__modelmanager.update() 1311 1311 1312 1312 def pulgins_reset(self): 1313 1313 return self.__modelmanager.pulgins_reset() 1314 1314 1315 1315 def populate_menu(self, modelmenu, event_owner): 1316 1316 return self.__modelmanager.populate_menu(modelmenu, event_owner) 1317 1317 1318 1318 def _on_model(self, evt): 1319 1319 return self.__modelmanager._on_model(evt) 1320 1320 1321 1321 def _get_multifunc_models(self): 1322 1322 return self.__modelmanager._get_multifunc_models() 1323 1323 1324 1324 def get_model_list(self): 1325 1325 return self.__modelmanager.get_model_list() 1326 1326 1327 1327 def get_model_name_list(self): 1328 1328 return self.__modelmanager.get_model_name_list()
Note: See TracChangeset
for help on using the changeset viewer.