Ignore:
Timestamp:
Sep 20, 2017 12:21:41 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
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.
Message:

Merge branch 'master' into ticket-639-katex

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/fitting/models.py

    rb1c2011 r13374be  
    1414import py_compile 
    1515import shutil 
     16from copy import copy 
    1617# Explicitly import from the pluginmodel module so that py2exe 
    1718# places it in the distribution. The Model1DPlugin class is used 
     
    2021from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller 
    2122from sasmodels.sasview_model import load_custom_model, load_standard_models 
     23from sas.sasgui.perspectives.fitting.fitpage import CUSTOM_MODEL 
    2224 
    2325logger = logging.getLogger(__name__) 
     
    265267        temp = {} 
    266268        if self.is_changed(): 
    267             return  _find_models() 
     269            temp =  _find_models() 
     270            self.last_time_dir_modified = time.time() 
     271            return temp 
    268272        logger.info("plugin model : %s" % str(temp)) 
    269273        return temp 
     
    278282        """ 
    279283 
    280         # regular model names only 
     284        # Regular model names only 
    281285        self.model_name_list = [] 
    282286 
    283         #Build list automagically from sasmodels package 
     287        # Build list automagically from sasmodels package 
    284288        for model in load_standard_models(): 
    285289            self.model_dictionary[model.name] = model 
     
    293297                self.model_name_list.append(model.name) 
    294298 
    295         #Looking for plugins 
     299        # Looking for plugins 
    296300        self.stored_plugins = self.findModels() 
    297301        self.plugins = self.stored_plugins.values() 
    298302        for name, plug in self.stored_plugins.iteritems(): 
    299303            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) 
    300314 
    301315        self._get_multifunc_models() 
     
    312326        if os.path.isdir(plugin_dir): 
    313327            temp = os.path.getmtime(plugin_dir) 
    314             if  self.last_time_dir_modified != temp: 
     328            if  self.last_time_dir_modified < temp: 
    315329                is_modified = True 
    316330                self.last_time_dir_modified = temp 
     
    323337        new models were added else return empty dictionary 
    324338        """ 
     339        self.plugins = [] 
    325340        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) 
    333347            return self.model_combobox.get_list() 
    334348        else: 
     
    340354        """ 
    341355        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 
    349390            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) 
    351394            self.model_dictionary[name] = plug 
    352395 
    353396        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 
    354400        return self.model_combobox.get_list() 
    355401 
Note: See TracChangeset for help on using the changeset viewer.