Coverage Report - orca.scripts.gnome-panel

ModuleCoverage %
orca.scripts.gnome-panel
75%
1
# Orca
2
#
3
# Copyright 2004-2007 Sun Microsystems Inc.
4
#
5
# This library is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU Library General Public
7
# License as published by the Free Software Foundation; either
8
# version 2 of the License, or (at your option) any later version.
9
#
10
# This library is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# Library General Public License for more details.
14
#
15
# You should have received a copy of the GNU Library General Public
16
# License along with this library; if not, write to the
17
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
# Boston, MA 02111-1307, USA.
19
20
""" Custom script for gnome-panel
21 1
"""
22
23 1
__id__        = "$Id: gnome-panel.py 2251 2007-04-05 01:42:41Z lmonsanto $"
24 1
__version__   = "$Revision: 2251 $"
25 1
__date__      = "$Date: 2007-04-04 18:42:41 -0700 (Wed, 04 Apr 2007) $"
26 1
__copyright__ = "Copyright (c) 2005-2007 Sun Microsystems Inc."
27 1
__license__   = "LGPL"
28
29 1
import orca.orca as orca
30 1
import orca.atspi as atspi
31 1
import orca.default as default
32 1
import orca.debug as debug
33 1
import orca.braille as braille
34 1
import orca.speech as speech
35 1
import orca.rolenames as rolenames
36
37 1
from orca.orca_i18n import _
38
39
########################################################################
40
#                                                                      #
41
# The gnome-panel script class.                                        #
42
#                                                                      #
43
########################################################################
44
45 2
class Script(default.Script):
46
47 1
    def __init__(self, app):
48
        """Creates a new script for gnome-panel
49
50
        Arguments:
51
        - app: the application to create a script for.
52
        """
53
54
        # Set the debug level for all the methods in this script.
55
        #
56 1
        self.debugLevel = debug.LEVEL_FINEST
57
58 1
        self._debug("__init__")
59 1
        default.Script.__init__(self, app)
60
61 1
    def _debug(self, msg):
62
        """ Convenience method for printing debug messages
63
        """
64 2
        debug.println(self.debugLevel, "gnome-panel.py: "+msg)
65
66 1
    def onStateChanged(self, event):
67
        """Called whenever an object's state changes.
68
69
        Arguments:
70
        - event: the Event
71
        """
72 1
        obj = event.source
73
74 1
        self._debug("onStateChanged: '%s' %s (%d, %d)" % \
75 1
                    (obj.name, event.type, event.detail1, event.detail2))
76
77
        # Handle tooltip popups.
78
        #
79 1
        if obj.role == rolenames.ROLE_TOOL_TIP:
80 0
            if event.type == "object:state-changed:showing" and \
81 0
               event.detail1 == 1:
82 0
                braille.displayMessage(obj.name)
83 0
                speech.speak(obj.name)
84
            # Delete the cached accessible to force the AT-SPI to update
85
            # the accessible cache. Otherwise, the event references the
86
            # previous popup object.
87
            #
88 0
            atspi.Accessible.deleteAccessible(obj._acc)
89
90
        # If focus moves to something within a panel and focus was not
91
        # already in the containing panel, the panel will issue its
92
        # own state-changed:focused event with detail1 == 1 after the
93
        # event for the item with focus.  The panel is not focused,
94
        # plus the extraneous event results in unnecessary chattiness
95
        # and updates the braille display to "panel."
96
        #
97 1
        elif obj.role == rolenames.ROLE_PANEL and \
98 0
             event.type == "object:state-changed:focused" and \
99 0
             event.detail1 == 1 and not \
100 0
             event.source.state.count(atspi.Accessibility.STATE_FOCUSED):
101 0
            return
102
103
        else:
104 1
            default.Script.onStateChanged(self, event)