Changeset 465 – Pyragua

Changeset 465

Show
Ignore:
Timestamp:
08/09/10 02:15:01 (22 months ago)
Author:
ogranada
Message:

2010-08-09 Oscar Andres Granada <ogranada@…>

  • The Plugin architecture are implemented in pyragua.py file
  • Many methods were added to make more orderly implementation
  • The option parser are added and add the options "-s" (not Splash) and "-d" (debug)
  • yapsy library were modified in the file PluginManager?.py that without this amendment would be

required to install the library on the system.

  • They have positioned sample plugins in the plugins folder, it is necessary to improve the

documentation about this.

Location:
trunk/pyragua
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/pyragua/configmanager/config.py

    r461 r465  
    3434        except: 
    3535            f = open(user_root+sep+'.pyragua/pyragua.conf','w') 
    36             from sk_files import pyragua_conf as pyragua_conf_data 
    37             f.write(pyragua_conf_data) 
     36            f.write('[plugins]\nlocation=.pyragua/plugins') 
    3837            f.close() 
    3938            self.files['pyragua_conf'].readfp(open(user_root+sep+'.pyragua/pyragua.conf')) 
    4039             
    41         print self.files['pyragua_conf'].sections() 
     40         
    4241        
    4342 
  • trunk/pyragua/pyragua.py

    r458 r465  
    1616 
    1717from ui import mainwindow 
     18import wx  
     19# imports required by the splash and plugins. 
     20from shared import gaugesplash 
     21from os import getcwd, path, system 
     22from user import home as userhome 
     23 
    1824 
    1925class Pyragua(object): 
     
    2127    """ 
    2228    def __init__(self): 
    23         self.main_window = mainwindow.MainWindow() 
     29        self.__opt_manage() 
     30        self.main_window = mainwindow.MainWindow()      
    2431        self.main_window.pyragua = self 
    2532 
    2633    def start(self): 
     34        self.__start() 
    2735        self.main_window.show() 
    2836        self.main_window.start()  # The wx main loop gets started 
     37         
     38    def __opt_manage(self): 
     39        ''' 
     40        Destined for add the command line options 
     41        ''' 
     42        from modparser import ModParser 
     43        self.__modparser = ModParser({'opt':'-s','large_opt':'--has-splash','default':True,'action':"store_false"}, 
     44                                     {'opt':'-d','large_opt':'--debug','default':False,'action':"store_true"})         
     45         
     46    def __start(self): 
     47        ''' 
     48            Run the IDE with the data of the options. 
     49        ''' 
     50        if self.__modparser.get('has_splash') not in ['no', 'No', None, 'false', 'FALSE', 'False',False]: 
     51            splash = gaugesplash.GaugeSplash(getcwd()+'/img/pyragua_splash.png') 
     52            splash.Show() 
     53            splash.Update() 
     54            wx.Yield() 
     55        else: 
     56            splash = None 
     57        if self.__modparser.get('debug'): 
     58            globals()['debug']=True 
     59        else: 
     60            globals()['debug']=False 
     61        # loads 
     62        self.__load(splash) 
     63        #end loads 
     64        if splash != None: 
     65            splash.Destroy() 
     66        wx.GetApp().Yield() 
     67         
     68    def __load(self, splash=None): 
     69        import shared 
     70        from shared.yapsy.PluginManager import PluginManager 
     71        from shared.yapsy.IPlugin import IPlugin 
     72        pm = PluginManager() 
     73        if not path.exists(getcwd()+'/pyragua'): 
     74            system('mkdir %s'%(getcwd()+'/pyragua')) 
     75        if not path.exists(getcwd()+'/pyragua/plugins'): 
     76            system('mkdir %s'%(getcwd()+'/pyragua/plugins')) 
     77        if not path.exists(userhome+'/.pyragua'): 
     78            system('mkdir %s'%(userhome+'/.pyragua')) 
     79        if not path.exists(userhome+'/.pyragua/plugins'): 
     80            system('mkdir %s'%(userhome+'/.pyragua/plugins')) 
     81        pm.setPluginPlaces([getcwd()+'/pyragua/plugins',userhome+'/.pyragua/plugins'])         
     82        pm.locatePlugins() 
     83        pm.loadPlugins(candidate_globals={'IPlugin':IPlugin}) 
     84        pluginList = pm.getPluginsOfCategory("Default") 
     85          
     86        #============================ 
     87        if splash != None: 
     88            from time import sleep 
     89            count = len(pluginList) 
     90            splash.setTicks(count)         
     91            for i in range(count):                 
     92                item=pluginList[i] 
     93                if globals()['debug']: 
     94                    print "Load: ", 
     95                    print item.name 
     96                pluginobject = item.plugin_object 
     97                try: 
     98                    pluginobject.run(self.main_window) 
     99                except: 
     100                    pass 
     101                splash.tick("Loading %s" % item.name) 
     102                sleep(.1) 
     103        #============================ 
    29104 
    30105    def stop(self): 
  • trunk/pyragua/shared/gaugesplash.py

    r464 r465  
    3838        wx.Frame.__init__(self, None, style=wx.FRAME_NO_TASKBAR) 
    3939        self.border = 2 
    40  
     40        if type(bmp) == type(''): 
     41            bmp = wx.Bitmap(bmp) 
    4142        self.SetBackgroundColour(wx.WHITE) 
    4243 
  • trunk/pyragua/shared/yapsy/PluginManager.py

    r461 r465  
    305305                return len(self._candidates) 
    306306 
    307         def loadPlugins(self, callback=None): 
     307        def loadPlugins(self, callback=None, candidate_globals=None): 
    308308                """ 
    309309                Load the candidate plugins that have been identified through a 
     
    316316                the callback. 
    317317                """ 
     318                 
     319                if type(candidate_globals) != type({}): 
     320                        candidate_globals = {} 
     321                 
    318322#               print "%s.loadPlugins" % self.__class__          
    319323                if not hasattr(self, '_candidates'): 
     
    328332                        # now execute the file and get its content into a 
    329333                        # specific dictionnary 
    330                         candidate_globals = {"__file__":candidate_filepath+".py"} 
     334                        candidate_globals["__file__"]= candidate_filepath+".py" 
    331335                        if "__init__" in  os.path.basename(candidate_filepath): 
    332336                                sys.path.append(plugin_info.path)                                
    333337                        try: 
    334338                                execfile(candidate_filepath+".py",candidate_globals) 
    335                         except Exception,e: 
     339                        except Exception,e:                              
    336340                                logging.debug("Unable to execute the code in plugin: %s" % candidate_filepath) 
    337341                                logging.debug("\t The following problem occured: %s %s " % (os.linesep, e)) 
  • trunk/pyragua/ui/mainwindow.py

    r464 r465  
    2929class MainWindow(object): 
    3030    def __init__(self): 
    31         self.app = PyraguaApp(0) 
     31        self.app = PyraguaApp(0)         
    3232        self.window = PyraguaMainFrame(None) 
    3333