source: sasview/src/sas/perspectives/fitting/models.py @ 6c9f25d

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 6c9f25d was 6c9f25d, checked in by ajj, 10 years ago

Auto filling model lists

  • Property mode set to 100644
File size: 52.7 KB
Line 
1"""
2    Utilities to manage models
3"""
4import wx
5import imp
6import os
7import sys
8import math
9import os.path
10# Time is needed by the log method
11import time
12import logging
13import py_compile
14import shutil
15from sas.guiframe.events import StatusEvent
16# Explicitly import from the pluginmodel module so that py2exe
17# places it in the distribution. The Model1DPlugin class is used
18# as the base class of plug-in models.
19from sas.models.pluginmodel import Model1DPlugin
20from sas.models.BaseComponent import BaseComponent
21from sas.guiframe.CategoryInstaller import CategoryInstaller
22
23from sasmodels.sasview_model import make_class
24   
25PLUGIN_DIR = 'plugin_models'
26
27def get_model_python_path():
28    return os.path.dirname(__file__)
29
30
31def log(message):
32    """
33        Log a message in a file located in the user's home directory
34    """
35    dir = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR)
36    out = open(os.path.join(dir, "plugins.log"), 'a')
37    out.write("%10g%s\n" % (time.clock(), message))
38    out.close()
39
40
41def _check_plugin(model, name):
42    """
43    Do some checking before model adding plugins in the list
44   
45    :param model: class model to add into the plugin list
46    :param name:name of the module plugin
47   
48    :return model: model if valid model or None if not valid
49   
50    """
51    #Check if the plugin is of type Model1DPlugin
52    if not issubclass(model, Model1DPlugin):
53        msg = "Plugin %s must be of type Model1DPlugin \n" % str(name)
54        log(msg)
55        return None
56    if model.__name__ != "Model":
57        msg = "Plugin %s class name must be Model \n" % str(name)
58        log(msg)
59        return None
60    try:
61        new_instance = model()
62    except:
63        msg = "Plugin %s error in __init__ \n\t: %s %s\n" % (str(name),
64                                    str(sys.exc_type), sys.exc_value)
65        log(msg)
66        return None
67   
68    if hasattr(new_instance, "function"):
69        try:
70            value = new_instance.function()
71        except:
72            msg = "Plugin %s: error writing function \n\t :%s %s\n " % (str(name),
73                                    str(sys.exc_type), sys.exc_value)
74            log(msg)
75            return None
76    else:
77        msg = "Plugin  %s needs a method called function \n" % str(name)
78        log(msg)
79        return None
80    return model
81 
82 
83def find_plugins_dir():
84    """
85        Find path of the plugins directory.
86        The plugin directory is located in the user's home directory.
87    """
88    dir = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR)
89   
90    # If the plugin directory doesn't exist, create it
91    if not os.path.isdir(dir):
92        os.makedirs(dir)
93       
94    # Find paths needed
95    try:
96        # For source
97        if os.path.isdir(os.path.dirname(__file__)):
98            p_dir = os.path.join(os.path.dirname(__file__), PLUGIN_DIR)
99        else:
100            raise
101    except:
102        # Check for data path next to exe/zip file.
103        #Look for maximum n_dir up of the current dir to find plugins dir
104        n_dir = 12
105        p_dir = None
106        f_dir = os.path.join(os.path.dirname(__file__))
107        for i in range(n_dir):
108            if i > 1:
109                f_dir, _ = os.path.split(f_dir)
110            plugin_path = os.path.join(f_dir, PLUGIN_DIR)
111            if os.path.isdir(plugin_path):
112                p_dir = plugin_path
113                break
114        if not p_dir:
115            raise
116    # Place example user models as needed
117    if os.path.isdir(p_dir):
118        for file in os.listdir(p_dir):
119            file_path = os.path.join(p_dir, file)
120            if os.path.isfile(file_path):
121                if file.split(".")[-1] == 'py' and\
122                    file.split(".")[0] != '__init__':
123                    if not os.path.isfile(os.path.join(dir, file)):
124                        shutil.copy(file_path, dir)
125
126    return dir
127
128
129class ReportProblem:
130    def __nonzero__(self):
131        type, value, traceback = sys.exc_info()
132        if type is not None and issubclass(type, py_compile.PyCompileError):
133            print "Problem with", repr(value)
134            raise type, value, traceback
135        return 1
136   
137report_problem = ReportProblem()
138
139
140def compile_file(dir):
141    """
142    Compile a py file
143    """
144    try:
145        import compileall
146        compileall.compile_dir(dir=dir, ddir=dir, force=1,
147                               quiet=report_problem)
148    except:
149        type, value, traceback = sys.exc_info()
150        return value
151    return None
152
153
154def _findModels(dir):
155    """
156    """
157    # List of plugin objects
158    plugins = {}
159    # Go through files in plug-in directory
160    #always recompile the folder plugin
161    dir = find_plugins_dir()
162    if not os.path.isdir(dir):
163        msg = "SasView couldn't locate Model plugin folder."
164        msg += """ "%s" does not exist""" % dir
165        logging.warning(msg)
166        return plugins
167    else:
168        log("looking for models in: %s" % str(dir))
169        compile_file(dir)
170        logging.info("pluging model dir: %s\n" % str(dir))
171    try:
172        list = os.listdir(dir)
173        for item in list:
174            toks = os.path.splitext(os.path.basename(item))
175            if toks[1] == '.py' and not toks[0] == '__init__':
176                name = toks[0]
177           
178                path = [os.path.abspath(dir)]
179                file = None
180                try:
181                    (file, path, info) = imp.find_module(name, path)
182                    module = imp.load_module(name, file, item, info)
183                    if hasattr(module, "Model"):
184                        try:
185                            if _check_plugin(module.Model, name) != None:
186                                plugins[name] = module.Model
187                        except:
188                            msg = "Error accessing Model"
189                            msg += "in %s\n  %s %s\n" % (name,
190                                    str(sys.exc_type), sys.exc_value)
191                            log(msg)
192                except:
193                    msg = "Error accessing Model"
194                    msg += " in %s\n  %s %s \n" % (name,
195                                    str(sys.exc_type), sys.exc_value)
196                    log(msg)
197                finally:
198             
199                    if not file == None:
200                        file.close()
201    except:
202        # Don't deal with bad plug-in imports. Just skip.
203        msg = "Could not import model plugin: %s\n" % sys.exc_value
204        log(msg)
205        pass
206    return plugins
207
208
209class ModelList(object):
210    """
211    Contains dictionary of model and their type
212    """
213    def __init__(self):
214        """
215        """
216        self.mydict = {}
217       
218    def set_list(self, name, mylist):
219        """
220        :param name: the type of the list
221        :param mylist: the list to add
222       
223        """
224        if name not in self.mydict.keys():
225            self.reset_list(name, mylist)
226           
227    def reset_list(self, name, mylist):
228        """
229        :param name: the type of the list
230        :param mylist: the list to add
231        """
232        self.mydict[name] = mylist
233           
234    def get_list(self):
235        """
236        return all the list stored in a dictionary object
237        """
238        return self.mydict
239       
240       
241class ModelManagerBase:
242    """
243        Base class for the model manager
244    """
245    ## external dict for models
246    model_combobox = ModelList()
247    ## Dictionary of form factor models
248    form_factor_dict = {}
249    ## dictionary of structure factor models
250    struct_factor_dict = {}
251    ##list of shape models -- this is superseded by categories
252#    shape_list = []
253    ## shape independent model list-- this is superseded by categories
254#    shape_indep_list = []
255    ##list of structure factors
256    struct_list = []
257    ##list of model allowing multiplication by a structure factor
258    multiplication_factor = []
259    ##list of multifunctional shapes (i.e. that have user defined number of levels
260    multi_func_list = []
261    ## list of added models -- currently python models found in the plugin dir.
262    plugins = []
263    ## Event owner (guiframe)
264    event_owner = None
265    last_time_dir_modified = 0
266   
267    def __init__(self):
268        """
269        """
270        self.model_dictionary = {}
271        self.stored_plugins = {}
272        self._getModelList()
273       
274    def findModels(self):
275        """
276        find  plugin model in directory of plugin .recompile all file
277        in the directory if file were modified
278        """
279        temp = {}
280        if self.is_changed():
281            return  _findModels(dir)
282        logging.info("pluging model : %s\n" % str(temp))
283        return temp
284       
285    def _getModelList(self):
286        """
287        List of models we want to make available by default
288        for this application
289   
290        :return: the next free event ID following the new menu events
291       
292        """
293
294        ## NOTE: as of April 26, 2014, as part of first pass on fixing categories,
295        ## all the appends to shape_list or shape_independent_list are
296        ## commented out.  They should be possible to remove.  They are in
297        ## fact a "category" of model whereas the other list are actually
298        ## "attributes" of a model.  In other words is it a structure factor
299        ## that can be used against a form factor, is it a form factor that is
300        ## knows how to be multiplied by a structure factor, does it have user
301        ## defined number of parameters, etc.
302        ##
303        ## We hope this whole list will be superseded by the new C models
304        ## structure where each model will provide a method to interrogate it
305        ## about its "attributes" -- then this long list becomes a loop reading
306        ## each model in the category list to populate the "attribute"lists. 
307        ## We should also refactor the whole category vs attribute list
308        ## structure when doing this as now the attribute lists think they are
309        ## also category lists.
310        ##
311        ##   -PDB  April 26, 2014
312
313        # regular model names only
314        self.model_name_list = []
315
316        #Build list automagically
317        import pkgutil
318        from importlib import import_module
319        import sasmodels.models
320        for importer,modname,ispkg in pkgutil.iter_modules(sasmodels.models.__path__):
321            if not ispkg:
322                #do sasview stuff
323                module = import_module('.'+modname,'sasmodels.models')
324                self.model_dictionary[module.oldname] = make_class(module, dtype='single',namestyle='oldname')
325                self.model_name_list.append(module.oldname)
326
327        # try:
328        #     # from sas.models.SphereModel import SphereModel
329        #     from sasmodels.models import sphere
330        #     SphereModel = make_class(sphere, dtype='single',namestyle='oldname')
331        #     self.model_dictionary[SphereModel.__name__] = SphereModel
332        #     #        self.shape_list.append(SphereModel)
333        #     self.multiplication_factor.append(SphereModel)
334        #     self.model_name_list.append(SphereModel.__name__)
335        # except:
336        #     pass
337
338        # try:
339        #     from sas.models.BinaryHSModel import BinaryHSModel
340        #     self.model_dictionary[BinaryHSModel.__name__] = BinaryHSModel
341        #     #        self.shape_list.append(BinaryHSModel)
342        #     self.model_name_list.append(BinaryHSModel.__name__)
343        # except:
344        #     pass
345        #
346        # try:
347        #     from sas.models.FuzzySphereModel import FuzzySphereModel
348        #     self.model_dictionary[FuzzySphereModel.__name__] = FuzzySphereModel
349        #     #        self.shape_list.append(FuzzySphereModel)
350        #     self.multiplication_factor.append(FuzzySphereModel)
351        #     self.model_name_list.append(FuzzySphereModel.__name__)
352        # except:
353        #     pass
354        #
355        # try:
356        #     from sas.models.RaspBerryModel import RaspBerryModel
357        #     self.model_dictionary[RaspBerryModel.__name__] = RaspBerryModel
358        #     #        self.shape_list.append(RaspBerryModel)
359        #     self.model_name_list.append(RaspBerryModel.__name__)
360        # except:
361        #     pass
362        #
363        # try:
364        #     from sas.models.CoreShellModel import CoreShellModel
365        #
366        #     self.model_dictionary[CoreShellModel.__name__] = CoreShellModel
367        #     #        self.shape_list.append(CoreShellModel)
368        #     self.multiplication_factor.append(CoreShellModel)
369        #     self.model_name_list.append(CoreShellModel.__name__)
370        # except:
371        #     pass
372        #
373        # try:
374        #     from sas.models.Core2ndMomentModel import Core2ndMomentModel
375        #     self.model_dictionary[Core2ndMomentModel.__name__] = Core2ndMomentModel
376        #     #        self.shape_list.append(Core2ndMomentModel)
377        #     self.model_name_list.append(Core2ndMomentModel.__name__)
378        # except:
379        #     pass
380        #
381        # try:
382        #     from sas.models.CoreMultiShellModel import CoreMultiShellModel
383        #     self.model_dictionary[CoreMultiShellModel.__name__] = CoreMultiShellModel
384        #     #        self.shape_list.append(CoreMultiShellModel)
385        #     self.multiplication_factor.append(CoreMultiShellModel)
386        #     self.multi_func_list.append(CoreMultiShellModel)
387        # except:
388        #     pass
389        #
390        # try:
391        #     from sas.models.VesicleModel import VesicleModel
392        #     self.model_dictionary[VesicleModel.__name__] = VesicleModel
393        #     #        self.shape_list.append(VesicleModel)
394        #     self.multiplication_factor.append(VesicleModel)
395        #     self.model_name_list.append(VesicleModel.__name__)
396        # except:
397        #     pass
398        #
399        # try:
400        #     from sas.models.MultiShellModel import MultiShellModel
401        #     self.model_dictionary[MultiShellModel.__name__] = MultiShellModel
402        #     #        self.shape_list.append(MultiShellModel)
403        #     self.multiplication_factor.append(MultiShellModel)
404        #     self.model_name_list.append(MultiShellModel.__name__)
405        # except:
406        #     pass
407        #
408        # try:
409        #     from sas.models.OnionExpShellModel import OnionExpShellModel
410        #     self.model_dictionary[OnionExpShellModel.__name__] = OnionExpShellModel
411        #     #        self.shape_list.append(OnionExpShellModel)
412        #     self.multiplication_factor.append(OnionExpShellModel)
413        #     self.multi_func_list.append(OnionExpShellModel)
414        # except:
415        #     pass
416        #
417        # try:
418        #     from sas.models.SphericalSLDModel import SphericalSLDModel
419        #
420        #     self.model_dictionary[SphericalSLDModel.__name__] = SphericalSLDModel
421        #     #        self.shape_list.append(SphericalSLDModel)
422        #     self.multiplication_factor.append(SphericalSLDModel)
423        #     self.multi_func_list.append(SphericalSLDModel)
424        # except:
425        #     pass
426        #
427        # try:
428        #     from sas.models.LinearPearlsModel import LinearPearlsModel
429        #
430        #     self.model_dictionary[LinearPearlsModel.__name__] = LinearPearlsModel
431        #     #        self.shape_list.append(LinearPearlsModel)
432        #     self.model_name_list.append(LinearPearlsModel.__name__)
433        # except:
434        #     pass
435        #
436        # try:
437        #     from sas.models.PearlNecklaceModel import PearlNecklaceModel
438        #
439        #     self.model_dictionary[PearlNecklaceModel.__name__] = PearlNecklaceModel
440        #     #        self.shape_list.append(PearlNecklaceModel)
441        #     self.model_name_list.append(PearlNecklaceModel.__name__)
442        # except:
443        #     pass
444        #
445        # try:
446        #     from sas.models.CylinderModel import CylinderModel
447        #
448        #     self.model_dictionary[CylinderModel.__name__] = CylinderModel
449        #     #        self.shape_list.append(CylinderModel)
450        #     self.multiplication_factor.append(CylinderModel)
451        #     self.model_name_list.append(CylinderModel.__name__)
452        # except:
453        #     pass
454        #
455        # try:
456        #     from sas.models.CoreShellCylinderModel import CoreShellCylinderModel
457        #
458        #     self.model_dictionary[CoreShellCylinderModel.__name__] = CoreShellCylinderModel
459        #     #        self.shape_list.append(CoreShellCylinderModel)
460        #     self.multiplication_factor.append(CoreShellCylinderModel)
461        #     self.model_name_list.append(CoreShellCylinderModel.__name__)
462        # except:
463        #     pass
464        #
465        # try:
466        #     from sas.models.CoreShellBicelleModel import CoreShellBicelleModel
467        #
468        #     self.model_dictionary[CoreShellBicelleModel.__name__] = CoreShellBicelleModel
469        #     #        self.shape_list.append(CoreShellBicelleModel)
470        #     self.multiplication_factor.append(CoreShellBicelleModel)
471        #     self.model_name_list.append(CoreShellBicelleModel.__name__)
472        # except:
473        #     pass
474        #
475        # try:
476        #     from sas.models.HollowCylinderModel import HollowCylinderModel
477        #
478        #     self.model_dictionary[HollowCylinderModel.__name__] = HollowCylinderModel
479        #     #        self.shape_list.append(HollowCylinderModel)
480        #     self.multiplication_factor.append(HollowCylinderModel)
481        #     self.model_name_list.append(HollowCylinderModel.__name__)
482        # except:
483        #     pass
484        #
485        # try:
486        #     from sas.models.FlexibleCylinderModel import FlexibleCylinderModel
487        #
488        #     self.model_dictionary[FlexibleCylinderModel.__name__] = FlexibleCylinderModel
489        #     #        self.shape_list.append(FlexibleCylinderModel)
490        #     self.model_name_list.append(FlexibleCylinderModel.__name__)
491        # except:
492        #     pass
493        #
494        # try:
495        #     from sas.models.FlexCylEllipXModel import FlexCylEllipXModel
496        #
497        #     self.model_dictionary[FlexCylEllipXModel.__name__] = FlexCylEllipXModel
498        #     #        self.shape_list.append(FlexCylEllipXModel)
499        #     self.model_name_list.append(FlexCylEllipXModel.__name__)
500        # except:
501        #     pass
502        #
503        # try:
504        #     from sas.models.StackedDisksModel import StackedDisksModel
505        #
506        #     self.model_dictionary[StackedDisksModel.__name__] = StackedDisksModel
507        #     #        self.shape_list.append(StackedDisksModel)
508        #     self.multiplication_factor.append(StackedDisksModel)
509        #     self.model_name_list.append(StackedDisksModel.__name__)
510        # except:
511        #     pass
512        #
513        # try:
514        #     from sas.models.ParallelepipedModel import ParallelepipedModel
515        #
516        #     self.model_dictionary[ParallelepipedModel.__name__] = ParallelepipedModel
517        #     #        self.shape_list.append(ParallelepipedModel)
518        #     self.multiplication_factor.append(ParallelepipedModel)
519        #     self.model_name_list.append(ParallelepipedModel.__name__)
520        # except:
521        #     pass
522        #
523        # try:
524        #     from sas.models.CSParallelepipedModel import CSParallelepipedModel
525        #
526        #     self.model_dictionary[CSParallelepipedModel.__name__] = CSParallelepipedModel
527        #     #        self.shape_list.append(CSParallelepipedModel)
528        #     self.multiplication_factor.append(CSParallelepipedModel)
529        #     self.model_name_list.append(CSParallelepipedModel.__name__)
530        # except:
531        #     pass
532        #
533        # try:
534        #     from sas.models.EllipticalCylinderModel import EllipticalCylinderModel
535        #
536        #     self.model_dictionary[EllipticalCylinderModel.__name__] = EllipticalCylinderModel
537        #     #        self.shape_list.append(EllipticalCylinderModel)
538        #     self.multiplication_factor.append(EllipticalCylinderModel)
539        #     self.model_name_list.append(EllipticalCylinderModel.__name__)
540        # except:
541        #     pass
542        #
543        # try:
544        #     from sas.models.CappedCylinderModel import CappedCylinderModel
545        #
546        #     self.model_dictionary[CappedCylinderModel.__name__] = CappedCylinderModel
547        #     #       self.shape_list.append(CappedCylinderModel)
548        #     self.model_name_list.append(CappedCylinderModel.__name__)
549        # except:
550        #     pass
551        #
552        # try:
553        #     from sas.models.EllipsoidModel import EllipsoidModel
554        #
555        #     self.model_dictionary[EllipsoidModel.__name__] = EllipsoidModel
556        #     #        self.shape_list.append(EllipsoidModel)
557        #     self.multiplication_factor.append(EllipsoidModel)
558        #     self.model_name_list.append(EllipsoidModel.__name__)
559        # except:
560        #     pass
561        #
562        # try:
563        #     from sas.models.CoreShellEllipsoidModel import CoreShellEllipsoidModel
564        #
565        #     self.model_dictionary[CoreShellEllipsoidModel.__name__] = CoreShellEllipsoidModel
566        #     #        self.shape_list.append(CoreShellEllipsoidModel)
567        #     self.multiplication_factor.append(CoreShellEllipsoidModel)
568        #     self.model_name_list.append(CoreShellEllipsoidModel.__name__)
569        # except:
570        #     pass
571        #
572        # try:
573        #     from sas.models.CoreShellEllipsoidXTModel import CoreShellEllipsoidXTModel
574        #
575        #     self.model_dictionary[CoreShellEllipsoidXTModel.__name__] = CoreShellEllipsoidXTModel
576        #     #        self.shape_list.append(CoreShellEllipsoidXTModel)
577        #     self.multiplication_factor.append(CoreShellEllipsoidXTModel)
578        #     self.model_name_list.append(CoreShellEllipsoidXTModel.__name__)
579        # except:
580        #     pass
581        #
582        # try:
583        #     from sas.models.TriaxialEllipsoidModel import TriaxialEllipsoidModel
584        #
585        #     self.model_dictionary[TriaxialEllipsoidModel.__name__] = TriaxialEllipsoidModel
586        #     #        self.shape_list.append(TriaxialEllipsoidModel)
587        #     self.multiplication_factor.append(TriaxialEllipsoidModel)
588        #     self.model_name_list.append(TriaxialEllipsoidModel.__name__)
589        # except:
590        #     pass
591        #
592        # try:
593        #     from sas.models.LamellarModel import LamellarModel
594        #
595        #     self.model_dictionary[LamellarModel.__name__] = LamellarModel
596        #     #        self.shape_list.append(LamellarModel)
597        #     self.model_name_list.append(LamellarModel.__name__)
598        # except:
599        #     pass
600        #
601        # try:
602        #     from sas.models.LamellarFFHGModel import LamellarFFHGModel
603        #
604        #     self.model_dictionary[LamellarFFHGModel.__name__] = LamellarFFHGModel
605        #     #        self.shape_list.append(LamellarFFHGModel)
606        #     self.model_name_list.append(LamellarFFHGModel.__name__)
607        # except:
608        #     pass
609        #
610        # try:
611        #     from sas.models.LamellarPSModel import LamellarPSModel
612        #
613        #     self.model_dictionary[LamellarPSModel.__name__] = LamellarPSModel
614        #     #        self.shape_list.append(LamellarPSModel)
615        #     self.model_name_list.append(LamellarPSModel.__name__)
616        # except:
617        #     pass
618        #
619        # try:
620        #     from sas.models.LamellarPSHGModel import LamellarPSHGModel
621        #
622        #     self.model_dictionary[LamellarPSHGModel.__name__] = LamellarPSHGModel
623        #     #        self.shape_list.append(LamellarPSHGModel)
624        #     self.model_name_list.append(LamellarPSHGModel.__name__)
625        # except:
626        #     pass
627        #
628        # try:
629        #     from sas.models.LamellarPCrystalModel import LamellarPCrystalModel
630        #
631        #     self.model_dictionary[LamellarPCrystalModel.__name__] = LamellarPCrystalModel
632        #     #        self.shape_list.append(LamellarPCrystalModel)
633        #     self.model_name_list.append(LamellarPCrystalModel.__name__)
634        # except:
635        #     pass
636        #
637        # try:
638        #     from sas.models.SCCrystalModel import SCCrystalModel
639        #
640        #     self.model_dictionary[SCCrystalModel.__name__] = SCCrystalModel
641        #     #        self.shape_list.append(SCCrystalModel)
642        #     self.model_name_list.append(SCCrystalModel.__name__)
643        # except:
644        #     pass
645        #
646        # try:
647        #     from sas.models.FCCrystalModel import FCCrystalModel
648        #
649        #     self.model_dictionary[FCCrystalModel.__name__] = FCCrystalModel
650        #     #        self.shape_list.append(FCCrystalModel)
651        #     self.model_name_list.append(FCCrystalModel.__name__)
652        # except:
653        #     pass
654        #
655        # try:
656        #     from sas.models.BCCrystalModel import BCCrystalModel
657        #
658        #     self.model_dictionary[BCCrystalModel.__name__] = BCCrystalModel
659        #     #        self.shape_list.append(BCCrystalModel)
660        #     self.model_name_list.append(BCCrystalModel.__name__)
661        # except:
662        #     pass
663        #
664        #
665        # ## Structure factor
666        # try:
667        #     from sas.models.SquareWellStructure import SquareWellStructure
668        #
669        #     self.model_dictionary[SquareWellStructure.__name__] = SquareWellStructure
670        #     self.struct_list.append(SquareWellStructure)
671        #     self.model_name_list.append(SquareWellStructure.__name__)
672        # except:
673        #     pass
674        #
675        # try:
676        #     from sas.models.HardsphereStructure import HardsphereStructure
677        #
678        #     self.model_dictionary[HardsphereStructure.__name__] = HardsphereStructure
679        #     self.struct_list.append(HardsphereStructure)
680        #     self.model_name_list.append(HardsphereStructure.__name__)
681        # except:
682        #     pass
683        #
684        # try:
685        #     from sas.models.StickyHSStructure import StickyHSStructure
686        #
687        #     self.model_dictionary[StickyHSStructure.__name__] = StickyHSStructure
688        #     self.struct_list.append(StickyHSStructure)
689        #     self.model_name_list.append(StickyHSStructure.__name__)
690        # except:
691        #     pass
692        #
693        # try:
694        #     from sas.models.HayterMSAStructure import HayterMSAStructure
695        #
696        #     self.model_dictionary[HayterMSAStructure.__name__] = HayterMSAStructure
697        #     self.struct_list.append(HayterMSAStructure)
698        #     self.model_name_list.append(HayterMSAStructure.__name__)
699        # except:
700        #     pass
701        #
702        #
703        #
704        # ##shape-independent models
705        # try:
706        #     from sas.models.PowerLawAbsModel import PowerLawAbsModel
707        #
708        #     self.model_dictionary[PowerLawAbsModel.__name__] = PowerLawAbsModel
709        #     #        self.shape_indep_list.append(PowerLawAbsModel)
710        #     self.model_name_list.append(PowerLawAbsModel.__name__)
711        # except:
712        #     pass
713        #
714        # try:
715        #     from sas.models.BEPolyelectrolyte import BEPolyelectrolyte
716        #
717        #     self.model_dictionary[BEPolyelectrolyte.__name__] = BEPolyelectrolyte
718        #     #        self.shape_indep_list.append(BEPolyelectrolyte)
719        #     self.model_name_list.append(BEPolyelectrolyte.__name__)
720        #     self.form_factor_dict[str(wx.NewId())] =  [SphereModel]
721        # except:
722        #     pass
723        #
724        # try:
725        #     from sas.models.BroadPeakModel import BroadPeakModel
726        #
727        #     self.model_dictionary[BroadPeakModel.__name__] = BroadPeakModel
728        #     #        self.shape_indep_list.append(BroadPeakModel)
729        #     self.model_name_list.append(BroadPeakModel.__name__)
730        # except:
731        #     pass
732        #
733        # try:
734        #     from sas.models.CorrLengthModel import CorrLengthModel
735        #
736        #     self.model_dictionary[CorrLengthModel.__name__] = CorrLengthModel
737        #     #        self.shape_indep_list.append(CorrLengthModel)
738        #     self.model_name_list.append(CorrLengthModel.__name__)
739        # except:
740        #     pass
741        #
742        # try:
743        #     from sas.models.DABModel import DABModel
744        #
745        #     self.model_dictionary[DABModel.__name__] = DABModel
746        #     #        self.shape_indep_list.append(DABModel)
747        #     self.model_name_list.append(DABModel.__name__)
748        # except:
749        #     pass
750        #
751        # try:
752        #     from sas.models.DebyeModel import DebyeModel
753        #
754        #     self.model_dictionary[DebyeModel.__name__] = DebyeModel
755        #     #        self.shape_indep_list.append(DebyeModel)
756        #     self.model_name_list.append(DebyeModel.__name__)
757        # except:
758        #     pass
759        #
760        # try:
761        #     from sas.models.FractalModel import FractalModel
762        #
763        #     self.model_dictionary[FractalModel.__name__] = FractalModel
764        #     #        self.shape_indep_list.append(FractalModel)
765        #     self.model_name_list.append(FractalModel.__name__)
766        # except:
767        #     pass
768        #
769        # try:
770        #     from sas.models.FractalCoreShellModel import FractalCoreShellModel
771        #
772        #     self.model_dictionary[FractalCoreShellModel.__name__] = FractalCoreShellModel
773        #     #        self.shape_indep_list.append(FractalCoreShellModel)
774        #     self.model_name_list.append(FractalCoreShellModel.__name__)
775        # except:
776        #     pass
777        #
778        # try:
779        #     from sas.models.GaussLorentzGelModel import GaussLorentzGelModel
780        #
781        #     self.model_dictionary[GaussLorentzGelModel.__name__] = GaussLorentzGelModel
782        #     #        self.shape_indep_list.append(GaussLorentzGelModel)
783        #     self.model_name_list.append(GaussLorentzGelModel.__name__)
784        # except:
785        #     pass
786        #
787        # try:
788        #     from sas.models.GuinierModel import GuinierModel
789        #
790        #     self.model_dictionary[GuinierModel.__name__] = GuinierModel
791        #     #        self.shape_indep_list.append(GuinierModel)
792        #     self.model_name_list.append(GuinierModel.__name__)
793        # except:
794        #     pass
795        #
796        # try:
797        #     from sas.models.GuinierPorodModel import GuinierPorodModel
798        #
799        #     self.model_dictionary[GuinierPorodModel.__name__] = GuinierPorodModel
800        #     #        self.shape_indep_list.append(GuinierPorodModel)
801        #     self.model_name_list.append(GuinierPorodModel.__name__)
802        # except:
803        #     pass
804        #
805        # try:
806        #     from sas.models.LorentzModel import LorentzModel
807        #
808        #     self.model_dictionary[LorentzModel.__name__] = LorentzModel
809        #     #        self.shape_indep_list.append(LorentzModel)
810        #     self.model_name_list.append(LorentzModel.__name__)
811        # except:
812        #     pass
813        #
814        # try:
815        #     from sas.models.MassFractalModel import MassFractalModel
816        #
817        #     self.model_dictionary[MassFractalModel.__name__] = MassFractalModel
818        #     #        self.shape_indep_list.append(MassFractalModel)
819        #     self.model_name_list.append(MassFractalModel.__name__)
820        # except:
821        #     pass
822        #
823        # try:
824        #     from sas.models.MassSurfaceFractal import MassSurfaceFractal
825        #
826        #     self.model_dictionary[MassSurfaceFractal.__name__] = MassSurfaceFractal
827        #     #        self.shape_indep_list.append(MassSurfaceFractal)
828        #     self.model_name_list.append(MassSurfaceFractal.__name__)
829        # except:
830        #     pass
831        #
832        # try:
833        #     from sas.models.PeakGaussModel import PeakGaussModel
834        #
835        #     self.model_dictionary[PeakGaussModel.__name__] = PeakGaussModel
836        #     #        self.shape_indep_list.append(PeakGaussModel)
837        #     self.model_name_list.append(PeakGaussModel.__name__)
838        # except:
839        #     pass
840        #
841        # try:
842        #     from sas.models.PeakLorentzModel import PeakLorentzModel
843        #
844        #     self.model_dictionary[PeakLorentzModel.__name__] = PeakLorentzModel
845        #     #        self.shape_indep_list.append(PeakLorentzModel)
846        #     self.model_name_list.append(PeakLorentzModel.__name__)
847        # except:
848        #     pass
849        #
850        # try:
851        #     from sas.models.Poly_GaussCoil import Poly_GaussCoil
852        #
853        #     self.model_dictionary[Poly_GaussCoil.__name__] = Poly_GaussCoil
854        #     #        self.shape_indep_list.append(Poly_GaussCoil)
855        #     self.model_name_list.append(Poly_GaussCoil.__name__)
856        # except:
857        #     pass
858        #
859        # try:
860        #     from sas.models.PolymerExclVolume import PolymerExclVolume
861        #
862        #     self.model_dictionary[PolymerExclVolume.__name__] = PolymerExclVolume
863        #     #        self.shape_indep_list.append(PolymerExclVolume)
864        #     self.model_name_list.append(PolymerExclVolume.__name__)
865        # except:
866        #     pass
867        #
868        # try:
869        #     from sas.models.PorodModel import PorodModel
870        #
871        #     self.model_dictionary[PorodModel.__name__] = PorodModel
872        #     #        self.shape_indep_list.append(PorodModel)
873        #     self.model_name_list.append(PorodModel.__name__)
874        # except:
875        #     pass
876        #
877        # try:
878        #     from sas.models.RPA10Model import RPA10Model
879        #
880        #     self.model_dictionary[RPA10Model.__name__] = RPA10Model
881        #     #        self.shape_indep_list.append(RPA10Model)
882        #     self.multi_func_list.append(RPA10Model)
883        # except:
884        #     pass
885        #
886        # try:
887        #     from sas.models.StarPolymer import StarPolymer
888        #
889        #     self.model_dictionary[StarPolymer.__name__] = StarPolymer
890        #     #        self.shape_indep_list.append(StarPolymer)
891        #     self.model_name_list.append(StarPolymer.__name__)
892        # except:
893        #     pass
894        #
895        # try:
896        #     from sas.models.SurfaceFractalModel import SurfaceFractalModel
897        #
898        #     self.model_dictionary[SurfaceFractalModel.__name__] = SurfaceFractalModel
899        #     #        self.shape_indep_list.append(SurfaceFractalModel)
900        #     self.model_name_list.append(SurfaceFractalModel.__name__)
901        # except:
902        #     pass
903        #
904        # try:
905        #     from sas.models.TeubnerStreyModel import TeubnerStreyModel
906        #
907        #     self.model_dictionary[TeubnerStreyModel.__name__] = TeubnerStreyModel
908        #     #        self.shape_indep_list.append(TeubnerStreyModel)
909        #     self.model_name_list.append(TeubnerStreyModel.__name__)
910        # except:
911        #     pass
912        #
913        # try:
914        #     from sas.models.TwoLorentzianModel import TwoLorentzianModel
915        #
916        #     self.model_dictionary[TwoLorentzianModel.__name__] = TwoLorentzianModel
917        #     #        self.shape_indep_list.append(TwoLorentzianModel)
918        #     self.model_name_list.append(TwoLorentzianModel.__name__)
919        # except:
920        #     pass
921        #
922        # try:
923        #     from sas.models.TwoPowerLawModel import TwoPowerLawModel
924        #
925        #     self.model_dictionary[TwoPowerLawModel.__name__] = TwoPowerLawModel
926        #     #        self.shape_indep_list.append(TwoPowerLawModel)
927        #     self.model_name_list.append(TwoPowerLawModel.__name__)
928        # except:
929        #     pass
930        #
931        # try:
932        #     from sas.models.UnifiedPowerRgModel import UnifiedPowerRgModel
933        #
934        #     self.model_dictionary[UnifiedPowerRgModel.__name__] = UnifiedPowerRgModel
935        #     #        self.shape_indep_list.append(UnifiedPowerRgModel)
936        #     self.multi_func_list.append(UnifiedPowerRgModel)
937        # except:
938        #     pass
939        #
940        # try:
941        #     from sas.models.LineModel import LineModel
942        #
943        #     self.model_dictionary[LineModel.__name__] = LineModel
944        #     #        self.shape_indep_list.append(LineModel)
945        #     self.model_name_list.append(LineModel.__name__)
946        # except:
947        #     pass
948        #
949        # try:
950        #     from sas.models.ReflectivityModel import ReflectivityModel
951        #
952        #     self.model_dictionary[ReflectivityModel.__name__] = ReflectivityModel
953        #     #        self.shape_indep_list.append(ReflectivityModel)
954        #     self.multi_func_list.append(ReflectivityModel)
955        # except:
956        #     pass
957        #
958        # try:
959        #     from sas.models.ReflectivityIIModel import ReflectivityIIModel
960        #
961        #     self.model_dictionary[ReflectivityIIModel.__name__] = ReflectivityIIModel
962        #     #        self.shape_indep_list.append(ReflectivityIIModel)
963        #     self.multi_func_list.append(ReflectivityIIModel)
964        # except:
965        #     pass
966        #
967        # try:
968        #     from sas.models.GelFitModel import GelFitModel
969        #
970        #     self.model_dictionary[GelFitModel.__name__] = GelFitModel
971        #     #        self.shape_indep_list.append(GelFitModel)
972        #     self.model_name_list.append(GelFitModel.__name__)
973        # except:
974        #     pass
975        #
976        # try:
977        #     from sas.models.PringlesModel import PringlesModel
978        #
979        #     self.model_dictionary[PringlesModel.__name__] = PringlesModel
980        #     #        self.shape_indep_list.append(PringlesModel)
981        #     self.model_name_list.append(PringlesModel.__name__)
982        # except:
983        #     pass
984        #
985        # try:
986        #     from sas.models.RectangularPrismModel import RectangularPrismModel
987        #
988        #     self.model_dictionary[RectangularPrismModel.__name__] = RectangularPrismModel
989        #     #        self.shape_list.append(RectangularPrismModel)
990        #     self.multiplication_factor.append(RectangularPrismModel)
991        #     self.model_name_list.append(RectangularPrismModel.__name__)
992        # except:
993        #     pass
994        #
995        # try:
996        #     from sas.models.RectangularHollowPrismInfThinWallsModel import RectangularHollowPrismInfThinWallsModel
997        #
998        #     self.model_dictionary[RectangularHollowPrismInfThinWallsModel.__name__] = RectangularHollowPrismInfThinWallsModel
999        #     #        self.shape_list.append(RectangularHollowPrismInfThinWallsModel)
1000        #     self.multiplication_factor.append(RectangularHollowPrismInfThinWallsModel)
1001        #     self.model_name_list.append(RectangularHollowPrismInfThinWallsModel.__name__)
1002        # except:
1003        #     pass
1004        #
1005        # try:
1006        #     from sas.models.RectangularHollowPrismModel import RectangularHollowPrismModel
1007        #
1008        #     self.model_dictionary[RectangularHollowPrismModel.__name__] = RectangularHollowPrismModel
1009        #     #        self.shape_list.append(RectangularHollowPrismModel)
1010        #     self.multiplication_factor.append(RectangularHollowPrismModel)
1011        #     self.model_name_list.append(RectangularHollowPrismModel.__name__)
1012        # except:
1013        #     pass
1014        #
1015        # try:
1016        #     from sas.models.MicelleSphCoreModel import MicelleSphCoreModel
1017        #
1018        #     self.model_dictionary[MicelleSphCoreModel.__name__] = MicelleSphCoreModel
1019        #     #        self.shape_list.append(MicelleSphCoreModel)
1020        #     self.multiplication_factor.append(MicelleSphCoreModel)
1021        #     self.model_name_list.append(MicelleSphCoreModel.__name__)
1022        # except:
1023        #     pass
1024
1025
1026
1027        #from sas.models.FractalO_Z import FractalO_Z
1028        #self.model_dictionary[FractalO_Z.__name__] = FractalO_Z
1029        #self.shape_indep_list.append(FractalO_Z)
1030        #self.model_name_list.append(FractalO_Z.__name__)
1031   
1032        #Looking for plugins
1033        self.stored_plugins = self.findModels()
1034        self.plugins = self.stored_plugins.values()
1035        for name, plug in self.stored_plugins.iteritems():
1036            self.model_dictionary[name] = plug
1037           
1038        self._get_multifunc_models()
1039       
1040        return 0
1041
1042    def is_changed(self):
1043        """
1044        check the last time the plugin dir has changed and return true
1045         is the directory was modified else return false
1046        """
1047        is_modified = False
1048        plugin_dir = find_plugins_dir()
1049        if os.path.isdir(plugin_dir):
1050            temp = os.path.getmtime(plugin_dir)
1051            if  self.last_time_dir_modified != temp:
1052                is_modified = True
1053                self.last_time_dir_modified = temp
1054       
1055        return is_modified
1056   
1057    def update(self):
1058        """
1059        return a dictionary of model if
1060        new models were added else return empty dictionary
1061        """
1062        new_plugins = self.findModels()
1063        if len(new_plugins) > 0:
1064            for name, plug in  new_plugins.iteritems():
1065                if name not in self.stored_plugins.keys():
1066                    self.stored_plugins[name] = plug
1067                    self.plugins.append(plug)
1068                    self.model_dictionary[name] = plug
1069            self.model_combobox.set_list("Customized Models", self.plugins)
1070            return self.model_combobox.get_list()
1071        else:
1072            return {}
1073   
1074    def pulgins_reset(self):
1075        """
1076        return a dictionary of model
1077        """
1078        self.plugins = []
1079        new_plugins = _findModels(dir)
1080        for name, plug in  new_plugins.iteritems():
1081            for stored_name, stored_plug in self.stored_plugins.iteritems():
1082                if name == stored_name:
1083                    del self.stored_plugins[name]
1084                    del self.model_dictionary[name]
1085                    break
1086            self.stored_plugins[name] = plug
1087            self.plugins.append(plug)
1088            self.model_dictionary[name] = plug
1089
1090        self.model_combobox.reset_list("Customized Models", self.plugins)
1091        return self.model_combobox.get_list()
1092       
1093##   I believe the next four methods are for the old form factor GUI
1094##   where the dropdown showed a list of categories which then rolled out
1095##   in a second dropdown to the side. Some testing shows they indeed no longer
1096##   seem to be called.  If no problems are found during testing of release we
1097##   can remove this huge chunck of stuff.
1098##
1099##   -PDB  April 26, 2014
1100
1101#   def populate_menu(self, modelmenu, event_owner):
1102#       """
1103#       Populate a menu with our models
1104#       
1105#       :param id: first menu event ID to use when binding the menu events
1106#       :param modelmenu: wx.Menu object to populate
1107#       :param event_owner: wx object to bind the menu events to
1108#       
1109#       :return: the next free event ID following the new menu events
1110#       
1111#       """
1112#
1113        ## Fill model lists
1114#        self._getModelList()
1115        ## store reference to model menu of guiframe
1116#        self.modelmenu = modelmenu
1117        ## guiframe reference
1118#        self.event_owner = event_owner
1119       
1120#        shape_submenu = wx.Menu()
1121#        shape_indep_submenu = wx.Menu()
1122#        structure_factor = wx.Menu()
1123#        added_models = wx.Menu()
1124#        multip_models = wx.Menu()
1125        ## create menu with shape
1126#        self._fill_simple_menu(menuinfo=["Shapes",
1127#                                         shape_submenu,
1128#                                         " simple shape"],
1129#                         list1=self.shape_list)
1130       
1131#        self._fill_simple_menu(menuinfo=["Shape-Independent",
1132#                                         shape_indep_submenu,
1133#                                         "List of shape-independent models"],
1134#                         list1=self.shape_indep_list)
1135       
1136#        self._fill_simple_menu(menuinfo=["Structure Factors",
1137#                                         structure_factor,
1138#                                         "List of Structure factors models"],
1139#                                list1=self.struct_list)
1140       
1141#        self._fill_plugin_menu(menuinfo=["Customized Models", added_models,
1142#                                            "List of additional models"],
1143#                                 list1=self.plugins)
1144       
1145#        self._fill_menu(menuinfo=["P(Q)*S(Q)", multip_models,
1146#                                  "mulplication of 2 models"],
1147#                                   list1=self.multiplication_factor,
1148#                                   list2=self.struct_list)
1149#        return 0
1150   
1151#    def _fill_plugin_menu(self, menuinfo, list1):
1152#        """
1153#        fill the plugin menu with costumized models
1154#        """
1155#        print ("got to fill plugin menu")
1156#        if len(list1) == 0:
1157#            id = wx.NewId()
1158#            msg = "No model available check plugins.log for errors to fix problem"
1159#            menuinfo[1].Append(int(id), "Empty", msg)
1160#        self._fill_simple_menu(menuinfo, list1)
1161       
1162#   def _fill_simple_menu(self, menuinfo, list1):
1163#       """
1164#       Fill the menu with list item
1165#       
1166#       :param modelmenu: the menu to fill
1167#       :param menuinfo: submenu item for the first column of this modelmenu
1168#                        with info.Should be a list :
1169#                        [name(string) , menu(wx.menu), help(string)]
1170#       :param list1: contains item (form factor )to fill modelmenu second column
1171#       
1172#       """
1173#       if len(list1) > 0:
1174#           self.model_combobox.set_list(menuinfo[0], list1)
1175           
1176#            for item in list1:
1177#                try:
1178#                    id = wx.NewId()
1179#                    struct_factor = item()
1180#                    struct_name = struct_factor.__class__.__name__
1181#                    if hasattr(struct_factor, "name"):
1182#                        struct_name = struct_factor.name
1183#                       
1184#                    menuinfo[1].Append(int(id), struct_name, struct_name)
1185#                    if not  item in self.struct_factor_dict.itervalues():
1186#                        self.struct_factor_dict[str(id)] = item
1187#                    wx.EVT_MENU(self.event_owner, int(id), self._on_model)
1188#                except:
1189#                    msg = "Error Occured: %s" % sys.exc_value
1190#                    wx.PostEvent(self.event_owner, StatusEvent(status=msg))
1191#               
1192#        id = wx.NewId()
1193#        self.modelmenu.AppendMenu(id, menuinfo[0], menuinfo[1], menuinfo[2])
1194#       
1195#    def _fill_menu(self, menuinfo, list1, list2):
1196#        """
1197#        Fill the menu with list item
1198#       
1199#        :param menuinfo: submenu item for the first column of this modelmenu
1200#                         with info.Should be a list :
1201#                         [name(string) , menu(wx.menu), help(string)]
1202#        :param list1: contains item (form factor )to fill modelmenu second column
1203#        :param list2: contains item (Structure factor )to fill modelmenu
1204#                third column
1205#               
1206#        """
1207#        if len(list1) > 0:
1208#            self.model_combobox.set_list(menuinfo[0], list1)
1209#           
1210#            for item in list1:
1211#                form_factor = item()
1212#                form_name = form_factor.__class__.__name__
1213#                if hasattr(form_factor, "name"):
1214#                    form_name = form_factor.name
1215#                ### store form factor to return to other users
1216#                newmenu = wx.Menu()
1217#                if len(list2) > 0:
1218#                    for model  in list2:
1219#                        id = wx.NewId()
1220#                        struct_factor = model()
1221#                        name = struct_factor.__class__.__name__
1222#                        if hasattr(struct_factor, "name"):
1223#                            name = struct_factor.name
1224#                        newmenu.Append(id, name, name)
1225#                        wx.EVT_MENU(self.event_owner, int(id), self._on_model)
1226#                        ## save form_fact and struct_fact
1227#                        self.form_factor_dict[int(id)] = [form_factor,
1228#                                                          struct_factor]
1229#                       
1230#                form_id = wx.NewId()
1231#                menuinfo[1].AppendMenu(int(form_id), form_name,
1232#                                       newmenu, menuinfo[2])
1233#        id = wx.NewId()
1234#        self.modelmenu.AppendMenu(id, menuinfo[0], menuinfo[1], menuinfo[2])
1235       
1236    def _on_model(self, evt):
1237        """
1238        React to a model menu event
1239       
1240        :param event: wx menu event
1241       
1242        """
1243        if int(evt.GetId()) in self.form_factor_dict.keys():
1244            from sas.models.MultiplicationModel import MultiplicationModel
1245            self.model_dictionary[MultiplicationModel.__name__] = MultiplicationModel
1246            model1, model2 = self.form_factor_dict[int(evt.GetId())]
1247            model = MultiplicationModel(model1, model2)
1248        else:
1249            model = self.struct_factor_dict[str(evt.GetId())]()
1250       
1251        #TODO: investigate why the following two lines were left in the code
1252        #      even though the ModelEvent class doesn't exist
1253        #evt = ModelEvent(model=model)
1254        #wx.PostEvent(self.event_owner, evt)
1255       
1256    def _get_multifunc_models(self):
1257        """
1258        Get the multifunctional models
1259        """
1260        for item in self.plugins:
1261            try:
1262                # check the multiplicity if any
1263                if item.multiplicity_info[0] > 1:
1264                    self.multi_func_list.append(item)
1265            except:
1266                # pass to other items
1267                pass
1268                   
1269    def get_model_list(self):
1270        """
1271        return dictionary of models for fitpanel use
1272       
1273        """
1274        ## Model_list now only contains attribute lists not category list.
1275        ## Eventually this should be in one master list -- read in category
1276        ## list then pull those models that exist and get attributes then add
1277        ## to list ..and if model does not exist remove from list as now
1278        ## and update json file.
1279        ##
1280        ## -PDB   April 26, 2014
1281       
1282#        self.model_combobox.set_list("Shapes", self.shape_list)
1283#        self.model_combobox.set_list("Shape-Independent",
1284#                                     self.shape_indep_list)
1285        self.model_combobox.set_list("Structure Factors", self.struct_list)
1286        self.model_combobox.set_list("Customized Models", self.plugins)
1287        self.model_combobox.set_list("P(Q)*S(Q)", self.multiplication_factor)
1288        self.model_combobox.set_list("multiplication",
1289                                     self.multiplication_factor)
1290        self.model_combobox.set_list("Multi-Functions", self.multi_func_list)
1291        return self.model_combobox.get_list()
1292   
1293    def get_model_name_list(self):
1294        """
1295        return regular model name list
1296        """
1297        return self.model_name_list
1298
1299    def get_model_dictionary(self):
1300        """
1301        return dictionary linking model names to objects
1302        """
1303        return self.model_dictionary
1304 
1305       
1306class ModelManager(object):
1307    """
1308    implement model
1309    """
1310    __modelmanager = ModelManagerBase()
1311    cat_model_list = [model_name for model_name \
1312                      in __modelmanager.model_dictionary.keys() \
1313                      if model_name not in __modelmanager.stored_plugins.keys()]
1314
1315    CategoryInstaller.check_install(model_list=cat_model_list)
1316    def findModels(self):
1317        return self.__modelmanager.findModels()
1318   
1319    def _getModelList(self):
1320        return self.__modelmanager._getModelList()
1321   
1322    def is_changed(self):
1323        return self.__modelmanager.is_changed()
1324   
1325    def update(self):
1326        return self.__modelmanager.update()
1327   
1328    def pulgins_reset(self):
1329        return self.__modelmanager.pulgins_reset()
1330   
1331    def populate_menu(self, modelmenu, event_owner):
1332        return self.__modelmanager.populate_menu(modelmenu, event_owner)
1333   
1334    def _on_model(self, evt):
1335        return self.__modelmanager._on_model(evt)
1336   
1337    def _get_multifunc_models(self):
1338        return self.__modelmanager._get_multifunc_models()
1339   
1340    def get_model_list(self):
1341        return self.__modelmanager.get_model_list()
1342   
1343    def get_model_name_list(self):
1344        return self.__modelmanager.get_model_name_list()
1345
1346    def get_model_dictionary(self):
1347        return self.__modelmanager.get_model_dictionary()
Note: See TracBrowser for help on using the repository browser.