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