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