00001 ############################################################################## 00002 # 00003 # Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. 00004 # Fabien Pinckaers <fp@tiny.Be> 00005 # Copyright (c) 2007-2008 Albert Cervera i Areny <albert@nan-tic.com> 00006 # 00007 # WARNING: This program as such is intended to be used by professional 00008 # programmers who take the whole responsability of assessing all potential 00009 # consequences resulting from its eventual inadequacies and bugs 00010 # End users who are looking for a ready-to-use solution with commercial 00011 # garantees and support are strongly adviced to contract a Free Software 00012 # Service Company 00013 # 00014 # This program is Free Software; you can redistribute it and/or 00015 # modify it under the terms of the GNU General Public License 00016 # as published by the Free Software Foundation; either version 2 00017 # of the License, or (at your option) any later version. 00018 # 00019 # This program is distributed in the hope that it will be useful, 00020 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 # GNU General Public License for more details. 00023 # 00024 # You should have received a copy of the GNU General Public License 00025 # along with this program; if not, write to the Free Software 00026 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00027 # 00028 ############################################################################## 00029 00030 from PyQt4.QtGui import * 00031 from Koo.Common import Common 00032 import Koo.Common.Plugins 00033 import re 00034 import os 00035 00036 class Plugins: 00037 plugins = {} 00038 00039 ## @brief This function obtains the list of all available plugins by iterating 00040 # over every subdirectory inside Plugins/ 00041 # 00042 # This means that some plugins are activated the first time this function is 00043 # called. 00044 @staticmethod 00045 def list( model = None ): 00046 # Search for all available plugins 00047 # Scan only once 00048 if not Plugins.plugins: 00049 Koo.Common.Plugins.scan( 'Koo.Plugins', os.path.abspath(os.path.dirname(__file__)) ) 00050 00051 plugins = {} 00052 for name, plugin in Plugins.plugins.items(): 00053 if model: 00054 if plugin['model_regexp'].search( model ): 00055 plugins[name] = plugin 00056 else: 00057 plugins[name] = plugin 00058 return plugins 00059 00060 ## @brief Executes the given plugin. 00061 @staticmethod 00062 def execute(plugin, model, id, ids, context): 00063 plugins = Plugins.list() 00064 action = plugins[plugin]['action'] 00065 action( model, id, ids, context ) 00066 00067 @staticmethod 00068 def register(name, model, title, action): 00069 Plugins.plugins[ name ] = { 00070 'model': model, 00071 'string': title, 00072 'action': action, 00073 'model_regexp': re.compile( model ) 00074 }