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