1# Orca
2#
3# Copyright 2005-2009 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 Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 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# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public
16# License along with this library; if not, write to the
17# Free Software Foundation, Inc., Franklin Street, Fifth Floor,
18# Boston MA  02110-1301 USA.
19
20"""Custom script for Ekiga."""
21
22__id__        = "$Id$"
23__version__   = "$Revision$"
24__date__      = "$Date$"
25__copyright__ = "Copyright (c) 2005-2009 Sun Microsystems Inc."
26__license__   = "LGPL"
27
28import pyatspi
29
30import orca.scripts.default as default
31
32########################################################################
33#                                                                      #
34# The Ekiga script class.                                              #
35#                                                                      #
36########################################################################
37
38class Script(default.Script):
39
40    def __init__(self, app):
41        """Creates a new script for the given application.
42
43        Arguments:
44        - app: the application to create a script for.
45        """
46
47        default.Script.__init__(self, app)
48
49    def isChatRoomMsg(self, obj):
50        """Returns True if the given accessible is the text object for
51        associated with a chat room conversation.
52
53        Arguments:
54        - obj: the accessible object to examine.
55        """
56
57        if obj and obj.getRole() == pyatspi.ROLE_TEXT \
58           and obj.parent.getRole() == pyatspi.ROLE_SCROLL_PANE:
59            state = obj.getState()
60            if not state.contains(pyatspi.STATE_EDITABLE) \
61               and state.contains(pyatspi.STATE_MULTI_LINE):
62                return True
63
64        return False
65
66    def onTextInserted(self, event):
67        """Called whenever text is inserted into one of Ekiga's text objects.
68        Overridden here so that we can present new messages to the user.
69
70        Arguments:
71        - event: the Event
72        """
73
74        if self.isChatRoomMsg(event.source):
75            self.presentMessage(event.any_data)
76            return
77
78        default.Script.onTextInserted(self, event)
79
80    def onValueChanged(self, event):
81        """Called whenever an object's value changes. Overridden here because
82        new chat windows are not issuing text-inserted events for the chat
83        history until we "tickle" the hierarchy. However, we do seem to get
84        object:property-change:accessible-value events on the split pane. So
85        we'll use that as our trigger to do the tickling.
86
87        Arguments:
88        - event: the Event
89        """
90
91        if event.source.getRole() == pyatspi.ROLE_SPLIT_PANE:
92            hasRole = lambda x: x and x.getRole() == pyatspi.ROLE_TEXT
93            textObjects = pyatspi.findAllDescendants(event.source, hasRole)
94            return
95
96        default.Script.onValueChanged(self, event)
97