orca r4208 - branches/phase2/src/orca



Author: wwalker
Date: Sun Sep 14 01:24:29 2008
New Revision: 4208
URL: http://svn.gnome.org/viewvc/orca?rev=4208&view=rev

Log:
Add subscript class.


Added:
   branches/phase2/src/orca/subscript.py   (contents, props changed)
Modified:
   branches/phase2/src/orca/Makefile.am
   branches/phase2/src/orca/script.py

Modified: branches/phase2/src/orca/Makefile.am
==============================================================================
--- branches/phase2/src/orca/Makefile.am	(original)
+++ branches/phase2/src/orca/Makefile.am	Sun Sep 14 01:24:29 2008
@@ -19,6 +19,7 @@
 	script_manager.py \
 	script.py \
 	settings.py \
+	subscript.py \
 	utils.py
 
 orca_pythondir=$(pyexecdir)/orca

Modified: branches/phase2/src/orca/script.py
==============================================================================
--- branches/phase2/src/orca/script.py	(original)
+++ branches/phase2/src/orca/script.py	Sun Sep 14 01:24:29 2008
@@ -59,22 +59,13 @@
     """The specific focus tracking scripts for applications.
     """
     def __init__(self, application):
-        """Creates a script for the given application, if necessary.
+        """Creates a script for the given application.
         This method should not be called by anyone except the
         focus_tracking_presenter.
 
         Arguments:
         - application: the Python Accessible application to create a script for
         """
-        self._application = application
-
-        if application:
-            self._name = self._application.name
-        else:
-            self._name = "default"
-
-        self._name += " (module=" + self.__module__ + ")"
-        
         self._isActive = False
         self.presentIfInactive = False
         
@@ -84,15 +75,33 @@
             self._createKeyBindings(self._inputEventHandlers)
         self._brailleBindings = \
             self._createBrailleBindings(self._inputEventHandlers)
-
+        
+        self._name = None
+        self._application = application
         self._focus = None
         self._pointOfReference = {}
+        self._completeInit(application)
 
+    def _completeInit(self, application):
+        """Completes the __init__ step.
+        """
+        if application:
+            self._name = self._application.name
+        else:
+            self._name = "default"
+        self._name += " (module=" + self.__module__ + ")"
         log.debug("NEW SCRIPT: %s" % self)
 
     def __str__(self):
         """Returns a human readable representation of the script.
         """
+        if not self._name:
+            if application:
+                self._name = self._application.name
+            else:
+                self._name = "default"
+            self._name += " (module=" + self.__module__ + ")"
+
         return self._name
 
     def _createObjectEventListeners(self):
@@ -112,15 +121,6 @@
         """
         return {}
 
-    def getInputEventHandlerKey(self, inputEventHandler):
-        """Returns the name of the key that contains an inputEventHadler
-        passed as argument
-        """
-        for keyName, handler in self._inputEventHandlers.iteritems():
-            if handler == inputEventHandler:
-                return keyName
-        return None
-
     def _createKeyBindings(self, handlers):
         """Defines the key bindings for this script.
 
@@ -148,6 +148,15 @@
         # TODO: implement click count
         return 1
 
+    def getInputEventHandlerKey(self, inputEventHandler):
+        """Returns the name of the key that contains an inputEventHadler
+        passed as argument
+        """
+        for keyName, handler in self._inputEventHandlers.iteritems():
+            if handler == inputEventHandler:
+                return keyName
+        return None
+
     def consumesKeyboardEvent(self, keyboardEvent):
         """Called when a key is pressed on the keyboard.  If we care
         about it, our processKeyboardEvent method will get called a

Added: branches/phase2/src/orca/subscript.py
==============================================================================
--- (empty file)
+++ branches/phase2/src/orca/subscript.py	Sun Sep 14 01:24:29 2008
@@ -0,0 +1,76 @@
+# Copyright 2004-2008 Sun Microsystems Inc.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; either
+# version 2 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
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library 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.
+
+"""Each subscript maintains a set of key bindings, braille bindings,
+and AT-SPI event listeners.  The key bindings are an instance of
+KeyBindings.  The braille bindings are also a dictionary where the
+keys are BrlTTY command integers and the values are instances of
+InputEventHandler.  The listeners field is a dictionary where the keys
+are AT-SPI event names and the values are function pointers.
+
+Instances of subscripts are intended to be created solely by the
+script that owns them.
+"""
+
+__id__        = "$Id$"
+__copyright__ = "Copyright (c) 2005-2008 Sun Microsystems Inc."
+__license__   = "LGPL"
+
+import logging
+log = logging.getLogger('orca.subscript')
+
+import script
+
+class SubScript(script.Script):
+    """A SubScript is owned by a Script.  It can be viewed as being
+    something like a plugin for a Script.
+    """
+    def __init__(self, superScript):
+        """Creates a SubScript for the given script.
+        This method should not be called by anyone except the
+        superScript.
+
+        Arguments:
+        - application: the Script owning this SubScript
+        """
+        self._script = None
+        script.Script.__init__(self, superScript)
+
+    def _completeInit(self, superScript):
+        """Completes the __init__ step.
+        """
+        self._script = superScript
+        self._name = "subscript %s script=%s" % (self.__module__, self._script)
+        log.debug("NEW SUBSCRIPT: %s" % self)
+
+if __name__ == "__main__":
+    logging.basicConfig(format="%(name)s %(message)s")
+    log.setLevel(logging.DEBUG)
+
+    scrypt = script.Script(None)
+    subscript = SubScript(scrypt)
+    print script, subscript
+
+    subscript.processObjectEvent(None)
+
+    subscript.activate()
+    try:
+        subscript.processObjectEvent(None)
+    except:
+        # Expected since no event was passed in
+        #
+        pass



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