[orca/orca-gnome3: 14/87] Run plugin in its first loading



commit bf9663d0dca2af56f00236caf328467e036af6d2
Author: José Ignacio �lvarez Ruiz <jialvarez emergya es>
Date:   Wed Mar 2 12:42:30 2011 +0100

    Run plugin in its first loading

 src/orca/baseplugins/test.py   |   55 ++++++++++++++++++++++++++++-
 src/orca/pluglib/interfaces.py |   75 ++++++++++++++++++++++++++++++++--------
 src/orca/pluglib/manager.py    |    9 ++++-
 3 files changed, 121 insertions(+), 18 deletions(-)
---
diff --git a/src/orca/baseplugins/test.py b/src/orca/baseplugins/test.py
index 17e6814..004f009 100644
--- a/src/orca/baseplugins/test.py
+++ b/src/orca/baseplugins/test.py
@@ -19,8 +19,58 @@
 # along with Pluglib.  If not, see <http://www.gnu.org/licenses/>.
 
 from pluglib.interfaces import *
+import input_event as input_event
 
-class testPlugin(IPlugin):
+from settings_manager import SettingsManager
+_settingsManager = SettingsManager()
+if _settingsManager is None:
+    print "Could not load the settings manager. Exiting."
+    sys.exit(1)
+
+from orca_i18n import _         # for gettext support
+from orca_i18n import ngettext  # for ngettext support
+from orca_i18n import C_        # to provide qualified translatable strings
+
+#import notification_messages as notification_messages
+
+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):
     name = 'Test Plugin'
     description = 'A testing plugin for code tests' 
     version = '0.1pre'
@@ -30,5 +80,8 @@ class testPlugin(IPlugin):
 
     def __init__(self):
         print 'Hello World (plugin started)!'
+        cp = callPresenter()
+
+
 
 IPlugin.register(testPlugin)
diff --git a/src/orca/pluglib/interfaces.py b/src/orca/pluglib/interfaces.py
index 9bdf6a1..b383d8e 100644
--- a/src/orca/pluglib/interfaces.py
+++ b/src/orca/pluglib/interfaces.py
@@ -162,7 +162,7 @@ class IConfigureDialog(IConfigurable):
         """Display preferences dialog"""
 
 class ICommand(object):
-    """Allows to operate with commands"""
+    """Allows to operate with commands plugins"""
 
     __metaclass__ = abc.ABCMeta
 
@@ -182,24 +182,69 @@ class ICommand(object):
         """Return a command in this environment"""
 
 class IPresenter(object):
-    """Allows to operate with presenters"""
-    
-    __metaclass__ = abc.ABCMeta
-  
-    def presenters_getter(self):
-        """ You must implement this method in your class """
-
-    def presenters_setter(self, new_presenters):
-         """ You must implement this method in your class """
+    """Allows to operate with presentation plugins"""
 
-    # Set of managed plugins
-    presenters = abc.abstractproperty(presenters_getter, presenters_setter)
+    __metaclass__ = abc.ABCMeta
 
     ############## METHODS #################
 
-    @abc.abstractmethod
-    def get_presenters():
-        """Return all commands in this environment"""
+    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)
 
 class IDependenciesChecker(object):
     """Allows to check for dependencies before run"""
diff --git a/src/orca/pluglib/manager.py b/src/orca/pluglib/manager.py
index 40a5478..b6b1946 100644
--- a/src/orca/pluglib/manager.py
+++ b/src/orca/pluglib/manager.py
@@ -142,6 +142,13 @@ class ModulePluginManager(IPluginManager):
                     try:
                         self.load_class_in_plugin(load_plugins[module_name], 
                                 module_name, [load_plugins[module_name]['path']])
+
+                        plugin_class = load_plugins[module_name]['class']
+                        plugin_object = plugin_class()
+                        if isinstance(plugin_object, IConfigurable):
+                	        plugin_object.load()
+                        
+                        load_plugins[module_name]['object'] = plugin_object
                         print "Starting existent module: " + str(module_name)
                     except Exception, e:
                         raise PluginManagerError, 'Cannot load module %s: %s' % \
@@ -151,8 +158,6 @@ class ModulePluginManager(IPluginManager):
                     load_plugins[module_name].update({'object': None})
  
             self.plugins = load_plugins
-            
-
 
     def enable_plugin(self, plugin_name):
         enabling_plugins = self.store_conf.getPluginByName(plugin_name)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]