Changeset b30f001 in sasview for sansview/perspectives/fitting
- Timestamp:
- Sep 10, 2008 3:49:53 PM (16 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:
- 49b7efa
- Parents:
- aa92772
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/models.py
raa92772 rb30f001 1 1 import wx 2 import os 2 import imp 3 import os,sys 3 4 import os.path 4 5 5 6 (ModelEvent, EVT_MODEL) = wx.lib.newevent.NewEvent() 7 def log(message): 8 print message 9 out = open("plugins.log", 'a') 10 out.write("%10g: %s\n" % (time.clock(), message)) 11 out.close() 12 6 13 def findModels(): 7 14 print "looking for models" 8 try: 9 cwd= os.path.split(__file__)[0] 10 except: 11 cwd= os.getcwd() 12 print "models cwd",cwd 13 dir=os.path.join(cwd,'plugins') 14 print "models: find plugins",dir 15 if os.path.isdir(dir): 16 return _findModels(dir) 17 else: 18 return [] 19 20 15 if os.path.isdir('plugins'): 16 return _findModels('plugins') 17 return [] 21 18 22 19 def _findModels(dir): … … 27 24 list = os.listdir(dir) 28 25 for item in list: 29 print "models: _findModels:",item30 26 toks = os.path.splitext(os.path.basename(item)) 31 print "models: toks:",toks32 27 if toks[1]=='.py' and not toks[0]=='__init__': 33 28 name = toks[0] … … 37 32 try: 38 33 (file, path, info) = imp.find_module(name, path) 34 print "models:module ",file 39 35 module = imp.load_module( name, file, item, info ) 36 print "models:module ",module 40 37 if hasattr(module, "Model"): 41 38 try: … … 44 41 log("Error accessing Model in %s\n %s" % (name, sys.exc_value)) 45 42 except: 46 pass43 log("Error accessing Model in %s\n %s" % (name, sys.exc_value)) 47 44 finally: 48 45 if not file==None: … … 51 48 pass 52 49 return plugins 53 54 55 56 50 class ModelManager: 57 51 … … 59 53 model_list = {} 60 54 model_list_box = {} 55 custom_models={} 56 plugins=[] 61 57 ## Event owner 62 58 event_owner = None … … 80 76 from sans.guitools.LineModel import LineModel 81 77 self.model_list[str(wx.NewId())] = LineModel 82 78 self.plugins =findModels() 79 80 print "models: plugings",self.plugins 83 81 return 0 84 82 … … 96 94 self._getModelList() 97 95 self.event_owner = event_owner 98 96 shape_submenu= wx.Menu() 97 indep_submenu = wx.Menu() 98 added_models = wx.Menu() 99 99 for id_str,value in self.model_list.iteritems(): 100 100 item = self.model_list[id_str] … … 105 105 106 106 self.model_list_box[name] =value 107 108 modelmenu.Append(int(id_str), name, name) 109 wx.EVT_MENU(event_owner, int(id_str), self._on_model) 110 plugings=findModels() 111 print "models: plugings",plugings 107 108 109 shape_submenu.Append(int(id_str), name, name) 110 wx.EVT_MENU(event_owner, int(id_str), self._on_model) 111 modelmenu.AppendMenu(wx.NewId(), "Shapes...", shape_submenu, "List of shape-based models") 112 modelmenu.AppendMenu(wx.NewId(), "Shape-independent...", indep_submenu, "List of shape-independent models") 113 114 id = wx.NewId() 115 if len(self.custom_models) == 0: 116 print self.plugins 117 for item in self.plugins: 118 if item not in self.custom_models.keys(): 119 self.custom_models[str(id)] = item 120 self.model_list[str(id)]=item 121 added_models.Append(id, item.name, item.name) 122 wx.EVT_MENU(event_owner, int(id), self._on_model) 123 id = wx.NewId() 124 125 126 modelmenu.AppendMenu(wx.NewId(),"Added models...", added_models, "List of additional models") 127 128 129 112 130 return 0 113 131
Note: See TracChangeset
for help on using the changeset viewer.