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

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 f0d720b was f0d720b, checked in by ajj, 8 years ago

fixing line endings

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