Changeset b30f001 in sasview for sansview/perspectives


Ignore:
Timestamp:
Sep 10, 2008 3:49:53 PM (16 years ago)
Author:
Gervaise Alina <gervyh@…>
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
Message:

working on model menu

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansview/perspectives/fitting/models.py

    raa92772 rb30f001  
    11import wx 
    2 import os 
     2import imp 
     3import os,sys 
    34import os.path 
    45 
    56(ModelEvent, EVT_MODEL) = wx.lib.newevent.NewEvent() 
     7def log(message): 
     8    print message 
     9    out = open("plugins.log", 'a') 
     10    out.write("%10g:  %s\n" % (time.clock(), message)) 
     11    out.close() 
     12 
    613def findModels(): 
    714    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 [] 
    2118     
    2219def _findModels(dir): 
     
    2724        list = os.listdir(dir) 
    2825        for item in list: 
    29             print "models: _findModels:",item 
    3026            toks = os.path.splitext(os.path.basename(item)) 
    31             print "models: toks:",toks 
    3227            if toks[1]=='.py' and not toks[0]=='__init__': 
    3328                name = toks[0] 
     
    3732                try: 
    3833                    (file, path, info) = imp.find_module(name, path) 
     34                    print "models:module ",file 
    3935                    module = imp.load_module( name, file, item, info ) 
     36                    print "models:module ",module 
    4037                    if hasattr(module, "Model"): 
    4138                        try: 
     
    4441                            log("Error accessing Model in %s\n  %s" % (name, sys.exc_value)) 
    4542                except: 
    46                     pass 
     43                    log("Error accessing Model in %s\n  %s" % (name, sys.exc_value)) 
    4744                finally: 
    4845                    if not file==None: 
     
    5148        pass 
    5249    return plugins 
    53      
    54  
    55  
    5650class ModelManager: 
    5751     
     
    5953    model_list = {} 
    6054    model_list_box = {} 
     55    custom_models={} 
     56    plugins=[] 
    6157    ## Event owner 
    6258    event_owner = None 
     
    8076        from sans.guitools.LineModel import LineModel 
    8177        self.model_list[str(wx.NewId())]  = LineModel 
    82        
     78        self.plugins =findModels() 
     79         
     80        print "models: plugings",self.plugins 
    8381        return 0 
    8482 
     
    9694        self._getModelList() 
    9795        self.event_owner = event_owner 
    98  
     96        shape_submenu= wx.Menu()  
     97        indep_submenu = wx.Menu() 
     98        added_models = wx.Menu() 
    9999        for id_str,value in self.model_list.iteritems(): 
    100100            item = self.model_list[id_str] 
     
    105105                 
    106106            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         
    112130        return 0 
    113131     
Note: See TracChangeset for help on using the changeset viewer.