class Plugin(QObject): ''' Base class for ALL Plugin All plugins should inherit from this class ''' def __init__(self, locator, metadata=None): QObject.__init__(self) self.locator = locator if metadata is None: self.metadata = {} else: self.metadata = metadata klass = self.__class__ plugin_name = "%s.%s" % (klass.__module__, klass.__name__) self.logger = NinjaLogger('ninja_ide.plugins.%s' % plugin_name) #set the path! try: self_module = self.__module__ path = os.path.abspath(sys.modules[self_module].__file__) self._path = os.path.dirname(path) except: self._path = '' def initialize(self): """The initialization of the Plugin should be here.""" self.logger.info("Initializing Plugin...") def finish(self): pass def get_preferences_widget(self): pass @property def path(self): return self._path
class Plugin(QObject): ''' Base class for ALL Plugin All plugins should inherit from this class ''' def __init__(self, locator, metadata=None): QObject.__init__(self) self.locator = locator if metadata is None: self.metadata = {} else: self.metadata = metadata klass = self.__class__ plugin_name = "%s.%s" % (klass.__module__, klass.__name__) self.logger = NinjaLogger('ninja_ide.plugins.%s' % plugin_name) # set the path! try: self_module = self.__module__ path = os.path.abspath(sys.modules[self_module].__file__) self._path = os.path.dirname(path) except BaseException: self._path = '' def initialize(self): """The initialization of the Plugin should be here.""" self.logger.info("Initializing Plugin...") def finish(self): pass def get_preferences_widget(self): pass @property def path(self): return self._path
folders += [os.path.join(root, d) for d in dirs] folders.reverse() for f in folders: if os.path.isdir(f): os.removedirs(f) #remove ths plugin_name.plugin file os.remove(fileName) #write the new info descriptor = open(resources.PLUGINS_DESCRIPTOR, 'w') json.dump(structure, descriptor, indent=2) ############################################################################### # Module Test ############################################################################### if __name__ == '__main__': folders = resources.PLUGINS services = {} sl = ServiceLocator(services) pm = PluginManager(folders, sl) #There are not plugins yet...lets discover pm.discover() logger.info("listing plugins names...") for p in pm: print(p) logger.info("Activating plugins...") pm.load_all() logger.info("Plugins already actives...") logger.info(pm.get_active_plugins())
from PyQt4.QtGui import QCompleter from PyQt4.QtGui import QDirModel from PyQt4.QtGui import QPixmap from PyQt4.QtCore import Qt from PyQt4.QtCore import SIGNAL from ninja_ide import resources from ninja_ide.core import settings from ninja_ide.core import plugin_interfaces from ninja_ide.core import file_manager from ninja_ide.tools import json_manager from ninja_ide.tools.logger import NinjaLogger logger = NinjaLogger('ninja_ide.gui.dialogs.wizard_new_project') logger.info("loaded") DEBUG = logger.debug ############################################################################### # Wizard handler and Python Project handler ############################################################################### class WizardNewProject(QWizard): """ Wizard to create a new project (of any kind), it implements the base behavior. Also, it set two special projects type handler (PythonProjectHandler, ImportFromSourcesProjectHandler) """ def __init__(self, parent): QWizard.__init__(self, parent)
#collect subfolders folders += [os.path.join(root, d) for d in dirs] folders.reverse() for f in folders: if os.path.isdir(f): os.removedirs(f) #remove ths plugin_name.plugin file os.remove(fileName) #write the new info json_manager.write_json(structure, resources.PLUGINS_DESCRIPTOR) ############################################################################### # Module Test ############################################################################### if __name__ == '__main__': folders = resources.PLUGINS services = {} sl = ServiceLocator(services) pm = PluginManager(folders, sl) #There are not plugins yet...lets discover pm.discover() logger.info("listing plugins names...") for p in pm: print(p) logger.info("Activating plugins...") pm.load_all() logger.info("Plugins already actives...") logger.info(pm.get_active_plugins())
def load_all_external(self, plugin_path): # Copy the list because may be we REMOVE item while iterate! found_plugins_aux = copy.copy(self._found_plugins) for plugin_name in found_plugins_aux: self.load(plugin_name, plugin_path) def unload(self, plugin_name): try: plugin_object = self._active_plugins[plugin_name][0] # call a special method *finish* in the plugin! plugin_object.finish() del self._active_plugins[plugin_name] except Exception, reason: logger.error("Finishing plugin (%s): %s", plugin_name, reason) else: logger.info("Successfuly finished (%s)", plugin_name) def unload_all(self): # Copy the list because may be we REMOVE item while iterate! active_plugins_aux = copy.copy(self._active_plugins) for plugin_name in active_plugins_aux: self.unload(plugin_name) def shutdown(self): self.unload_all() def get_availables_services(self): """ Returns all services availables """ self._service_locator.get_availables_services()
def load_all_external(self, plugin_path): #Copy the list because may be we REMOVE item while iterate! found_plugins_aux = copy.copy(self._found_plugins) for plugin_name in found_plugins_aux: self.load(plugin_name, plugin_path) def unload(self, plugin_name): try: plugin_object = self._active_plugins[plugin_name][0] #call a special method *finish* in the plugin! plugin_object.finish() del self._active_plugins[plugin_name] except Exception, reason: logger.error("Finishing plugin (%s): %s", plugin_name, reason) else: logger.info("Successfuly finished (%s)", plugin_name) def unload_all(self): #Copy the list because may be we REMOVE item while iterate! active_plugins_aux = copy.copy(self._active_plugins) for plugin_name in active_plugins_aux: self.unload(plugin_name) def shutdown(self): self.unload_all() def get_availables_services(self): """ Returns all services availables """ self._service_locator.get_availables_services()