[orca] Move caching from speech_generator to the script
- From: William Walker <wwalker src gnome org>
- To: svn-commits-list gnome org
- Subject: [orca] Move caching from speech_generator to the script
- Date: Fri, 12 Jun 2009 09:53:59 -0400 (EDT)
commit bf8fb938a2f2f2d02f73862d34878390622a2437
Author: Willie Walker <william walker sun com>
Date: Fri Jun 12 09:48:59 2009 -0400
Move caching from speech_generator to the script
This allows us to share computed information between the speech
and braille generators
src/orca/script.py | 5 +++++
src/orca/speech_generator.py | 36 +++++++++++++++++-------------------
2 files changed, 22 insertions(+), 19 deletions(-)
---
diff --git a/src/orca/script.py b/src/orca/script.py
index 6b67418..458e869 100644
--- a/src/orca/script.py
+++ b/src/orca/script.py
@@ -90,6 +90,7 @@ class Script:
self.formatting = self.getFormatting()
self.brailleGenerator = self.getBrailleGenerator()
self.speechGenerator = self.getSpeechGenerator()
+ self.generatorCache = {}
self.whereAmI = self.getWhereAmI()
self.bookmarks = self.getBookmarks()
self.voices = settings.voices
@@ -340,6 +341,10 @@ class Script:
if not processEvent:
return
+ # Clear the generator cache for each event.
+ #
+ self.generatorCache = {}
+
# This calls the first listener it finds whose key *begins with* or is
# the same as the event.type. The reason we do this is that the event
# type in the listeners dictionary may not be as specific as the event
diff --git a/src/orca/speech_generator.py b/src/orca/speech_generator.py
index 3ffedd4..15a843c 100644
--- a/src/orca/speech_generator.py
+++ b/src/orca/speech_generator.py
@@ -1257,21 +1257,24 @@ class SpeechGenerator:
return attribStr
- def _generateTextInformation(self, obj, **args):
- """Returns an empty array, but sets up a 'textInformation' attribute
- in self._valueCache for other methods to use. The information
- is either:
+ def _getTextInformation(self, obj):
+ """Returns [textContents, startOffset, endOffset, selected] as
+ follows:
A. if no text on the current line is selected, the current line
B. if text is selected, the selected text
C. if the current line is blank/empty, 'blank'
- For all the above, we'll get a 'textInformation' entry in
- self._valueCache that is the following list:
-
- [textContents, startOffset, endOffset, selected]
+ Also sets up a 'textInformation' attribute in
+ self._script.generatorCache to prevent computing this
+ information repeatedly while processing a single event.
"""
+ try:
+ return self._script.generatorCache['textInformation']
+ except:
+ pass
+
textObj = obj.queryText()
caretOffset = textObj.caretOffset
textContents = ""
@@ -1303,10 +1306,10 @@ class SpeechGenerator:
#
textContents = (_("blank"))
- self._valueCache['textInformation'] = \
+ self._script.generatorCache['textInformation'] = \
[textContents, startOffset, endOffset, selected]
- return []
+ return self._script.generatorCache['textInformation']
def _generateTextContent(self, obj, **args):
"""Returns an array of strings (and possibly voice and audio
@@ -1318,10 +1321,9 @@ class SpeechGenerator:
except NotImplementedError:
return []
- if not self._valueCache.has_key('textInformation'):
- self._generateTextInformation(obj, **args)
[line, startOffset, endOffset, selected] = \
- self._valueCache['textInformation']
+ self._getTextInformation(obj)
+
# The empty string seems to be messing with using 'or' in
# formatting strings.
#
@@ -1341,10 +1343,8 @@ class SpeechGenerator:
except NotImplementedError:
return []
- if not self._valueCache.has_key('textInformation'):
- self._generateTextInformation(obj, **args)
[line, startOffset, endOffset, selected] = \
- self._valueCache['textInformation']
+ self._getTextInformation(obj)
newLine = ""
lastAttribs = None
@@ -1398,10 +1398,8 @@ class SpeechGenerator:
"""
result = []
- if not self._valueCache.has_key('textInformation'):
- self._generateTextInformation(obj, **args)
[line, startOffset, endOffset, selected] = \
- self._valueCache['textInformation']
+ self._getTextInformation(obj)
if selected:
# Translators: when the user selects (highlights) text in
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]