[orca] Begin migration of Evolution script to using Orca's WebKitGtk support



commit 1bcd9931972c7908b0846d2fb1506d6f41fa9b80
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Sun May 12 09:59:59 2013 -0400

    Begin migration of Evolution script to using Orca's WebKitGtk support

 src/orca/scripts/apps/evolution/script.py          |  190 +-------------------
 .../scripts/apps/evolution/script_utilities.py     |    5 +-
 .../scripts/apps/evolution/speech_generator.py     |    5 +-
 src/orca/scripts/toolkits/WebKitGtk/__init__.py    |    3 +
 4 files changed, 12 insertions(+), 191 deletions(-)
---
diff --git a/src/orca/scripts/apps/evolution/script.py b/src/orca/scripts/apps/evolution/script.py
index c25318d..7c3e3e3 100644
--- a/src/orca/scripts/apps/evolution/script.py
+++ b/src/orca/scripts/apps/evolution/script.py
@@ -32,12 +32,11 @@ import pyatspi
 import orca.cmdnames as cmdnames
 import orca.debug as debug
 import orca.scripts.default as default
-import orca.keybindings as keybindings
-import orca.input_event as input_event
 import orca.braille as braille
 import orca.messages as messages
 import orca.orca as orca
 import orca.orca_state as orca_state
+import orca.scripts.toolkits.WebKitGtk as WebKitGtk
 import orca.speech as speech
 import orca.speechserver as speechserver
 import orca.settings as settings
@@ -55,7 +54,7 @@ _settingsManager = settings_manager.getManager()
 #                                                                      #
 ########################################################################
 
-class Script(default.Script):
+class Script(WebKitGtk.Script):
 
     def __init__(self, app):
         """Creates a new script for the given application.
@@ -68,7 +67,7 @@ class Script(default.Script):
         #
         self.debugLevel = debug.LEVEL_FINEST
 
-        default.Script.__init__(self, app)
+        WebKitGtk.Script.__init__(self, app)
 
         # This will be used to cache a handle to the message area in the
         # Mail compose window.
@@ -110,19 +109,6 @@ class Script(default.Script):
 
         return Utilities(self)
 
-    def setupInputEventHandlers(self):
-        """Defines InputEventHandler fields for this script that can be
-        called by the key and braille bindings. In this particular case,
-        we just want to be able to define our own sayAll() method.
-        """
-
-        default.Script.setupInputEventHandlers(self)
-
-        self.inputEventHandlers["sayAllHandler"] = \
-            input_event.InputEventHandler(
-                Script.sayAll,
-                cmdnames.SAY_ALL)
-
     def isActivatableEvent(self, event):
         """Returns True if the given event is one that should cause this
         script to become the active script.  This is only a hint to
@@ -351,173 +337,3 @@ class Script(default.Script):
             'speechVerbosityLevel', savedSpeechVerbosityLevel)
 
         self.displayBrailleRegions(brailleGen.generateBraille(tab))
-
-    def textLines(self, obj):
-        """Creates a generator that can be used to iterate over each line
-        of a text object, starting at the caret offset.
-
-        We have to subclass this because Evolution lays out its messages
-        such that each paragraph is in its own panel, each of which is
-        in a higher level panel.  So, we just traverse through the
-        children.
-
-        Arguments:
-        - obj: an Accessible that has a text specialization
-
-        Returns an iterator that produces elements of the form:
-        [SayAllContext, acss], where SayAllContext has the text to be
-        spoken and acss is an ACSS instance for speaking the text.
-        """
-
-        if not obj:
-            return
-
-        try:
-            text = obj.queryText()
-        except NotImplementedError:
-            return
-
-        panel = obj.parent
-        htmlPanel = panel.parent
-        startIndex = panel.getIndexInParent()
-        i = startIndex
-        total = htmlPanel.childCount
-        textObjs = []
-        startOffset = text.caretOffset
-        offset = text.caretOffset
-        string = ""
-        done = False
-
-        # Determine the correct "say all by" mode to use.
-        #
-        sayAllStyle = _settingsManager.getSetting('sayAllStyle')
-        if sayAllStyle == settings.SAYALL_STYLE_SENTENCE:
-            mode = pyatspi.TEXT_BOUNDARY_SENTENCE_END
-        elif sayAllStyle == settings.SAYALL_STYLE_LINE:
-            mode = pyatspi.TEXT_BOUNDARY_LINE_START
-        else:
-            mode = pyatspi.TEXT_BOUNDARY_LINE_START
-        voices = _settingsManager.getSetting('voices')
-
-        while not done:
-            panel = htmlPanel.getChildAtIndex(i)
-            if panel != None:
-                textObj = panel.getChildAtIndex(0)
-                try:
-                    text = textObj.queryText()
-                except NotImplementedError:
-                    return
-                textObjs.append(textObj)
-                length = text.characterCount
-
-                while offset <= length:
-                    [mystr, start, end] = text.getTextAtOffset(offset, mode)
-                    endOffset = end
-
-                    if len(mystr) != 0:
-                        string += " " + mystr
-
-                    if mode == pyatspi.TEXT_BOUNDARY_LINE_START or \
-                       len(mystr) == 0 or mystr[len(mystr)-1] in '.?!':
-                        string = self.utilities.adjustForRepeats(string)
-                        if string.isupper():
-                            voice = voices[settings.UPPERCASE_VOICE]
-                        else:
-                            voice = voices[settings.DEFAULT_VOICE]
-
-                        if not textObjs:
-                            textObjs.append(textObj)
-                        if len(string) != 0:
-                            yield [speechserver.SayAllContext(textObjs, string,
-                                                      startOffset, endOffset),
-                               voice]
-                        textObjs = []
-                        string = ""
-                        startOffset = endOffset
-
-                    if len(mystr) == 0 or end == length:
-                        break
-                    else:
-                        offset = end
-
-            offset = 0
-            i += 1
-            if i == total:
-                done = True
-
-        # If there is anything left unspoken, speak it now.
-        #
-        if len(string) != 0:
-            string = self.utilities.adjustForRepeats(string)
-            if string.isupper():
-                voice = voices[settings.UPPERCASE_VOICE]
-            else:
-                voice = voices[settings.DEFAULT_VOICE]
-
-            yield [speechserver.SayAllContext(textObjs, string,
-                                              startOffset, endOffset),
-                   voice]
-
-    def __sayAllProgressCallback(self, context, callbackType):
-        """Provide feedback during the sayAll operation.
-        """
-
-        if callbackType == speechserver.SayAllContext.PROGRESS:
-            #print "PROGRESS", context.utterance, context.currentOffset
-            return
-        elif callbackType == speechserver.SayAllContext.INTERRUPTED:
-            #print "INTERRUPTED", context.utterance, context.currentOffset
-            offset = context.currentOffset
-            for i in range(0, len(context.obj)):
-                obj = context.obj[i]
-                charCount = obj.queryText().characterCount
-                if offset > charCount:
-                    offset -= charCount
-                else:
-                    obj.queryText().setCaretOffset(offset)
-                    break
-        elif callbackType == speechserver.SayAllContext.COMPLETED:
-            #print "COMPLETED", context.utterance, context.currentOffset
-            obj = context.obj[len(context.obj)-1]
-            obj.queryText().setCaretOffset(context.currentOffset)
-            orca.setLocusOfFocus(None, obj, notifyScript=False)
-
-        # If there is a selection, clear it. See bug #489504 for more details.
-        # This is not straight forward with Evolution. all the text is in
-        # an HTML panel which contains multiple panels, each containing a
-        # single text object.
-        #
-        panel = obj.parent
-        htmlPanel = panel.parent
-        for i in range(0, htmlPanel.childCount):
-            panel = htmlPanel.getChildAtIndex(i)
-            if panel != None:
-                textObj = panel.getChildAtIndex(0)
-                try:
-                    text = textObj.queryText()
-                except:
-                    pass
-                else:
-                    if text.getNSelections():
-                        text.removeSelection(0)
-
-    def sayAll(self, inputEvent):
-        """Speak all the text associated with the text object that has
-           focus. We have to define our own method here because Evolution
-           does not implement the FLOWS_TO relationship and all the text
-           are in an HTML panel which contains multiple panels, each
-           containing a single text object.
-
-        Arguments:
-        - inputEvent: if not None, the input event that caused this action.
-        """
-
-        debug.println(self.debugLevel, "evolution.sayAll.")
-        try:
-            if orca_state.locusOfFocus and orca_state.locusOfFocus.queryText():
-                speech.sayAll(self.textLines(orca_state.locusOfFocus),
-                              self.__sayAllProgressCallback)
-        except:
-            default.Script.sayAll(self, inputEvent)
-
-        return True
diff --git a/src/orca/scripts/apps/evolution/script_utilities.py 
b/src/orca/scripts/apps/evolution/script_utilities.py
index 00b9f01..5ddedae 100644
--- a/src/orca/scripts/apps/evolution/script_utilities.py
+++ b/src/orca/scripts/apps/evolution/script_utilities.py
@@ -32,6 +32,7 @@ import pyatspi
 
 import orca.debug as debug
 import orca.script_utilities as script_utilities
+import orca.scripts.toolkits.WebKitGtk as WebKitGtk
 import orca.settings as settings
 
 #############################################################################
@@ -40,7 +41,7 @@ import orca.settings as settings
 #                                                                           #
 #############################################################################
 
-class Utilities(script_utilities.Utilities):
+class Utilities(WebKitGtk.Utilities):
 
     def __init__(self, script):
         """Creates an instance of the Utilities class.
@@ -49,7 +50,7 @@ class Utilities(script_utilities.Utilities):
         - script: the script with which this instance is associated.
         """
 
-        script_utilities.Utilities.__init__(self, script)
+        WebKitGtk.Utilities.__init__(self, script)
 
     #########################################################################
     #                                                                       #
diff --git a/src/orca/scripts/apps/evolution/speech_generator.py 
b/src/orca/scripts/apps/evolution/speech_generator.py
index 30cc273..24daf73 100644
--- a/src/orca/scripts/apps/evolution/speech_generator.py
+++ b/src/orca/scripts/apps/evolution/speech_generator.py
@@ -27,13 +27,14 @@ __license__   = "LGPL"
 
 import pyatspi
 
+import orca.scripts.toolkits.WebKitGtk as WebKitGtk
 import orca.settings_manager as settings_manager
 import orca.speech_generator as speech_generator
 from orca.orca_i18n import _
 
 _settingsManager = settings_manager.getManager()
 
-class SpeechGenerator(speech_generator.SpeechGenerator):
+class SpeechGenerator(WebKitGtk.SpeechGenerator):
     """Overrides _generateSpeechForTableCell so that, if this is an
        expanded table cell, we can strip off the "0 items".
     """
@@ -41,7 +42,7 @@ class SpeechGenerator(speech_generator.SpeechGenerator):
     # pylint: disable-msg=W0142
 
     def __init__(self, script):
-        speech_generator.SpeechGenerator.__init__(self, script)
+        WebKitGtk.SpeechGenerator.__init__(self, script)
 
     def _generateRealTableCell(self, obj, **args):
         # Check that we are in a table cell in the mail message header list.
diff --git a/src/orca/scripts/toolkits/WebKitGtk/__init__.py b/src/orca/scripts/toolkits/WebKitGtk/__init__.py
index 585c964..a2b1964 100644
--- a/src/orca/scripts/toolkits/WebKitGtk/__init__.py
+++ b/src/orca/scripts/toolkits/WebKitGtk/__init__.py
@@ -1 +1,4 @@
 from .script import Script
+from .speech_generator import SpeechGenerator
+from .braille_generator import BrailleGenerator
+from .script_utilities import Utilities


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