[orca] Fix for bgo#568696 - locus of focus changes when updating list of files in nautilus



commit 340b3e1a895f514d01273e997e4fbbfd43b99b3f
Author: Willie Walker <william walker sun com>
Date:   Mon Jul 20 12:10:28 2009 -0400

    Fix for bgo#568696 - locus of focus changes when updating list of files in nautilus

 src/orca/focus_tracking_presenter.py |   21 +++++++++---
 src/orca/script.py                   |   23 ++++++++++---
 src/orca/scripts/apps/nautilus.py    |   58 +++++++++++++++++++++++++++-------
 3 files changed, 79 insertions(+), 23 deletions(-)
---
diff --git a/src/orca/focus_tracking_presenter.py b/src/orca/focus_tracking_presenter.py
index d417cc8..c6767a3 100644
--- a/src/orca/focus_tracking_presenter.py
+++ b/src/orca/focus_tracking_presenter.py
@@ -1,6 +1,6 @@
 # Orca
 #
-# Copyright 2004-2008 Sun Microsystems Inc.
+# Copyright 2004-2009 Sun Microsystems Inc.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Library General Public
@@ -22,7 +22,7 @@
 __id__  = "$Id$"
 __version__   = "$Revision$"
 __date__      = "$Date$"
-__copyright__ = "Copyright (c) 2005-2008 Sun Microsystems Inc."
+__copyright__ = "Copyright (c) 2005-2009 Sun Microsystems Inc."
 __license__   = "LGPL"
 
 import gobject
@@ -147,7 +147,7 @@ class FocusTrackingPresenter(presentation_manager.PresentationManager):
         - script: the script.
         """
 
-        if settings.listenAllEvents: 
+        if settings.listenAllEvents:
             # We are always listening to everything.
             return
 
@@ -161,7 +161,7 @@ class FocusTrackingPresenter(presentation_manager.PresentationManager):
         Arguments:
         - script: the script.
         """
-        if settings.listenAllEvents: 
+        if settings.listenAllEvents:
             # We are always listening to everything.
             return
 
@@ -667,6 +667,17 @@ class FocusTrackingPresenter(presentation_manager.PresentationManager):
                                 and (orca_state.activeScript.app \
                                      != event.host_application)
 
+                    # One last check -- let's make sure the new script
+                    # thinks it should become active.
+                    #
+                    if setNewActiveScript:
+                        theScript = \
+                            self.getScript(event.host_application \
+                                           or event.source.getApplication())
+                        setNewActiveScript = theScript.isActivatableEvent(event)
+                        if not reason and setNewActiveScript:
+                            reason = "script requested it"
+
                     if not reason and setNewActiveScript:
                         reason = "object received focus"
 
@@ -785,7 +796,7 @@ class FocusTrackingPresenter(presentation_manager.PresentationManager):
             # If the event doesn't have a source or that source is not marked
             # valid, then we don't care about this event. Just return.
             #
-            
+
             event = e
             if not event.source:
                 debug.println(debug.LEVEL_FINEST,
diff --git a/src/orca/script.py b/src/orca/script.py
index 5bbca01..e7b9c52 100644
--- a/src/orca/script.py
+++ b/src/orca/script.py
@@ -1,6 +1,6 @@
 # Orca
 #
-# Copyright 2004-2008 Sun Microsystems Inc.
+# Copyright 2004-2009 Sun Microsystems Inc.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Library General Public
@@ -36,7 +36,7 @@ instance of the Script subclass.  See default.py for an example."""
 __id__        = "$Id$"
 __version__   = "$Revision$"
 __date__      = "$Date$"
-__copyright__ = "Copyright (c) 2005-2008 Sun Microsystems Inc."
+__copyright__ = "Copyright (c) 2005-2009 Sun Microsystems Inc."
 __license__   = "LGPL"
 
 import braille_generator
@@ -72,7 +72,7 @@ class Script:
             self.name = "default"
 
         self.name += " (module=" + self.__module__ + ")"
-        
+
         self.listeners = self.getListeners()
 
         # By default, handle events for non-active applications.
@@ -225,10 +225,10 @@ class Script:
         """Returns the "where am I" class for this script.
         """
         return where_am_I.WhereAmI(self)
-    
+
     def echoKey(self, keyEvent):
         """Determine whether this script should echo the current key event.
-        Note that the keyEcho() method in orca.py will still take into 
+        Note that the keyEcho() method in orca.py will still take into
         account whatever the user's various preferences for key echoing
         are, which may override what is return by this echoKey() method.
 
@@ -245,7 +245,7 @@ class Script:
         """Returns the "bookmarks" class for this script.
         """
         try:
-            return self.bookmarks 
+            return self.bookmarks
         except AttributeError:
             self.bookmarks = bookmarks.Bookmarks(self)
             return self.bookmarks
@@ -549,6 +549,17 @@ class Script:
         """
         pass
 
+    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
+        the focus tracking manager and it is not guaranteed this
+        request will be honored.  Note that by the time the focus
+        tracking manager calls this method, it thinks the script
+        should become active.  This is an opportunity for the script
+        to say it shouldn't.
+        """
+        return True
+
     def activate(self):
         """Called when this script is activated."""
         pass
diff --git a/src/orca/scripts/apps/nautilus.py b/src/orca/scripts/apps/nautilus.py
index 75da7e2..ad57274 100644
--- a/src/orca/scripts/apps/nautilus.py
+++ b/src/orca/scripts/apps/nautilus.py
@@ -1,6 +1,6 @@
 # Orca
 #
-# Copyright 2006-2008 Sun Microsystems Inc.
+# Copyright 2006-2009 Sun Microsystems Inc.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Library General Public
@@ -22,7 +22,7 @@
 __id__        = "$Id$"
 __version__   = "$Revision$"
 __date__      = "$Date$"
-__copyright__ = "Copyright (c) 2006-2008 Sun Microsystems Inc."
+__copyright__ = "Copyright (c) 2006-2009 Sun Microsystems Inc."
 __license__   = "LGPL"
 
 import pyatspi
@@ -62,14 +62,48 @@ class Script(default.Script):
         #
         self.oldFolderName = None
 
+    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
+        the focus tracking manager and it is not guaranteed this
+        request will be honored.  Note that by the time the focus
+        tracking manager calls this method, it thinks the script
+        should become active.  This is an opportunity for the script
+        to say it shouldn't.
+        """
+
+        # Let's make sure we have an active window if focus on an icon
+        # changes. Focus can change when we don't have an an active
+        # window when someone deletes a file from a shell and nautilus
+        # happens to be showing the directory where that file exists.
+        # See bug #568696.  We'll be specific here so as to avoid
+        # looking at the child states for every single event from
+        # nautilus, which happens to be an event-happy application.
+        #
+        if event and event.type == "focus:" \
+           and event.source.getRole() == pyatspi.ROLE_ICON:
+            shouldActivate = False
+            for child in self.app:
+                if child.getState().contains(pyatspi.STATE_ACTIVE):
+                    shouldActivate = True
+                    break
+        else:
+            shouldActivate = True
+
+        if not shouldActivate:
+            debug.println(debug.LEVEL_FINE,
+                          "%s does not want to become active" % self.name)
+
+        return shouldActivate
+
     def getItemCount(self, frame):
-        """Return a string containing the number of items in the current 
+        """Return a string containing the number of items in the current
         folder.
 
         Arguments:
         - frame: the top-level frame for this Nautilus window.
 
-        Return a string containing the number of items in the current 
+        Return a string containing the number of items in the current
         folder.
         """
 
@@ -84,7 +118,7 @@ class Script(default.Script):
                      pyatspi.ROLE_FRAME, \
                      pyatspi.ROLE_APPLICATION]
 
-        # Look for the scroll pane containing the folder items. If this 
+        # Look for the scroll pane containing the folder items. If this
         # window is showing an icon view, then the child will be a layered
         # pane. If it's showing a list view, then the child will be a table.
         # Create a string of the number of items in the folder.
@@ -127,18 +161,18 @@ class Script(default.Script):
             # Unfortunately we get two of what appear to be idential events
             # when the accessible name of the frame changes. We only want to
             # speak/braille the new folder name if its different then last
-            # time, so, if the Location bar is showing, look to see if the 
-            # same toggle button (with the same name) in the "path view" is 
+            # time, so, if the Location bar is showing, look to see if the
+            # same toggle button (with the same name) in the "path view" is
             # checked. If it isn't, then this is a new folder, so announce it.
             #
             # If the Location bar isn't showing, then just do a comparison of
-            # the new folder name with the old folder name and if they are 
-            # different, announce it. Note that this doesn't do the right 
-            # thing when navigating directory hierarchies such as 
+            # the new folder name with the old folder name and if they are
+            # different, announce it. Note that this doesn't do the right
+            # thing when navigating directory hierarchies such as
             # /path/to/same/same/same.
             #
             allTokens = event.source.name.split(" - ")
-            newFolderName = allTokens[0] 
+            newFolderName = allTokens[0]
 
             allPanels = self.findByRole(event.source, pyatspi.ROLE_PANEL)
             rolesList = [pyatspi.ROLE_PANEL, \
@@ -195,7 +229,7 @@ class Script(default.Script):
         # poorly named gtk-edit toggle button, then just return. We will have
         # spoken the information for this component with the previously
         # received "object:state-changed:focused" event. For all other events,
-        # just let the parent class handle it. See bug #371637 for more 
+        # just let the parent class handle it. See bug #371637 for more
         # details.
         #
         if event.type.startswith("object:state-changed:showing"):



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