~ubuntu-branches/ubuntu/wily/gnome-orca/wily-proposed

« back to all changes in this revision

Viewing changes to src/orca/scripts/toolkits/clutter/script.py

  • Committer: Package Import Robot
  • Author(s): Mario Lang, Emilio Pozuelo Monfort, Mario Lang
  • Date: 2014-03-26 09:02:03 UTC
  • mfrom: (1.1.19)
  • Revision ID: package-import@ubuntu.com-20140326090203-hklufxw4me5mq70b
Tags: 3.12.0-1
[ Emilio Pozuelo Monfort ]
* debian/control.in:
  + Depend on gsettings-desktop-schemas, needed for the a11y gsettings
    keys. Closes: #741211.

[ Mario Lang ]
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Orca
 
2
#
 
3
# Copyright (C) 2010-2013 Igalia, S.L.
 
4
#
 
5
# Author: Alejandro Pinheiro Iglesias <apinheiro@igalia.com>
 
6
# Author: Joanmarie Diggs <jdiggs@igalia.com>
 
7
#
 
8
# This library is free software; you can redistribute it and/or
 
9
# modify it under the terms of the GNU Lesser General Public
 
10
# License as published by the Free Software Foundation; either
 
11
# version 2.1 of the License, or (at your option) any later version.
 
12
#
 
13
# This library is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
# Lesser General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU Lesser General Public
 
19
# License along with this library; if not, write to the
 
20
# Free Software Foundation, Inc., Franklin Street, Fifth Floor,
 
21
# Boston MA  02110-1301 USA.
 
22
 
 
23
__id__        = "$Id$"
 
24
__version__   = "$Revision$"
 
25
__date__      = "$Date$"
 
26
__copyright__ = "Copyright (c) 2010-2013 Igalia, S.L."
 
27
__license__   = "LGPL"
 
28
 
 
29
from gi.repository import Gdk
 
30
 
 
31
import orca.scripts.default as default
 
32
import orca.debug as debug
 
33
 
 
34
# Set with non printable unicode categories. Full table:
 
35
# http://www.fileformat.info/info/unicode/category/index.htm
 
36
non_printable_set = ('Cc', 'Cf', 'Cn', 'Co', 'Cs')
 
37
 
 
38
def _unicharIsPrint(unichar):
 
39
    """ Checks if the unichar is printable
 
40
 
 
41
    Equivalent to g_unichar_isprint
 
42
 
 
43
    Arguments:
 
44
    - unichar: unichar to check if it is printable
 
45
    """
 
46
    try:
 
47
        import unicodedata
 
48
        category = unicodedata.category (unichar)
 
49
        result = category not in non_printable_set
 
50
    except:
 
51
        # Normally a exception is because there are a string
 
52
        # instead of a single unicode, 'Control_L'
 
53
        result = False
 
54
 
 
55
    return result
 
56
 
 
57
def _computeIsText(string):
 
58
    """Decides if the string representation of a keyboard event is
 
59
    text or not
 
60
 
 
61
    Based on the at-spi equivalent code.
 
62
 
 
63
    Arguments:
 
64
    - string: a string representation of a keyboardEvent.
 
65
    """
 
66
    is_text = False
 
67
 
 
68
    if string:
 
69
        if _unicharIsPrint(string):
 
70
            is_text = True
 
71
        else:
 
72
            is_text = False
 
73
 
 
74
    return is_text
 
75
 
 
76
class Script(default.Script):
 
77
 
 
78
    def __init__(self, app):
 
79
        default.Script.__init__(self, app)
 
80
 
 
81
    def checkKeyboardEventData(self, keyboardEvent):
 
82
        """Processes the given keyboard event.
 
83
 
 
84
        Here is used to:
 
85
        * Fill event_string using the key.id
 
86
        * Set the is_text properly
 
87
 
 
88
        Arguments:
 
89
        - keyboardEvent: an instance of input_event.KeyboardEvent
 
90
        """
 
91
 
 
92
        # On the AtkKeyEventStruct documentation you can find this
 
93
        # description:
 
94
        # guint keyval;
 
95
        # A guint representing a keysym value corresponding to those
 
96
        # used by GDK
 
97
        #
 
98
        # There are no Clutter way to get a gdk-like keyvalname.
 
99
        # Anyway, cally will fill event_string with the final
 
100
        # representation of a text char.
 
101
        #
 
102
        # In the same way, Clutter provides the keyval without the
 
103
        # modifiers, and GDK yes. We will try to apply it, at least
 
104
        # to compute keyval_name
 
105
        #
 
106
        # More information:
 
107
        # http://library.gnome.org/devel/atk/stable/AtkUtil.html
 
108
        # http://bugzilla.o-hand.com/show_bug.cgi?id=2072
 
109
 
 
110
        # apply the modifiers to keyboardEvent.id
 
111
        #
 
112
        keyval = keyboardEvent.id
 
113
        try:
 
114
            keymap = Gdk.Keymap.get_default()
 
115
 
 
116
            if keymap:
 
117
                success, entries = keymap.get_entries_for_keyval(keyval)
 
118
                group = entries[0].group
 
119
                modifiers = Gdk.ModifierType(keyboardEvent.modifiers)
 
120
                success, keyval, egroup, level, consumed = \
 
121
                    keymap.translate_keyboard_state (keyboardEvent.hw_code,
 
122
                                                     modifiers,
 
123
                                                     group)
 
124
        except:
 
125
            debug.println(debug.LEVEL_FINE,
 
126
                          "Could not compute keyval with modifiers")
 
127
 
 
128
        string = "prev keyval=%d" % keyboardEvent.id
 
129
        string = string + " post keyval=%d" % keyval
 
130
 
 
131
        debug.println(debug.LEVEL_FINE, string)
 
132
 
 
133
        keyboardEvent.id = keyval
 
134
 
 
135
        # if cally doesn't provide a event_string we get that using
 
136
        # Gdk. I know that it will probably called again computing
 
137
        # keyval_name but to simplify code, and not start to add
 
138
        # guess-code here I will maintain that in this way
 
139
        #
 
140
        if (keyboardEvent.event_string == ""):
 
141
            debug.println (debug.LEVEL_FINE, "Computing event_string")
 
142
            try:
 
143
                keyboardEvent.event_string = Gdk.keyval_name(keyboardEvent.id)
 
144
            except:
 
145
                debug.println(debug.LEVEL_FINE,
 
146
                              "Could not obtain keyval_name for id: %d" \
 
147
                                  % keyboardEvent.id)
 
148
 
 
149
            # at-spi uses event_string to compute is_text, so if it is
 
150
            # NULL we should compute again with the proper
 
151
            # event_string
 
152
            #
 
153
            keyboardEvent.is_text = _computeIsText(keyboardEvent.event_string)
 
154
 
 
155
        return default.Script.checkKeyboardEventData(self, keyboardEvent)