source: sasview/src/sas/sasgui/perspectives/fitting/models.py @ 50a77df

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

Merge branch 'master' into sasmodels-integration

  • Property mode set to 100644
File size: 53.7 KB
Line 
1"""
2    Utilities to manage models
3"""
4import wx
5import imp
6import os
7import sys
8import math
9import os.path
10# Time is needed by the log method
11import time
12import logging
13import py_compile
14import shutil
15from sas.guiframe.events import StatusEvent
16# Explicitly import from the pluginmodel module so that py2exe
17# places it in the distribution. The Model1DPlugin class is used
18# as the base class of plug-in models.
19from sas.models.pluginmodel import Model1DPlugin
20from sas.models.BaseComponent import BaseComponent
21from sas.sasgui.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.BarBellModel import BarBellModel
555
556            self.model_dictionary[BarBellModel.__name__] = BarBellModel
557            #       self.shape_list.append(BarBellModel)
558            self.model_name_list.append(BarBellModel.__name__)
559        except:
560            logging.error(base_message.format(BarBellModel.__name__))
561
562        try:
563            from sas.models.CappedCylinderModel import CappedCylinderModel
564
565            self.model_dictionary[CappedCylinderModel.__name__] = CappedCylinderModel
566            #       self.shape_list.append(CappedCylinderModel)
567            self.model_name_list.append(CappedCylinderModel.__name__)
568        except:
569            logging.error(base_message.format(CappedCylinderModel.__name__))
570
571        try:
572            from sas.models.EllipsoidModel import EllipsoidModel
573
574            self.model_dictionary[EllipsoidModel.__name__] = EllipsoidModel
575            #        self.shape_list.append(EllipsoidModel)
576            self.multiplication_factor.append(EllipsoidModel)
577            self.model_name_list.append(EllipsoidModel.__name__)
578        except:
579            logging.error(base_message.format(EllipsoidModel.__name__))
580
581        try:
582            from sas.models.CoreShellEllipsoidModel import CoreShellEllipsoidModel
583
584            self.model_dictionary[CoreShellEllipsoidModel.__name__] = CoreShellEllipsoidModel
585            #        self.shape_list.append(CoreShellEllipsoidModel)
586            self.multiplication_factor.append(CoreShellEllipsoidModel)
587            self.model_name_list.append(CoreShellEllipsoidModel.__name__)
588        except:
589            logging.error(base_message.format(CoreShellEllipsoidModel.__name__))
590
591        try:
592            from sas.models.CoreShellEllipsoidXTModel import CoreShellEllipsoidXTModel
593
594            self.model_dictionary[CoreShellEllipsoidXTModel.__name__] = CoreShellEllipsoidXTModel
595            #        self.shape_list.append(CoreShellEllipsoidXTModel)
596            self.multiplication_factor.append(CoreShellEllipsoidXTModel)
597            self.model_name_list.append(CoreShellEllipsoidXTModel.__name__)
598        except:
599            logging.error(base_message.format(CoreShellEllipsoidXTModel.__name__))
600
601        try:
602            from sas.models.TriaxialEllipsoidModel import TriaxialEllipsoidModel
603
604            self.model_dictionary[TriaxialEllipsoidModel.__name__] = TriaxialEllipsoidModel
605            #        self.shape_list.append(TriaxialEllipsoidModel)
606            self.multiplication_factor.append(TriaxialEllipsoidModel)
607            self.model_name_list.append(TriaxialEllipsoidModel.__name__)
608        except:
609            logging.error(base_message.format(TriaxialEllipsoidModel.__name__))
610
611        try:
612            from sas.models.LamellarModel import LamellarModel
613
614            self.model_dictionary[LamellarModel.__name__] = LamellarModel
615            #        self.shape_list.append(LamellarModel)
616            self.model_name_list.append(LamellarModel.__name__)
617        except:
618            logging.error(base_message.format(LamellarModel.__name__))
619
620        try:
621            from sas.models.LamellarFFHGModel import LamellarFFHGModel
622
623            self.model_dictionary[LamellarFFHGModel.__name__] = LamellarFFHGModel
624            #        self.shape_list.append(LamellarFFHGModel)
625            self.model_name_list.append(LamellarFFHGModel.__name__)
626        except:
627            logging.error(base_message.format(LamellarFFHGModel.__name__))
628
629        try:
630            from sas.models.LamellarPSModel import LamellarPSModel
631
632            self.model_dictionary[LamellarPSModel.__name__] = LamellarPSModel
633            #        self.shape_list.append(LamellarPSModel)
634            self.model_name_list.append(LamellarPSModel.__name__)
635        except:
636            logging.error(base_message.format(LamellarPSModel.__name__))
637
638        try:
639            from sas.models.LamellarPSHGModel import LamellarPSHGModel
640
641            self.model_dictionary[LamellarPSHGModel.__name__] = LamellarPSHGModel
642            #        self.shape_list.append(LamellarPSHGModel)
643            self.model_name_list.append(LamellarPSHGModel.__name__)
644        except:
645            logging.error(base_message.format(LamellarPSHGModel.__name__))
646
647        try:
648            from sas.models.LamellarPCrystalModel import LamellarPCrystalModel
649
650            self.model_dictionary[LamellarPCrystalModel.__name__] = LamellarPCrystalModel
651            #        self.shape_list.append(LamellarPCrystalModel)
652            self.model_name_list.append(LamellarPCrystalModel.__name__)
653        except:
654            logging.error(base_message.format(LamellarPCrystalModel.__name__))
655
656        try:
657            from sas.models.SCCrystalModel import SCCrystalModel
658
659            self.model_dictionary[SCCrystalModel.__name__] = SCCrystalModel
660            #        self.shape_list.append(SCCrystalModel)
661            self.model_name_list.append(SCCrystalModel.__name__)
662        except:
663            logging.error(base_message.format(SCCrystalModel.__name__))
664           
665        try:
666            from sas.models.FCCrystalModel import FCCrystalModel
667
668            self.model_dictionary[FCCrystalModel.__name__] = FCCrystalModel
669            #        self.shape_list.append(FCCrystalModel)
670            self.model_name_list.append(FCCrystalModel.__name__)
671        except:
672            logging.error(base_message.format(FCCrystalModel.__name__))
673
674        try:
675            from sas.models.BCCrystalModel import BCCrystalModel
676
677            self.model_dictionary[BCCrystalModel.__name__] = BCCrystalModel
678            #        self.shape_list.append(BCCrystalModel)
679            self.model_name_list.append(BCCrystalModel.__name__)
680        except:
681            logging.error(base_message.format(BCCrystalModel.__name__))
682
683
684        ## Structure factor
685        try:
686            from sas.models.SquareWellStructure import SquareWellStructure
687
688            self.model_dictionary[SquareWellStructure.__name__] = SquareWellStructure
689            self.struct_list.append(SquareWellStructure)
690            self.model_name_list.append(SquareWellStructure.__name__)
691        except:
692            logging.error(base_message.format(SquareWellStructure.__name__))
693
694        try:
695            from sas.models.HardsphereStructure import HardsphereStructure
696
697            self.model_dictionary[HardsphereStructure.__name__] = HardsphereStructure
698            self.struct_list.append(HardsphereStructure)
699            self.model_name_list.append(HardsphereStructure.__name__)
700        except:
701            logging.error(base_message.format(HardsphereStructure.__name__))
702
703        try:
704            from sas.models.StickyHSStructure import StickyHSStructure
705
706            self.model_dictionary[StickyHSStructure.__name__] = StickyHSStructure
707            self.struct_list.append(StickyHSStructure)
708            self.model_name_list.append(StickyHSStructure.__name__)
709        except:
710            logging.error(base_message.format(StickyHSStructure.__name__))
711
712        try:
713            from sas.models.HayterMSAStructure import HayterMSAStructure
714
715            self.model_dictionary[HayterMSAStructure.__name__] = HayterMSAStructure
716            self.struct_list.append(HayterMSAStructure)
717            self.model_name_list.append(HayterMSAStructure.__name__)
718        except:
719            logging.error(base_message.format(HayterMSAStructure.__name__))
720
721
722
723        ##shape-independent models
724        try:
725            from sas.models.PowerLawAbsModel import PowerLawAbsModel
726
727            self.model_dictionary[PowerLawAbsModel.__name__] = PowerLawAbsModel
728            #        self.shape_indep_list.append(PowerLawAbsModel)
729            self.model_name_list.append(PowerLawAbsModel.__name__)
730        except:
731            logging.error(base_message.format(PowerLawAbsModel.__name__))
732
733        try:
734            from sas.models.BEPolyelectrolyte import BEPolyelectrolyte
735
736            self.model_dictionary[BEPolyelectrolyte.__name__] = BEPolyelectrolyte
737            #        self.shape_indep_list.append(BEPolyelectrolyte)
738            self.model_name_list.append(BEPolyelectrolyte.__name__)
739            self.form_factor_dict[str(wx.NewId())] = [SphereModel]
740        except:
741            logging.error(base_message.format(BEPolyelectrolyte.__name__))
742
743        try:
744            from sas.models.BroadPeakModel import BroadPeakModel
745
746            self.model_dictionary[BroadPeakModel.__name__] = BroadPeakModel
747            #        self.shape_indep_list.append(BroadPeakModel)
748            self.model_name_list.append(BroadPeakModel.__name__)
749        except:
750            logging.error(base_message.format(BroadPeakModel.__name__))
751
752        try:
753            from sas.models.CorrLengthModel import CorrLengthModel
754
755            self.model_dictionary[CorrLengthModel.__name__] = CorrLengthModel
756            #        self.shape_indep_list.append(CorrLengthModel)
757            self.model_name_list.append(CorrLengthModel.__name__)
758        except:
759            logging.error(base_message.format(CorrLengthModel.__name__))
760
761        try:
762            from sas.models.DABModel import DABModel
763
764            self.model_dictionary[DABModel.__name__] = DABModel
765            #        self.shape_indep_list.append(DABModel)
766            self.model_name_list.append(DABModel.__name__)
767        except:
768            logging.error(base_message.format(DABModel.__name__))
769
770        try:
771            from sas.models.DebyeModel import DebyeModel
772
773            self.model_dictionary[DebyeModel.__name__] = DebyeModel
774            #        self.shape_indep_list.append(DebyeModel)
775            self.model_name_list.append(DebyeModel.__name__)
776        except:
777            logging.error(base_message.format(DebyeModel.__name__))
778
779        try:
780            from sas.models.FractalModel import FractalModel
781
782            self.model_dictionary[FractalModel.__name__] = FractalModel
783            #        self.shape_indep_list.append(FractalModel)
784            self.model_name_list.append(FractalModel.__name__)
785        except:
786            logging.error(base_message.format(FractalModel.__name__))
787
788        try:
789            from sas.models.FractalCoreShellModel import FractalCoreShellModel
790
791            self.model_dictionary[FractalCoreShellModel.__name__] = FractalCoreShellModel
792            #        self.shape_indep_list.append(FractalCoreShellModel)
793            self.model_name_list.append(FractalCoreShellModel.__name__)
794        except:
795            logging.error(base_message.format(FractalCoreShellModel.__name__))
796
797        try:
798            from sas.models.GaussLorentzGelModel import GaussLorentzGelModel
799
800            self.model_dictionary[GaussLorentzGelModel.__name__] = GaussLorentzGelModel
801            #        self.shape_indep_list.append(GaussLorentzGelModel)
802            self.model_name_list.append(GaussLorentzGelModel.__name__)
803        except:
804            logging.error(base_message.format(GaussLorentzGelModel.__name__))
805
806        try:
807            from sas.models.GuinierModel import GuinierModel
808
809            self.model_dictionary[GuinierModel.__name__] = GuinierModel
810            #        self.shape_indep_list.append(GuinierModel)
811            self.model_name_list.append(GuinierModel.__name__)
812        except:
813            logging.error(base_message.format(GuinierModel.__name__))
814
815        try:
816            from sas.models.GuinierPorodModel import GuinierPorodModel
817
818            self.model_dictionary[GuinierPorodModel.__name__] = GuinierPorodModel
819            #        self.shape_indep_list.append(GuinierPorodModel)
820            self.model_name_list.append(GuinierPorodModel.__name__)
821        except:
822            logging.error(base_message.format(GuinierPorodModel.__name__))
823
824        try:
825            from sas.models.LorentzModel import LorentzModel
826
827            self.model_dictionary[LorentzModel.__name__] = LorentzModel
828            #        self.shape_indep_list.append(LorentzModel)
829            self.model_name_list.append(LorentzModel.__name__)
830        except:
831            logging.error(base_message.format(LorentzModel.__name__))
832
833        try:
834            from sas.models.MassFractalModel import MassFractalModel
835
836            self.model_dictionary[MassFractalModel.__name__] = MassFractalModel
837            #        self.shape_indep_list.append(MassFractalModel)
838            self.model_name_list.append(MassFractalModel.__name__)
839        except:
840            logging.error(base_message.format(MassFractalModel.__name__))
841
842        try:
843            from sas.models.MassSurfaceFractal import MassSurfaceFractal
844
845            self.model_dictionary[MassSurfaceFractal.__name__] = MassSurfaceFractal
846            #        self.shape_indep_list.append(MassSurfaceFractal)
847            self.model_name_list.append(MassSurfaceFractal.__name__)
848        except:
849            logging.error(base_message.format(MassSurfaceFractal.__name__))
850
851        try:
852            from sas.models.PeakGaussModel import PeakGaussModel
853
854            self.model_dictionary[PeakGaussModel.__name__] = PeakGaussModel
855            #        self.shape_indep_list.append(PeakGaussModel)
856            self.model_name_list.append(PeakGaussModel.__name__)
857        except:
858            logging.error(base_message.format(PeakGaussModel.__name__))
859
860        try:
861            from sas.models.PeakLorentzModel import PeakLorentzModel
862
863            self.model_dictionary[PeakLorentzModel.__name__] = PeakLorentzModel
864            #        self.shape_indep_list.append(PeakLorentzModel)
865            self.model_name_list.append(PeakLorentzModel.__name__)
866        except:
867            logging.error(base_message.format(PeakLorentzModel.__name__))
868
869        try:
870            from sas.models.Poly_GaussCoil import Poly_GaussCoil
871
872            self.model_dictionary[Poly_GaussCoil.__name__] = Poly_GaussCoil
873            #        self.shape_indep_list.append(Poly_GaussCoil)
874            self.model_name_list.append(Poly_GaussCoil.__name__)
875        except:
876            logging.error(base_message.format(Poly_GaussCoil.__name__))
877
878        try:
879            from sas.models.PolymerExclVolume import PolymerExclVolume
880
881            self.model_dictionary[PolymerExclVolume.__name__] = PolymerExclVolume
882            #        self.shape_indep_list.append(PolymerExclVolume)
883            self.model_name_list.append(PolymerExclVolume.__name__)
884        except:
885            logging.error(base_message.format(PolymerExclVolume.__name__))
886
887        try:
888            from sas.models.PorodModel import PorodModel
889
890            self.model_dictionary[PorodModel.__name__] = PorodModel
891            #        self.shape_indep_list.append(PorodModel)
892            self.model_name_list.append(PorodModel.__name__)
893        except:
894            logging.error(base_message.format(PorodModel.__name__))
895
896        try:
897            from sas.models.RPA10Model import RPA10Model
898
899            self.model_dictionary[RPA10Model.__name__] = RPA10Model
900            #        self.shape_indep_list.append(RPA10Model)
901            self.multi_func_list.append(RPA10Model)
902        except:
903            logging.error(base_message.format(RPA10Model.__name__))
904
905        try:
906            from sas.models.StarPolymer import StarPolymer
907
908            self.model_dictionary[StarPolymer.__name__] = StarPolymer
909            #        self.shape_indep_list.append(StarPolymer)
910            self.model_name_list.append(StarPolymer.__name__)
911        except:
912            logging.error(base_message.format(StarPolymer.__name__))
913
914        try:
915            from sas.models.SurfaceFractalModel import SurfaceFractalModel
916
917            self.model_dictionary[SurfaceFractalModel.__name__] = SurfaceFractalModel
918            #        self.shape_indep_list.append(SurfaceFractalModel)
919            self.model_name_list.append(SurfaceFractalModel.__name__)
920        except:
921            logging.error(base_message.format(SurfaceFractalModel.__name__))
922
923        try:
924            from sas.models.TeubnerStreyModel import TeubnerStreyModel
925
926            self.model_dictionary[TeubnerStreyModel.__name__] = TeubnerStreyModel
927            #        self.shape_indep_list.append(TeubnerStreyModel)
928            self.model_name_list.append(TeubnerStreyModel.__name__)
929        except:
930            logging.error(base_message.format(TeubnerStreyModel.__name__))
931
932        try:
933            from sas.models.TwoLorentzianModel import TwoLorentzianModel
934
935            self.model_dictionary[TwoLorentzianModel.__name__] = TwoLorentzianModel
936            #        self.shape_indep_list.append(TwoLorentzianModel)
937            self.model_name_list.append(TwoLorentzianModel.__name__)
938        except:
939            logging.error(base_message.format(TwoLorentzianModel.__name__))
940
941        try:
942            from sas.models.TwoPowerLawModel import TwoPowerLawModel
943
944            self.model_dictionary[TwoPowerLawModel.__name__] = TwoPowerLawModel
945            #        self.shape_indep_list.append(TwoPowerLawModel)
946            self.model_name_list.append(TwoPowerLawModel.__name__)
947        except:
948            logging.error(base_message.format(TwoPowerLawModel.__name__))
949
950        try:
951            from sas.models.UnifiedPowerRgModel import UnifiedPowerRgModel
952
953            self.model_dictionary[UnifiedPowerRgModel.__name__] = UnifiedPowerRgModel
954            #        self.shape_indep_list.append(UnifiedPowerRgModel)
955            self.multi_func_list.append(UnifiedPowerRgModel)
956        except:
957            logging.error(base_message.format(UnifiedPowerRgModel.__name__))
958
959        try:
960            from sas.models.LineModel import LineModel
961
962            self.model_dictionary[LineModel.__name__] = LineModel
963            #        self.shape_indep_list.append(LineModel)
964            self.model_name_list.append(LineModel.__name__)
965        except:
966            logging.error(base_message.format(LineModel.__name__))
967
968        try:
969            from sas.models.ReflectivityModel import ReflectivityModel
970
971            self.model_dictionary[ReflectivityModel.__name__] = ReflectivityModel
972            #        self.shape_indep_list.append(ReflectivityModel)
973            self.multi_func_list.append(ReflectivityModel)
974        except:
975            logging.error(base_message.format(ReflectivityModel.__name__))
976
977        try:
978            from sas.models.ReflectivityIIModel import ReflectivityIIModel
979
980            self.model_dictionary[ReflectivityIIModel.__name__] = ReflectivityIIModel
981            #        self.shape_indep_list.append(ReflectivityIIModel)
982            self.multi_func_list.append(ReflectivityIIModel)
983        except:
984            logging.error(base_message.format(ReflectivityIIModel.__name__))
985
986        try:
987            from sas.models.GelFitModel import GelFitModel
988
989            self.model_dictionary[GelFitModel.__name__] = GelFitModel
990            #        self.shape_indep_list.append(GelFitModel)
991            self.model_name_list.append(GelFitModel.__name__)
992        except:
993            logging.error(base_message.format(GelFitModel.__name__))
994
995        try:
996            from sas.models.PringlesModel import PringlesModel
997
998            self.model_dictionary[PringlesModel.__name__] = PringlesModel
999            #        self.shape_indep_list.append(PringlesModel)
1000            self.model_name_list.append(PringlesModel.__name__)
1001        except:
1002            logging.error(base_message.format(PringlesModel.__name__))
1003
1004        try:
1005            from sas.models.RectangularPrismModel import RectangularPrismModel
1006
1007            self.model_dictionary[RectangularPrismModel.__name__] = RectangularPrismModel
1008            #        self.shape_list.append(RectangularPrismModel)
1009            self.multiplication_factor.append(RectangularPrismModel)
1010            self.model_name_list.append(RectangularPrismModel.__name__)
1011        except:
1012            logging.error(base_message.format(RectangularPrismModel.__name__))
1013
1014        try:
1015            from sas.models.RectangularHollowPrismInfThinWallsModel import RectangularHollowPrismInfThinWallsModel
1016
1017            self.model_dictionary[RectangularHollowPrismInfThinWallsModel.__name__] = RectangularHollowPrismInfThinWallsModel
1018            #        self.shape_list.append(RectangularHollowPrismInfThinWallsModel)
1019            self.multiplication_factor.append(RectangularHollowPrismInfThinWallsModel)
1020            self.model_name_list.append(RectangularHollowPrismInfThinWallsModel.__name__)
1021        except:
1022            logging.error(base_message.format(RectangularHollowPrismInfThinWallsModel.__name__))
1023
1024        try:
1025            from sas.models.RectangularHollowPrismModel import RectangularHollowPrismModel
1026
1027            self.model_dictionary[RectangularHollowPrismModel.__name__] = RectangularHollowPrismModel
1028            #        self.shape_list.append(RectangularHollowPrismModel)
1029            self.multiplication_factor.append(RectangularHollowPrismModel)
1030            self.model_name_list.append(RectangularHollowPrismModel.__name__)
1031        except:
1032            logging.error(base_message.format(RectangularHollowPrismModel.__name__))
1033
1034        try:
1035            from sas.models.MicelleSphCoreModel import MicelleSphCoreModel
1036
1037            self.model_dictionary[MicelleSphCoreModel.__name__] = MicelleSphCoreModel
1038            #        self.shape_list.append(MicelleSphCoreModel)
1039            self.multiplication_factor.append(MicelleSphCoreModel)
1040            self.model_name_list.append(MicelleSphCoreModel.__name__)
1041        except:
1042            logging.error(base_message.format(MicelleSphCoreModel.__name__))
1043
1044
1045
1046        #from sas.models.FractalO_Z import FractalO_Z
1047        #self.model_dictionary[FractalO_Z.__name__] = FractalO_Z
1048        #self.shape_indep_list.append(FractalO_Z)
1049        #self.model_name_list.append(FractalO_Z.__name__)
1050
1051        #Looking for plugins
1052        self.stored_plugins = self.findModels()
1053        self.plugins = self.stored_plugins.values()
1054        for name, plug in self.stored_plugins.iteritems():
1055            self.model_dictionary[name] = plug
1056
1057        self._get_multifunc_models()
1058
1059        return 0
1060
1061    def is_changed(self):
1062        """
1063        check the last time the plugin dir has changed and return true
1064         is the directory was modified else return false
1065        """
1066        is_modified = False
1067        plugin_dir = find_plugins_dir()
1068        if os.path.isdir(plugin_dir):
1069            temp = os.path.getmtime(plugin_dir)
1070            if  self.last_time_dir_modified != temp:
1071                is_modified = True
1072                self.last_time_dir_modified = temp
1073
1074        return is_modified
1075
1076    def update(self):
1077        """
1078        return a dictionary of model if
1079        new models were added else return empty dictionary
1080        """
1081        new_plugins = self.findModels()
1082        if len(new_plugins) > 0:
1083            for name, plug in  new_plugins.iteritems():
1084                if name not in self.stored_plugins.keys():
1085                    self.stored_plugins[name] = plug
1086                    self.plugins.append(plug)
1087                    self.model_dictionary[name] = plug
1088            self.model_combobox.set_list("Customized Models", self.plugins)
1089            return self.model_combobox.get_list()
1090        else:
1091            return {}
1092
1093    def pulgins_reset(self):
1094        """
1095        return a dictionary of model
1096        """
1097        self.plugins = []
1098        new_plugins = _findModels(dir)
1099        for name, plug in  new_plugins.iteritems():
1100            for stored_name, stored_plug in self.stored_plugins.iteritems():
1101                if name == stored_name:
1102                    del self.stored_plugins[name]
1103                    del self.model_dictionary[name]
1104                    break
1105            self.stored_plugins[name] = plug
1106            self.plugins.append(plug)
1107            self.model_dictionary[name] = plug
1108
1109        self.model_combobox.reset_list("Customized Models", self.plugins)
1110        return self.model_combobox.get_list()
1111
1112##   I believe the next four methods are for the old form factor GUI
1113##   where the dropdown showed a list of categories which then rolled out
1114##   in a second dropdown to the side. Some testing shows they indeed no longer
1115##   seem to be called.  If no problems are found during testing of release we
1116##   can remove this huge chunck of stuff.
1117##
1118##   -PDB  April 26, 2014
1119
1120#   def populate_menu(self, modelmenu, event_owner):
1121#       """
1122#       Populate a menu with our models
1123#       
1124#       :param id: first menu event ID to use when binding the menu events
1125#       :param modelmenu: wx.Menu object to populate
1126#       :param event_owner: wx object to bind the menu events to
1127#       
1128#       :return: the next free event ID following the new menu events
1129#       
1130#       """
1131#
1132        ## Fill model lists
1133#        self._getModelList()
1134        ## store reference to model menu of guiframe
1135#        self.modelmenu = modelmenu
1136        ## guiframe reference
1137#        self.event_owner = event_owner
1138
1139#        shape_submenu = wx.Menu()
1140#        shape_indep_submenu = wx.Menu()
1141#        structure_factor = wx.Menu()
1142#        added_models = wx.Menu()
1143#        multip_models = wx.Menu()
1144        ## create menu with shape
1145#        self._fill_simple_menu(menuinfo=["Shapes",
1146#                                         shape_submenu,
1147#                                         " simple shape"],
1148#                         list1=self.shape_list)
1149
1150#        self._fill_simple_menu(menuinfo=["Shape-Independent",
1151#                                         shape_indep_submenu,
1152#                                         "List of shape-independent models"],
1153#                         list1=self.shape_indep_list)
1154
1155#        self._fill_simple_menu(menuinfo=["Structure Factors",
1156#                                         structure_factor,
1157#                                         "List of Structure factors models"],
1158#                                list1=self.struct_list)
1159
1160#        self._fill_plugin_menu(menuinfo=["Customized Models", added_models,
1161#                                            "List of additional models"],
1162#                                 list1=self.plugins)
1163
1164#        self._fill_menu(menuinfo=["P(Q)*S(Q)", multip_models,
1165#                                  "mulplication of 2 models"],
1166#                                   list1=self.multiplication_factor,
1167#                                   list2=self.struct_list)
1168#        return 0
1169
1170#    def _fill_plugin_menu(self, menuinfo, list1):
1171#        """
1172#        fill the plugin menu with costumized models
1173#        """
1174#        print ("got to fill plugin menu")
1175#        if len(list1) == 0:
1176#            id = wx.NewId()
1177#            msg = "No model available check plugins.log for errors to fix problem"
1178#            menuinfo[1].Append(int(id), "Empty", msg)
1179#        self._fill_simple_menu(menuinfo, list1)
1180
1181#   def _fill_simple_menu(self, menuinfo, list1):
1182#       """
1183#       Fill the menu with list item
1184#       
1185#       :param modelmenu: the menu to fill
1186#       :param menuinfo: submenu item for the first column of this modelmenu
1187#                        with info.Should be a list :
1188#                        [name(string) , menu(wx.menu), help(string)]
1189#       :param list1: contains item (form factor )to fill modelmenu second column
1190#       
1191#       """
1192#       if len(list1) > 0:
1193#           self.model_combobox.set_list(menuinfo[0], list1)
1194
1195#            for item in list1:
1196#                try:
1197#                    id = wx.NewId()
1198#                    struct_factor = item()
1199#                    struct_name = struct_factor.__class__.__name__
1200#                    if hasattr(struct_factor, "name"):
1201#                        struct_name = struct_factor.name
1202#                       
1203#                    menuinfo[1].Append(int(id), struct_name, struct_name)
1204#                    if not  item in self.struct_factor_dict.itervalues():
1205#                        self.struct_factor_dict[str(id)] = item
1206#                    wx.EVT_MENU(self.event_owner, int(id), self._on_model)
1207#                except:
1208#                    msg = "Error Occured: %s" % sys.exc_value
1209#                    wx.PostEvent(self.event_owner, StatusEvent(status=msg))
1210#               
1211#        id = wx.NewId()
1212#        self.modelmenu.AppendMenu(id, menuinfo[0], menuinfo[1], menuinfo[2])
1213#       
1214#    def _fill_menu(self, menuinfo, list1, list2):
1215#        """
1216#        Fill the menu with list item
1217#       
1218#        :param menuinfo: submenu item for the first column of this modelmenu
1219#                         with info.Should be a list :
1220#                         [name(string) , menu(wx.menu), help(string)]
1221#        :param list1: contains item (form factor )to fill modelmenu second column
1222#        :param list2: contains item (Structure factor )to fill modelmenu
1223#                third column
1224#               
1225#        """
1226#        if len(list1) > 0:
1227#            self.model_combobox.set_list(menuinfo[0], list1)
1228#           
1229#            for item in list1:
1230#                form_factor = item()
1231#                form_name = form_factor.__class__.__name__
1232#                if hasattr(form_factor, "name"):
1233#                    form_name = form_factor.name
1234#                ### store form factor to return to other users
1235#                newmenu = wx.Menu()
1236#                if len(list2) > 0:
1237#                    for model  in list2:
1238#                        id = wx.NewId()
1239#                        struct_factor = model()
1240#                        name = struct_factor.__class__.__name__
1241#                        if hasattr(struct_factor, "name"):
1242#                            name = struct_factor.name
1243#                        newmenu.Append(id, name, name)
1244#                        wx.EVT_MENU(self.event_owner, int(id), self._on_model)
1245#                        ## save form_fact and struct_fact
1246#                        self.form_factor_dict[int(id)] = [form_factor,
1247#                                                          struct_factor]
1248#                       
1249#                form_id = wx.NewId()
1250#                menuinfo[1].AppendMenu(int(form_id), form_name,
1251#                                       newmenu, menuinfo[2])
1252#        id = wx.NewId()
1253#        self.modelmenu.AppendMenu(id, menuinfo[0], menuinfo[1], menuinfo[2])
1254
1255    def _on_model(self, evt):
1256        """
1257        React to a model menu event
1258
1259        :param event: wx menu event
1260
1261        """
1262        if int(evt.GetId()) in self.form_factor_dict.keys():
1263            from sas.models.MultiplicationModel import MultiplicationModel
1264            self.model_dictionary[MultiplicationModel.__name__] = MultiplicationModel
1265            model1, model2 = self.form_factor_dict[int(evt.GetId())]
1266            model = MultiplicationModel(model1, model2)
1267        else:
1268            model = self.struct_factor_dict[str(evt.GetId())]()
1269
1270        #TODO: investigate why the following two lines were left in the code
1271        #      even though the ModelEvent class doesn't exist
1272        #evt = ModelEvent(model=model)
1273        #wx.PostEvent(self.event_owner, evt)
1274
1275    def _get_multifunc_models(self):
1276        """
1277        Get the multifunctional models
1278        """
1279        for item in self.plugins:
1280            try:
1281                # check the multiplicity if any
1282                if item.multiplicity_info[0] > 1:
1283                    self.multi_func_list.append(item)
1284            except:
1285                # pass to other items
1286                pass
1287
1288    def get_model_list(self):
1289        """
1290        return dictionary of models for fitpanel use
1291
1292        """
1293        ## Model_list now only contains attribute lists not category list.
1294        ## Eventually this should be in one master list -- read in category
1295        ## list then pull those models that exist and get attributes then add
1296        ## to list ..and if model does not exist remove from list as now
1297        ## and update json file.
1298        ##
1299        ## -PDB   April 26, 2014
1300
1301#        self.model_combobox.set_list("Shapes", self.shape_list)
1302#        self.model_combobox.set_list("Shape-Independent",
1303#                                     self.shape_indep_list)
1304        self.model_combobox.set_list("Structure Factors", self.struct_list)
1305        self.model_combobox.set_list("Customized Models", self.plugins)
1306        self.model_combobox.set_list("P(Q)*S(Q)", self.multiplication_factor)
1307        self.model_combobox.set_list("multiplication",
1308                                     self.multiplication_factor)
1309        self.model_combobox.set_list("Multi-Functions", self.multi_func_list)
1310        return self.model_combobox.get_list()
1311
1312    def get_model_name_list(self):
1313        """
1314        return regular model name list
1315        """
1316        return self.model_name_list
1317
1318    def get_model_dictionary(self):
1319        """
1320        return dictionary linking model names to objects
1321        """
1322        return self.model_dictionary
1323
1324
1325class ModelManager(object):
1326    """
1327    implement model
1328    """
1329    __modelmanager = ModelManagerBase()
1330    cat_model_list = [model_name for model_name \
1331                      in __modelmanager.model_dictionary.keys() \
1332                      if model_name not in __modelmanager.stored_plugins.keys()]
1333
1334    CategoryInstaller.check_install(model_list=cat_model_list)
1335    def findModels(self):
1336        return self.__modelmanager.findModels()
1337
1338    def _getModelList(self):
1339        return self.__modelmanager._getModelList()
1340
1341    def is_changed(self):
1342        return self.__modelmanager.is_changed()
1343
1344    def update(self):
1345        return self.__modelmanager.update()
1346
1347    def pulgins_reset(self):
1348        return self.__modelmanager.pulgins_reset()
1349
1350    def populate_menu(self, modelmenu, event_owner):
1351        return self.__modelmanager.populate_menu(modelmenu, event_owner)
1352
1353    def _on_model(self, evt):
1354        return self.__modelmanager._on_model(evt)
1355
1356    def _get_multifunc_models(self):
1357        return self.__modelmanager._get_multifunc_models()
1358
1359    def get_model_list(self):
1360        return self.__modelmanager.get_model_list()
1361
1362    def get_model_name_list(self):
1363        return self.__modelmanager.get_model_name_list()
1364
1365    def get_model_dictionary(self):
1366        return self.__modelmanager.get_model_dictionary()
Note: See TracBrowser for help on using the repository browser.