Changeset bfe4644 in sasview for sansview/perspectives/fitting/models.py
- Timestamp:
- Sep 17, 2009 8:21:56 AM (15 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 104f3da
- Parents:
- c5cd3b9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/models.py
r9002927 rbfe4644 11 11 import os,sys,math 12 12 import os.path 13 13 from sans.models.pluginmodel import Model1DPlugin 14 14 (ModelEvent, EVT_MODEL) = wx.lib.newevent.NewEvent() 15 15 from sans.guicomm.events import StatusEvent … … 33 33 return [] 34 34 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 40 @return model: model if valid model or nothing if not valid 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) 46 return 47 if model.__name__!="Model": 48 msg= "Plugin %s class name must be Model \n"%str(name) 49 log(msg) 50 return 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) 57 return 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) 67 return 68 else: 69 msg="Plugin %s needs a method called function \n"%str(name) 70 log(msg) 71 return 72 return model 73 74 35 75 def _findModels(dir): 36 76 # List of plugin objects … … 51 91 if hasattr(module, "Model"): 52 92 try: 53 plugins.append(module.Model) 93 if _check_plugin(module.Model, name)!=None: 94 #plugins.append(module.Model) 95 plugins.append(module.Model) 54 96 except: 55 log("Error accessing Model in %s\n %s" % (name, sys.exc_value)) 97 msg="Error accessing Model" 98 msg+="in %s\n %s %s\n" % (name, 99 str(sys.exc_type), sys.exc_value) 100 log(msg) 56 101 except: 57 log("Error accessing Model in %s\n %s" % (name, sys.exc_value)) 102 msg="Error accessing Model" 103 msg +=" in %s\n %s %s \n" %(name, 104 str(sys.exc_type), sys.exc_value) 105 log(msg) 58 106 finally: 59 107 … … 285 333 list1= self.struct_list ) 286 334 287 self._fill_ simple_menu( menuinfo = ["Customized Models", added_models,335 self._fill_plugin_menu( menuinfo = ["Customized Models", added_models, 288 336 "List of additional models"], 289 337 list1= self.plugins ) … … 297 345 return 0 298 346 347 def _fill_plugin_menu(self,menuinfo, list1): 348 """ 349 fill the plugin menu with costumized models 350 """ 351 if len(list1)==0: 352 id = wx.NewId() 353 msg= "No model available check plugins.log for errors to fix problem" 354 menuinfo[1].Append(int(id),"Empty",msg) 355 self._fill_simple_menu( menuinfo,list1) 356 357 299 358 def _fill_simple_menu(self,menuinfo, list1): 300 359 """
Note: See TracChangeset
for help on using the changeset viewer.