Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replaced all tabs with spaces (using reindent.py from standard Python…

… distribution). Tabnanny was complaining about some. Addresses SF issue (patch) 1559082.

git-svn-id: https://python-xlib.svn.sourceforge.net/svnroot/python-xlib/trunk@116 f4f28c72-a847-0410-8928-82246e20c517
  • Loading branch information...
commit 8984f33ff42fea9b4105e2409995e666edfb7575 1 parent 2d6158b
mggrant authored
Showing with 13,171 additions and 13,212 deletions.
  1. +40 −40 Xlib/X.py
  2. +5 −5 Xlib/XK.py
  3. +1 −2  Xlib/Xatom.py
  4. +2 −2 Xlib/Xutil.py
  5. +1 −2  Xlib/__init__.py
  6. +413 −414 Xlib/display.py
  7. +58 −59 Xlib/error.py
  8. +2 −3 Xlib/ext/__init__.py
  9. +195 −195 Xlib/ext/record.py
  10. +217 −217 Xlib/ext/shape.py
  11. +8 −9 Xlib/ext/xinerama.py
  12. +61 −65 Xlib/ext/xtest.py
  13. +835 −838 Xlib/protocol/display.py
  14. +268 −268 Xlib/protocol/event.py
  15. +1,303 −1,303 Xlib/protocol/request.py
  16. +1,020 −1,020 Xlib/protocol/rq.py
  17. +57 −59 Xlib/protocol/structs.py
  18. +395 −395 Xlib/rdb.py
  19. +5 −6 Xlib/support/connect.py
  20. +11 −11 Xlib/support/lock.py
  21. +64 −64 Xlib/support/unix_connect.py
  22. +15 −17 Xlib/support/vms_connect.py
  23. +1 −2  Xlib/threaded.py
  24. +87 −88 Xlib/xauth.py
  25. +77 −78 Xlib/xobject/colormap.py
  26. +15 −19 Xlib/xobject/cursor.py
  27. +591 −591 Xlib/xobject/drawable.py
  28. +56 −58 Xlib/xobject/fontable.py
  29. +44 −45 Xlib/xobject/icccm.py
  30. +18 −19 Xlib/xobject/resource.py
  31. +172 −175 examples/draw-proto.py
  32. +174 −177 examples/draw.py
  33. +14 −15 examples/profilex.py
  34. +54 −54 examples/record_demo.py
  35. +138 −141 examples/shapewin.py
  36. +20 −20 examples/threadtest.py
  37. +9 −9 setup.py
  38. +716 −716 test/gen/genprottest.py
  39. +350 −350 test/test_events_be.py
  40. +350 −350 test/test_events_le.py
  41. +22 −22 test/test_rdb.py
  42. +2,520 −2,520 test/test_requests_be.py
  43. +2,520 −2,520 test/test_requests_le.py
  44. +188 −189 utils/parsexbug.py
  45. +59 −60 utils/tcpbug.py
80 Xlib/X.py
View
@@ -1,4 +1,4 @@
-# $Id: X.py,v 1.2 2000-08-07 10:30:19 petli Exp $
+# $Id: X.py,v 1.3 2007-06-10 14:11:58 mggrant Exp $
#
# Xlib.X -- basic X constants
#
@@ -22,60 +22,60 @@
NONE = 0
ParentRelative = 1 # background pixmap in CreateWindow
- # and ChangeWindowAttributes
+ # and ChangeWindowAttributes
CopyFromParent = 0 # border pixmap in CreateWindow
# and ChangeWindowAttributes
# special VisualID and special window
- # class passed to CreateWindow
+ # class passed to CreateWindow
-PointerWindow = 0 # destination window in SendEvent
-InputFocus = 1 # destination window in SendEvent
-PointerRoot = 1 # focus window in SetInputFocus
-AnyPropertyType = 0 # special Atom, passed to GetProperty
-AnyKey = 0 # special Key Code, passed to GrabKey
-AnyButton = 0 # special Button Code, passed to GrabButton
-AllTemporary = 0 # special Resource ID passed to KillClient
-CurrentTime = 0 # special Time
-NoSymbol = 0 # special KeySym
+PointerWindow = 0 # destination window in SendEvent
+InputFocus = 1 # destination window in SendEvent
+PointerRoot = 1 # focus window in SetInputFocus
+AnyPropertyType = 0 # special Atom, passed to GetProperty
+AnyKey = 0 # special Key Code, passed to GrabKey
+AnyButton = 0 # special Button Code, passed to GrabButton
+AllTemporary = 0 # special Resource ID passed to KillClient
+CurrentTime = 0 # special Time
+NoSymbol = 0 # special KeySym
#-----------------------------------------------------------------------
# Event masks:
#
NoEventMask = 0
-KeyPressMask = (1<<0)
-KeyReleaseMask = (1<<1)
-ButtonPressMask = (1<<2)
-ButtonReleaseMask = (1<<3)
-EnterWindowMask = (1<<4)
-LeaveWindowMask = (1<<5)
-PointerMotionMask = (1<<6)
-PointerMotionHintMask = (1<<7)
-Button1MotionMask = (1<<8)
-Button2MotionMask = (1<<9)
-Button3MotionMask = (1<<10)
-Button4MotionMask = (1<<11)
-Button5MotionMask = (1<<12)
-ButtonMotionMask = (1<<13)
+KeyPressMask = (1<<0)
+KeyReleaseMask = (1<<1)
+ButtonPressMask = (1<<2)
+ButtonReleaseMask = (1<<3)
+EnterWindowMask = (1<<4)
+LeaveWindowMask = (1<<5)
+PointerMotionMask = (1<<6)
+PointerMotionHintMask = (1<<7)
+Button1MotionMask = (1<<8)
+Button2MotionMask = (1<<9)
+Button3MotionMask = (1<<10)
+Button4MotionMask = (1<<11)
+Button5MotionMask = (1<<12)
+ButtonMotionMask = (1<<13)
KeymapStateMask = (1<<14)
-ExposureMask = (1<<15)
-VisibilityChangeMask = (1<<16)
-StructureNotifyMask = (1<<17)
-ResizeRedirectMask = (1<<18)
-SubstructureNotifyMask = (1<<19)
-SubstructureRedirectMask = (1<<20)
-FocusChangeMask = (1<<21)
-PropertyChangeMask = (1<<22)
-ColormapChangeMask = (1<<23)
-OwnerGrabButtonMask = (1<<24)
+ExposureMask = (1<<15)
+VisibilityChangeMask = (1<<16)
+StructureNotifyMask = (1<<17)
+ResizeRedirectMask = (1<<18)
+SubstructureNotifyMask = (1<<19)
+SubstructureRedirectMask = (1<<20)
+FocusChangeMask = (1<<21)
+PropertyChangeMask = (1<<22)
+ColormapChangeMask = (1<<23)
+OwnerGrabButtonMask = (1<<24)
#-----------------------------------------------------------------------
# Event names:
#
# Used in "type" field in XEvent structures. Not to be confused with event
# masks above. They start from 2 because 0 and 1 are reserved in the
-# protocol for errors and replies.
+# protocol for errors and replies.
#
KeyPress = 2
KeyRelease = 3
@@ -110,7 +110,7 @@
ColormapNotify = 32
ClientMessage = 33
MappingNotify = 34
-LASTEvent = 35 # must be bigger than any event
+LASTEvent = 35 # must be bigger than any event
#-----------------------------------------------------------------------
@@ -156,14 +156,14 @@
Button4Mask = (1<<11)
Button5Mask = (1<<12)
-AnyModifier = (1<<15) # used in GrabButton, GrabKey
+AnyModifier = (1<<15) # used in GrabButton, GrabKey
#-----------------------------------------------------------------------
# Button names:
#
# Used as arguments to GrabButton and as detail in ButtonPress and
# ButtonRelease events. Not to be confused with button masks above.
-# Note that 0 is already defined above as "AnyButton".
+# Note that 0 is already defined above as "AnyButton".
#
Button1 = 1
Button2 = 2
10 Xlib/XK.py
View
@@ -1,4 +1,4 @@
-# $Id: XK.py,v 1.6 2005-09-06 19:18:19 calroc99 Exp $
+# $Id: XK.py,v 1.7 2007-06-10 14:11:58 mggrant Exp $
#
# Xlib.XK -- X keysym defs
#
@@ -38,7 +38,7 @@ def load_keysym_group(group):
Given a group name such as 'latin1' or 'katakana' load the keysyms
defined in module 'Xlib.keysymdef.group-name' into this XK module.'''
if '.' in group:
- raise ValueError('invalid keysym group name: %s' % group)
+ raise ValueError('invalid keysym group name: %s' % group)
G = globals() #Get a reference to XK.__dict__ a.k.a. globals
@@ -75,11 +75,11 @@ def keysym_to_string(keysym):
# ISO latin 1, LSB is the code
if keysym & 0xff00 == 0:
- return chr(keysym & 0xff)
+ return chr(keysym & 0xff)
if keysym in [XK_BackSpace, XK_Tab, XK_Clear, XK_Return,
- XK_Pause, XK_Scroll_Lock, XK_Escape, XK_Delete]:
- return chr(keysym & 0xff)
+ XK_Pause, XK_Scroll_Lock, XK_Escape, XK_Delete]:
+ return chr(keysym & 0xff)
# We should be able to do these things quite automatically
# for latin2, latin3, etc, in Python 2.0 using the Unicode,
3  Xlib/Xatom.py
View
@@ -1,4 +1,4 @@
-# $Id: Xatom.py,v 1.2 2000-08-22 14:06:22 petli Exp $
+# $Id: Xatom.py,v 1.3 2007-06-10 14:11:58 mggrant Exp $
#
# Xlib.Xatom -- Standard X atoms
#
@@ -87,4 +87,3 @@
WM_CLASS = 67
WM_TRANSIENT_FOR = 68
LAST_PREDEFINED = 68
-
4 Xlib/Xutil.py
View
@@ -1,4 +1,4 @@
-# $Id: Xutil.py,v 1.2 2000-08-22 14:06:22 petli Exp $
+# $Id: Xutil.py,v 1.3 2007-06-10 14:11:58 mggrant Exp $
#
# Xlib.Xutil -- ICCCM definitions and similar stuff
#
@@ -46,7 +46,7 @@
IconMaskHint = (1 << 5)
WindowGroupHint = (1 << 6)
AllHints = (InputHint|StateHint|IconPixmapHint|IconWindowHint|
- IconPositionHint|IconMaskHint|WindowGroupHint)
+ IconPositionHint|IconMaskHint|WindowGroupHint)
WithdrawnState = 0
NormalState = 1
IconicState = 3
3  Xlib/__init__.py
View
@@ -1,4 +1,4 @@
-# $Id: __init__.py,v 1.14 2002-03-30 00:34:53 petli Exp $
+# $Id: __init__.py,v 1.15 2007-06-10 14:11:58 mggrant Exp $
#
# Xlib.__init__ -- glue for Xlib package
#
@@ -38,4 +38,3 @@
# Explicitly exclude threaded, so that it isn't imported by
# from Xlib import *
]
-
827 Xlib/display.py
View
@@ -1,4 +1,4 @@
-# $Id: display.py,v 1.22 2007-03-17 22:24:47 mggrant Exp $
+# $Id: display.py,v 1.23 2007-06-10 14:11:58 mggrant Exp $
#
# Xlib.display -- high level display object
#
@@ -51,8 +51,8 @@
_resource_hierarchy = {
'resource': ('drawable', 'window', 'pixmap',
- 'fontable', 'font', 'gc',
- 'colormap', 'cursor'),
+ 'fontable', 'font', 'gc',
+ 'colormap', 'cursor'),
'drawable': ('window', 'pixmap'),
'fontable': ('font', 'gc')
}
@@ -62,7 +62,7 @@ class _BaseDisplay(protocol.display.Display):
# Implement a cache of atom names, used by Window objects when
# dealing with some ICCCM properties not defined in Xlib.Xatom
-
+
def __init__(self, *args, **keys):
apply(protocol.display.Display.__init__, (self, ) + args, keys)
self._atom_cache = {}
@@ -82,111 +82,111 @@ def get_atom(self, atomname, only_if_exists=0):
class Display:
def __init__(self, display = None):
- self.display = _BaseDisplay(display)
-
- # Create the keymap cache
- self._keymap_codes = [()] * 256
- self._keymap_syms = {}
- self._update_keymap(self.display.info.min_keycode,
- (self.display.info.max_keycode
- - self.display.info.min_keycode + 1))
-
- # Translations for keysyms to strings.
- self.keysym_translations = {}
-
- # Find all supported extensions
- self.extensions = []
- self.class_extension_dicts = {}
- self.display_extension_methods = {}
-
- self.extension_event = rq.DictWrapper({})
-
- exts = self.list_extensions()
-
- # Go through all extension modules
- for extname, modname in ext.__extensions__:
- if extname in exts:
-
- # Import the module and fetch it
- __import__('Xlib.ext.' + modname)
- mod = getattr(ext, modname)
-
- info = self.query_extension(extname)
- self.display.set_extension_major(extname, info.major_opcode)
-
- # Call initialiasation function
- mod.init(self, info)
-
- self.extensions.append(extname)
-
-
- # Finalize extensions by creating new classes
- for type, dict in self.class_extension_dicts.items():
- origcls = self.display.resource_classes[type]
- self.display.resource_classes[type] = new.classobj(origcls.__name__,
- (origcls,),
- dict)
-
- # Problem: we have already created some objects without the
- # extensions: the screen roots and default colormaps.
- # Fix that by reinstantiating them.
- for screen in self.display.info.roots:
- screen.root = self.display.resource_classes['window'](self.display, screen.root.id)
- screen.default_colormap = self.display.resource_classes['colormap'](self.display, screen.default_colormap.id)
-
-
+ self.display = _BaseDisplay(display)
+
+ # Create the keymap cache
+ self._keymap_codes = [()] * 256
+ self._keymap_syms = {}
+ self._update_keymap(self.display.info.min_keycode,
+ (self.display.info.max_keycode
+ - self.display.info.min_keycode + 1))
+
+ # Translations for keysyms to strings.
+ self.keysym_translations = {}
+
+ # Find all supported extensions
+ self.extensions = []
+ self.class_extension_dicts = {}
+ self.display_extension_methods = {}
+
+ self.extension_event = rq.DictWrapper({})
+
+ exts = self.list_extensions()
+
+ # Go through all extension modules
+ for extname, modname in ext.__extensions__:
+ if extname in exts:
+
+ # Import the module and fetch it
+ __import__('Xlib.ext.' + modname)
+ mod = getattr(ext, modname)
+
+ info = self.query_extension(extname)
+ self.display.set_extension_major(extname, info.major_opcode)
+
+ # Call initialiasation function
+ mod.init(self, info)
+
+ self.extensions.append(extname)
+
+
+ # Finalize extensions by creating new classes
+ for type, dict in self.class_extension_dicts.items():
+ origcls = self.display.resource_classes[type]
+ self.display.resource_classes[type] = new.classobj(origcls.__name__,
+ (origcls,),
+ dict)
+
+ # Problem: we have already created some objects without the
+ # extensions: the screen roots and default colormaps.
+ # Fix that by reinstantiating them.
+ for screen in self.display.info.roots:
+ screen.root = self.display.resource_classes['window'](self.display, screen.root.id)
+ screen.default_colormap = self.display.resource_classes['colormap'](self.display, screen.default_colormap.id)
+
+
def get_display_name(self):
"""Returns the name used to connect to the server, either
provided when creating the Display object, or fetched from the
environmental variable $DISPLAY."""
- return self.display.get_display_name()
+ return self.display.get_display_name()
def fileno(self):
"""Returns the file descriptor number of the underlying socket.
This method is provided to allow Display objects to be passed
select.select()."""
- return self.display.fileno()
+ return self.display.fileno()
def close(self):
"""Close the display, freeing the resources that it holds."""
- self.display.close()
+ self.display.close()
def set_error_handler(self, handler):
"""Set the default error handler which will be called for all
unhandled errors. handler should take two arguments as a normal
request error handler, but the second argument (the request) will
be None. See section Error Handling."""
- self.display.set_error_handler(handler)
+ self.display.set_error_handler(handler)
def flush(self):
"""Flush the request queue, building and sending the queued
requests. This can be necessary in applications that never wait
for events, and in threaded applications."""
- self.display.flush()
+ self.display.flush()
def sync(self):
"""Flush the queue and wait until the server has processed all
the queued requests. Use this e.g. when it is important that
errors caused by a certain request is trapped."""
- # Do a light-weight replyrequest to sync. There must
- # be a better way to do it...
- self.get_pointer_control()
-
+ # Do a light-weight replyrequest to sync. There must
+ # be a better way to do it...
+ self.get_pointer_control()
+
def next_event(self):
"""Return the next event. If there are no events queued, it will
block until the next event is fetched from the server."""
- return self.display.next_event()
+ return self.display.next_event()
def pending_events(self):
"""Return the number of events queued, i.e. the number of times
that Display.next_event() can be called without blocking."""
- return self.display.pending_events()
+ return self.display.pending_events()
def has_extension(self, extension):
"""Check if both the server and the client library support the X
extension named extension."""
- return extension in self.extensions
-
+ return extension in self.extensions
+
def create_resource_object(self, type, id):
"""Create a resource object of type for the integer id. type
should be one of the following strings:
@@ -207,113 +207,113 @@ def create_resource_object(self, type, id):
class directly, since any X extensions dynamically added by the
library will not be available.
"""
- return self.display.resource_classes[type](self.display, id)
+ return self.display.resource_classes[type](self.display, id)
# We need this to handle display extension methods
def __getattr__(self, attr):
- try:
- function = self.display_extension_methods[attr]
- return new.instancemethod(function, self, self.__class__)
- except KeyError:
- raise AttributeError(attr)
-
+ try:
+ function = self.display_extension_methods[attr]
+ return new.instancemethod(function, self, self.__class__)
+ except KeyError:
+ raise AttributeError(attr)
+
###
### display information retrieval
###
def screen(self, sno = None):
- if sno is None:
- return self.display.info.roots[self.display.default_screen]
- else:
- return self.display.info.roots[sno]
+ if sno is None:
+ return self.display.info.roots[self.display.default_screen]
+ else:
+ return self.display.info.roots[sno]
def screen_count(self):
"""Return the total number of screens on the display."""
- return len(self.display.info.roots)
+ return len(self.display.info.roots)
def get_default_screen(self):
"""Return the number of the default screen, extracted from the
display name."""
- return self.display.get_default_screen()
-
+ return self.display.get_default_screen()
+
###
### Extension module interface
###
def extension_add_method(self, object, name, function):
- """extension_add_method(object, name, function)
-
- Add an X extension module method. OBJECT is the type of
- object to add the function to, a string from this list:
-
- display
- resource
- drawable
- window
- pixmap
- fontable
- font
- gc
- colormap
- cursor
-
- NAME is the name of the method, a string. FUNCTION is a
- normal function whose first argument is a 'self'.
- """
-
- if object == 'display':
- if hasattr(self, name):
- raise error.MethodOverrideError('attempting to replace display method: %s' % name)
-
- self.display_extension_methods[name] = function
-
- else:
- types = (object, ) + _resource_hierarchy.get(object, ())
- for type in types:
- cls = _resource_baseclasses[type]
- if hasattr(cls, name):
- raise error.MethodOverrideError('attempting to replace %s method: %s' % (type, name))
-
- method = new.instancemethod(function, None, cls)
-
- # Maybe should check extension overrides too
- try:
- self.class_extension_dicts[type][name] = method
- except KeyError:
- self.class_extension_dicts[type] = { name: method }
-
+ """extension_add_method(object, name, function)
+
+ Add an X extension module method. OBJECT is the type of
+ object to add the function to, a string from this list:
+
+ display
+ resource
+ drawable
+ window
+ pixmap
+ fontable
+ font
+ gc
+ colormap
+ cursor
+
+ NAME is the name of the method, a string. FUNCTION is a
+ normal function whose first argument is a 'self'.
+ """
+
+ if object == 'display':
+ if hasattr(self, name):
+ raise error.MethodOverrideError('attempting to replace display method: %s' % name)
+
+ self.display_extension_methods[name] = function
+
+ else:
+ types = (object, ) + _resource_hierarchy.get(object, ())
+ for type in types:
+ cls = _resource_baseclasses[type]
+ if hasattr(cls, name):
+ raise error.MethodOverrideError('attempting to replace %s method: %s' % (type, name))
+
+ method = new.instancemethod(function, None, cls)
+
+ # Maybe should check extension overrides too
+ try:
+ self.class_extension_dicts[type][name] = method
+ except KeyError:
+ self.class_extension_dicts[type] = { name: method }
+
def extension_add_event(self, code, evt, name = None):
- """extension_add_event(code, evt, [name])
+ """extension_add_event(code, evt, [name])
- Add an extension event. CODE is the numeric code, and EVT is
- the event class. EVT will be cloned, and the attribute _code
- of the new event class will be set to CODE.
+ Add an extension event. CODE is the numeric code, and EVT is
+ the event class. EVT will be cloned, and the attribute _code
+ of the new event class will be set to CODE.
- If NAME is ommitted, it will be set to the name of EVT. This
- name is used to insert an entry in the DictWrapper
- extension_event.
- """
+ If NAME is ommitted, it will be set to the name of EVT. This
+ name is used to insert an entry in the DictWrapper
+ extension_event.
+ """
+
+ newevt = new.classobj(evt.__name__, evt.__bases__,
+ evt.__dict__.copy())
+ newevt._code = code
+
+ self.display.add_extension_event(code, newevt)
+
+ if name is None:
+ name = evt.__name__
- newevt = new.classobj(evt.__name__, evt.__bases__,
- evt.__dict__.copy())
- newevt._code = code
-
- self.display.add_extension_event(code, newevt)
+ setattr(self.extension_event, name, code)
- if name is None:
- name = evt.__name__
-
- setattr(self.extension_event, name, code)
-
def add_extension_error(self, code, err):
- """add_extension_error(code, err)
+ """add_extension_error(code, err)
- Add an extension error. CODE is the numeric code, and ERR is
- the error class.
- """
-
- self.display.add_extension_error(code, err)
+ Add an extension error. CODE is the numeric code, and ERR is
+ the error class.
+ """
+
+ self.display.add_extension_error(code, err)
###
### keymap cache implementation
@@ -334,107 +334,107 @@ def keycode_to_keysym(self, keycode, index):
Normally index 0 is unshifted, 1 is shifted, 2 is alt grid, and 3
is shift+alt grid. If that key entry is not bound, X.NoSymbol is
returned."""
- try:
- return self._keymap_codes[keycode][index]
- except IndexError:
- return X.NoSymbol
+ try:
+ return self._keymap_codes[keycode][index]
+ except IndexError:
+ return X.NoSymbol
def keysym_to_keycode(self, keysym):
"""Look up the primary keycode that is bound to keysym. If
several keycodes are found, the one with the lowest index and
lowest code is returned. If keysym is not bound to any key, 0 is
returned."""
- try:
- return self._keymap_syms[keysym][0][1]
- except (KeyError, IndexError):
- return 0
+ try:
+ return self._keymap_syms[keysym][0][1]
+ except (KeyError, IndexError):
+ return 0
def keysym_to_keycodes(self, keysym):
"""Look up all the keycodes that is bound to keysym. A list of
tuples (keycode, index) is returned, sorted primarily on the
lowest index and secondarily on the lowest keycode."""
- try:
- # Copy the map list, reversing the arguments
- return map(lambda x: (x[1], x[0]), self._keymap_syms[keysym])
- except KeyError:
- return []
-
+ try:
+ # Copy the map list, reversing the arguments
+ return map(lambda x: (x[1], x[0]), self._keymap_syms[keysym])
+ except KeyError:
+ return []
+
def refresh_keyboard_mapping(self, evt):
"""This method should be called once when a MappingNotify event
is received, to update the keymap cache. evt should be the event
object."""
- if isinstance(evt, event.MappingNotify):
- if evt.request == X.MappingKeyboard:
- self._update_keymap(evt.first_keycode, evt.count)
- else:
- raise TypeError('expected a MappingNotify event')
-
+ if isinstance(evt, event.MappingNotify):
+ if evt.request == X.MappingKeyboard:
+ self._update_keymap(evt.first_keycode, evt.count)
+ else:
+ raise TypeError('expected a MappingNotify event')
+
def _update_keymap(self, first_keycode, count):
- """Internal function, called to refresh the keymap cache.
- """
-
- # Delete all sym->code maps for the changed codes
-
- lastcode = first_keycode + count
- for keysym, codes in self._keymap_syms.items():
- i = 0
- while i < len(codes):
- code = codes[i][1]
- if code >= first_keycode and code < lastcode:
- del codes[i]
- else:
- i = i + 1
-
- # Get the new keyboard mapping
- keysyms = self.get_keyboard_mapping(first_keycode, count)
-
- # Replace code->sym map with the new map
- self._keymap_codes[first_keycode:lastcode] = keysyms
-
- # Update sym->code map
- code = first_keycode
- for syms in keysyms:
- index = 0
- for sym in syms:
- if sym != X.NoSymbol:
- if self._keymap_syms.has_key(sym):
- symcodes = self._keymap_syms[sym]
- symcodes.append((index, code))
- symcodes.sort()
- else:
- self._keymap_syms[sym] = [(index, code)]
-
- index = index + 1
- code = code + 1
+ """Internal function, called to refresh the keymap cache.
+ """
+
+ # Delete all sym->code maps for the changed codes
+
+ lastcode = first_keycode + count
+ for keysym, codes in self._keymap_syms.items():
+ i = 0
+ while i < len(codes):
+ code = codes[i][1]
+ if code >= first_keycode and code < lastcode:
+ del codes[i]
+ else:
+ i = i + 1
+
+ # Get the new keyboard mapping
+ keysyms = self.get_keyboard_mapping(first_keycode, count)
+
+ # Replace code->sym map with the new map
+ self._keymap_codes[first_keycode:lastcode] = keysyms
+
+ # Update sym->code map
+ code = first_keycode
+ for syms in keysyms:
+ index = 0
+ for sym in syms:
+ if sym != X.NoSymbol:
+ if self._keymap_syms.has_key(sym):
+ symcodes = self._keymap_syms[sym]
+ symcodes.append((index, code))
+ symcodes.sort()
+ else:
+ self._keymap_syms[sym] = [(index, code)]
+
+ index = index + 1
+ code = code + 1
###
### client-internal keysym to string translations
###
-
+
def lookup_string(self, keysym):
- """Return a string corresponding to KEYSYM, or None if no
- reasonable translation is found.
- """
- s = self.keysym_translations.get(keysym)
- if s is not None:
- return s
-
- import Xlib.XK
- return Xlib.XK.keysym_to_string(keysym)
-
+ """Return a string corresponding to KEYSYM, or None if no
+ reasonable translation is found.
+ """
+ s = self.keysym_translations.get(keysym)
+ if s is not None:
+ return s
+
+ import Xlib.XK
+ return Xlib.XK.keysym_to_string(keysym)
+
def rebind_string(self, keysym, newstring):
- """Change the translation of KEYSYM to NEWSTRING.
- If NEWSTRING is None, remove old translation if any.
- """
- if newstring is None:
- try:
- del self.keysym_translations[keysym]
- except KeyError:
- pass
- else:
- self.keysym_translations[keysym] = newstring
-
-
+ """Change the translation of KEYSYM to NEWSTRING.
+ If NEWSTRING is None, remove old translation if any.
+ """
+ if newstring is None:
+ try:
+ del self.keysym_translations[keysym]
+ except KeyError:
+ pass
+ else:
+ self.keysym_translations[keysym] = newstring
+
+
###
### X requests
###
@@ -451,84 +451,84 @@ def intern_atom(self, name, only_if_exists = 0):
def get_atom(self, atom, only_if_exists = 0):
"""Alias for intern_atom, using internal cache"""
return self.display.get_atom(atom, only_if_exists)
-
+
def get_atom_name(self, atom):
"""Look up the name of atom, returning it as a string. Will raise
BadAtom if atom does not exist."""
- r = request.GetAtomName(display = self.display,
- atom = atom)
- return r.name
+ r = request.GetAtomName(display = self.display,
+ atom = atom)
+ return r.name
def get_selection_owner(self, selection):
"""Return the window that owns selection (an atom), or X.NONE if
there is no owner for the selection. Can raise BadAtom."""
- r = request.GetSelectionOwner(display = self.display,
- selection = selection)
- return r.owner
+ r = request.GetSelectionOwner(display = self.display,
+ selection = selection)
+ return r.owner
- def send_event(self, destination, event, event_mask = 0, propagate = 0,
- onerror = None):
+ def send_event(self, destination, event, event_mask = 0, propagate = 0,
+ onerror = None):
"""Send a synthetic event to the window destination which can be
a window object, or X.PointerWindow or X.InputFocus. event is the
event object to send, instantiated from one of the classes in
protocol.events. See XSendEvent(3X11) for details.
There is also a Window.send_event() method."""
- request.SendEvent(display = self.display,
- onerror = onerror,
- propagate = propagate,
- destination = destination,
- event_mask = event_mask,
- event = event)
+ request.SendEvent(display = self.display,
+ onerror = onerror,
+ propagate = propagate,
+ destination = destination,
+ event_mask = event_mask,
+ event = event)
def ungrab_pointer(self, time, onerror = None):
"""elease a grabbed pointer and any queued events. See
XUngrabPointer(3X11)."""
- request.UngrabPointer(display = self.display,
- onerror = onerror,
- time = time)
-
+ request.UngrabPointer(display = self.display,
+ onerror = onerror,
+ time = time)
+
def change_active_pointer_grab(self, event_mask, cursor, time, onerror = None):
"""Change the dynamic parameters of a pointer grab. See
XChangeActivePointerGrab(3X11)."""
- request.ChangeActivePointerGrab(display = self.display,
- onerror = onerror,
- cursor = cursor,
- time = time,
- event_mask = event_mask)
-
+ request.ChangeActivePointerGrab(display = self.display,
+ onerror = onerror,
+ cursor = cursor,
+ time = time,
+ event_mask = event_mask)
+
def ungrab_keyboard(self, time, onerror = None):
"""Ungrab a grabbed keyboard and any queued events. See
XUngrabKeyboard(3X11)."""
- request.UngrabKeyboard(display = self.display,
- onerror = onerror,
- time = time)
+ request.UngrabKeyboard(display = self.display,
+ onerror = onerror,
+ time = time)
def allow_events(self, mode, time, onerror = None):
"""Release some queued events. mode should be one of
X.AsyncPointer, X.SyncPointer, X.AsyncKeyboard, X.SyncKeyboard,
X.ReplayPointer, X.ReplayKeyboard, X.AsyncBoth, or X.SyncBoth.
time should be a timestamp or X.CurrentTime."""
- request.AllowEvents(display = self.display,
- onerror = onerror,
- mode = mode,
- time = time)
+ request.AllowEvents(display = self.display,
+ onerror = onerror,
+ mode = mode,
+ time = time)
def grab_server(self, onerror = None):
"""Disable processing of requests on all other client connections
until the server is ungrabbed. Server grabbing should be avoided
as much as possible."""
- request.GrabServer(display = self.display,
- onerror = onerror)
+ request.GrabServer(display = self.display,
+ onerror = onerror)
def ungrab_server(self, onerror = None):
"""Release the server if it was previously grabbed by this client."""
- request.UngrabServer(display = self.display,
- onerror = onerror)
+ request.UngrabServer(display = self.display,
+ onerror = onerror)
def warp_pointer(self, x, y, src_window = X.NONE, src_x = 0, src_y = 0,
- src_width = 0, src_height = 0, onerror = None):
+ src_width = 0, src_height = 0, onerror = None):
"""Move the pointer relative its current position by the offsets
(x, y). However, if src_window is a window the pointer is only
moved if the specified rectangle in src_window contains it. If
@@ -536,16 +536,16 @@ def warp_pointer(self, x, y, src_window = X.NONE, src_x = 0, src_y = 0,
src_x. src_height is treated in a similar way.
To move the pointer to absolute coordinates, use Window.warp_pointer()."""
- request.WarpPointer(display = self.display,
- onerror = onerror,
- src_window = src_window,
- dst_window = X.NONE,
- src_x = src_x,
- src_y = src_y,
- src_width = src_width,
- src_height = src_height,
- dst_x = x,
- dst_y = y)
+ request.WarpPointer(display = self.display,
+ onerror = onerror,
+ src_window = src_window,
+ dst_window = X.NONE,
+ src_x = src_x,
+ src_y = src_y,
+ src_width = src_width,
+ src_height = src_height,
+ dst_x = x,
+ dst_y = y)
def set_input_focus(self, focus, revert_to, time, onerror = None):
"""Set input focus to focus, which should be a window,
@@ -555,22 +555,22 @@ def set_input_focus(self, focus, revert_to, time, onerror = None):
XSetInputFocus(3X11) for details.
There is also a Window.set_input_focus()."""
- request.SetInputFocus(display = self.display,
- onerror = onerror,
- revert_to = revert_to,
- focus = focus,
- time = time)
+ request.SetInputFocus(display = self.display,
+ onerror = onerror,
+ revert_to = revert_to,
+ focus = focus,
+ time = time)
def get_input_focus(self):
"""Return an object with the following attributes:
focus
The window which currently holds the input
- focus, X.NONE or X.PointerRoot.
+ focus, X.NONE or X.PointerRoot.
revert_to
Where the focus will revert, one of X.RevertToParent,
RevertToPointerRoot, or RevertToNone. """
- return request.GetInputFocus(display = self.display)
+ return request.GetInputFocus(display = self.display)
def query_keymap(self):
"""Return a bit vector for the logical state of the keyboard,
@@ -578,35 +578,35 @@ def query_keymap(self):
currently pressed down. The vector is represented as a list of 32
integers. List item N contains the bits for keys 8N to 8N + 7
with the least significant bit in the byte representing key 8N."""
- r = request.QueryKeymap(display = self.display)
- return r.map
+ r = request.QueryKeymap(display = self.display)
+ return r.map
def open_font(self, name):
"""Open the font identifed by the pattern name and return its
font object. If name does not match any font, None is returned."""
- fid = self.display.allocate_resource_id()
- ec = error.CatchError(error.BadName)
-
- request.OpenFont(display = self.display,
- onerror = ec,
- fid = fid,
- name = name)
- self.sync()
-
- if ec.get_error():
- self.display.free_resource_id(fid)
- return None
- else:
- cls = self.display.get_resource_class('font', xobject.fontable.Font)
- return cls(self.display, fid, owner = 1)
+ fid = self.display.allocate_resource_id()
+ ec = error.CatchError(error.BadName)
+
+ request.OpenFont(display = self.display,
+ onerror = ec,
+ fid = fid,
+ name = name)
+ self.sync()
+
+ if ec.get_error():
+ self.display.free_resource_id(fid)
+ return None
+ else:
+ cls = self.display.get_resource_class('font', xobject.fontable.Font)
+ return cls(self.display, fid, owner = 1)
def list_fonts(self, pattern, max_names):
"""Return a list of font names matching pattern. No more than
max_names will be returned."""
- r = request.ListFonts(display = self.display,
- max_names = max_names,
- pattern = pattern)
- return r.fonts
+ r = request.ListFonts(display = self.display,
+ max_names = max_names,
+ pattern = pattern)
+ return r.fonts
def list_fonts_with_info(self, pattern, max_names):
"""Return a list of fonts matching pattern. No more than
@@ -614,7 +614,7 @@ def list_fonts_with_info(self, pattern, max_names):
and has the following properties:
name
- The name of the font.
+ The name of the font.
min_bounds
max_bounds
min_char_or_byte2
@@ -628,86 +628,86 @@ def list_fonts_with_info(self, pattern, max_names):
font_descent
replies_hint
See the descripton of XFontStruct in XGetFontProperty(3X11)
- for details on these values.
+ for details on these values.
properties
A list of properties. Each entry has two attributes:
name
- The atom identifying this property.
+ The atom identifying this property.
value
A 32-bit unsigned value.
"""
- return request.ListFontsWithInfo(display = self.display,
- max_names = max_names,
- pattern = pattern)
+ return request.ListFontsWithInfo(display = self.display,
+ max_names = max_names,
+ pattern = pattern)
def set_font_path(self, path, onerror = None):
"""Set the font path to path, which should be a list of strings.
If path is empty, the default font path of the server will be
restored."""
- request.SetFontPath(display = self.display,
- onerror = onerror,
- path = path)
+ request.SetFontPath(display = self.display,
+ onerror = onerror,
+ path = path)
def get_font_path(self):
"""Return the current font path as a list of strings."""
- r = request.GetFontPath(display = self.display)
- return r.paths
+ r = request.GetFontPath(display = self.display)
+ return r.paths
def query_extension(self, name):
"""Ask the server if it supports the extension name. If it is
supported an object with the following attributes is returned:
major_opcode
- The major opcode that the requests of this extension uses.
+ The major opcode that the requests of this extension uses.
first_event
- The base event code if the extension have additional events, or 0.
+ The base event code if the extension have additional events, or 0.
first_error
- The base error code if the extension have additional errors, or 0.
+ The base error code if the extension have additional errors, or 0.
If the extension is not supported, None is returned."""
- r = request.QueryExtension(display = self.display,
- name = name)
- if r.present:
- return r
- else:
- return None
-
+ r = request.QueryExtension(display = self.display,
+ name = name)
+ if r.present:
+ return r
+ else:
+ return None
+
def list_extensions(self):
"""Return a list of all the extensions provided by the server."""
- r = request.ListExtensions(display = self.display)
- return r.names
+ r = request.ListExtensions(display = self.display)
+ return r.names
def change_keyboard_mapping(self, first_keycode, keysyms, onerror = None):
"""Modify the keyboard mapping, starting with first_keycode.
keysyms is a list of tuples of keysyms. keysyms[n][i] will be
assigned to keycode first_keycode+n at index i."""
- request.ChangeKeyboardMapping(display = self.display,
- onerror = onerror,
- first_keycode = first_keycode,
- keysyms = keysyms)
+ request.ChangeKeyboardMapping(display = self.display,
+ onerror = onerror,
+ first_keycode = first_keycode,
+ keysyms = keysyms)
def get_keyboard_mapping(self, first_keycode, count):
"""Return the current keyboard mapping as a list of tuples,
starting at first_keycount and no more than count."""
- r = request.GetKeyboardMapping(display = self.display,
- first_keycode = first_keycode,
- count = count)
- return r.keysyms
+ r = request.GetKeyboardMapping(display = self.display,
+ first_keycode = first_keycode,
+ count = count)
+ return r.keysyms
def change_keyboard_control(self, onerror = None, **keys):
"""Change the parameters provided as keyword arguments:
key_click_percent
The volume of key clicks between 0 (off) and 100 (load).
- -1 will restore default setting.
+ -1 will restore default setting.
bell_percent
- The base volume of the bell, coded as above.
+ The base volume of the bell, coded as above.
bell_pitch
- The pitch of the bell in Hz, -1 restores the default.
+ The pitch of the bell in Hz, -1 restores the default.
bell_duration
The duration of the bell in milliseconds, -1 restores
- the default.
+ the default.
led
led_mode
@@ -721,27 +721,27 @@ def change_keyboard_control(self, onerror = None, **keys):
X.AutoRepeatModeOn, or X.AutoRepeatModeDefault. If key is
provided, that key will be modified, otherwise the global
state for the entire keyboard will be modified."""
- request.ChangeKeyboardControl(display = self.display,
- onerror = onerror,
- attrs = keys)
+ request.ChangeKeyboardControl(display = self.display,
+ onerror = onerror,
+ attrs = keys)
def get_keyboard_control(self):
"""Return an object with the following attributes:
global_auto_repeat
- X.AutoRepeatModeOn or X.AutoRepeatModeOff.
+ X.AutoRepeatModeOn or X.AutoRepeatModeOff.
auto_repeats
A list of 32 integers. List item N contains the bits for keys
8N to 8N + 7 with the least significant bit in the byte
representing key 8N. If a bit is on, autorepeat is enabled
- for the corresponding key.
+ for the corresponding key.
led_mask
- A 32-bit mask indicating which LEDs are on.
+ A 32-bit mask indicating which LEDs are on.
key_click_percent
- The volume of key click, from 0 to 100.
+ The volume of key click, from 0 to 100.
bell_percent
@@ -749,41 +749,41 @@ def get_keyboard_control(self):
bell_duration
The volume, pitch and duration of the bell. """
- return request.GetKeyboardControl(display = self.display)
-
+ return request.GetKeyboardControl(display = self.display)
+
def bell(self, percent = 0, onerror = None):
"""Ring the bell at the volume percent which is relative the base
volume. See XBell(3X11)."""
- request.Bell(display = self.display,
- onerror = onerror,
- percent = percent)
-
+ request.Bell(display = self.display,
+ onerror = onerror,
+ percent = percent)
+
def change_pointer_control(self, accel = None, threshold = None, onerror = None):
"""To change the pointer acceleration, set accel to a tuple (num,
denum). The pointer will then move num/denum times the normal
speed if it moves beyond the threshold number of pixels at once.
To change the threshold, set it to the number of pixels. -1
restores the default."""
- if accel is None:
- do_accel = 0
- accel_num = 0
- accel_denum = 0
- else:
- do_accel = 1
- accel_num, accel_denum = accel
-
- if threshold is None:
- do_threshold = 0
- else:
- do_threshold = 1
-
- request.ChangePointerControl(display = self.display,
- onerror = onerror,
- do_accel = do_accel,
- do_thres = do_threshold,
- accel_num = accel_num,
- accel_denum = accel_denum,
- threshold = threshold)
+ if accel is None:
+ do_accel = 0
+ accel_num = 0
+ accel_denum = 0
+ else:
+ do_accel = 1
+ accel_num, accel_denum = accel
+
+ if threshold is None:
+ do_threshold = 0
+ else:
+ do_threshold = 1
+
+ request.ChangePointerControl(display = self.display,
+ onerror = onerror,
+ do_accel = do_accel,
+ do_thres = do_threshold,
+ accel_num = accel_num,
+ accel_denum = accel_denum,
+ threshold = threshold)
def get_pointer_control(self):
"""Return an object with the following attributes:
@@ -791,27 +791,27 @@ def get_pointer_control(self):
accel_num
accel_denom
- The acceleration as numerator/denumerator.
+ The acceleration as numerator/denumerator.
threshold
The number of pixels the pointer must move before the
acceleration kicks in."""
- return request.GetPointerControl(display = self.display)
+ return request.GetPointerControl(display = self.display)
def set_screen_saver(self, timeout, interval, prefer_blank, allow_exposures, onerror = None):
"""See XSetScreenSaver(3X11)."""
- request.SetScreenSaver(display = self.display,
- onerror = onerror,
- timeout = timeout,
- interval = interval,
- prefer_blank = prefer_blank,
- allow_exposures = allow_exposures)
+ request.SetScreenSaver(display = self.display,
+ onerror = onerror,
+ timeout = timeout,
+ interval = interval,
+ prefer_blank = prefer_blank,
+ allow_exposures = allow_exposures)
def get_screen_saver(self):
"""Return an object with the attributes timeout, interval,
prefer_blanking, allow_exposures. See XGetScreenSaver(3X11) for
details."""
- return request.GetScreenSaver(display = self.display)
+ return request.GetScreenSaver(display = self.display)
def change_hosts(self, mode, host_family, host, onerror = None):
"""mode is either X.HostInsert or X.HostDelete. host_family is
@@ -819,51 +819,51 @@ def change_hosts(self, mode, host_family, host, onerror = None):
host is a list of bytes. For the Internet family, it should be the
four bytes of an IPv4 address."""
- request.ChangeHosts(display = self.display,
- onerror = onerror,
- mode = mode,
- host_family = host_family,
- host = host)
+ request.ChangeHosts(display = self.display,
+ onerror = onerror,
+ mode = mode,
+ host_family = host_family,
+ host = host)
def list_hosts(self):
"""Return an object with the following attributes:
mode
- X.EnableAccess if the access control list is used, X.DisableAccess otherwise.
+ X.EnableAccess if the access control list is used, X.DisableAccess otherwise.
hosts
The hosts on the access list. Each entry has the following attributes:
family
- X.FamilyInternet, X.FamilyDECnet, or X.FamilyChaos.
+ X.FamilyInternet, X.FamilyDECnet, or X.FamilyChaos.
name
- A list of byte values, the coding depends on family. For the Internet family, it is the 4 bytes of an IPv4 address.
+ A list of byte values, the coding depends on family. For the Internet family, it is the 4 bytes of an IPv4 address.
"""
- return request.ListHosts(display = self.display)
-
+ return request.ListHosts(display = self.display)
+
def set_access_control(self, mode, onerror = None):
"""Enable use of access control lists at connection setup if mode
is X.EnableAccess, disable if it is X.DisableAccess."""
- request.SetAccessControl(display = self.display,
- onerror = onerror,
- mode = mode)
+ request.SetAccessControl(display = self.display,
+ onerror = onerror,
+ mode = mode)
def set_close_down_mode(self, mode, onerror = None):
"""Control what will happen with the client's resources at
connection close. The default is X.DestroyAll, the other values
are X.RetainPermanent and X.RetainTemporary."""
- request.SetCloseDownMode(display = self.display,
- onerror = onerror,
- mode = mode)
-
+ request.SetCloseDownMode(display = self.display,
+ onerror = onerror,
+ mode = mode)
+
def force_screen_saver(self, mode, onerror = None):
"""If mode is X.ScreenSaverActive the screen saver is activated.
If it is X.ScreenSaverReset, the screen saver is deactivated as
if device input had been received."""
- request.ForceScreenSaver(display = self.display,
- onerror = onerror,
- mode = mode)
-
+ request.ForceScreenSaver(display = self.display,
+ onerror = onerror,
+ mode = mode)
+
def set_pointer_mapping(self, map):
"""Set the mapping of the pointer buttons. map is a list of
logical button numbers. map must be of the same length as the
@@ -878,15 +878,15 @@ def set_pointer_mapping(self, map):
logically in the down state, X.MappingBusy is returned and the
mapping is not changed. Otherwise the mapping is changed and
X.MappingSuccess is returned."""
- r = request.SetPointerMapping(display = self.display,
- map = map)
- return r.status
+ r = request.SetPointerMapping(display = self.display,
+ map = map)
+ return r.status
def get_pointer_mapping(self):
"""Return a list of the pointer button mappings. Entry N in the
list sets the logical button number for the physical button N+1."""
- r = request.GetPointerMapping(display = self.display)
- return r.map
+ r = request.GetPointerMapping(display = self.display)
+ return r.map
def set_modifier_mapping(self, keycodes):
"""Set the keycodes for the eight modifiers X.Shift, X.Lock,
@@ -899,19 +899,18 @@ def set_modifier_mapping(self, keycodes):
the mapping is not changed. If the mapping violates some server
restriction, X.MappingFailed is returned. Otherwise the mapping
is changed and X.MappingSuccess is returned."""
- r = request.SetModifierMapping(display = self.display,
- keycodes = keycodes)
- return r.status
+ r = request.SetModifierMapping(display = self.display,
+ keycodes = keycodes)
+ return r.status
def get_modifier_mapping(self):
"""Return a list of eight lists, one for each modifier. The list
can be indexed using X.ShiftMapIndex, X.Mod1MapIndex, and so on.
The sublists list the keycodes bound to that modifier."""
- r = request.GetModifierMapping(display = self.display)
- return r.keycodes
+ r = request.GetModifierMapping(display = self.display)
+ return r.keycodes
def no_operation(self, onerror = None):
"""Do nothing but send a request to the server."""
- request.NoOperation(display = self.display,
- onerror = onerror)
-
+ request.NoOperation(display = self.display,
+ onerror = onerror)
117 Xlib/error.py
View
@@ -1,4 +1,4 @@
-# $Id: error.py,v 1.5 2003-01-29 23:53:31 petli Exp $
+# $Id: error.py,v 1.6 2007-06-10 14:11:58 mggrant Exp $
#
# Xlib.error -- basic error classes
#
@@ -30,29 +30,29 @@
class DisplayError(Exception):
def __init__(self, display):
- self.display = display
-
+ self.display = display
+
def __str__(self):
- return 'Display error "%s"' % self.display
-
+ return 'Display error "%s"' % self.display
+
class DisplayNameError(DisplayError):
def __str__(self):
- return 'Bad display name "%s"' % self.display
-
+ return 'Bad display name "%s"' % self.display
+
class DisplayConnectionError(DisplayError):
def __init__(self, display, msg):
- self.display = display
- self.msg = msg
+ self.display = display
+ self.msg = msg
def __str__(self):
- return 'Can\'t connect to display "%s": %s' % (self.display, self.msg)
+ return 'Can\'t connect to display "%s": %s' % (self.display, self.msg)
class ConnectionClosedError(Exception):
def __init__(self, whom):
- self.whom = whom
+ self.whom = whom
def __str__(self):
- return 'Display connection closed by %s' % self.whom
+ return 'Display connection closed by %s' % self.whom
class XauthError(Exception): pass
@@ -60,38 +60,38 @@ class XNoAuthError(Exception): pass
class ResourceIDError(Exception): pass
-
+
class XError(rq.GetAttrData, Exception):
_fields = rq.Struct( rq.Card8('type'), # Always 0
- rq.Card8('code'),
- rq.Card16('sequence_number'),
- rq.Card32('resource_id'),
- rq.Card16('minor_opcode'),
- rq.Card8('major_opcode'),
- rq.Pad(21)
- )
+ rq.Card8('code'),
+ rq.Card16('sequence_number'),
+ rq.Card32('resource_id'),
+ rq.Card16('minor_opcode'),
+ rq.Card8('major_opcode'),
+ rq.Pad(21)
+ )
def __init__(self, display, data):
- self._data, data = self._fields.parse_binary(data, display, rawdict = 1)
-
+ self._data, data = self._fields.parse_binary(data, display, rawdict = 1)
+
def __str__(self):
- s = []
- for f in ('code', 'resource_id', 'sequence_number',
- 'major_opcode', 'minor_opcode'):
- s.append('%s = %s' % (f, self._data[f]))
-
- return '%s: %s' % (self.__class__, string.join(s, ', '))
+ s = []
+ for f in ('code', 'resource_id', 'sequence_number',
+ 'major_opcode', 'minor_opcode'):
+ s.append('%s = %s' % (f, self._data[f]))
+
+ return '%s: %s' % (self.__class__, string.join(s, ', '))
class XResourceError(XError):
_fields = rq.Struct( rq.Card8('type'), # Always 0
- rq.Card8('code'),
- rq.Card16('sequence_number'),
- rq.Resource('resource_id'),
- rq.Card16('minor_opcode'),
- rq.Card8('major_opcode'),
- rq.Pad(21)
- )
-
+ rq.Card8('code'),
+ rq.Card16('sequence_number'),
+ rq.Resource('resource_id'),
+ rq.Card16('minor_opcode'),
+ rq.Card8('major_opcode'),
+ rq.Pad(21)
+ )
+
class BadRequest(XError): pass
class BadValue(XError): pass
class BadWindow(XResourceError): pass
@@ -128,36 +128,35 @@ class BadImplementation(XError): pass
X.BadName: BadName,
X.BadLength: BadLength,
X.BadImplementation: BadImplementation,
- }
+ }
class CatchError:
def __init__(self, *errors):
- self.error_types = errors
- self.error = None
- self.request = None
-
+ self.error_types = errors
+ self.error = None
+ self.request = None
+
def __call__(self, error, request):
- if self.error_types:
- for etype in self.error_types:
- if isinstance(error, etype):
- self.error = error
- self.request = request
- return 1
-
- return 0
- else:
- self.error = error
- self.request = request
- return 1
-
+ if self.error_types:
+ for etype in self.error_types:
+ if isinstance(error, etype):
+ self.error = error
+ self.request = request
+ return 1
+
+ return 0
+ else:
+ self.error = error
+ self.request = request
+ return 1
+
def get_error(self):
- return self.error
+ return self.error
def get_request(self):
- return self.request
+ return self.request
def reset(self):
- self.error = None
- self.request = None
-
+ self.error = None
+ self.request = None
5 Xlib/ext/__init__.py
View
@@ -1,6 +1,6 @@
-# $Id: __init__.py,v 1.4 2006-11-22 13:39:29 mggrant Exp $
+# $Id: __init__.py,v 1.5 2007-06-10 14:11:58 mggrant Exp $
#
-# Xlib.ext.__init__ -- X extension modules
+# Xlib.ext.__init__ -- X extension modules
#
# Copyright (C) 2000 Peter Liljenberg <petli@ctrl-c.liu.se>
#
@@ -30,4 +30,3 @@
]
__all__ = map(lambda x: x[1], __extensions__)
-
390 Xlib/ext/record.py
View
@@ -1,4 +1,4 @@
-# $Id: record.py,v 1.1 2006-11-22 13:39:29 mggrant Exp $
+# $Id: record.py,v 1.2 2007-06-10 14:11:58 mggrant Exp $
#
# Xlib.ext.record -- RECORD extension module
#
@@ -23,258 +23,258 @@
extname = 'RECORD'
-FromServerTime = 0x01
-FromClientTime = 0x02
-FromClientSequence = 0x04
+FromServerTime = 0x01
+FromClientTime = 0x02
+FromClientSequence = 0x04
-CurrentClients = 1
-FutureClients = 2
-AllClients = 3
+CurrentClients = 1
+FutureClients = 2
+AllClients = 3
-FromServer = 0
+FromServer = 0
FromClient = 1
ClientStarted = 2
ClientDied = 3
-StartOfData = 4
-EndOfData = 5
+StartOfData = 4
+EndOfData = 5
Record_Range8 = rq.Struct(
- rq.Card8('first'),
- rq.Card8('last'))
+ rq.Card8('first'),
+ rq.Card8('last'))
Record_Range16 = rq.Struct(
- rq.Card16('first'),
- rq.Card16('last'))
+ rq.Card16('first'),
+ rq.Card16('last'))
Record_ExtRange = rq.Struct(
- rq.Object('major_range', Record_Range8),
- rq.Object('minor_range', Record_Range16))
+ rq.Object('major_range', Record_Range8),
+ rq.Object('minor_range', Record_Range16))
Record_Range = rq.Struct(
- rq.Object('core_requests', Record_Range8),
- rq.Object('core_replies', Record_Range8),
- rq.Object('ext_requests', Record_ExtRange),
- rq.Object('ext_replies', Record_ExtRange),
- rq.Object('delivered_events', Record_Range8),
- rq.Object('device_events', Record_Range8),
- rq.Object('errors', Record_Range8),
- rq.Bool('client_started'),
- rq.Bool('client_died'))
+ rq.Object('core_requests', Record_Range8),
+ rq.Object('core_replies', Record_Range8),
+ rq.Object('ext_requests', Record_ExtRange),
+ rq.Object('ext_replies', Record_ExtRange),
+ rq.Object('delivered_events', Record_Range8),
+ rq.Object('device_events', Record_Range8),
+ rq.Object('errors', Record_Range8),
+ rq.Bool('client_started'),
+ rq.Bool('client_died'))
Record_ClientInfo = rq.Struct(
- rq.Card32('client_resource'),
- rq.LengthOf('ranges', 4),
- rq.List('ranges', Record_Range))
+ rq.Card32('client_resource'),
+ rq.LengthOf('ranges', 4),
+ rq.List('ranges', Record_Range))
class RawField(rq.ValueField):
- """A field with raw data, stored as a string"""
+ """A field with raw data, stored as a string"""
- structcode = None
+ structcode = None
- def pack_value(self, val):
- return val, len(val), None
+ def pack_value(self, val):
+ return val, len(val), None
- def parse_binary_value(self, data, display, length, format):
- return str(data), ''
+ def parse_binary_value(self, data, display, length, format):
+ return str(data), ''
class GetVersion(rq.ReplyRequest):
- _request = rq.Struct(
- rq.Card8('opcode'),
- rq.Opcode(0),
- rq.RequestLength(),
- rq.Card16('major_version'),
- rq.Card16('minor_version'))
- _reply = rq.Struct(
- rq.Pad(2),
- rq.Card16('sequence_number'),
- rq.ReplyLength(),
- rq.Card16('major_version'),
- rq.Card16('minor_version'),
- rq.Pad(20))
+ _request = rq.Struct(
+ rq.Card8('opcode'),
+ rq.Opcode(0),
+ rq.RequestLength(),
+ rq.Card16('major_version'),
+ rq.Card16('minor_version'))
+ _reply = rq.Struct(
+ rq.Pad(2),
+ rq.Card16('sequence_number'),
+ rq.ReplyLength(),
+ rq.Card16('major_version'),
+ rq.Card16('minor_version'),
+ rq.Pad(20))
def get_version(self, major, minor):
- return GetVersion(
- display = self.display,
- opcode = self.display.get_extension_major(extname),
- major_version = major,
- minor_version = minor)
+ return GetVersion(
+ display = self.display,
+ opcode = self.display.get_extension_major(extname),
+ major_version = major,
+ minor_version = minor)
class CreateContext(rq.Request):
- _request = rq.Struct(
- rq.Card8('opcode'),
- rq.Opcode(1),
- rq.RequestLength(),
- rq.Card32('context'), # Record_RC
- rq.Card8('element_header'), # Record_Element_Header
- rq.Pad(3),
- rq.LengthOf('clients', 4),
- rq.LengthOf('ranges', 4),
- rq.List('clients', rq.Card32Obj),
- rq.List('ranges', Record_Range))
+ _request = rq.Struct(
+ rq.Card8('opcode'),
+ rq.Opcode(1),
+ rq.RequestLength(),
+ rq.Card32('context'), # Record_RC
+ rq.Card8('element_header'), # Record_Element_Header
+ rq.Pad(3),
+ rq.LengthOf('clients', 4),
+ rq.LengthOf('ranges', 4),
+ rq.List('clients', rq.Card32Obj),
+ rq.List('ranges', Record_Range))
def create_context(self, datum_flags, clients, ranges):
- context = self.display.allocate_resource_id()
- CreateContext(
- display = self.display,
- opcode = self.display.get_extension_major(extname),
- context = context,
- element_header = datum_flags,
- clients = clients,
- ranges = ranges)
- return context
+ context = self.display.allocate_resource_id()
+ CreateContext(
+ display = self.display,
+ opcode = self.display.get_extension_major(extname),
+ context = context,
+ element_header = datum_flags,
+ clients = clients,
+ ranges = ranges)
+ return context
class RegisterClients(rq.Request):
- _request = rq.Struct(
- rq.Card8('opcode'),
- rq.Opcode(2),
- rq.RequestLength(),
- rq.Card32('context'), # Record_RC
- rq.Card8('element_header'), # Record_Element_Header
- rq.Pad(3),
- rq.LengthOf('clients', 4),
- rq.LengthOf('ranges', 4),
- rq.List('clients', rq.Card32Obj),
- rq.List('ranges', Record_Range))
+ _request = rq.Struct(
+ rq.Card8('opcode'),
+ rq.Opcode(2),
+ rq.RequestLength(),
+ rq.Card32('context'), # Record_RC
+ rq.Card8('element_header'), # Record_Element_Header
+ rq.Pad(3),
+ rq.LengthOf('clients', 4),
+ rq.LengthOf('ranges', 4),
+ rq.List('clients', rq.Card32Obj),
+ rq.List('ranges', Record_Range))
def register_clients(self, context, element_header, clients, ranges):
- RegisterClients(
- display = self.display,
- opcode = self.display.get_extension_major(extname),
- context = context,
- element_header = element_header,
- clients = clients,
- ranges = ranges)
+ RegisterClients(
+ display = self.display,
+ opcode = self.display.get_extension_major(extname),
+ context = context,
+ element_header = element_header,
+ clients = clients,
+ ranges = ranges)
class UnregisterClients(rq.Request):
- _request = rq.Struct(
- rq.Card8('opcode'),
- rq.Opcode(3),
- rq.RequestLength(),
- rq.Card32('context'), # Record_RC
- rq.LengthOf('clients', 4),
- rq.List('clients', rq.Card32Obj))
+ _request = rq.Struct(
+ rq.Card8('opcode'),
+ rq.Opcode(3),
+ rq.RequestLength(),
+ rq.Card32('context'), # Record_RC
+ rq.LengthOf('clients', 4),
+ rq.List('clients', rq.Card32Obj))
def unregister_clients(self, context, clients):
- UnregisterClients(
- display = self.display,
- opcode = self.display.get_extension_major(extname),
- context = context,
- clients = clients)
+ UnregisterClients(
+ display = self.display,
+ opcode = self.display.get_extension_major(extname),
+ context = context,
+ clients = clients)
class GetContext(rq.ReplyRequest):
- _request = rq.Struct(
- rq.Card8('opcode'),
- rq.Opcode(4),
- rq.RequestLength(),
- rq.Card32('context')) # Record_RC
- _reply = rq.Struct(
- rq.Pad(2),
- rq.Card16('sequence_number'),
- rq.ReplyLength(),
- rq.Card8('element_header'), # Record_Element_Header
- rq.Pad(3),
- rq.LengthOf('client_info', 4),
- rq.Pad(16),
- rq.List('client_info', Record_ClientInfo))
+ _request = rq.Struct(
+ rq.Card8('opcode'),
+ rq.Opcode(4),
+ rq.RequestLength(),
+ rq.Card32('context')) # Record_RC
+ _reply = rq.Struct(
+ rq.Pad(2),
+ rq.Card16('sequence_number'),
+ rq.ReplyLength(),
+ rq.Card8('element_header'), # Record_Element_Header
+ rq.Pad(3),
+ rq.LengthOf('client_info', 4),
+ rq.Pad(16),
+ rq.List('client_info', Record_ClientInfo))
def get_context(self, context):
- return GetContext(
- display = self.display,
- opcode = self.display.get_extension_major(extname),
- context = context)
+ return GetContext(
+ display = self.display,
+ opcode = self.display.get_extension_major(extname),
+ context = context)
class EnableContext(rq.ReplyRequest):
- _request = rq.Struct(
- rq.Card8('opcode'),
- rq.Opcode(5),
- rq.RequestLength(),
- rq.Card32('context')) # Record_RC
- _reply = rq.Struct(
- rq.Pad(1),
- rq.Card8('category'),
- rq.Card16('sequence_number'),
- rq.ReplyLength(),
- rq.Card8('element_header'), # Record_Element_Header
- rq.Bool('client_swapped'),
- rq.Pad(2),
- rq.Card32('id_base'), # Record_XIDBase
- rq.Card32('server_time'),
- rq.Card32('recorded_sequence_number'),
- rq.Pad(8),
- RawField('data'))
-
- # This request receives multiple responses, so we need to keep
- # ourselves in the 'sent_requests' list in order to receive them all.
-
- # See the discussion on ListFonstsWithInfo in request.py
-
- def __init__(self, callback, *args, **keys):
- self._callback = callback
- apply(rq.ReplyRequest.__init__, (self, ) + args, keys)
-
- def _parse_response(self, data):
- r, d = self._reply.parse_binary(data, self._display)
- self._callback(r)
-
- if r.category == StartOfData:
- # Hack ourselves a sequence number, used by the code in
- # Xlib.protocol.display.Display.parse_request_response()
- self.sequence_number = r.sequence_number
-
- if r.category == EndOfData:
- self._response_lock.acquire()
- self._data = r
- self._response_lock.release()
- else:
- self._display.sent_requests.insert(0, self)
+ _request = rq.Struct(
+ rq.Card8('opcode'),
+ rq.Opcode(5),
+ rq.RequestLength(),
+ rq.Card32('context')) # Record_RC
+ _reply = rq.Struct(
+ rq.Pad(1),
+ rq.Card8('category'),
+ rq.Card16('sequence_number'),
+ rq.ReplyLength(),
+ rq.Card8('element_header'), # Record_Element_Header
+ rq.Bool('client_swapped'),
+ rq.Pad(2),
+ rq.Card32('id_base'), # Record_XIDBase
+ rq.Card32('server_time'),
+ rq.Card32('recorded_sequence_number'),
+ rq.Pad(8),
+ RawField('data'))
+
+ # This request receives multiple responses, so we need to keep
+ # ourselves in the 'sent_requests' list in order to receive them all.
+
+ # See the discussion on ListFonstsWithInfo in request.py
+
+ def __init__(self, callback, *args, **keys):
+ self._callback = callback
+ apply(rq.ReplyRequest.__init__, (self, ) + args, keys)
+
+ def _parse_response(self, data):
+ r, d = self._reply.parse_binary(data, self._display)
+ self._callback(r)
+
+ if r.category == StartOfData:
+ # Hack ourselves a sequence number, used by the code in
+ # Xlib.protocol.display.Display.parse_request_response()
+ self.sequence_number = r.sequence_number
+
+ if r.category == EndOfData:
+ self._response_lock.acquire()
+ self._data = r
+ self._response_lock.release()
+ else:
+ self._display.sent_requests.insert(0, self)
def enable_context(self, context, callback):
- EnableContext(
- callback = callback,
- display = self.display,
- opcode = self.display.get_extension_major(extname),
- context = context)
+ EnableContext(
+ callback = callback,
+ display = self.display,
+ opcode = self.display.get_extension_major(extname),
+ context = context)
class DisableContext(rq.Request):
- _request = rq.Struct(
- rq.Card8('opcode'),
- rq.Opcode(6),
- rq.RequestLength(),
- rq.Card32('context')) # Record_RC
+ _request = rq.Struct(
+ rq.Card8('opcode'),
+ rq.Opcode(6),
+ rq.RequestLength(),
+ rq.Card32('context')) # Record_RC
def disable_context(self, context):
- DisableContext(
- display = self.display,
- opcode = self.display.get_extension_major(extname),
- context = context)
+ DisableContext(
+ display = self.display,
+ opcode = self.display.get_extension_major(extname),
+ context = context)
class FreeContext(rq.Request):
- _request = rq.Struct(
- rq.Card8('opcode'),
- rq.Opcode(7),
- rq.RequestLength(),
- rq.Card32('context')) # Record_RC
+ _request = rq.Struct(
+ rq.Card8('opcode'),
+ rq.Opcode(7),
+ rq.RequestLength(),
+ rq.Card32('context')) # Record_RC
def free_context(self, context):
- FreeContext(
- display = self.display,
- opcode = self.display.get_extension_major(extname),
- context = context)
- self.display.free_resource_id(context)
+ FreeContext(
+ display = self.display,
+ opcode = self.display.get_extension_major(extname),
+ context = context)
+ self.display.free_resource_id(context)
def init(disp, info):
- disp.extension_add_method('display', 'record_get_version', get_version)
- disp.extension_add_method('display', 'record_create_context', create_context)
- disp.extension_add_method('display', 'record_register_clients', register_clients)
- disp.extension_add_method('display', 'record_unregister_clients', unregister_clients)
- disp.extension_add_method('display', 'record_get_context', get_context)
- disp.extension_add_method('display', 'record_enable_context', enable_context)
- disp.extension_add_method('display', 'record_disable_context', disable_context)
- disp.extension_add_method('display', 'record_free_context', free_context)
+ disp.extension_add_method('display', 'record_get_version', get_version)
+ disp.extension_add_method('display', 'record_create_context', create_context)
+ disp.extension_add_method('display', 'record_register_clients', register_clients)
+ disp.extension_add_method('display', 'record_unregister_clients', unregister_clients)
+ disp.extension_add_method('display', 'record_get_context', get_context)
+ disp.extension_add_method('display', 'record_enable_context', enable_context)
+ disp.extension_add_method('display', 'record_disable_context', disable_context)
+ disp.extension_add_method('display', 'record_free_context', free_context)
434 Xlib/ext/shape.py
View
@@ -20,41 +20,41 @@
# Constants to use
#
# Regions of a window
-ShapeBounding = 0 # the 'edge' of a shaped window
-ShapeClip = 1 # the clipping region
+ShapeBounding = 0 # the 'edge' of a shaped window
+ShapeClip = 1 # the clipping region
# Shape Operations
-ShapeSet = 0 # Set the region unmodified (dest=src)
-ShapeUnion = 1 # Add the new region to the old (dest=src|dest)
-ShapeIntersect = 2 # Use the intersection (dest=src&dest)
-ShapeSubtract = 3 # remove region (dest = dest - intersect)
-ShapeInvert = 4 # opposite of subtract (dest = src - intersect)
+ShapeSet = 0 # Set the region unmodified (dest=src)
+ShapeUnion = 1 # Add the new region to the old (dest=src|dest)
+ShapeIntersect = 2 # Use the intersection (dest=src&dest)
+ShapeSubtract = 3 # remove region (dest = dest - intersect)
+ShapeInvert = 4 # opposite of subtract (dest = src - intersect)
# Events
-ShapeNotifyMask = (1<<0) #a keypress mask?
-ShapeNotify = 0 #still unsure of these values
+ShapeNotifyMask = (1<<0) #a keypress mask?
+ShapeNotify = 0 #still unsure of these values
# How to Use
# The basic functions that change the shapes of things are:
# shape_rectangles (uses a set of rectangles as the source)
-# operation, region, ordering, rects
+# operation, region, ordering, rects
# shape_mask (uses a bitmap as the source)
-# operation, region, x_offset, y_offset, bitmap
+# operation, region, x_offset, y_offset, bitmap
# shape_combine (uses a window as the source)
-# operation, src_region, dest_region, x_offset, y_offset, src_window
+# operation, src_region, dest_region, x_offset, y_offset, src_window
# shape_offset (moves the region)
-# region, x_offset, y_offset
+# region, x_offset, y_offset
# The functions to find stuff out (these three return mappings of field/values):
# shape_query_version (shape extension version)
-# major_version, minor_version
+# major_version, minor_version
# shape_query_extents (rectangle boundaries of a window's regions)
-# clip_shaped, clip_x, clip_y, clip_width, clip_height,
-# bounding_shaped, bounding_x, bounding_y, bounding_width, bounding_height
+# clip_shaped, clip_x, clip_y, clip_width, clip_height,
+# bounding_shaped, bounding_x, bounding_y, bounding_width, bounding_height
# shape_input_selected (if the window products shapenotify events)
-# enabled
+# enabled
# shape_get_rectangles (the rectangles set by shape_rectangles)
-# ordering, rects
+# ordering, rects
# And to turn on shape notify events:
# shape_select_input
-# enable
+# enable
@@ -65,270 +65,270 @@
class QueryVersion(rq.ReplyRequest):
_request = rq.Struct(
- rq.Card8('opcode'),
- rq.Opcode(0),
- rq.RequestLength(),
- )
+ rq.Card8('opcode'),
+ rq.Opcode(0),
+ rq.RequestLength(),
+ )
_reply = rq.Struct(
- rq.ReplyCode(),
- rq.Pad(1),
- rq.Card16('sequence_number'),
- rq.ReplyLength(),
- rq.Card16('major_version'),
- rq.Card16('minor_version'),
- rq.Pad(20),
- )
+ rq.ReplyCode(),
+ rq.Pad(1),
+ rq.Card16('sequence_number'),
+ rq.ReplyLength(),
+ rq.Card16('major_version'),
+ rq.Card16('minor_version'),
+ rq.Pad(20),
+ )
def query_version(self):
return QueryVersion(
- display = self.display,
- opcode = self.display.get_extension_major(extname),
- )
+ display = self.display,
+ opcode = self.display.get_extension_major(extname),
+ )
class Rectangles(rq.Request):
_request = rq.Struct(
- rq.Card8('opcode'),
- rq.Opcode(1),
- rq.RequestLength(),
- rq.Card8('operation'),
- rq.Set('region', 1, (ShapeBounding, ShapeClip)),
- rq.Card8('ordering'),
- rq.Pad(1),
- rq.Window('window'),
- rq.Int16('x'),
- rq.Int16('y'),
- rq.List('rectangles', structs.Rectangle),
- )
-
+ rq.Card8('opcode'),
+ rq.Opcode(1),
+ rq.RequestLength(),
+ rq.Card8('operation'),
+ rq.Set('region', 1, (ShapeBounding, ShapeClip)),
+ rq.Card8('ordering'),
+ rq.Pad(1),
+ rq.Window('window'),
+ rq.Int16('x'),
+ rq.Int16('y'),
+ rq.List('rectangles', structs.Rectangle),
+ )
+
def rectangles(self, region, operation, ordering, x, y, rectangles):
Rectangles(
- display = self.display,
- opcode = self.display.get_extension_major(extname),
- operation = operation,
- region = region,
- ordering = ordering,
- window = self.id,
- x = x,
- y = y,
- rectangles = rectangles,
- )
+ display = self.display,
+ opcode = self.display.get_extension_major(extname),
+ operation = operation,
+ region = region,
+ ordering = ordering,
+ window = self.id,
+ x = x,
+ y = y,
+ rectangles = rectangles,
+ )
class Mask(rq.Request):
_request = rq.Struct(
- rq.Card8('opcode'),
- rq.Opcode(2),
- rq.RequestLength(),
- rq.Card8('operation'),
- rq.Set('region', 1, (ShapeBounding, ShapeClip)),
- rq.Pad(2),
- rq.Window('window'),
- rq.Int16('x'),
- rq.Int16('y'),