[orca/orca-gnome3: 17/87] Working with old event manager



commit 0bf2782e021e6757e05a50f6ce5e8f0c64f71119
Author: José Ignacio �lvarez Ruiz <jialvarez emergya es>
Date:   Mon Mar 7 17:11:33 2011 +0100

    Working with old event manager

 src/orca/Makefile.am           |    1 +
 src/orca/baseplugins/test.py   |  111 ++++++++++++++++++----------------------
 src/orca/plug_event_manager.py |   79 ++++++++++++++++++++++++++++
 src/orca/plugin_manager.py     |    3 +
 src/orca/pluglib/interfaces.py |   83 +++++++++++-------------------
 src/orca/pluglib/manager.py    |   55 +++++++++++++-------
 src/orca/scripts/default.py    |   38 +++++++++-----
 src/orca/store_config.py       |   41 +++++++++------
 8 files changed, 248 insertions(+), 163 deletions(-)
---
diff --git a/src/orca/Makefile.am b/src/orca/Makefile.am
index 3b3d4f4..0d198c9 100644
--- a/src/orca/Makefile.am
+++ b/src/orca/Makefile.am
@@ -57,6 +57,7 @@ orca_python_PYTHON = \
 	outloud.py \
 	phonnames.py \
 	orca_platform.py \
+	plug_event_manager.py \
 	plugin_manager.py \
 	pronunciation_dict.py \
 	punctuation_settings.py \
diff --git a/src/orca/baseplugins/test.py b/src/orca/baseplugins/test.py
index 5508f19..0e0c072 100644
--- a/src/orca/baseplugins/test.py
+++ b/src/orca/baseplugins/test.py
@@ -1,22 +1,30 @@
-# - coding: utf-8 -
-
-# Copyright (C) 2010, J. Félix Ontañón <felixonta gmail com>
-# Copyright (C) 2011, J. Ignacio Ã?lvarez <neonigma gmail com>
-
-# This file is part of Pluglib.
-
-# Pluglib is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# Pluglib is distributed in the hope that it will be useful,
+# Orca                                                                              
+#
+# Copyright 2011 Consorcio Fernando de los Rios.
+# Author: J. Ignacio Alvarez <jialvarez emergya es>                                 
+#
+# This library is free software; you can redistribute it and/or                     
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.                
+#
+# This library is distributed in the hope that it will be useful,                   
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with Pluglib.  If not, see <http://www.gnu.org/licenses/>.
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                 
+# Lesser General Public License for more details.                                   
+#
+# You should have received a copy of the GNU Lesser General Public                  
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., Franklin Street, Fifth Floor,                     
+# Boston MA  02110-1301 USA.                                                        
+
+"""Test script example."""
+
+__id__        = "$Id$"
+__version__   = "$Revision$"
+__date__      = "$Date$"
+__copyright__ = "Copyright (c) 2011 Consorcio Fernando de los Rios."
+__license__   = "LGPL"
 
 import time
 from pluglib.interfaces import *
@@ -29,65 +37,44 @@ from orca_i18n import ngettext  # for ngettext support
 from orca_i18n import C_        # to provide qualified translatable strings
 
 import notification_messages as notification_messages
-print notification_messages
 
-class callPresenter(IPresenter):
-    inputEventHandlers = {}
+from event_manager import EventManager
+_eventManager = EventManager()
+
+_settingsManager = SettingsManager()
+if _settingsManager is None:
+    print "Could not load the settings manager. Exiting."
+    sys.exit(1)
 
-    _settingsManager = SettingsManager()
-    if _settingsManager is None:
-        print "Could not load the settings manager. Exiting."
-        sys.exit(1)
+
+class testPlugin(IPlugin, IPresenter):
+    name = 'Test Plugin'
+    description = 'A testing plugin for code tests' 
+    version = '0.1pre'
+    authors = ['J. Ignacio Alvarez <neonigma gmail com>']
+    website = 'http://fontanon.org'
+    icon = 'gtk-missing-image'
 
     def __init__(self):
+        print 'Hello World (plugin started)!'
 
-        print "Init call presenter..."
-        self.inputEventHandlers["presentTimeHandler"] = \
-            input_event.InputEventHandler(
-                callPresenter.presentTime,
+    def getPresentTimeHandler(self, function):
+        return input_event.InputEventHandler(
+                function,
                 # 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,
+    def getPresentDateHandler(self, function):
+        return input_event.InputEventHandler(
+                function,
                 # Translators: Orca can present the current date to the
                 # user when the user presses
                 # a shortcut key.
                 #
                 _("Present current date."))
-        
-        self.inputEventHandlers.update(notification_messages.inputEventHandlers)
-
-    def presentTime(self, inputEvent):
-        """ Presents the current time. """
-        timeFormat = self._settingsManager.getSetting('presentTimeFormat')
-        message = time.strftime(timeFormat, time.localtime())
-        super(callPresenter, self).presentMessage(message)
-        return True
-
-    def presentDate(self, inputEvent):
-        """ Presents the current date. """
-        dateFormat = self._settingsManager.getSetting('presentDateFormat')
-        message = time.strftime(dateFormat, time.localtime())
-        super(callPresenter, self).presentMessage(message)
-        return True
-
-class testPlugin(IPlugin, IPresenter):
-    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'
-    icon = 'gtk-missing-image'
-
-    def __init__(self):
-        print 'Hello World (plugin started)!'
-        cp = callPresenter()
-
-
 
 IPlugin.register(testPlugin)
+
diff --git a/src/orca/plug_event_manager.py b/src/orca/plug_event_manager.py
new file mode 100644
index 0000000..935c259
--- /dev/null
+++ b/src/orca/plug_event_manager.py
@@ -0,0 +1,79 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2011, J. Ignacio Ã?lvarez <neonigma gmail com>
+
+# This file is part of Pluglib ABC.
+
+# Pluglib is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# Pluglib is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with Pluglib.  If not, see <http://www.gnu.org/licenses/>.
+
+import sys
+
+class Event:
+    def __init__(self, name):
+        self.name = name
+        self.listeners = {}
+
+    def add(self, function, data=None):
+        self.listeners[function] = data
+
+    def delete(self, function):
+        self.listeners.pop(function)
+
+    def called(self, data=None):
+        for function, d in self.listeners.items():
+            if data is None:
+                if d is None:
+                    function()
+                else:
+                    if type(d) == type([]):
+                        function(*d)
+                    elif type(d) == type({}):
+                        function(**d)
+                    else:
+                        function(d)
+            else:
+                if type(data) == type([]):
+                    function(*data)
+                elif type(data) == type({}):
+                    function(**data)
+                else:
+                    function(data)
+
+class EventManager:
+    def __init__(self):
+        self.events = {}
+
+    def add_event(self, Event):
+        self.events[Event.name] = Event
+
+    def del_event(self, Event):
+        self.events.pop(Event.name)
+
+    def connect(self, event, function, data=None):
+        self.events[event].add(function, data)
+
+    def disconnect(self, event, function):
+        self.events[event].delete(function)
+
+    def signal(self, event, data=None):
+        try:
+            if data is None:
+                self.events[event].called()
+            else:
+                self.events[event].called(data)
+        except Exception, e:
+            print "ERROR: Event "+str(event)+" not in queue"
+            return
+
+event_manager = EventManager()
diff --git a/src/orca/plugin_manager.py b/src/orca/plugin_manager.py
index d0b344f..ead6d60 100644
--- a/src/orca/plugin_manager.py
+++ b/src/orca/plugin_manager.py
@@ -48,4 +48,7 @@ class TestPluginManager(ModulePluginManager):
         else:
             raise PluginManagerError, 'No plugin named %s' % plugin_name
 
+    def get_plugin_object_by_name(self, plugin_name):
+        return super(TestPluginManager, self).get_plugin_object_by_name(plugin_name)
+
 plugmanager = TestPluginManager()
diff --git a/src/orca/pluglib/interfaces.py b/src/orca/pluglib/interfaces.py
index 4607e82..d19b03f 100644
--- a/src/orca/pluglib/interfaces.py
+++ b/src/orca/pluglib/interfaces.py
@@ -1,22 +1,31 @@
-# -*- coding: utf-8 -*-
-
-# Copyright (C) 2010, J. Félix Ontañón <felixonta gmail com>
-# Copyright (C) 2011, J. Ignacio Ã?lvarez <neonigma gmail com>
-
-# This file is part of Pluglib.
-
-# Pluglib is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# Pluglib is distributed in the hope that it will be useful,
+# Orca                                                                              
+#
+# Copyright 2011 Consorcio Fernando de los Rios.
+# Author: J. Ignacio Alvarez <jialvarez emergya es>
+# Author: J. Felix Ontanon <fontanon emergya es>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with Pluglib.  If not, see <http://www.gnu.org/licenses/>.
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., Franklin Street, Fifth Floor,
+# Boston MA  02110-1301 USA.
+
+"""Definition of interfaces must be implemented in plugins."""
+
+__id__        = "$Id$"
+__version__   = "$Revision$"
+__date__      = "$Date$"
+__copyright__ = "Copyright (c) 2011 Consorcio Fernando de los Rios."
+__license__   = "LGPL"
 
 import exceptions
 import abc
@@ -181,39 +190,7 @@ class ICommand(object):
     def get_command(command_name):
         """Return a command in this environment"""
 
-import locale
-import time
-
-from settings_manager import SettingsManager
-_settingsManager = SettingsManager()
-if _settingsManager is None:
-    print "Could not load the settings manager. Exiting."
-    sys.exit(1)
-
-import pyatspi
-import braille as braille
-import debug as debug
-import eventsynthesizer as eventsynthesizer
-import find as find
-import flat_review as flat_review
-import input_event as input_event
-import keybindings as keybindings
-try:
-    import gsmag as mag
-except:
-    import mag as mag
-import outline as outline
-import orca_state as orca_state
-import phonnames as phonnames
-import script as script
-import settings as settings
-import speech as speech
-import speech_generator as speech_generator
-import speechserver as speechserver
-import mouse_review as mouse_review
-import text_attribute_names as text_attribute_names
-import notification_messages as notification_messages
-import orca_gui_prefs as orca_gui_prefs
+import script
 
 class Messaging(script.Script):
 
@@ -278,11 +255,13 @@ class Messaging(script.Script):
 class IPresenter(object):
     """Allows to operate with presentation plugins"""
 
+    __metaclass__ = abc.ABCMeta
+
     ############## METHODS #################
 
     def presentMessage(self, fullMessage, briefMessage=None, voice=None):
         print "Calling Messaging with fullMessage: " + str(fullMessage) 
-        msg = Messaging(fullMessage, briefMessage, voice)
+#        msg = Messaging(fullMessage, briefMessage, voice)
 
 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 b6b1946..de58444 100644
--- a/src/orca/pluglib/manager.py
+++ b/src/orca/pluglib/manager.py
@@ -1,22 +1,31 @@
-# -*- coding: utf-8 -*-
-
-# Copyright (C) 2010, J. Félix Ontañón <felixonta gmail com>
-# Copyright (C) 2011, J. Ignacio Ã?lvarez <neonigma gmail com>
-
-# This file is part of Pluglib.
-
-# Pluglib is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# Pluglib is distributed in the hope that it will be useful,
+# Orca                                                                              
+#
+# Copyright 2011 Consorcio Fernando de los Rios.
+# Author: J. Ignacio Alvarez <jialvarez emergya es>
+# Author: J. Felix Ontanon <fontanon emergya es>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with Pluglib.  If not, see <http://www.gnu.org/licenses/>.
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., Franklin Street, Fifth Floor,
+# Boston MA  02110-1301 USA.
+
+"""Superclass for managing the plugins."""
+
+__id__        = "$Id$"
+__version__   = "$Revision$"
+__date__      = "$Date$"
+__copyright__ = "Copyright (c) 2011 Consorcio Fernando de los Rios."
+__license__   = "LGPL"
 
 import os
 import sys
@@ -197,10 +206,16 @@ class ModulePluginManager(IPluginManager):
         del (plugin_name)
 
     def get_plugins(self):
-        return [(plugin_name, plugin['class'], 
-                 plugin['type'], plugin['registered'], plugin['name']) 
+        return [(plugin_name, plugin['class'], plugin['type'], 
+            plugin['registered'], plugin['name']) 
             for (plugin_name, plugin) in self.plugins.items()]
 
+    def get_plugin_object_by_name(self, plugin_name):
+        if self.plugins.has_key(plugin_name):
+            return self.plugins[plugin_name]['object']
+        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
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index f2f775d..d489579 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -145,6 +145,12 @@ class Script(script.Script):
         """Defines InputEventHandler fields for this script that can be
         called by the key and braille bindings."""
 
+        from plugin_manager import plugmanager
+        plugmanager.scan_plugins()
+        plugmanager.get_plugins()
+
+        from plug_event_manager import EventManager, Event, plug_event_manager as pem
+
         self.inputEventHandlers["routePointerToItemHandler"] = \
             input_event.InputEventHandler(
                 Script.routePointerToItem,
@@ -1067,6 +1073,12 @@ class Script(script.Script):
                 #
                 _("Toggle mouse review mode."))
 
+        testPluginObj = plugmanager.get_plugin_object_by_name("test")
+
+        if testPluginObj:
+            self.inputEventHandlers["presentTimeHandler"] = testPluginObj.getPresentTimeHandler(Script.presentTime)
+            self.inputEventHandlers["presentDateHandler"] = testPluginObj.getPresentDateHandler(Script.presentDate)
+
 #        self.inputEventHandlers["presentTimeHandler"] = \
 #            input_event.InputEventHandler(
 #                Script.presentTime,
@@ -5810,19 +5822,19 @@ class Script(script.Script):
         speech.speak(_("Unicode %s") % \
                          self.utilities.unicodeValueString(character))
 
-#    def presentTime(self, inputEvent):
-#        """ Presents the current time. """
-#        timeFormat = _settingsManager.getSetting('presentTimeFormat')
-#        message = time.strftime(timeFormat, time.localtime())
-#        self.presentMessage(message)
-#        return True
-#
-#    def presentDate(self, inputEvent):
-#        """ Presents the current date. """
-#        dateFormat = _settingsManager.getSetting('presentDateFormat')
-#        message = time.strftime(dateFormat, time.localtime())
-#        self.presentMessage(message)
-#        return True
+    def presentTime(self, inputEvent):
+        """ Presents the current time. """
+        timeFormat = _settingsManager.getSetting('presentTimeFormat')
+        message = time.strftime(timeFormat, time.localtime())
+        self.presentMessage(message)
+        return True
+
+    def presentDate(self, inputEvent):
+        """ Presents the current date. """
+        dateFormat = _settingsManager.getSetting('presentDateFormat')
+        message = time.strftime(dateFormat, time.localtime())
+        self.presentMessage(message)
+        return True
 
 # Dictionary that defines the state changes we care about for various
 # objects.  The key represents the role and the value represents a list
diff --git a/src/orca/store_config.py b/src/orca/store_config.py
index 2d34172..58df6e5 100644
--- a/src/orca/store_config.py
+++ b/src/orca/store_config.py
@@ -1,21 +1,30 @@
-# -*- coding: utf-8 -*-
-
-# Copyright (C) 2011, J. Ignacio Ã?lvarez <neonigma gmail com>
-
-# This file is part of Pluglib ABC.
-
-# Pluglib is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# Pluglib is distributed in the hope that it will be useful,
+# Orca                                                                              
+#
+# Copyright 2011 Consorcio Fernando de los Rios.
+# Author: J. Ignacio Alvarez <jialvarez emergya es>                                 
+#
+# This library is free software; you can redistribute it and/or                     
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.                
+#
+# This library is distributed in the hope that it will be useful,                   
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with Pluglib.  If not, see <http://www.gnu.org/licenses/>.
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                 
+# Lesser General Public License for more details.                                   
+#
+# You should have received a copy of the GNU Lesser General Public                  
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., Franklin Street, Fifth Floor,                     
+# Boston MA  02110-1301 USA.                                                        
+
+"""Instance for managing the plugings."""
+
+__id__        = "$Id$"
+__version__   = "$Revision$"
+__date__      = "$Date$"
+__copyright__ = "Copyright (c) 2011 Consorcio Fernando de los Rios."
+__license__   = "LGPL"
 
 from settings_manager import SettingsManager
 



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