<commit_before>#TODO: add comments to document this module
#TODO: clean-up the exception handling.
#TODO: clean-up existing comments/documentation. 
#      For example, the _getModelList method advertises 
#      an 'id' parameter that is not part of the method's signature.
#      It also advertises an ID as return value but it always returns zero.
#TODO: clean-up the FractalAbsModel and PowerLawAbsModel menu items. Those
#      model definitions do not belong here. They belong with the rest of the
#      models.

import wx
import wx.lib.newevent
import imp
import os,sys,math
import os.path

(ModelEvent, EVT_MODEL) = wx.lib.newevent.NewEvent()

# Time is needed by the log method
import time

# Explicitly import from the pluginmodel module so that py2exe
# places it in the distribution. The Model1DPlugin class is used
# as the base class of plug-in models.
from sans.models.pluginmodel import Model1DPlugin
    
def log(message):
    out = open("plugins.log", 'a')
    out.write("%10g:  %s\n" % (time.clock(), message))
    out.close()

def findModels():
    log("looking for models in: %s/plugins" % os.getcwd())
    if os.path.isdir('plugins'):
        return _findModels('plugins')
    return []
    
def _findModels(dir):
    # List of plugin objects
    plugins = []
    # Go through files in plug-in directory
    try:
        list = os.listdir(dir)
        for item in list:
            toks = os.path.splitext(os.path.basename(item))
            if toks[1]=='.py' and not toks[0]=='__init__':
                name = toks[0]
            
                path = [os.path.abspath(dir)]
                file = None
                try:
                    (file, path, info) = imp.find_module(name, path)
                    module = imp.load_module( name, file, item, info )
                    if hasattr(module, "Model"):
                        try:
                            plugins.append(module.Model)
                        except:
                            log("Error accessing Model in %s\n  %s" % (name, sys.exc_value))
                except:
                    log("Error accessing Model in %s\n  %s" % (name, sys.exc_value))
                finally:
              
                    if not file==None:
                        file.close()
    except:
        # Don't deal with bad plug-in imports. Just skip.
        pass
    return plugins

class ModelList(object):
    """
        Contains dictionary of model and their type
    """
    def __init__(self):
        self.mydict={}
        
    def set_list(self, name, mylist):
        """
            @param name: the type of the list
            @param mylist: the list to add
        """
        if name not in self.mydict.keys():
            self.mydict[name] = mylist
            
            
    def get_list(self):
        """
         return all the list stored in a dictionary object
        """
        return self.mydict
        
class ModelManager:
    ## external dict for models
    model_combobox = ModelList()
    ## Dictionary of form models
    form_factor_dict = {}
    ## dictionary of other
    struct_factor_dict = {}
    ##list of form factors
    shape_list =[]
    ## independent shape model list
    shape_indep_list = []
    ##list of structure factors 
    struct_list= []
    ##list of model allowing multiplication
    multiplication_factor=[]
    ## list of added models
    plugins=[]
    ## Event owner (guiframe)
    event_owner = None
    
    def _getModelList(self):
        """
            List of models we want to make available by default
            for this application
            
            @param id: first event ID to register the menu events with
            @return: the next free event ID following the new menu events
        """
        ## form factor
        from sans.models.SphereModel import SphereModel
        self.shape_list.append(SphereModel)
        self.multiplication_factor.append(SphereModel)
        
        from sans.models.CylinderModel import CylinderModel
        self.shape_list.append(CylinderModel)
        self.multiplication_factor.append(CylinderModel)
        
        from sans.models.ParallelepipedModel import ParallelepipedModel
        self.shape_list.append(ParallelepipedModel)
        self.multiplication_factor.append(ParallelepipedModel)
        
        from sans.models.CoreShellModel import CoreShellModel
        self.shape_list.append(CoreShellModel)
        
        from sans.models.CoreShellCylinderModel import CoreShellCylinderModel
        self.shape_list.append(CoreShellCylinderModel)
        
        from sans.models.EllipticalCylinderModel import EllipticalCylinderModel
        self.shape_list.append(EllipticalCylinderModel)
        
        from sans.models.EllipsoidModel import EllipsoidModel
        self.shape_list.append(EllipsoidModel)
        self.multiplication_factor.append(EllipsoidModel)
         
        from sans.models.TriaxialEllipsoidModel import TriaxialEllipsoidModel
        self.shape_list.append(TriaxialEllipsoidModel)
        self.multiplication_factor.append(TriaxialEllipsoidModel)
        
        from sans.models.FlexibleCylinderModel import FlexibleCylinderModel
        self.shape_list.append(FlexibleCylinderModel)
        self.multiplication_factor.append(FlexibleCylinderModel)
        
        from sans.models.StackedDisksModel import StackedDisksModel
        self.shape_list.append(StackedDisksModel)
        self.multiplication_factor.append(StackedDisksModel)
        
        from sans.models.LamellarModel import LamellarModel
        self.shape_list.append(LamellarModel)
        self.multiplication_factor.append(LamellarModel)
        
        from sans.models.LamellarFFHGModel import LamellarFFHGModel
        self.shape_list.append(LamellarFFHGModel)
        self.multiplication_factor.append(LamellarFFHGModel)
        
        from sans.models.LamellarPSModel import LamellarPSModel
        self.shape_list.append(LamellarPSModel)
        self.multiplication_factor.append(LamellarPSModel)
        
        from sans.models.LamellarPSHGModel import LamellarPSHGModel
        self.shape_list.append(LamellarPSHGModel)
        self.multiplication_factor.append(LamellarPSHGModel)
        
        from sans.models.OblateModel import OblateModel
        self.shape_list.append(OblateModel)
        self.multiplication_factor.append(OblateModel)
        
        from sans.models.ProlateModel import ProlateModel
        self.shape_list.append(ProlateModel)
        self.multiplication_factor.append(ProlateModel)
        
        ## Structure factor 
        from sans.models.SquareWellStructure import SquareWellStructure
        self.struct_list.append(SquareWellStructure)
        
        from sans.models.HardsphereStructure import HardsphereStructure
        self.struct_list.append(HardsphereStructure)
         
        from sans.models.StickyHSStructure import StickyHSStructure
        self.struct_list.append(StickyHSStructure)<commit_msg>disable multplication for new models<commit_after>#TODO: add comments to document this module
#TODO: clean-up the exception handling.
#TODO: clean-up existing comments/documentation. 
#      For example, the _getModelList method advertises 
#      an 'id' parameter that is not part of the method's signature.
#      It also advertises an ID as return value but it always returns zero.
#TODO: clean-up the FractalAbsModel and PowerLawAbsModel menu items. Those
#      model definitions do not belong here. They belong with the rest of the
#      models.

import wx
import wx.lib.newevent
import imp
import os,sys,math
import os.path

(ModelEvent, EVT_MODEL) = wx.lib.newevent.NewEvent()

# Time is needed by the log method
import time

# Explicitly import from the pluginmodel module so that py2exe
# places it in the distribution. The Model1DPlugin class is used
# as the base class of plug-in models.
from sans.models.pluginmodel import Model1DPlugin
    
def log(message):
    out = open("plugins.log", 'a')
    out.write("%10g:  %s\n" % (time.clock(), message))
    out.close()

def findModels():
    log("looking for models in: %s/plugins" % os.getcwd())
    if os.path.isdir('plugins'):
        return _findModels('plugins')
    return []
    
def _findModels(dir):
    # List of plugin objects
    plugins = []
    # Go through files in plug-in directory
    try:
        list = os.listdir(dir)
        for item in list:
            toks = os.path.splitext(os.path.basename(item))
            if toks[1]=='.py' and not toks[0]=='__init__':
                name = toks[0]
            
                path = [os.path.abspath(dir)]
                file = None
                try:
                    (file, path, info) = imp.find_module(name, path)
                    module = imp.load_module( name, file, item, info )
                    if hasattr(module, "Model"):
                        try:
                            plugins.append(module.Model)
                        except:
                            log("Error accessing Model in %s\n  %s" % (name, sys.exc_value))
                except:
                    log("Error accessing Model in %s\n  %s" % (name, sys.exc_value))
                finally:
              
                    if not file==None:
                        file.close()
    except:
        # Don't deal with bad plug-in imports. Just skip.
        pass
    return plugins

class ModelList(object):
    """
        Contains dictionary of model and their type
    """
    def __init__(self):
        self.mydict={}
        
    def set_list(self, name, mylist):
        """
            @param name: the type of the list
            @param mylist: the list to add
        """
        if name not in self.mydict.keys():
            self.mydict[name] = mylist
            
            
    def get_list(self):
        """
         return all the list stored in a dictionary object
        """
        return self.mydict
        
class ModelManager:
    ## external dict for models
    model_combobox = ModelList()
    ## Dictionary of form models
    form_factor_dict = {}
    ## dictionary of other
    struct_factor_dict = {}
    ##list of form factors
    shape_list =[]
    ## independent shape model list
    shape_indep_list = []
    ##list of structure factors 
    struct_list= []
    ##list of model allowing multiplication
    multiplication_factor=[]
    ## list of added models
    plugins=[]
    ## Event owner (guiframe)
    event_owner = None
    
    def _getModelList(self):
        """
            List of models we want to make available by default
            for this application
            
            @param id: first event ID to register the menu events with
            @return: the next free event ID following the new menu events
        """
        ## form factor
        from sans.models.SphereModel import SphereModel
        self.shape_list.append(SphereModel)
        self.multiplication_factor.append(SphereModel)
        
        from sans.models.CylinderModel import CylinderModel
        self.shape_list.append(CylinderModel)
        self.multiplication_factor.append(CylinderModel)
        
        from sans.models.ParallelepipedModel import ParallelepipedModel
        self.shape_list.append(ParallelepipedModel)
        self.multiplication_factor.append(ParallelepipedModel)
        
        from sans.models.CoreShellModel import CoreShellModel
        self.shape_list.append(CoreShellModel)
        
        from sans.models.CoreShellCylinderModel import CoreShellCylinderModel
        self.shape_list.append(CoreShellCylinderModel)
        
        from sans.models.EllipticalCylinderModel import EllipticalCylinderModel
        self.shape_list.append(EllipticalCylinderModel)
        
        from sans.models.EllipsoidModel import EllipsoidModel
        self.shape_list.append(EllipsoidModel)
        self.multiplication_factor.append(EllipsoidModel)
         
        from sans.models.TriaxialEllipsoidModel import TriaxialEllipsoidModel
        self.shape_list.append(TriaxialEllipsoidModel)
       
        from sans.models.FlexibleCylinderModel import FlexibleCylinderModel
        self.shape_list.append(FlexibleCylinderModel)
        
        from sans.models.StackedDisksModel import StackedDisksModel
        self.shape_list.append(StackedDisksModel)
        
        from sans.models.LamellarModel import LamellarModel
        self.shape_list.append(LamellarModel)
        
        from sans.models.LamellarFFHGModel import LamellarFFHGModel
        self.shape_list.append(LamellarFFHGModel)
        
        from sans.models.LamellarPSModel import LamellarPSModel
        self.shape_list.append(LamellarPSModel)
     
        from sans.models.LamellarPSHGModel import LamellarPSHGModel
        self.shape_list.append(LamellarPSHGModel)
      
        from sans.models.OblateModel import OblateModel
        self.shape_list.append(OblateModel)
        
        from sans.models.ProlateModel import ProlateModel
        self.shape_list.append(ProlateModel)
      
        ## Structure factor 
        from sans.models.SquareWellStructure import SquareWellStructure
        self.struct_list.append(SquareWellStructure)
        
        from sans.models.HardsphereStructure import HardsphereStructure
        self.struct_list.append(HardsphereStructure)
         
        from sans.models.StickyHSStructure import StickyHSStructure
        self.struct_list.append(StickyHSStructure)
{'fraction_non_alphanumeric': 0.07261657261657262, 'fraction_numerical': 0.001188001188001188, 'mean_word_length': 2.2549540840985984, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7645750', 'n_tokens_mistral': 3859, 'n_tokens_neox': 3687, 'n_words': 944}