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

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 4666660 was 415fb82, checked in by krzywon, 10 years ago

Fixed the perspectives loading error. Cleaned up the sasview.log by
removing any extra linefeeds/carraige returns and added a start session
and end session message.

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