1- # $Id: XK.py,v 1.5 2005-02 -06 02:32:34 calroc99 Exp $
1+ # $Id: XK.py,v 1.6 2005-09 -06 19:18:19 calroc99 Exp $
22#
33# Xlib.XK -- X keysym defs
44#
1717# You should have received a copy of the GNU General Public License
1818# along with this program; if not, write to the Free Software
1919# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20+ #
21+ # This module defines some functions for working with X keysyms as well
22+ # as a modular keysym definition and loading mechanism. See the keysym
23+ # definition modules in the Xlib/keysymdef directory.
2024
2125from X import NoSymbol
2226
23- def string_to_keysym (str ):
24- '''Given the name of a keysym as a string, return its numeric code.
25- Don't include the 'XK_' prefix. Just use the base, i.e. 'Delete'
27+ def string_to_keysym (keysym ):
28+ '''Return the (16 bit) numeric code of keysym.
29+
30+ Given the name of a keysym as a string, return its numeric code.
31+ Don't include the 'XK_' prefix, just use the base, i.e. 'Delete'
2632 instead of 'XK_Delete'.'''
27- return globals ().get ('XK_' + str , NoSymbol )
33+ return globals ().get ('XK_' + keysym , NoSymbol )
2834
2935def load_keysym_group (group ):
30- '''Given a group name such as 'latin1' or 'katakana' load the keysyms
36+ '''Load all the keysyms in group.
37+
38+ Given a group name such as 'latin1' or 'katakana' load the keysyms
3139 defined in module 'Xlib.keysymdef.group-name' into this XK module.'''
3240 if '.' in group :
3341 raise ValueError ('invalid keysym group name: %s' % group )
@@ -38,24 +46,33 @@ def load_keysym_group(group):
3846 mod = __import__ ('Xlib.keysymdef.%s' % group , G , locals (), [group ])
3947
4048 #Extract names of just the keysyms.
41- keysyms = [n for n in dir (mod ) if n [: 3 ] == 'XK_' ]
49+ keysyms = [n for n in dir (mod ) if n . startswith ( 'XK_' ) ]
4250
4351 #Copy the named keysyms into XK.__dict__
4452 for keysym in keysyms :
4553 ## k = mod.__dict__[keysym]; assert k == int(k) #probably too much.
4654 G [keysym ] = mod .__dict__ [keysym ]
4755
56+ #And get rid of the keysym module.
57+ del mod
58+
4859def _load_keysyms_into_XK (mod ):
4960 '''keysym definition modules need no longer call Xlib.XK._load_keysyms_into_XK().
5061 You should remove any calls to that function from your keysym modules.'''
5162 pass
5263
5364# Always import miscellany and latin1 keysyms
54- import Xlib . keysymdef . miscellany
55- import Xlib . keysymdef . latin1
65+ load_keysym_group ( ' miscellany' )
66+ load_keysym_group ( ' latin1' )
5667
5768
5869def keysym_to_string (keysym ):
70+ '''Translate a keysym (16 bit number) into a python string.
71+
72+ This will pass 0 to 0xff as well as XK_BackSpace, XK_Tab, XK_Clear,
73+ XK_Return, XK_Pause, XK_Scroll_Lock, XK_Escape, XK_Delete. For other
74+ values it returns None.'''
75+
5976 # ISO latin 1, LSB is the code
6077 if keysym & 0xff00 == 0 :
6178 return chr (keysym & 0xff )
0 commit comments