1 |
|
# Orca |
2 |
|
# |
3 |
|
# Copyright 2006 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 |
|
"""Exposes a dictionary, keynames, that maps key events |
21 |
1 |
into localized words.""" |
22 |
|
|
23 |
1 |
__id__ = "$Id: keynames.py 1529 2006-10-05 16:31:04Z wwalker $" |
24 |
1 |
__version__ = "$Revision: 1529 $" |
25 |
1 |
__date__ = "$Date: 2006-10-05 09:31:04 -0700 (Thu, 05 Oct 2006) $" |
26 |
1 |
__copyright__ = "Copyright (c) 2006 Sun Microsystems Inc." |
27 |
1 |
__license__ = "LGPL" |
28 |
|
|
29 |
1 |
import chnames |
30 |
|
|
31 |
1 |
from orca_i18n import _ # for gettext support |
32 |
|
|
33 |
|
# __keynames is a dictionary where the keys represent a UTF-8 |
34 |
|
# string for a keyboard key and the values represent the common |
35 |
|
# phrase used to describe the key. |
36 |
|
# |
37 |
1 |
__keynames = {} |
38 |
1 |
__keynames["Shift_L"] = _("left shift") |
39 |
1 |
__keynames["Alt_L"] = _("left alt") |
40 |
1 |
__keynames["Control_L"] = _("left control") |
41 |
1 |
__keynames["Shift_L"] = _("left shift") |
42 |
1 |
__keynames["Shift_R"] = _("right shift") |
43 |
1 |
__keynames["Alt_R"] = _("right alt") |
44 |
1 |
__keynames["Control_R"] = _("right control") |
45 |
1 |
__keynames["Meta_L"] = _("left meta") |
46 |
1 |
__keynames["Meta_R"] = _("right meta") |
47 |
1 |
__keynames["Num_Lock"] = _("num lock") |
48 |
1 |
__keynames["Caps_Lock"] = _("caps lock") |
49 |
1 |
__keynames["Scroll_Lock"] = _("scroll lock") |
50 |
1 |
__keynames["Page_Up"] = _("page up") |
51 |
1 |
__keynames["Page_Down"] = _("page down") |
52 |
1 |
__keynames["ISO_Left_Tab"] = _("left tab") |
53 |
1 |
__keynames["SunF36"] = _("F 11") |
54 |
1 |
__keynames["SunF37"] = _("F 12") |
55 |
|
|
56 |
1 |
def getKeyName(key): |
57 |
|
"""Given a keyboard key, return its name as people might refer to it |
58 |
|
in ordinary conversation. |
59 |
|
|
60 |
|
Arguments: |
61 |
|
- key: the key to get the name for |
62 |
|
|
63 |
|
Returns a string representing the name for the key |
64 |
|
""" |
65 |
|
|
66 |
0 |
if isinstance(key, unicode): |
67 |
0 |
key = key.encode("UTF-8") |
68 |
|
|
69 |
0 |
try: |
70 |
0 |
return __keynames[key] |
71 |
0 |
except: |
72 |
0 |
return chnames.getCharacterName(key) |