orca r4310 - in trunk: . src/orca src/orca/scripts/toolkits/Gecko
- From: joanied svn gnome org
- To: svn-commits-list gnome org
- Subject: orca r4310 - in trunk: . src/orca src/orca/scripts/toolkits/Gecko
- Date: Thu, 30 Oct 2008 05:04:30 +0000 (UTC)
Author: joanied
Date: Thu Oct 30 05:04:30 2008
New Revision: 4310
URL: http://svn.gnome.org/viewvc/orca?rev=4310&view=rev
Log:
* src/orca/scripts/toolkits/Gecko/script.py:
src/orca/app_gui_prefs.py:
src/orca/default.py:
src/orca/text_attribute_names.py:
src/orca/orca_gui_prefs.py:
Fix for bug #434780 - Orca does not provide access to text
attributes in Firefox.
Modified:
trunk/ChangeLog
trunk/src/orca/app_gui_prefs.py
trunk/src/orca/default.py
trunk/src/orca/orca_gui_prefs.py
trunk/src/orca/scripts/toolkits/Gecko/script.py
trunk/src/orca/text_attribute_names.py
Modified: trunk/src/orca/app_gui_prefs.py
==============================================================================
--- trunk/src/orca/app_gui_prefs.py (original)
+++ trunk/src/orca/app_gui_prefs.py Thu Oct 30 05:04:30 2008
@@ -135,6 +135,21 @@
ftp = focus_tracking_presenter.FocusTrackingPresenter()
ftp.loadAppSettings(self.appScript)
+ def _getAppNameForAttribute(self, attributeName):
+ """Converts the given Atk attribute name into the application's
+ equivalent. This is necessary because an application or toolkit
+ (e.g. Gecko) might invent entirely new names for the same text
+ attributes.
+
+ Arguments:
+ - attribName: The name of the text attribute
+
+ Returns the application's equivalent name if found or attribName
+ otherwise.
+ """
+
+ return self.appScript.getAppNameForAttribute(attributeName)
+
def _markModified(self):
""" Mark as modified the user application specific custom key bindings:
"""
Modified: trunk/src/orca/default.py
==============================================================================
--- trunk/src/orca/default.py (original)
+++ trunk/src/orca/default.py Thu Oct 30 05:04:30 2008
@@ -114,6 +114,11 @@
self.lastSelectedMenu = None
+ # A dictionary of non-standardly-named text attributes and their
+ # Atk equivalents.
+ #
+ self.attributeNamesDict = {}
+
def setupInputEventHandlers(self):
"""Defines InputEventHandler fields for this script that can be
called by the key and braille bindings."""
@@ -4279,6 +4284,38 @@
return True
+ def getAtkNameForAttribute(self, attribName):
+ """Converts the given attribute name into the Atk equivalent. This
+ is necessary because an application or toolkit (e.g. Gecko) might
+ invent entirely new names for the same attributes.
+
+ Arguments:
+ - attribName: The name of the text attribute
+
+ Returns the Atk equivalent name if found or attribName otherwise.
+ """
+
+ return self.attributeNamesDict.get(attribName, attribName)
+
+ def getAppNameForAttribute(self, attribName):
+ """Converts the given Atk attribute name into the application's
+ equivalent. This is necessary because an application or toolkit
+ (e.g. Gecko) might invent entirely new names for the same text
+ attributes.
+
+ Arguments:
+ - attribName: The name of the text attribute
+
+ Returns the application's equivalent name if found or attribName
+ otherwise.
+ """
+
+ for key, value in self.attributeNamesDict.items():
+ if value == attribName:
+ return key
+
+ return attribName
+
def textAttrsToDictionary(self, tokenString):
"""Converts a string of text attribute tokens of the form
<key>:<value>; into a dictionary of keys and values.
@@ -4316,18 +4353,21 @@
for key in keys:
localizedKey = text_attribute_names.getTextAttributeName(key)
if key in attributes:
+ line = ""
attribute = attributes[key]
localizedValue = \
text_attribute_names.getTextAttributeName(attribute)
if attribute:
+ key = self.getAtkNameForAttribute(key)
# If it's the 'weight' attribute and greater than 400, just
# speak it as bold, otherwise speak the weight.
#
- if key == "weight" and int(attribute) > 400:
+ if key == "weight" \
+ and (attribute == "bold" or int(attribute) > 400):
# Translators: bold as in the font sense.
#
line = _("bold")
- elif key == "left-margin" or key == "right-margin":
+ elif key in ["left-margin", "right-margin"]:
# We need to test if we are getting a margin value
# that includes unit information (OOo now provides
# this). If not, then we will assume it's pixels.
@@ -4347,10 +4387,19 @@
"%s %s pixels",
int(attribute)) % \
(localizedKey, localizedValue)
- else:
- line = localizedKey + " " + localizedValue
- else:
- line = localizedKey + " " + localizedValue
+ elif key in ["indent", "size"]:
+ # In Gecko, we seem to get these values as a number
+ # immediately followed by "px". But we'll hedge our
+ # bet.
+ #
+ value = attribute.split("px")
+ if len(value) > 1:
+ line = ngettext("%s %s pixel",
+ "%s %s pixels",
+ float(value[0])) % \
+ (localizedKey, value[0])
+
+ line = line or (localizedKey + " " + localizedValue)
speech.speak(line)
def readCharAttributes(self, inputEvent=None):
@@ -7528,7 +7577,7 @@
try:
return dict(
map(lambda pair: pair.strip().split(':'),
- dict_string.strip(';').split(';')))
+ dict_string.strip('; ').split(';')))
except ValueError:
return {}
Modified: trunk/src/orca/orca_gui_prefs.py
==============================================================================
--- trunk/src/orca/orca_gui_prefs.py (original)
+++ trunk/src/orca/orca_gui_prefs.py Thu Oct 30 05:04:30 2008
@@ -960,6 +960,21 @@
view.set_model(model)
+ def _getAppNameForAttribute(self, attributeName):
+ """Converts the given Atk attribute name into the application's
+ equivalent. This is necessary because an application or toolkit
+ (e.g. Gecko) might invent entirely new names for the same text
+ attributes.
+
+ Arguments:
+ - attribName: The name of the text attribute
+
+ Returns the application's equivalent name if found or attribName
+ otherwise.
+ """
+
+ return attributeName
+
def _updateTextDictEntry(self):
"""The user has updated the text attribute list in some way. Update
the "enabledSpokenTextAttributes" and "enabledBrailledTextAttributes"
@@ -974,6 +989,12 @@
for path in range(0, noRows):
localizedKey = model[path][NAME]
key = text_attribute_names.getTextAttributeKey(localizedKey)
+
+ # Convert the normalized, Atk attribute name back into what
+ # the app/toolkit uses.
+ #
+ key = self._getAppNameForAttribute(key)
+
localizedValue = model[path][VALUE]
value = text_attribute_names.getTextAttributeKey(localizedValue)
Modified: trunk/src/orca/scripts/toolkits/Gecko/script.py
==============================================================================
--- trunk/src/orca/scripts/toolkits/Gecko/script.py (original)
+++ trunk/src/orca/scripts/toolkits/Gecko/script.py Thu Oct 30 05:04:30 2008
@@ -198,6 +198,93 @@
#
self._currentFrame = None
+ # All of the text attributes available for presentation to the
+ # user. This is necessary because the attributes used by Gecko
+ # are different from the default set.
+ #
+ self.allTextAttributes = \
+ "background-color:; color:; font-family:; font-size:; " \
+ "font-style:normal; font-weight:400; language:none; " \
+ "text-line-through-style:; text-align:start; text-indent:0px; " \
+ "text-underline-style:; text-position:baseline; " \
+ "invalid:none; writing-mode:lr;"
+
+ # The default set of text attributes to present to the user. This
+ # is necessary because the attributes used by Gecko are different
+ # from the default set.
+ #
+ self.enabledBrailledTextAttributes = \
+ "font-size:; font-family:; font-weight:400; text-indent:0px; " \
+ "text-underline-style:none; text-align:start; " \
+ "text-line-through-style:none; font-style:normal; invalid:none;"
+ self.enabledSpokenTextAttributes = \
+ "font-size:; font-family:; font-weight:400; text-indent:0px; " \
+ "text-underline-style:none; text-align:start; " \
+ "text-line-through-style:none; font-style:normal; invalid:none;"
+
+ # A dictionary of Gecko-style attribute names and their equivalent/
+ # expected names. This is necessary so that we can present the
+ # attributes to the user in a consistent fashion across apps and
+ # toolkits. Note that underlinesolid and line-throughsolid are
+ # temporary fixes: text_attribute_names.py assumes a one-to-one
+ # correspondence. This is not a problem when going from attribute
+ # name to localized name; in the reverse direction, we need more
+ # context (i.e. we can't safely make them both be "solid"). A
+ # similar issue exists with "start" which means no justification
+ # has explicitly been set. If we set that to "none", "none" will
+ # no longer have a single reverse translation.
+ #
+ self.attributeNamesDict = {
+ "font-weight" : "weight",
+ "font-family" : "family-name",
+ "font-style" : "style",
+ "text-align" : "justification",
+ "text-indent" : "indent",
+ "font-size" : "size",
+ "background-color" : "bg-color",
+ "color" : "fg-color",
+ "text-line-through-style" : "strikethrough",
+ "text-underline-style" : "underline",
+ "text-position" : "vertical-align",
+ "writing-mode" : "direction",
+ "-moz-left" : "left",
+ "-moz-right" : "right",
+ "-moz-center" : "center",
+ "start" : "no justification",
+ "underlinesolid" : "single",
+ "line-throughsolid" : "solid"}
+
+ # We need to save our special attributes so that we can revert to
+ # the default text attributes when giving up focus to another app
+ # and restore them upon return.
+ #
+ self.savedEnabledBrailledTextAttributes = None
+ self.savedEnabledSpokenTextAttributes = None
+ self.savedAllTextAttributes = None
+
+ def activate(self):
+ """Called when this script is activated."""
+ self.savedEnabledBrailledTextAttributes = \
+ settings.enabledBrailledTextAttributes
+ settings.enabledBrailledTextAttributes = \
+ self.enabledBrailledTextAttributes
+
+ self.savedEnabledSpokenTextAttributes = \
+ settings.enabledSpokenTextAttributes
+ settings.enabledSpokenTextAttributes = \
+ self.enabledSpokenTextAttributes
+
+ self.savedAllTextAttributes = settings.allTextAttributes
+ settings.allTextAttributes = self.allTextAttributes
+
+ def deactivate(self):
+ """Called when this script is deactivated."""
+ settings.enabledBrailledTextAttributes = \
+ self.savedEnabledBrailledTextAttributes
+ settings.enabledSpokenTextAttributes = \
+ self.savedEnabledSpokenTextAttributes
+ settings.allTextAttributes = self.savedAllTextAttributes
+
def getWhereAmI(self):
"""Returns the "where am I" class for this script.
"""
Modified: trunk/src/orca/text_attribute_names.py
==============================================================================
--- trunk/src/orca/text_attribute_names.py (original)
+++ trunk/src/orca/text_attribute_names.py Thu Oct 30 05:04:30 2008
@@ -27,6 +27,7 @@
__license__ = "LGPL"
from orca_i18n import Q_ # to provide qualified translatable strings
+import orca_state
# Translators: this is a structure to assist in the generation of
# localized strings for the various text attributes.
@@ -145,6 +146,14 @@
#
_textAttributeTable["indent"] = Q_("textattr|indent")
+# Translators: this attribute specifies there is something "wrong" with
+# the text, such as it being a misspelled word. See:
+# https://developer.mozilla.org/en/Accessibility/AT-APIs/Gecko/TextAttrs
+#
+# ONLY TRANSLATE THE PART AFTER THE PIPE CHARACTER |
+#
+_textAttributeTable["invalid"] = Q_("textattr|invalid")
+
# Translators: this attribute specifies whether the text is invisible.
# It will be a "true" or "false" value.
# See
@@ -571,6 +580,14 @@
_textAttributeTable["center"] = Q_("textattr|center")
# Translators: this is one of the text attribute values for the following
+# text attributes: "justification". In Gecko, when no justification has
+# be explicitly set, they report a justification of "start".
+#
+# ONLY TRANSLATE THE PART AFTER THE PIPE CHARACTER |
+#
+_textAttributeTable["start"] = Q_("textattr|no justification")
+
+# Translators: this is one of the text attribute values for the following
# text attributes: "justification".
# See:
# http://library.gnome.org/devel/atk/1.22/AtkText.html#AtkTextAttribute
@@ -878,6 +895,21 @@
#
_textAttributeTable["tb"] = Q_("textattr|tb")
+# Translators: this is one of the text attribute values for the following
+# text attributes: "strikethrough." It refers to the line style.
+#
+# ONLY TRANSLATE THE PART AFTER THE PIPE CHARACTER |
+#
+_textAttributeTable["solid"] = Q_("textattr|solid")
+
+# Translators: this is one of the text attribute values for the following
+# text attributes: "invalid". It is an indication that the text is not
+# spelled correctly. See:
+# https://developer.mozilla.org/en/Accessibility/AT-APIs/Gecko/TextAttrs
+#
+# ONLY TRANSLATE THE PART AFTER THE PIPE CHARACTER |
+#
+_textAttributeTable["spelling"] = Q_("textattr|spelling")
def getTextAttributeKey(localizedTextAttr):
"""Given a localized text attribute, return the original text
@@ -912,6 +944,11 @@
if isinstance(textAttr, unicode):
textAttr = textAttr.encode("UTF-8")
+ # Normalize the name to an Atk name before attempting to look it up.
+ #
+ if orca_state.activeScript:
+ textAttr = orca_state.activeScript.getAtkNameForAttribute(textAttr)
+
try:
return _textAttributeTable[textAttr]
except:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]