[orca/orca-gnome3: 23/87] Plugin Date And Time working. Need to unregister keybinding correctly



commit d04dc0452b62e99e3794ceb4d475c6f4b5be95b0
Author: José Ignacio �lvarez Ruiz <jialvarez emergya es>
Date:   Fri Mar 11 00:09:08 2011 +0100

    Plugin Date And Time working. Need to unregister keybinding correctly

 src/orca/baseplugins/test.py       |   69 +++++++++++++++++++++++++++++++----
 src/orca/pluglib/interfaces.py     |   21 ++++++++---
 src/orca/pluglib/plugin_manager.py |   30 +++++++++------
 3 files changed, 94 insertions(+), 26 deletions(-)
---
diff --git a/src/orca/baseplugins/test.py b/src/orca/baseplugins/test.py
index b3cd579..c7cfefd 100644
--- a/src/orca/baseplugins/test.py
+++ b/src/orca/baseplugins/test.py
@@ -19,22 +19,75 @@
 # along with Pluglib.  If not, see <http://www.gnu.org/licenses/>.
 
 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
 
-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>']
+import orca.input_event
+import orca.keybindings
+import orca.orca as orca_module
+_settingsManager = getattr(orca_module, '_settingsManager')
+ 
+import time
+
+class testPlugin(IPlugin, IPresenter, ICommand):
+    name = 'Date and Time'
+    description = 'Present the date and time to the user' 
+    version = '0.9'
+    authors = ['J. Ignacio Alvarez <neonigma gmail com>']
     website = 'http://www.emergya.es'
     icon = 'gtk-missing-image'
 
     def __init__(self):
-        print 'Hello World (plugin started)!'
+        print 'Date and time plugin started'
+
+        self.myKeyBindings = orca.keybindings.KeyBindings()
+
+        self.presentTimeHandler = orca.input_event.InputEventHandler(
+            self.presentTime,
+            # Translators: Orca can present the current time to the
+            # user when the user presses
+            # a shortcut key.
+            #
+            _("Present current time."))
+
+        self.myKeyBindings.add(orca.keybindings.KeyBinding(
+            "t",
+            1 << orca.settings.MODIFIER_ORCA,
+            1 << orca.settings.MODIFIER_ORCA,
+            self.presentTimeHandler))
+
+
+        self.presentDateHandler = orca.input_event.InputEventHandler(
+            self.presentDate,
+            # Translators: Orca can present the current date to the
+            # user when the user presses
+            # a shortcut key.
+            #
+            _("Present current date."))
+
+        self.myKeyBindings.add(orca.keybindings.KeyBinding(
+            "d",
+            1 << orca.settings.MODIFIER_ORCA,
+            1 << orca.settings.MODIFIER_ORCA,
+            self.presentDateHandler))
+
+        orca.settings.keyBindingsMap["default"] = self.myKeyBindings
+
+    def presentTime(self, script, inputEvent=None):
+        timeFormat = _settingsManager.getSetting('presentTimeFormat')
+        message = time.strftime(timeFormat, time.localtime())
+        self.presentMessage(message, script)
+        return True
+
+    def presentDate(self, script, inputEvent=None):
+        dateFormat = _settingsManager.getSetting('presentDateFormat')
+        message = time.strftime(dateFormat, time.localtime())
+        self.presentMessage(message, script)
+        return True
+
+    def removePluginKeybinding(self):
+        self.removeKeybinding(self.presentTimeHandler)
 
 IPlugin.register(testPlugin)
diff --git a/src/orca/pluglib/interfaces.py b/src/orca/pluglib/interfaces.py
index b27f44d..cbc2a4f 100644
--- a/src/orca/pluglib/interfaces.py
+++ b/src/orca/pluglib/interfaces.py
@@ -20,7 +20,6 @@
 
 import exceptions
 import abc
-import orca.scripts.default as default
 
 class IPlugin(object):
     """Every plugin must implement this interface"""
@@ -164,18 +163,28 @@ class IConfigureDialog(IConfigurable):
 
 class ICommand(object):
     """Allows to operate with commands plugins"""
+    __metaclass__ = abc.ABCMeta
 
-    # What things need to be come here?
+    ############## METHODS #################
 
+    def removeKeybinding(self, kbHandler):
+        import orca.keybindings
 
-class IPresenter(default.Script):
-    """Allows to operate with presentation plugins"""
+        kbInstance = orca.keybindings.KeyBindings()
+        kbInstance.removeByHandler(kbHandler)
 
-    inputEventHandlers = {}
+
+class IPresenter(object):
+    """Allows to operate with presentation plugins"""
+    __metaclass__ = abc.ABCMeta
 
     ############## METHODS #################
 
-    # What things need to be come here?
+    def presentMessage(self, message, app):
+        import orca.scripts.default as default
+
+        defaultHandler = default.Script(app)
+        defaultHandler.presentMessage(message)
 
 class IDependenciesChecker(object):
     """Allows to check for dependencies before run"""
diff --git a/src/orca/pluglib/plugin_manager.py b/src/orca/pluglib/plugin_manager.py
index 18a22b6..60b7de4 100644
--- a/src/orca/pluglib/plugin_manager.py
+++ b/src/orca/pluglib/plugin_manager.py
@@ -141,7 +141,7 @@ class ModulePluginManager(IPluginManager):
         if self.plugins_conf:
             # take the plugins list in the backend
             self.plugins = self.plugins_conf.copy()
-            load_plugins = self.plugins['plugins'];
+            load_plugins = self.plugins['plugins']
     
             for module_name, data in load_plugins.iteritems():
                 if load_plugins[module_name]['active'] == True:
@@ -200,22 +200,28 @@ class ModulePluginManager(IPluginManager):
             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})
-
         if self.is_plugin_enabled(plugin_name):
             plugin_object = self.plugins[plugin_name]['object']
+    
             if isinstance(plugin_object, IConfigurable):
-	        plugin_object.save()
+    	        plugin_object.save()
+
+            if isinstance(plugin_object, ICommand):
+                plugin_object.removePluginKeybinding()
+ 
             self.plugins[plugin_name]['object'] = None
 
-        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)
+            # 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})
+    
+            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):
         return [(plugin_name, plugin['class'], 



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