3
# Copyright (C) 2010-2013 Igalia, S.L.
5
# Author: Alejandro Pinheiro Iglesias <apinheiro@igalia.com>
6
# Author: Joanmarie Diggs <jdiggs@igalia.com>
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.
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.
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.
24
__version__ = "$Revision$"
26
__copyright__ = "Copyright (c) 2010-2013 Igalia, S.L."
29
from gi.repository import Gdk
31
import orca.scripts.default as default
32
import orca.debug as debug
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')
38
def _unicharIsPrint(unichar):
39
""" Checks if the unichar is printable
41
Equivalent to g_unichar_isprint
44
- unichar: unichar to check if it is printable
48
category = unicodedata.category (unichar)
49
result = category not in non_printable_set
51
# Normally a exception is because there are a string
52
# instead of a single unicode, 'Control_L'
57
def _computeIsText(string):
58
"""Decides if the string representation of a keyboard event is
61
Based on the at-spi equivalent code.
64
- string: a string representation of a keyboardEvent.
69
if _unicharIsPrint(string):
76
class Script(default.Script):
78
def __init__(self, app):
79
default.Script.__init__(self, app)
81
def checkKeyboardEventData(self, keyboardEvent):
82
"""Processes the given keyboard event.
85
* Fill event_string using the key.id
86
* Set the is_text properly
89
- keyboardEvent: an instance of input_event.KeyboardEvent
92
# On the AtkKeyEventStruct documentation you can find this
95
# A guint representing a keysym value corresponding to those
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.
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
107
# http://library.gnome.org/devel/atk/stable/AtkUtil.html
108
# http://bugzilla.o-hand.com/show_bug.cgi?id=2072
110
# apply the modifiers to keyboardEvent.id
112
keyval = keyboardEvent.id
114
keymap = Gdk.Keymap.get_default()
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,
125
debug.println(debug.LEVEL_FINE,
126
"Could not compute keyval with modifiers")
128
string = "prev keyval=%d" % keyboardEvent.id
129
string = string + " post keyval=%d" % keyval
131
debug.println(debug.LEVEL_FINE, string)
133
keyboardEvent.id = keyval
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
140
if (keyboardEvent.event_string == ""):
141
debug.println (debug.LEVEL_FINE, "Computing event_string")
143
keyboardEvent.event_string = Gdk.keyval_name(keyboardEvent.id)
145
debug.println(debug.LEVEL_FINE,
146
"Could not obtain keyval_name for id: %d" \
149
# at-spi uses event_string to compute is_text, so if it is
150
# NULL we should compute again with the proper
153
keyboardEvent.is_text = _computeIsText(keyboardEvent.event_string)
155
return default.Script.checkKeyboardEventData(self, keyboardEvent)