[orca] Small cleanup of Rui's fix for bgo#431531 for unicode characters



commit 02465d1452cd89b4017f09ae31858b58f0491964
Author: Willie Walker <william walker sun com>
Date:   Wed Jan 20 09:14:10 2010 -0500

    Small cleanup of Rui's fix for bgo#431531 for unicode characters

 src/orca/default.py |   55 +++++++++++++++++++++++++++++---------------------
 1 files changed, 32 insertions(+), 23 deletions(-)
---
diff --git a/src/orca/default.py b/src/orca/default.py
index 4909140..f68ac7c 100644
--- a/src/orca/default.py
+++ b/src/orca/default.py
@@ -601,9 +601,9 @@ class Script(script.Script):
                 #
                 _("Phonetically speaks the current flat review character."))
 
-        self.inputEventHandlers["reviewUnicodeInformationCurrentCharacterHandler"] = \
+        self.inputEventHandlers["reviewUnicodeCurrentCharacterHandler"] = \
             input_event.InputEventHandler(
-                Script.reviewUnicodeInformationCurrentCharacter,
+                Script.reviewUnicodeCurrentCharacter,
                 # Translators: the 'flat review' feature of Orca
                 # allows the blind user to explore the text in a
                 # window in a 2D fashion.  That is, Orca treats all
@@ -616,7 +616,7 @@ class Script(script.Script):
                 # wrap across lines if necessary).  This command will
                 # cause Orca to speak information about the current character
                 # Like its unicode value and other relevant information
-                _("Speaks some extra information about the current flat review character."))
+                _("Speaks unicode value of the current flat review character."))
 
 
         self.inputEventHandlers["reviewNextCharacterHandler"] = \
@@ -1466,7 +1466,7 @@ class Script(script.Script):
                 "KP_2",
                 settings.defaultModifierMask,
                 settings.NO_MODIFIER_MASK,
-                self.inputEventHandlers["reviewUnicodeInformationCurrentCharacterHandler"],
+                self.inputEventHandlers["reviewUnicodeCurrentCharacterHandler"],
                 3))
 
 
@@ -1491,7 +1491,8 @@ class Script(script.Script):
                 "KP_Down",
                 settings.defaultModifierMask,
                 settings.NO_MODIFIER_MASK,
-                self.inputEventHandlers["reviewUnicodeInformationCurrentCharacterHandler"],
+                self.inputEventHandlers[
+                    "reviewUnicodeCurrentCharacterHandler"],
                 3))
 
         keyBindings.add(
@@ -5624,9 +5625,9 @@ class Script(script.Script):
 
         return True
 
-    def reviewUnicodeInformationCurrentCharacter(self, inputEvent):
-        """Brailles and speaks unicode information about the current flat review
-        character.
+    def reviewUnicodeCurrentCharacter(self, inputEvent):
+        """Brailles and speaks unicode information about the current flat
+        review character.
         """
 
         self._reviewCurrentCharacter(inputEvent, 3)
@@ -5639,7 +5640,10 @@ class Script(script.Script):
 
         Arguments:
         - inputEvent - the current input event.
-        - speechType - the desired presentation: speak (1), phonetic (2) or unicode value information (3)
+        - speechType - the desired presentation:
+                       speak (1),
+                       phonetic (2)
+                       unicode value information (3)
         """
 
         context = self.getFlatReviewContext()
@@ -5666,7 +5670,7 @@ class Script(script.Script):
                     #
                     speech.speak(_("blank"))
                 elif speechType == 3:
-                    self.speakUnicodeCharacterInformation(charString)
+                    self.speakUnicodeCharacter(charString)
                 elif speechType == 2:
                     self.phoneticSpellCurrentItem(charString)
                 elif charString.decode("UTF-8").isupper():
@@ -5679,30 +5683,35 @@ class Script(script.Script):
 
         return True
 
-    def speakUnicodeCharacterInformation(self, character):
+    def speakUnicodeCharacter(self, character):
         """ Speaks some information about an unicode character.
-        At the Momment it just anounces the character unicode number but this information may be
-        changed in the future
+        At the Momment it just anounces the character unicode number but
+        this information may be changed in the future
         
         Arguments:
         - character: the character to speak information of
         """
-        vars = {"value" : self.getUnicodeValueRepresentation(character)}
-        # Translators: this is information about an unicode character reported to the user.
-        # value is the unicode number value of this character in hex.
-        speech.speak(_("Character %(value)s" % vars))
+        # Translators: this is information about a unicode character
+        # reported to the user.  The value is the unicode number value
+        # of this character in hex.
+        #
+        speech.speak(_("Unicode %s" % self.getUnicodeValueString(character)))
 
-    def getUnicodeValueRepresentation(self, character):
-        """ Returns a four hex dijit representaiton of the given character
+    def getUnicodeValueString(self, character):
+        """ Returns a four hex digit representaiton of the given character
         
         Arguments:
         - The character to return representation
         
-        returns a string representaition of the given character unicode vlue
+        Returns a string representaition of the given character unicode vlue
         """
-        if not isinstance(character, unicode):
-            character = character.decode('UTF-8')
-        return "%04x" % ord(character)
+        try:
+            if not isinstance(character, unicode):
+                character = character.decode('UTF-8')
+            return "%04x" % ord(character)
+        except:
+            debug.printException(debug.LEVEL_WARNING)
+            return ""
 
     def reviewPreviousCharacter(self, inputEvent):
         """Moves the flat review context to the previous character.  Places



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