[orca/orca-gnome3: 22/87] Moved initial scan_plugins() to orca_gui_prefs allow import orca_mods in plugins
- From: Alejandro Leiva <aleiva src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [orca/orca-gnome3: 22/87] Moved initial scan_plugins() to orca_gui_prefs allow import orca_mods in plugins
- Date: Fri, 1 Apr 2011 11:14:39 +0000 (UTC)
commit 0394b2f462098bf50e8ae38b5051aa730c8c5b1d
Author: José Ignacio �lvarez Ruiz <jialvarez emergya es>
Date: Tue Mar 8 18:50:48 2011 +0100
Moved initial scan_plugins() to orca_gui_prefs allow import orca_mods in plugins
src/orca/baseplugins/test.py | 51 +---
src/orca/interfaces.py | 323 --------------------
src/orca/orca.py | 6 -
src/orca/orca_gui_prefs.py | 6 +-
src/orca/pluglib/Makefile.am | 2 +-
src/orca/pluglib/__init__.pyo | Bin 645 -> 0 bytes
src/orca/pluglib/interfaces.py | 79 +-----
src/orca/pluglib/interfaces.pyo | Bin 14786 -> 0 bytes
src/orca/pluglib/manager.py | 236 --------------
src/orca/pluglib/manager.pyo | Bin 7365 -> 0 bytes
src/orca/{manager.py => pluglib/plugin_manager.py} | 54 +++-
src/orca/scripts/default.py | 34 +-
12 files changed, 73 insertions(+), 718 deletions(-)
---
diff --git a/src/orca/baseplugins/test.py b/src/orca/baseplugins/test.py
index 39c5e8c..b3cd579 100644
--- a/src/orca/baseplugins/test.py
+++ b/src/orca/baseplugins/test.py
@@ -20,66 +20,21 @@
from orca.pluglib.interfaces import *
import orca.input_event as input_event
+import orca.scripts.default as default
from orca.orca_i18n import _ # for gettext support
from orca.orca_i18n import ngettext # for ngettext support
from orca.orca_i18n import C_ # to provide qualified translatable strings
-from orca.scripts.default import Script
-
-# test if I call any Orca code
-defaultObj = Script(None)
-print defaultObj.getListeners()
-
-class callPresenter(IPresenter):
- inputEventHandlers = {}
- def __init__(self):
-
- print "Init call presenter..."
- self.inputEventHandlers["presentTimeHandler"] = \
- input_event.InputEventHandler(
- callPresenter.presentTime,
- # Translators: Orca can present the current time to the
- # user when the user presses
- # a shortcut key.
- #
- _("Present current time."))
-
- self.inputEventHandlers["presentDateHandler"] = \
- input_event.InputEventHandler(
- callPresenter.presentDate,
- # Translators: Orca can present the current date to the
- # user when the user presses
- # a shortcut key.
- #
- _("Present current date."))
-
- def presentTime(self, inputEvent):
- """ Presents the current time. """
- timeFormat = self._settingsManager.getSetting('presentTimeFormat')
- message = time.strftime(timeFormat, time.localtime())
- super.presentMessage(message)
- return True
-
- def presentDate(self, inputEvent):
- """ Presents the current date. """
- dateFormat = self._settingsManager.getSetting('presentDateFormat')
- message = time.strftime(dateFormat, time.localtime())
- super.presentMessage(message)
- return True
-
-class testPlugin(IPlugin, IPresenter):
+class testPlugin(IPlugin):
name = 'Test Plugin'
description = 'A testing plugin for code tests'
version = '0.1pre'
authors = ['J. Félix Ontañón <felixonta gmail com>', 'J. Ignacio �lvarez <neonigma gmail com>']
- website = 'http://fontanon.org'
+ website = 'http://www.emergya.es'
icon = 'gtk-missing-image'
def __init__(self):
print 'Hello World (plugin started)!'
- cp = callPresenter()
-
-
IPlugin.register(testPlugin)
diff --git a/src/orca/orca.py b/src/orca/orca.py
index 04f95de..bd0278e 100644
--- a/src/orca/orca.py
+++ b/src/orca/orca.py
@@ -64,12 +64,6 @@ import settings
from orca_i18n import _
from orca_i18n import ngettext
-#dirname, filename = os.path.split(os.path.abspath(__file__))
-#sys.path.insert(0, os.path.join(dirname, 'pluglib'))
-#sys.path.insert(1, dirname)
-
-import pluglib
-
class Options:
"""Class to handle getting run-time options."""
diff --git a/src/orca/orca_gui_prefs.py b/src/orca/orca_gui_prefs.py
index dc39119..ee201d7 100644
--- a/src/orca/orca_gui_prefs.py
+++ b/src/orca/orca_gui_prefs.py
@@ -57,8 +57,10 @@ import orca_gui_profile
_settingsManager = getattr(orca, '_settingsManager')
_scriptManager = getattr(orca, '_scriptManager')
-# temp here - 3E
-from pluglib.manager import plugmanager
+# needed to fill the graphical treeview
+from pluglib.plugin_manager import plugmanager
+
+# temporary here?? START ACTIVE PLUGINS!
plugmanager.scan_plugins()
try:
diff --git a/src/orca/pluglib/Makefile.am b/src/orca/pluglib/Makefile.am
index f7e85ce..522b832 100644
--- a/src/orca/pluglib/Makefile.am
+++ b/src/orca/pluglib/Makefile.am
@@ -3,7 +3,7 @@ orca_pathdir=$(pyexecdir)
orca_python_PYTHON = \
__init__.py \
interfaces.py \
- manager.py
+ plugin_manager.py
orca_pythondir=$(pyexecdir)/orca/pluglib
diff --git a/src/orca/pluglib/interfaces.py b/src/orca/pluglib/interfaces.py
index b383d8e..b27f44d 100644
--- a/src/orca/pluglib/interfaces.py
+++ b/src/orca/pluglib/interfaces.py
@@ -20,6 +20,7 @@
import exceptions
import abc
+import orca.scripts.default as default
class IPlugin(object):
"""Every plugin must implement this interface"""
@@ -164,87 +165,17 @@ class IConfigureDialog(IConfigurable):
class ICommand(object):
"""Allows to operate with commands plugins"""
- __metaclass__ = abc.ABCMeta
-
- def command_name_getter(self):
- """ You must implement this method in your class """
+ # What things need to be come here?
- def command_name_setter(self, new_commands):
- """ You must implement this method in your class """
-
- # Set of managed plugins
- command_name = abc.abstractproperty(command_name_getter, command_name_setter)
- ############## METHODS #################
-
- @abc.abstractmethod
- def get_command(command_name):
- """Return a command in this environment"""
-
-class IPresenter(object):
+class IPresenter(default.Script):
"""Allows to operate with presentation plugins"""
- __metaclass__ = abc.ABCMeta
+ inputEventHandlers = {}
############## METHODS #################
- def presentMessage(self, fullMessage, briefMessage=None, voice=None):
- """Convenience method to speak a message and 'flash' it in braille.
-
- Arguments:
- - fullMessage: This can be a string or a list. This will be presented
- as the message for users whose flash or message verbosity level is
- verbose.
- - briefMessage: This can be a string or a list. This will be presented
- as the message for users whose flash or message verbosity level is
- brief. Note that providing no briefMessage will result in the full
- message being used for either. Callers wishing to present nothing as
- the briefMessage should set briefMessage to an empty string.
- - voice: The voice to use when speaking this message. By default, the
- "system" voice will be used.
- """
-
- print "Called presentMessage..."
-
- if not fullMessage:
- return
-
- if briefMessage is None:
- briefMessage = fullMessage
-
- if _settingsManager.getSetting('enableSpeech'):
- if _settingsManager.getSetting('messageVerbosityLevel') \
- == settings.VERBOSITY_LEVEL_BRIEF:
- message = briefMessage
- else:
- message = fullMessage
- if message:
- voice = voice or self.voices.get(settings.SYSTEM_VOICE)
- speech.speak(message, voice)
-
- if (_settingsManager.getSetting('enableBraille') \
- or _settingsManager.getSetting('enableBrailleMonitor')) \
- and _settingsManager.getSetting('enableFlashMessages'):
- if _settingsManager.getSetting('flashVerbosityLevel') \
- == settings.VERBOSITY_LEVEL_BRIEF:
- message = briefMessage
- else:
- message = fullMessage
- if not message:
- return
-
- if isinstance(message[0], list):
- message = message[0]
- if isinstance(message, list):
- message = filter(lambda i: isinstance(i, str), message)
- message = " ".join(message)
-
- if _settingsManager.getSetting('flashIsPersistent'):
- duration = -1
- else:
- duration = _settingsManager.getSetting('brailleFlashTime')
-
- braille.displayMessage(message, flashTime=duration)
+ # What things need to be come here?
class IDependenciesChecker(object):
"""Allows to check for dependencies before run"""
diff --git a/src/orca/manager.py b/src/orca/pluglib/plugin_manager.py
similarity index 84%
rename from src/orca/manager.py
rename to src/orca/pluglib/plugin_manager.py
index 4b27d6c..18a22b6 100644
--- a/src/orca/manager.py
+++ b/src/orca/pluglib/plugin_manager.py
@@ -29,14 +29,19 @@ import orca.store_config as store_config
from orca.pluglib.interfaces import *
+dirname, filename = os.path.split(os.path.abspath(__file__))
+PLUGINS_DIR = [os.path.join(dirname, '..', 'baseplugins')]
+
class ModulePluginManager(IPluginManager):
"""A plugin manager that handles with python modules"""
- def __init__(self, plugin_paths=['baseplugins']):
+ def __init__(self, plugin_paths=[]):
self.plugin_paths = plugin_paths
if not type(self.plugin_paths) is list:
self.plugin_paths = [self.plugin_paths]
+
+ print self.plugin_paths
#{'plugin_name': {'class': plugin_class, 'object': plugin_object,
# 'type': plugin_type, 'registered':, if_registered}
@@ -63,7 +68,8 @@ class ModulePluginManager(IPluginManager):
active = self.plugins_conf[module_name]['active'] \
if self.plugins_conf and module_name in self.plugins_conf \
else False
-
+
+ # REGISTERED NOT USED... IS ALL DONE WITH ACTIVE FIELD! (OR NOT?)
registered = self.plugins_conf[module_name]['registered'] \
if self.plugins_conf and module_name in self.plugins_conf \
else True
@@ -82,9 +88,6 @@ class ModulePluginManager(IPluginManager):
# ADD PLUGIN!
# pass name, module_name and registered or not
self.store_conf.addPlugin(name, registered, module_name, path)
-
- # update plugins container
- #self.plugins_conf = self.store_conf.getPlugins()
except Exception, e:
raise PluginManagerError, 'Cannot load module %s: %s' % \
@@ -97,7 +100,10 @@ class ModulePluginManager(IPluginManager):
def scan_more_plugins(self):
print "Scanning plugins..."
- # CHECK BASEPLUGINS FOR MORE PLUGINS
+ # CHECK BASEPLUGINS FOR PLUGINS
+ # In inspect_plugin_module we compare with the plugins list
+ # in the appropiate backend form and if a plugin is active,
+ # we will load it
new_plugins = {}
for path in self.plugin_paths:
if not path in sys.path:
@@ -128,21 +134,25 @@ class ModulePluginManager(IPluginManager):
dict_plugins.update(type_update)
def scan_plugins(self):
+ # Compare
self.scan_more_plugins()
# LOAD FROM STORE_CONF
if self.plugins_conf:
+ # take the plugins list in the backend
self.plugins = self.plugins_conf.copy()
-
load_plugins = self.plugins['plugins'];
for module_name, data in load_plugins.iteritems():
if load_plugins[module_name]['active'] == True:
try:
+ # if active, add the class into the plugin list
self.load_class_in_plugin(load_plugins[module_name],
module_name, [load_plugins[module_name]['path']])
plugin_class = load_plugins[module_name]['class']
+
+ # we have the class now, we can get an object
plugin_object = plugin_class()
if isinstance(plugin_object, IConfigurable):
plugin_object.load()
@@ -153,34 +163,44 @@ class ModulePluginManager(IPluginManager):
raise PluginManagerError, 'Cannot load module %s: %s' % \
(module_name, e)
else:
+ # plugin not active, bring into plugin list
+ # maintained in memory but not get the class
load_plugins[module_name].update({'class': None})
load_plugins[module_name].update({'object': None})
self.plugins = load_plugins
def enable_plugin(self, plugin_name):
+ # first, make the plugin active in appropiated backend
enabling_plugins = self.store_conf.getPluginByName(plugin_name)
enabling_plugins['active'] = True
self.store_conf.updatePlugin({plugin_name: enabling_plugins})
if self.plugins:
+ # load the class in the plugin list maintained in memory
self.load_class_in_plugin(self.plugins[plugin_name], plugin_name,
[self.plugins[plugin_name]['path']])
plugin_class = self.plugins[plugin_name]['class']
+ # this code is not checked actually
if issubclass(plugin_class, IDependenciesChecker) \
and not plugin_class.check_dependencies():
raise PluginManagerError, 'Cannot satisfy dependencies for %s: %s' % \
(plugin_name, plugin_class.check_err)
+ # instantiate an object, we have the class now
plugin_object = plugin_class()
+
+ # this code is not checked actually, but I know
+ # what to do with it
if isinstance(plugin_object, IConfigurable):
plugin_object.load()
self.plugins[plugin_name]['object'] = plugin_object
def disable_plugin(self, plugin_name):
+ # make the plugin inactive in the appropiated backend
disabling_plugins = self.store_conf.getPluginByName(plugin_name)
disabling_plugins['active'] = False
self.store_conf.updatePlugin({plugin_name: disabling_plugins})
@@ -193,6 +213,8 @@ class ModulePluginManager(IPluginManager):
print "Unloaded module " + str(plugin_name)
+ # this *only* delete the name from sys.modules,
+ # not the module itself. See http://bit.ly/gbjPnB
del (plugin_name)
def get_plugins(self):
@@ -200,15 +222,25 @@ class ModulePluginManager(IPluginManager):
plugin['type'], plugin['registered'], plugin['name'])
for (plugin_name, plugin) in self.plugins.items()]
+ def is_plugin_enabled(self, plugin_name):
+ check_plugin = self.store_conf.getPluginByName(plugin_name)
+ return check_plugin['active']
+
+ def get_plugin_class(self, plugin_name):
+ if self.plugins.has_key(plugin_name):
+ return self.plugins[plugin_name]['class']
+ else:
+ raise PluginManagerError, 'No plugin named %s' % plugin_name
+
def is_plugin_loaded(self, plugin_name):
if self.plugins.has_key(plugin_name):
return self.plugins[plugin_name]['object'] is not None
else:
raise PluginManagerError, 'No plugin named %s' % plugin_name
- def is_plugin_enabled(self, plugin_name):
- check_plugin = self.store_conf.getPluginByName(plugin_name)
- return check_plugin['active']
+
+
+ # ATTRIBS REQUIRES TO ACCOMPLISH THE ABSTRACTION CONCEPT
_plugin_paths = None
@@ -233,4 +265,4 @@ class ModulePluginManager(IPluginManager):
# Register implementation
IPluginManager.register(ModulePluginManager)
-plugmanager = ModulePluginManager()
+plugmanager = ModulePluginManager(PLUGINS_DIR)
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index 3eecc9f..cd8155f 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -1067,23 +1067,23 @@ class Script(script.Script):
#
_("Toggle mouse review mode."))
- self.inputEventHandlers["presentTimeHandler"] = \
- input_event.InputEventHandler(
- Script.presentTime,
- # Translators: Orca can present the current time to the
- # user when the user presses
- # a shortcut key.
- #
- _("Present current time."))
-
- self.inputEventHandlers["presentDateHandler"] = \
- input_event.InputEventHandler(
- Script.presentDate,
- # Translators: Orca can present the current date to the
- # user when the user presses
- # a shortcut key.
- #
- _("Present current date."))
+# self.inputEventHandlers["presentTimeHandler"] = \
+# input_event.InputEventHandler(
+# Script.presentTime,
+# # Translators: Orca can present the current time to the
+# # user when the user presses
+# # a shortcut key.
+# #
+# _("Present current time."))
+#
+# self.inputEventHandlers["presentDateHandler"] = \
+# input_event.InputEventHandler(
+# Script.presentDate,
+# # Translators: Orca can present the current date to the
+# # user when the user presses
+# # a shortcut key.
+# #
+# _("Present current date."))
self.inputEventHandlers["bypassNextCommandHandler"] = \
input_event.InputEventHandler(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]