[orca] Eliminate some unneeded access to the active script



commit 35aad09f96277dc5c1437528b1c33c0db2b29752
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Fri Jun 6 08:42:01 2014 -0400

    Eliminate some unneeded access to the active script

 src/orca/flat_review.py           |    2 +-
 src/orca/notification_messages.py |   59 ++++++++++++++++++-------------------
 src/orca/orca.py                  |    2 +-
 src/orca/orca_gui_commandlist.py  |    2 -
 src/orca/orca_gui_prefs.py        |   22 ++++++-------
 src/orca/scripts/default.py       |    6 ++--
 src/orca/speech_generator.py      |    7 ++--
 src/orca/text_attribute_names.py  |    7 ++--
 8 files changed, 51 insertions(+), 56 deletions(-)
---
diff --git a/src/orca/flat_review.py b/src/orca/flat_review.py
index a1ae3e1..b405363 100644
--- a/src/orca/flat_review.py
+++ b/src/orca/flat_review.py
@@ -616,7 +616,7 @@ class Context:
             role = None
 
         if role == pyatspi.ROLE_TABLE_CELL:
-            searchZone = orca_state.activeScript.\
+            searchZone = self.script.\
                 utilities.realActiveDescendant(orca_state.locusOfFocus)
         else:
             searchZone = orca_state.locusOfFocus
diff --git a/src/orca/notification_messages.py b/src/orca/notification_messages.py
index 57ee1cd..c72e1ca 100644
--- a/src/orca/notification_messages.py
+++ b/src/orca/notification_messages.py
@@ -31,7 +31,6 @@ from . import cmdnames
 from . import debug
 from . import input_event
 from . import messages
-from . import orca_state
 
 # to store  the messages generated by the notification daemon
 notificationMessages = []
@@ -52,22 +51,22 @@ invalidKeys = 0
 # input event handlers
 inputEventHandlers = {}
 
-def repeatLastNotificationMessage(script=None, inputEvent=None):
+def repeatLastNotificationMessage(script, inputEvent=None):
     """ Repeats the last notification message. """
 
-    _showNotificationMessage(1)
+    _showNotificationMessage(script, 1)
     return True
 
-def repeatPreviousNotificationMessage(script=None, inputEvent=None):
+def repeatPreviousNotificationMessage(script, inputEvent=None):
     """ Repeats the previous notification message. """
 
-    _showNotificationMessage(2)
+    _showNotificationMessage(script, 2)
     return True
 
-def enableNotificationMessageListMode(script=None, inputEvent=None):
+def enableNotificationMessageListMode(script, inputEvent=None):
     """ Enables the list of notification message. """
 
-    _listModeEnable()
+    _listModeEnable(script)
     return True
 
 inputEventHandlers["repeatLastNotificationMessageHandler"] = \
@@ -85,8 +84,8 @@ inputEventHandlers["enableNotificationMessageListModeHandler"] = \
             enableNotificationMessageListMode,
             cmdnames.NOTIFICATION_MESSAGES_LIST)
 
-def _showMessage(msg):
-    orca_state.activeScript.presentMessage(msg)
+def _showMessage(script, msg):
+    script.presentMessage(msg)
 
 def saveMessage(msg):
     """save the message in a list to be presented later"""
@@ -105,40 +104,40 @@ def size():
 
     return len(notificationMessages)
 
-def _messagesPresent():
+def _messagesPresent(script):
 
     if size() <= 0:
-        _showMessage(messages.NOTIFICATION_NO_MESSAGES)
+        _showMessage(script, messages.NOTIFICATION_NO_MESSAGES)
         return False
 
     return True
 
-def _listModeEnable():
+def _listModeEnable(script):
     """ enable the list mode if the queue is not empty """
 
     global indexNotificationMessages
     global listNotificationMessagesModeEnabled
     global invalidKeys
-    if _messagesPresent():
+    if _messagesPresent(script):
         indexNotificationMessages = 1
         invalidKeys = 0
         listNotificationMessagesModeEnabled = True
-        _help(True)
-        _showNotificationMessage(indexNotificationMessages)
+        _help(script, True)
+        _showNotificationMessage(script, indexNotificationMessages)
 
     return True
 
-def _showNotificationMessage(index):
+def _showNotificationMessage(script, index):
     global indexNotificationMessages
-    if not _messagesPresent():
+    if not _messagesPresent(script):
         return
 
     if index < 1:
         index = 1
-        _showMessage(messages.NOTIFICATION_LIST_TOP)
+        _showMessage(script, messages.NOTIFICATION_LIST_TOP)
     elif index > size():
         index = size()
-        _showMessage(messages.NOTIFICATION_LIST_BOTTOM)
+        _showMessage(script, messages.NOTIFICATION_LIST_BOTTOM)
 
     indexNotificationMessages = index
     index = size() - index
@@ -147,16 +146,16 @@ def _showNotificationMessage(index):
                    % (size(), index))
     if index >= 0 and index < size():
         msg = notificationMessages[index]
-        _showMessage(msg)
+        _showMessage(script, msg)
 
-def exitListNotificationMessagesMode():
+def exitListNotificationMessagesMode(script):
     """ Turns list notification messages mode off. """
 
     global listNotificationMessagesModeEnabled
     listNotificationMessagesModeEnabled = False
-    _showMessage(messages.NOTIFICATION_LIST_EXIT)
+    _showMessage(script, messages.NOTIFICATION_LIST_EXIT)
 
-def listNotificationMessages(event):
+def listNotificationMessages(script, event):
     """ When list notification messages  mode is enabled, this function
     provides a means by which users can navigate through the list the
     notification messages. User can use the navigation keys or press
@@ -170,9 +169,9 @@ def listNotificationMessages(event):
 
     if event.type != pyatspi.KEY_PRESSED_EVENT:
         return False
-    orca_state.activeScript.presentationInterrupt()
+    script.presentationInterrupt()
     if event.event_string == "Escape":
-        exitListNotificationMessagesMode()
+        exitListNotificationMessagesMode(script)
         speak = False
     elif event.event_string == "Home":
         indexNotificationMessages = 1
@@ -186,7 +185,7 @@ def listNotificationMessages(event):
                    [ '1', '2', '3', '4', '5', '6', '7', '8', '9' ]:
         indexNotificationMessages = int(event.event_string)
     elif event.event_string in [ 'h', 'H']:
-        _help(True)
+        _help(script, True)
         speak = False
     elif event.event_string == "space":
         pass
@@ -194,19 +193,19 @@ def listNotificationMessages(event):
         speak = False
         invalidKeys += 1
         if invalidKeys > 2:
-            _help()
+            _help(script)
             invalidKeys = 0
 
     if speak:
-        _showNotificationMessage(indexNotificationMessages)
+        _showNotificationMessage(script, indexNotificationMessages)
         invalidKeys = 0
 
     return consumed
 
-def _help(longHelp = False):
+def _help(script, longHelp = False):
     msg = messages.messagesCount(size())
     msg += messages.NOTIFICATION_LIST_HELP
     if longHelp:
         msg += messages.NOTIFICATION_LIST_TUTORIAL
 
-    _showMessage(msg)
+    _showMessage(script, msg)
diff --git a/src/orca/orca.py b/src/orca/orca.py
index f6b4781..f48280e 100644
--- a/src/orca/orca.py
+++ b/src/orca/orca.py
@@ -267,7 +267,7 @@ def _processKeyboardEvent(event):
     if orca_state.capturingKeys:
         return False
     if notification_messages.listNotificationMessagesModeEnabled:
-        return notification_messages.listNotificationMessages(keyboardEvent)
+        return notification_messages.listNotificationMessages(script, keyboardEvent)
 
     # See if the event manager wants it (i.e. it is bound to a command.
     if _eventManager.processKeyboardEvent(keyboardEvent):
diff --git a/src/orca/orca_gui_commandlist.py b/src/orca/orca_gui_commandlist.py
index 51b31c4..3032de9 100644
--- a/src/orca/orca_gui_commandlist.py
+++ b/src/orca/orca_gui_commandlist.py
@@ -34,8 +34,6 @@ from . import orca_state
 class OrcaCommandListGUI:
 
     def __init__(self, title, columnHeaders, rows, canPerformCommands):
-        self._focusedObject = orca_state.locusOfFocus
-        self._activeScript = orca_state.activeScript
         self._tree = None
         self._okButton = None
         self._gui = self._createCommandListDialog(columnHeaders, rows)
diff --git a/src/orca/orca_gui_prefs.py b/src/orca/orca_gui_prefs.py
index 443f8de..322ee2e 100644
--- a/src/orca/orca_gui_prefs.py
+++ b/src/orca/orca_gui_prefs.py
@@ -873,11 +873,10 @@ class OrcaSetupGUI(orca_gtkbuilder.GtkBuilderWrapper):
 
         for i in range(0, len(attrList)):
             for path in range(0, len(allAttrList)):
-                localizedKey = \
-                        text_attribute_names.getTextAttributeName(attrList[i])
-                localizedValue = \
-                        text_attribute_names.getTextAttributeName( \
-                                                        attrDict[attrList[i]])
+                localizedKey = text_attribute_names.getTextAttributeName(
+                    attrList[i], self.script)
+                localizedValue = text_attribute_names.getTextAttributeName(
+                    attrDict[attrList[i]], self.script)
                 if localizedKey == model[path][NAME]:
                     thisIter = model.get_iter(path)
                     model.set_value(thisIter, NAME, localizedKey)
@@ -911,8 +910,8 @@ class OrcaSetupGUI(orca_gtkbuilder.GtkBuilderWrapper):
 
         for i in range(0, len(attrList)):
             for path in range(0, len(allAttrList)):
-                localizedKey = \
-                        text_attribute_names.getTextAttributeName(attrList[i])
+                localizedKey = text_attribute_names.getTextAttributeName(
+                    attrList[i], self.script)
                 if localizedKey == model[path][NAME]:
                     thisIter = model.get_iter(path)
                     model.set_value(thisIter, IS_BRAILLED, state)
@@ -1067,11 +1066,10 @@ class OrcaSetupGUI(orca_gtkbuilder.GtkBuilderWrapper):
             _settingsManager.getSetting('allTextAttributes'))
         for i in range(0, len(allAttrList)):
             thisIter = model.append()
-            localizedKey = \
-                text_attribute_names.getTextAttributeName(allAttrList[i])
-            localizedValue = \
-                text_attribute_names.getTextAttributeName( \
-                                             allAttrDict[allAttrList[i]])
+            localizedKey = text_attribute_names.getTextAttributeName(
+                allAttrList[i], self.script)
+            localizedValue = text_attribute_names.getTextAttributeName(
+                allAttrDict[allAttrList[i]], self.script)
             model.set_value(thisIter, NAME, localizedKey)
             model.set_value(thisIter, IS_SPOKEN, False)
             model.set_value(thisIter, IS_BRAILLED, False)
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index 8a80bfd..ea2ada4 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -2079,7 +2079,7 @@ class Script(script.Script):
         debug.debugLevel = levels[levelIndex]
         briefMessage = levels[levelIndex + 1]
         fullMessage =  "Debug level %s." % briefMessage
-        orca_state.activeScript.presentMessage(fullMessage, briefMessage)
+        self.presentMessage(fullMessage, briefMessage)
 
         return True
 
@@ -3298,12 +3298,12 @@ class Script(script.Script):
         """
 
         for key in keys:
-            localizedKey = text_attribute_names.getTextAttributeName(key)
+            localizedKey = text_attribute_names.getTextAttributeName(key, self)
             if key in attributes:
                 line = ""
                 attribute = attributes[key]
                 localizedValue = \
-                    text_attribute_names.getTextAttributeName(attribute)
+                    text_attribute_names.getTextAttributeName(attribute, self)
                 if attribute:
                     key = self.getAtkNameForAttribute(key)
                     # If it's the 'weight' attribute and greater than 400, just
diff --git a/src/orca/speech_generator.py b/src/orca/speech_generator.py
index 01d29ca..a72c314 100644
--- a/src/orca/speech_generator.py
+++ b/src/orca/speech_generator.py
@@ -948,11 +948,12 @@ class SpeechGenerator(generator.Generator):
 
         if attributesDictionary:
             for key in keys:
-                localizedKey = text_attribute_names.getTextAttributeName(key)
+                localizedKey = text_attribute_names.getTextAttributeName(
+                    key, self._script)
                 if key in attributesDictionary:
                     attribute = attributesDictionary[key]
-                    localizedValue = \
-                        text_attribute_names.getTextAttributeName(attribute)
+                    localizedValue = text_attribute_names.getTextAttributeName(
+                        attribute, self._script)
                     if attribute:
                         # If it's the 'weight' attribute and greater than 400,
                         # just speak it as bold, otherwise speak the weight.
diff --git a/src/orca/text_attribute_names.py b/src/orca/text_attribute_names.py
index b7d0336..c488a35 100644
--- a/src/orca/text_attribute_names.py
+++ b/src/orca/text_attribute_names.py
@@ -27,7 +27,6 @@ __copyright__ = "Copyright (c) 2008 Sun Microsystems Inc."
 __license__   = "LGPL"
 
 from .orca_i18n import C_
-from . import orca_state
 
 # Translators: this is a structure to assist in the generation of
 # localized strings for the various text attributes. 
@@ -761,7 +760,7 @@ def getTextAttributeKey(localizedTextAttr):
 
     return localizedTextAttr
 
-def getTextAttributeName(textAttr):
+def getTextAttributeName(textAttr, script=None):
     """Given a text attribute, returns its localized equivalent.
 
     Arguments:
@@ -773,7 +772,7 @@ def getTextAttributeName(textAttr):
 
     # Normalize the name to an Atk name before attempting to look it up.
     #
-    if orca_state.activeScript:
-        textAttr = orca_state.activeScript.getAtkNameForAttribute(textAttr)
+    if script:
+        textAttr = script.getAtkNameForAttribute(textAttr)
 
     return _textAttributeTable.get(textAttr, textAttr)


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