1 | |
---|
2 | import wx |
---|
3 | import wx.lib.newevent |
---|
4 | import imp |
---|
5 | import os,sys,math |
---|
6 | import os.path |
---|
7 | |
---|
8 | (ModelEvent, EVT_MODEL) = wx.lib.newevent.NewEvent() |
---|
9 | from sans.guicomm.events import StatusEvent |
---|
10 | # Time is needed by the log method |
---|
11 | import time |
---|
12 | |
---|
13 | # Explicitly import from the pluginmodel module so that py2exe |
---|
14 | # places it in the distribution. The Model1DPlugin class is used |
---|
15 | # as the base class of plug-in models. |
---|
16 | from sans.models.pluginmodel import Model1DPlugin |
---|
17 | |
---|
18 | def log(message): |
---|
19 | """ |
---|
20 | """ |
---|
21 | out = open("plugins.log", 'a') |
---|
22 | out.write("%10g: %s\n" % (time.clock(), message)) |
---|
23 | out.close() |
---|
24 | |
---|
25 | def findModels(): |
---|
26 | """ |
---|
27 | """ |
---|
28 | log("looking for models in: %s/plugins" % os.getcwd()) |
---|
29 | if os.path.isdir('plugins'): |
---|
30 | return _findModels('plugins') |
---|
31 | return [] |
---|
32 | |
---|
33 | def _check_plugin(model, name): |
---|
34 | """ |
---|
35 | Do some checking before model adding plugins in the list |
---|
36 | |
---|
37 | :param model: class model to add into the plugin list |
---|
38 | :param name:name of the module plugin |
---|
39 | |
---|
40 | :return model: model if valid model or None if not valid |
---|
41 | |
---|
42 | """ |
---|
43 | #Check is the plugin is of type Model1DPlugin |
---|
44 | if not issubclass(model, Model1DPlugin): |
---|
45 | msg= "Plugin %s must be of type Model1DPlugin \n"%str(name) |
---|
46 | log(msg) |
---|
47 | return None |
---|
48 | if model.__name__!="Model": |
---|
49 | msg= "Plugin %s class name must be Model \n"%str(name) |
---|
50 | log(msg) |
---|
51 | return None |
---|
52 | try: |
---|
53 | new_instance= model() |
---|
54 | except: |
---|
55 | msg="Plugin %s error in __init__ \n\t: %s %s\n"%(str(name), |
---|
56 | str(sys.exc_type),sys.exc_value) |
---|
57 | log(msg) |
---|
58 | return None |
---|
59 | |
---|
60 | new_instance= model() |
---|
61 | if hasattr(new_instance,"function"): |
---|
62 | try: |
---|
63 | value=new_instance.function() |
---|
64 | except: |
---|
65 | msg="Plugin %s: error writing function \n\t :%s %s\n "%(str(name), |
---|
66 | str(sys.exc_type),sys.exc_value) |
---|
67 | log(msg) |
---|
68 | return None |
---|
69 | else: |
---|
70 | msg="Plugin %s needs a method called function \n"%str(name) |
---|
71 | log(msg) |
---|
72 | return None |
---|
73 | return model |
---|
74 | |
---|
75 | |
---|
76 | def _findModels(dir): |
---|
77 | """ |
---|
78 | """ |
---|
79 | # List of plugin objects |
---|
80 | plugins = [] |
---|
81 | # Go through files in plug-in directory |
---|
82 | try: |
---|
83 | list = os.listdir(dir) |
---|
84 | for item in list: |
---|
85 | toks = os.path.splitext(os.path.basename(item)) |
---|
86 | if toks[1]=='.py' and not toks[0]=='__init__': |
---|
87 | name = toks[0] |
---|
88 | |
---|
89 | path = [os.path.abspath(dir)] |
---|
90 | file = None |
---|
91 | try: |
---|
92 | (file, path, info) = imp.find_module(name, path) |
---|
93 | module = imp.load_module( name, file, item, info ) |
---|
94 | if hasattr(module, "Model"): |
---|
95 | try: |
---|
96 | if _check_plugin(module.Model, name)!=None: |
---|
97 | plugins.append(module.Model) |
---|
98 | except: |
---|
99 | msg="Error accessing Model" |
---|
100 | msg+="in %s\n %s %s\n" % (name, |
---|
101 | str(sys.exc_type), sys.exc_value) |
---|
102 | log(msg) |
---|
103 | except: |
---|
104 | msg="Error accessing Model" |
---|
105 | msg +=" in %s\n %s %s \n" %(name, |
---|
106 | str(sys.exc_type), sys.exc_value) |
---|
107 | log(msg) |
---|
108 | finally: |
---|
109 | |
---|
110 | if not file==None: |
---|
111 | file.close() |
---|
112 | except: |
---|
113 | # Don't deal with bad plug-in imports. Just skip. |
---|
114 | pass |
---|
115 | return plugins |
---|
116 | |
---|
117 | class ModelList(object): |
---|
118 | """ |
---|
119 | Contains dictionary of model and their type |
---|
120 | """ |
---|
121 | def __init__(self): |
---|
122 | """ |
---|
123 | """ |
---|
124 | self.mydict = {} |
---|
125 | |
---|
126 | def set_list(self, name, mylist): |
---|
127 | """ |
---|
128 | :param name: the type of the list |
---|
129 | :param mylist: the list to add |
---|
130 | |
---|
131 | """ |
---|
132 | if name not in self.mydict.keys(): |
---|
133 | self.mydict[name] = mylist |
---|
134 | |
---|
135 | |
---|
136 | def get_list(self): |
---|
137 | """ |
---|
138 | return all the list stored in a dictionary object |
---|
139 | """ |
---|
140 | return self.mydict |
---|
141 | |
---|
142 | class ModelManager: |
---|
143 | """ |
---|
144 | """ |
---|
145 | ## external dict for models |
---|
146 | model_combobox = ModelList() |
---|
147 | ## Dictionary of form models |
---|
148 | form_factor_dict = {} |
---|
149 | ## dictionary of other |
---|
150 | struct_factor_dict = {} |
---|
151 | ##list of form factors |
---|
152 | shape_list =[] |
---|
153 | ## independent shape model list |
---|
154 | shape_indep_list = [] |
---|
155 | ##list of structure factors |
---|
156 | struct_list= [] |
---|
157 | ##list of model allowing multiplication |
---|
158 | multiplication_factor=[] |
---|
159 | ##list of multifunctional shapes |
---|
160 | multi_func_list =[] |
---|
161 | ## list of added models |
---|
162 | plugins=[] |
---|
163 | ## Event owner (guiframe) |
---|
164 | event_owner = None |
---|
165 | |
---|
166 | def _getModelList(self): |
---|
167 | """ |
---|
168 | List of models we want to make available by default |
---|
169 | for this application |
---|
170 | |
---|
171 | :return: the next free event ID following the new menu events |
---|
172 | |
---|
173 | """ |
---|
174 | from sans.models.SphereModel import SphereModel |
---|
175 | self.shape_list.append(SphereModel) |
---|
176 | self.multiplication_factor.append(SphereModel) |
---|
177 | |
---|
178 | from sans.models.BinaryHSModel import BinaryHSModel |
---|
179 | self.shape_list.append(BinaryHSModel) |
---|
180 | |
---|
181 | from sans.models.FuzzySphereModel import FuzzySphereModel |
---|
182 | self.shape_list.append(FuzzySphereModel) |
---|
183 | self.multiplication_factor.append(FuzzySphereModel) |
---|
184 | |
---|
185 | from sans.models.CoreShellModel import CoreShellModel |
---|
186 | self.shape_list.append(CoreShellModel) |
---|
187 | self.multiplication_factor.append(CoreShellModel) |
---|
188 | |
---|
189 | from sans.models.CoreMultiShellModel import CoreMultiShellModel |
---|
190 | self.shape_list.append(CoreMultiShellModel) |
---|
191 | self.multiplication_factor.append(CoreMultiShellModel) |
---|
192 | self.multi_func_list.append(CoreMultiShellModel) |
---|
193 | |
---|
194 | from sans.models.VesicleModel import VesicleModel |
---|
195 | self.shape_list.append(VesicleModel) |
---|
196 | self.multiplication_factor.append(VesicleModel) |
---|
197 | |
---|
198 | from sans.models.MultiShellModel import MultiShellModel |
---|
199 | self.shape_list.append(MultiShellModel) |
---|
200 | self.multiplication_factor.append(MultiShellModel) |
---|
201 | |
---|
202 | from sans.models.OnionExpShellModel import OnionExpShellModel |
---|
203 | self.shape_list.append(OnionExpShellModel) |
---|
204 | self.multiplication_factor.append(OnionExpShellModel) |
---|
205 | self.multi_func_list.append(OnionExpShellModel) |
---|
206 | |
---|
207 | from sans.models.SphericalSLDModel import SphericalSLDModel |
---|
208 | self.shape_list.append(SphericalSLDModel) |
---|
209 | self.multiplication_factor.append(SphericalSLDModel) |
---|
210 | self.multi_func_list.append(SphericalSLDModel) |
---|
211 | |
---|
212 | from sans.models.CylinderModel import CylinderModel |
---|
213 | self.shape_list.append(CylinderModel) |
---|
214 | self.multiplication_factor.append(CylinderModel) |
---|
215 | |
---|
216 | from sans.models.CoreShellCylinderModel import CoreShellCylinderModel |
---|
217 | self.shape_list.append(CoreShellCylinderModel) |
---|
218 | self.multiplication_factor.append(CoreShellCylinderModel) |
---|
219 | |
---|
220 | from sans.models.HollowCylinderModel import HollowCylinderModel |
---|
221 | self.shape_list.append(HollowCylinderModel) |
---|
222 | self.multiplication_factor.append(HollowCylinderModel) |
---|
223 | |
---|
224 | from sans.models.FlexibleCylinderModel import FlexibleCylinderModel |
---|
225 | self.shape_list.append(FlexibleCylinderModel) |
---|
226 | |
---|
227 | from sans.models.FlexCylEllipXModel import FlexCylEllipXModel |
---|
228 | self.shape_list.append(FlexCylEllipXModel) |
---|
229 | |
---|
230 | from sans.models.StackedDisksModel import StackedDisksModel |
---|
231 | self.shape_list.append(StackedDisksModel) |
---|
232 | self.multiplication_factor.append(StackedDisksModel) |
---|
233 | |
---|
234 | from sans.models.ParallelepipedModel import ParallelepipedModel |
---|
235 | self.shape_list.append(ParallelepipedModel) |
---|
236 | self.multiplication_factor.append(ParallelepipedModel) |
---|
237 | |
---|
238 | from sans.models.CSParallelepipedModel import CSParallelepipedModel |
---|
239 | self.shape_list.append(CSParallelepipedModel) |
---|
240 | self.multiplication_factor.append(CSParallelepipedModel) |
---|
241 | |
---|
242 | from sans.models.EllipticalCylinderModel import EllipticalCylinderModel |
---|
243 | self.shape_list.append(EllipticalCylinderModel) |
---|
244 | self.multiplication_factor.append(EllipticalCylinderModel) |
---|
245 | |
---|
246 | from sans.models.BarBellModel import BarBellModel |
---|
247 | self.shape_list.append(BarBellModel) |
---|
248 | # not implemeted yet! |
---|
249 | #self.multiplication_factor.append(BarBellModel) |
---|
250 | |
---|
251 | from sans.models.CappedCylinderModel import CappedCylinderModel |
---|
252 | self.shape_list.append(CappedCylinderModel) |
---|
253 | # not implemeted yet! |
---|
254 | #self.multiplication_factor.append(CappedCylinderModel) |
---|
255 | |
---|
256 | from sans.models.EllipsoidModel import EllipsoidModel |
---|
257 | self.shape_list.append(EllipsoidModel) |
---|
258 | self.multiplication_factor.append(EllipsoidModel) |
---|
259 | |
---|
260 | from sans.models.CoreShellEllipsoidModel import CoreShellEllipsoidModel |
---|
261 | self.shape_list.append(CoreShellEllipsoidModel) |
---|
262 | self.multiplication_factor.append(CoreShellEllipsoidModel) |
---|
263 | |
---|
264 | from sans.models.TriaxialEllipsoidModel import TriaxialEllipsoidModel |
---|
265 | self.shape_list.append(TriaxialEllipsoidModel) |
---|
266 | self.multiplication_factor.append(TriaxialEllipsoidModel) |
---|
267 | |
---|
268 | from sans.models.LamellarModel import LamellarModel |
---|
269 | self.shape_list.append(LamellarModel) |
---|
270 | |
---|
271 | from sans.models.LamellarFFHGModel import LamellarFFHGModel |
---|
272 | self.shape_list.append(LamellarFFHGModel) |
---|
273 | |
---|
274 | from sans.models.LamellarPSModel import LamellarPSModel |
---|
275 | self.shape_list.append(LamellarPSModel) |
---|
276 | |
---|
277 | from sans.models.LamellarPSHGModel import LamellarPSHGModel |
---|
278 | self.shape_list.append(LamellarPSHGModel) |
---|
279 | |
---|
280 | from sans.models.LamellarPCrystalModel import LamellarPCrystalModel |
---|
281 | self.shape_list.append(LamellarPCrystalModel) |
---|
282 | |
---|
283 | from sans.models.SCCrystalModel import SCCrystalModel |
---|
284 | self.shape_list.append(SCCrystalModel) |
---|
285 | |
---|
286 | from sans.models.FCCrystalModel import FCCrystalModel |
---|
287 | self.shape_list.append(FCCrystalModel) |
---|
288 | |
---|
289 | from sans.models.BCCrystalModel import BCCrystalModel |
---|
290 | self.shape_list.append(BCCrystalModel) |
---|
291 | |
---|
292 | ## Structure factor |
---|
293 | from sans.models.SquareWellStructure import SquareWellStructure |
---|
294 | self.struct_list.append(SquareWellStructure) |
---|
295 | |
---|
296 | from sans.models.HardsphereStructure import HardsphereStructure |
---|
297 | self.struct_list.append(HardsphereStructure) |
---|
298 | |
---|
299 | from sans.models.StickyHSStructure import StickyHSStructure |
---|
300 | self.struct_list.append(StickyHSStructure) |
---|
301 | |
---|
302 | from sans.models.HayterMSAStructure import HayterMSAStructure |
---|
303 | self.struct_list.append(HayterMSAStructure) |
---|
304 | |
---|
305 | ##shape-independent models |
---|
306 | from sans.models.PowerLawAbsModel import PowerLawAbsModel |
---|
307 | self.shape_indep_list.append( PowerLawAbsModel ) |
---|
308 | |
---|
309 | from sans.models.BEPolyelectrolyte import BEPolyelectrolyte |
---|
310 | self.shape_indep_list.append(BEPolyelectrolyte ) |
---|
311 | self.form_factor_dict[str(wx.NewId())] = [SphereModel] |
---|
312 | |
---|
313 | from sans.models.BroadPeakModel import BroadPeakModel |
---|
314 | self.shape_indep_list.append(BroadPeakModel) |
---|
315 | |
---|
316 | from sans.models.CorrLengthModel import CorrLengthModel |
---|
317 | self.shape_indep_list.append(CorrLengthModel) |
---|
318 | |
---|
319 | from sans.models.DABModel import DABModel |
---|
320 | self.shape_indep_list.append(DABModel ) |
---|
321 | |
---|
322 | from sans.models.DebyeModel import DebyeModel |
---|
323 | self.shape_indep_list.append(DebyeModel ) |
---|
324 | |
---|
325 | #FractalModel (a c-model)is now being used instead of FractalAbsModel. |
---|
326 | from sans.models.FractalModel import FractalModel |
---|
327 | self.shape_indep_list.append(FractalModel ) |
---|
328 | |
---|
329 | from sans.models.FractalCoreShellModel import FractalCoreShellModel |
---|
330 | self.shape_indep_list.append(FractalCoreShellModel ) |
---|
331 | |
---|
332 | from sans.models.GaussLorentzGelModel import GaussLorentzGelModel |
---|
333 | self.shape_indep_list.append(GaussLorentzGelModel) |
---|
334 | |
---|
335 | from sans.models.GuinierModel import GuinierModel |
---|
336 | self.shape_indep_list.append(GuinierModel ) |
---|
337 | |
---|
338 | from sans.models.GuinierPorodModel import GuinierPorodModel |
---|
339 | self.shape_indep_list.append(GuinierPorodModel ) |
---|
340 | |
---|
341 | from sans.models.LorentzModel import LorentzModel |
---|
342 | self.shape_indep_list.append( LorentzModel) |
---|
343 | |
---|
344 | from sans.models.PeakGaussModel import PeakGaussModel |
---|
345 | self.shape_indep_list.append(PeakGaussModel) |
---|
346 | |
---|
347 | from sans.models.PeakLorentzModel import PeakLorentzModel |
---|
348 | self.shape_indep_list.append(PeakLorentzModel) |
---|
349 | |
---|
350 | from sans.models.Poly_GaussCoil import Poly_GaussCoil |
---|
351 | self.shape_indep_list.append(Poly_GaussCoil) |
---|
352 | |
---|
353 | from sans.models.PolymerExclVolume import PolymerExclVolume |
---|
354 | self.shape_indep_list.append(PolymerExclVolume) |
---|
355 | |
---|
356 | from sans.models.PorodModel import PorodModel |
---|
357 | self.shape_indep_list.append(PorodModel ) |
---|
358 | |
---|
359 | from sans.models.RPA10Model import RPA10Model |
---|
360 | self.shape_indep_list.append(RPA10Model) |
---|
361 | self.multi_func_list.append(RPA10Model) |
---|
362 | |
---|
363 | from sans.models.TeubnerStreyModel import TeubnerStreyModel |
---|
364 | self.shape_indep_list.append(TeubnerStreyModel ) |
---|
365 | |
---|
366 | from sans.models.TwoLorentzianModel import TwoLorentzianModel |
---|
367 | self.shape_indep_list.append(TwoLorentzianModel ) |
---|
368 | |
---|
369 | from sans.models.TwoPowerLawModel import TwoPowerLawModel |
---|
370 | self.shape_indep_list.append(TwoPowerLawModel ) |
---|
371 | |
---|
372 | from sans.models.UnifiedPowerRgModel import UnifiedPowerRgModel |
---|
373 | self.shape_indep_list.append(UnifiedPowerRgModel ) |
---|
374 | self.multi_func_list.append(UnifiedPowerRgModel) |
---|
375 | |
---|
376 | from sans.models.LineModel import LineModel |
---|
377 | self.shape_indep_list.append(LineModel) |
---|
378 | |
---|
379 | from sans.models.ReflectivityModel import ReflectivityModel |
---|
380 | self.multi_func_list.append(ReflectivityModel) |
---|
381 | |
---|
382 | #Looking for plugins |
---|
383 | self.plugins = findModels() |
---|
384 | self._get_multifunc_models() |
---|
385 | self.plugins.append(ReflectivityModel) |
---|
386 | return 0 |
---|
387 | |
---|
388 | |
---|
389 | def populate_menu(self, modelmenu, event_owner): |
---|
390 | """ |
---|
391 | Populate a menu with our models |
---|
392 | |
---|
393 | :param id: first menu event ID to use when binding the menu events |
---|
394 | :param modelmenu: wx.Menu object to populate |
---|
395 | :param event_owner: wx object to bind the menu events to |
---|
396 | |
---|
397 | :return: the next free event ID following the new menu events |
---|
398 | |
---|
399 | """ |
---|
400 | ## Fill model lists |
---|
401 | self._getModelList() |
---|
402 | ## store reference to model menu of guiframe |
---|
403 | self.modelmenu = modelmenu |
---|
404 | ## guiframe reference |
---|
405 | self.event_owner = event_owner |
---|
406 | |
---|
407 | shape_submenu = wx.Menu() |
---|
408 | shape_indep_submenu = wx.Menu() |
---|
409 | structure_factor = wx.Menu() |
---|
410 | added_models = wx.Menu() |
---|
411 | multip_models = wx.Menu() |
---|
412 | ## create menu with shape |
---|
413 | self._fill_simple_menu(menuinfo=["Shapes",shape_submenu," simple shape"], |
---|
414 | list1=self.shape_list) |
---|
415 | |
---|
416 | self._fill_simple_menu(menuinfo=["Shape-Independent",shape_indep_submenu, |
---|
417 | "List of shape-independent models"], |
---|
418 | list1=self.shape_indep_list ) |
---|
419 | |
---|
420 | self._fill_simple_menu(menuinfo=["Structure Factors",structure_factor, |
---|
421 | "List of Structure factors models" ], |
---|
422 | list1=self.struct_list) |
---|
423 | |
---|
424 | self._fill_plugin_menu(menuinfo=["Customized Models", added_models, |
---|
425 | "List of additional models"], |
---|
426 | list1=self.plugins) |
---|
427 | |
---|
428 | self._fill_menu(menuinfo=["P(Q)*S(Q)",multip_models, |
---|
429 | "mulplication of 2 models"], |
---|
430 | list1=self.multiplication_factor , |
---|
431 | list2= self.struct_list) |
---|
432 | return 0 |
---|
433 | |
---|
434 | def _fill_plugin_menu(self, menuinfo, list1): |
---|
435 | """ |
---|
436 | fill the plugin menu with costumized models |
---|
437 | """ |
---|
438 | if len(list1)==0: |
---|
439 | id = wx.NewId() |
---|
440 | msg= "No model available check plugins.log for errors to fix problem" |
---|
441 | menuinfo[1].Append(int(id),"Empty",msg) |
---|
442 | self._fill_simple_menu( menuinfo,list1) |
---|
443 | |
---|
444 | def _fill_simple_menu(self, menuinfo, list1): |
---|
445 | """ |
---|
446 | Fill the menu with list item |
---|
447 | |
---|
448 | :param modelmenu: the menu to fill |
---|
449 | :param menuinfo: submenu item for the first column of this modelmenu |
---|
450 | with info.Should be a list : |
---|
451 | [name(string) , menu(wx.menu), help(string)] |
---|
452 | :param list1: contains item (form factor )to fill modelmenu second column |
---|
453 | |
---|
454 | """ |
---|
455 | if len(list1)>0: |
---|
456 | self.model_combobox.set_list(menuinfo[0],list1) |
---|
457 | |
---|
458 | for item in list1: |
---|
459 | try: |
---|
460 | id = wx.NewId() |
---|
461 | struct_factor=item() |
---|
462 | struct_name = struct_factor.__class__.__name__ |
---|
463 | if hasattr(struct_factor, "name"): |
---|
464 | struct_name = struct_factor.name |
---|
465 | |
---|
466 | menuinfo[1].Append(int(id),struct_name,struct_name) |
---|
467 | if not item in self.struct_factor_dict.itervalues(): |
---|
468 | self.struct_factor_dict[str(id)]= item |
---|
469 | wx.EVT_MENU(self.event_owner, int(id), self._on_model) |
---|
470 | except: |
---|
471 | msg= "Error Occured: %s"%sys.exc_value |
---|
472 | wx.PostEvent(self.event_owner, StatusEvent(status=msg)) |
---|
473 | |
---|
474 | id = wx.NewId() |
---|
475 | self.modelmenu.AppendMenu(id, menuinfo[0],menuinfo[1],menuinfo[2]) |
---|
476 | |
---|
477 | def _fill_menu(self, menuinfo, list1, list2): |
---|
478 | """ |
---|
479 | Fill the menu with list item |
---|
480 | |
---|
481 | :param menuinfo: submenu item for the first column of this modelmenu |
---|
482 | with info.Should be a list : |
---|
483 | [name(string) , menu(wx.menu), help(string)] |
---|
484 | :param list1: contains item (form factor )to fill modelmenu second column |
---|
485 | :param list2: contains item (Structure factor )to fill modelmenu |
---|
486 | third column |
---|
487 | |
---|
488 | """ |
---|
489 | if len(list1)>0: |
---|
490 | self.model_combobox.set_list(menuinfo[0],list1) |
---|
491 | |
---|
492 | for item in list1: |
---|
493 | form_factor= item() |
---|
494 | form_name = form_factor.__class__.__name__ |
---|
495 | if hasattr(form_factor, "name"): |
---|
496 | form_name = form_factor.name |
---|
497 | ### store form factor to return to other users |
---|
498 | newmenu= wx.Menu() |
---|
499 | if len(list2)>0: |
---|
500 | for model in list2: |
---|
501 | id = wx.NewId() |
---|
502 | struct_factor = model() |
---|
503 | name = struct_factor.__class__.__name__ |
---|
504 | if hasattr(struct_factor, "name"): |
---|
505 | name = struct_factor.name |
---|
506 | newmenu.Append(id,name, name) |
---|
507 | wx.EVT_MENU(self.event_owner, int(id), self._on_model) |
---|
508 | ## save form_fact and struct_fact |
---|
509 | self.form_factor_dict[int(id)] = [form_factor,struct_factor] |
---|
510 | |
---|
511 | form_id= wx.NewId() |
---|
512 | menuinfo[1].AppendMenu(int(form_id), form_name,newmenu,menuinfo[2]) |
---|
513 | id=wx.NewId() |
---|
514 | self.modelmenu.AppendMenu(id,menuinfo[0],menuinfo[1], menuinfo[2]) |
---|
515 | |
---|
516 | def _on_model(self, evt): |
---|
517 | """ |
---|
518 | React to a model menu event |
---|
519 | |
---|
520 | :param event: wx menu event |
---|
521 | |
---|
522 | """ |
---|
523 | if int(evt.GetId()) in self.form_factor_dict.keys(): |
---|
524 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
525 | model1, model2 = self.form_factor_dict[int(evt.GetId())] |
---|
526 | model = MultiplicationModel(model1, model2) |
---|
527 | else: |
---|
528 | model= self.struct_factor_dict[str(evt.GetId())]() |
---|
529 | evt = ModelEvent( model= model ) |
---|
530 | wx.PostEvent(self.event_owner, evt) |
---|
531 | |
---|
532 | def _get_multifunc_models(self): |
---|
533 | """ |
---|
534 | Get the multifunctional models |
---|
535 | """ |
---|
536 | for item in self.plugins: |
---|
537 | try: |
---|
538 | # check the multiplicity if any |
---|
539 | if item.multiplicity_info[0] > 1: |
---|
540 | self.multi_func_list.append(item) |
---|
541 | except: |
---|
542 | # pass to other items |
---|
543 | pass |
---|
544 | |
---|
545 | def get_model_list(self): |
---|
546 | """ |
---|
547 | return dictionary of models for fitpanel use |
---|
548 | |
---|
549 | """ |
---|
550 | self.model_combobox.set_list("multiplication", self.multiplication_factor) |
---|
551 | self.model_combobox.set_list("Multi-Functions", self.multi_func_list) |
---|
552 | return self.model_combobox |
---|
553 | |
---|
554 | |
---|
555 | |
---|
556 | |
---|
557 | |
---|
558 | |
---|