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