~bennabiy/+junk/python-xlib

« back to all changes in this revision

Viewing changes to .pc/python3.patch/Xlib/XK.py

  • Committer: Package Import Robot
  • Author(s): Andrew Shadura, Ramkumar Ramachandra, Andrew Shadura
  • Date: 2015-08-13 08:14:19 UTC
  • mfrom: (6.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20150813081419-hdefinnghp2iydkx
Tags: 0.14+20091101-3
[ Ramkumar Ramachandra ]
* Remove useless debugging output (Closes: #565996)

[ Andrew Shadura ]
* Switch to 3.0 (quilt) format.
* Rename patches.
* Use debhelper 9 in its short form.
* Use pybuild.
* Bump Standards-Version.
* Don't build or install PostScript documentation and info files.
* Use system-provided texi2html instead of a shipped version
  (Closes: #795057).
* Update debian/copyright (Closes: #795057).
* Don't install Makefile or texi2html with the documentation.
* Set executable bit for examples.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Xlib.XK -- X keysym defs
 
2
#
 
3
#    Copyright (C) 2000 Peter Liljenberg <petli@ctrl-c.liu.se>
 
4
#
 
5
#    This program is free software; you can redistribute it and/or modify
 
6
#    it under the terms of the GNU General Public License as published by
 
7
#    the Free Software Foundation; either version 2 of the License, or
 
8
#    (at your option) any later version.
 
9
#
 
10
#    This program 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
 
13
#    GNU General Public License for more details.
 
14
#
 
15
#    You should have received a copy of the GNU General Public License
 
16
#    along with this program; if not, write to the Free Software
 
17
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
#
 
19
# This module defines some functions for working with X keysyms as well
 
20
# as a modular keysym definition and loading mechanism. See the keysym
 
21
# definition modules in the Xlib/keysymdef directory.
 
22
 
 
23
from X import NoSymbol
 
24
 
 
25
def string_to_keysym(keysym):
 
26
    '''Return the (16 bit) numeric code of keysym.
 
27
 
 
28
    Given the name of a keysym as a string, return its numeric code.
 
29
    Don't include the 'XK_' prefix, just use the base, i.e. 'Delete'
 
30
    instead of 'XK_Delete'.'''
 
31
    return globals().get('XK_' + keysym, NoSymbol)
 
32
 
 
33
def load_keysym_group(group):
 
34
    '''Load all the keysyms in group.
 
35
 
 
36
    Given a group name such as 'latin1' or 'katakana' load the keysyms
 
37
    defined in module 'Xlib.keysymdef.group-name' into this XK module.'''
 
38
    if '.' in group:
 
39
        raise ValueError('invalid keysym group name: %s' % group)
 
40
 
 
41
    G = globals() #Get a reference to XK.__dict__ a.k.a. globals
 
42
 
 
43
    #Import just the keysyms module.
 
44
    mod = __import__('Xlib.keysymdef.%s' % group, G, locals(), [group])
 
45
 
 
46
    #Extract names of just the keysyms.
 
47
    keysyms = [n for n in dir(mod) if n.startswith('XK_')]
 
48
 
 
49
    #Copy the named keysyms into XK.__dict__
 
50
    for keysym in keysyms:
 
51
        ## k = mod.__dict__[keysym]; assert k == int(k) #probably too much.
 
52
        G[keysym] = mod.__dict__[keysym]
 
53
 
 
54
    #And get rid of the keysym module.
 
55
    del mod
 
56
 
 
57
def _load_keysyms_into_XK(mod):
 
58
    '''keysym definition modules need no longer call Xlib.XK._load_keysyms_into_XK().
 
59
    You should remove any calls to that function from your keysym modules.'''
 
60
    pass
 
61
 
 
62
# Always import miscellany and latin1 keysyms
 
63
load_keysym_group('miscellany')
 
64
load_keysym_group('latin1')
 
65
 
 
66
 
 
67
def keysym_to_string(keysym):
 
68
    '''Translate a keysym (16 bit number) into a python string.
 
69
 
 
70
    This will pass 0 to 0xff as well as XK_BackSpace, XK_Tab, XK_Clear,
 
71
    XK_Return, XK_Pause, XK_Scroll_Lock, XK_Escape, XK_Delete. For other
 
72
    values it returns None.'''
 
73
 
 
74
    # ISO latin 1, LSB is the code
 
75
    if keysym & 0xff00 == 0:
 
76
        return chr(keysym & 0xff)
 
77
 
 
78
    if keysym in [XK_BackSpace, XK_Tab, XK_Clear, XK_Return,
 
79
                  XK_Pause, XK_Scroll_Lock, XK_Escape, XK_Delete]:
 
80
        return chr(keysym & 0xff)
 
81
 
 
82
    # We should be able to do these things quite automatically
 
83
    # for latin2, latin3, etc, in Python 2.0 using the Unicode,
 
84
    # but that will have to wait.
 
85
 
 
86
    return None