Changeset f80b416e in sasview for src/sas/sasgui/perspectives/fitting/models.py
- Timestamp:
- Sep 20, 2017 12:21:41 PM (7 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:
- fca1f50
- Parents:
- 2746eab (diff), ce0a245 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/models.py
rb1c2011 r13374be 14 14 import py_compile 15 15 import shutil 16 from copy import copy 16 17 # Explicitly import from the pluginmodel module so that py2exe 17 18 # places it in the distribution. The Model1DPlugin class is used … … 20 21 from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller 21 22 from sasmodels.sasview_model import load_custom_model, load_standard_models 23 from sas.sasgui.perspectives.fitting.fitpage import CUSTOM_MODEL 22 24 23 25 logger = logging.getLogger(__name__) … … 265 267 temp = {} 266 268 if self.is_changed(): 267 return _find_models() 269 temp = _find_models() 270 self.last_time_dir_modified = time.time() 271 return temp 268 272 logger.info("plugin model : %s" % str(temp)) 269 273 return temp … … 278 282 """ 279 283 280 # regular model names only284 # Regular model names only 281 285 self.model_name_list = [] 282 286 283 # Build list automagically from sasmodels package287 # Build list automagically from sasmodels package 284 288 for model in load_standard_models(): 285 289 self.model_dictionary[model.name] = model … … 293 297 self.model_name_list.append(model.name) 294 298 295 # Looking for plugins299 # Looking for plugins 296 300 self.stored_plugins = self.findModels() 297 301 self.plugins = self.stored_plugins.values() 298 302 for name, plug in self.stored_plugins.iteritems(): 299 303 self.model_dictionary[name] = plug 304 # TODO: Remove 'hasattr' statements when old style plugin models 305 # are no longer supported. All sasmodels models will have 306 # the required attributes. 307 if hasattr(plug, 'is_structure_factor') and plug.is_structure_factor: 308 self.struct_list.append(plug) 309 self.plugins.remove(plug) 310 elif hasattr(plug, 'is_form_factor') and plug.is_form_factor: 311 self.multiplication_factor.append(plug) 312 if hasattr(plug, 'is_multiplicity_model') and plug.is_multiplicity_model: 313 self.multi_func_list.append(plug) 300 314 301 315 self._get_multifunc_models() … … 312 326 if os.path.isdir(plugin_dir): 313 327 temp = os.path.getmtime(plugin_dir) 314 if self.last_time_dir_modified !=temp:328 if self.last_time_dir_modified < temp: 315 329 is_modified = True 316 330 self.last_time_dir_modified = temp … … 323 337 new models were added else return empty dictionary 324 338 """ 339 self.plugins = [] 325 340 new_plugins = self.findModels() 326 if len(new_plugins) > 0: 327 for name, plug in new_plugins.iteritems(): 328 if name not in self.stored_plugins.keys(): 329 self.stored_plugins[name] = plug 330 self.plugins.append(plug) 331 self.model_dictionary[name] = plug 332 self.model_combobox.set_list("Plugin Models", self.plugins) 341 if new_plugins: 342 for name, plug in new_plugins.items(): 343 self.stored_plugins[name] = plug 344 self.plugins.append(plug) 345 self.model_dictionary[name] = plug 346 self.model_combobox.set_list(CUSTOM_MODEL, self.plugins) 333 347 return self.model_combobox.get_list() 334 348 else: … … 340 354 """ 341 355 self.plugins = [] 342 new_plugins = _find_models() 343 for name, plug in new_plugins.iteritems(): 344 for stored_name, stored_plug in self.stored_plugins.iteritems(): 345 if name == stored_name: 346 del self.stored_plugins[name] 347 del self.model_dictionary[name] 348 break 356 self.stored_plugins = _find_models() 357 structure_names = [model.name for model in self.struct_list] 358 form_names = [model.name for model in self.multiplication_factor] 359 360 # Remove all plugin structure factors and form factors 361 for name in copy(structure_names): 362 if '[plug-in]' in name: 363 i = structure_names.index(name) 364 del self.struct_list[i] 365 structure_names.remove(name) 366 for name in copy(form_names): 367 if '[plug-in]' in name: 368 i = form_names.index(name) 369 del self.multiplication_factor[i] 370 form_names.remove(name) 371 372 # Add new plugin structure factors and form factors 373 for name, plug in self.stored_plugins.iteritems(): 374 if plug.is_structure_factor: 375 if name in structure_names: 376 # Delete the old model from self.struct list 377 i = structure_names.index(name) 378 del self.struct_list[i] 379 # Add the new model to self.struct_list 380 self.struct_list.append(plug) 381 elif plug.is_form_factor: 382 if name in form_names: 383 # Delete the old model from self.multiplication_factor 384 i = form_names.index(name) 385 del self.multiplication_factor[i] 386 # Add the new model to self.multiplication_factor 387 self.multiplication_factor.append(plug) 388 389 # Add references to the updated model 349 390 self.stored_plugins[name] = plug 350 self.plugins.append(plug) 391 if not plug.is_structure_factor: 392 # Don't show S(Q) models in the 'Plugin Models' dropdown 393 self.plugins.append(plug) 351 394 self.model_dictionary[name] = plug 352 395 353 396 self.model_combobox.reset_list("Plugin Models", self.plugins) 397 self.model_combobox.reset_list("Structure Factors", self.struct_list) 398 self.model_combobox.reset_list("P(Q)*S(Q)", self.multiplication_factor) 399 354 400 return self.model_combobox.get_list() 355 401
Note: See TracChangeset
for help on using the changeset viewer.