Commit f06064af authored by Andrej Shadura's avatar Andrej Shadura

Imported Upstream version 0.14

parent 89a047bd
include MANIFEST.in
include README COPYING NEWS TODO
global-include .cvsignore
recursive-include doc Makefile
include doc/src/*.texi
include doc/info/python-xlib.info doc/info/python-xlib.info-*[0-9]
include doc/html/index.html doc/html/python-xlib_toc.html
include doc/html/python-xlib_*.html doc/html/texi2html
include doc/ps/python-xlib.ps
include utils/tcpbug.py utils/parsexbug.py
include examples/draw.py examples/draw-proto.py examples/profilex.py
include examples/shapewin.py
include examples/threadtest.py
......@@ -2,9 +2,42 @@
NEWS for Python X Library
* Version 0.14 1 Oct 2007 (trialed as 0.14rc1 on 10 Jun 2007)
A couple of new extensions, a Python 2.5 fix and a couple of aliases
(Display.get_atom() now uses the internal cache and added
Window.raise_window()). Tabs converted to spaces (SF id: 1559082).
** RECORD extension (SF id: 1538663)
Alex Badea contributed a RECORD extension module, allowing Python Xlib
programs to capture mouse and keyboard events (or all other core or
extension events) easily. A demo is in the examples directory. See
http://refspecs.freestandards.org/X11/recordlib.pdf for more information.
** XINERAMA extension
Mike Meyer contributed a Xinerama extension module, allowing Python Xlib
programs to interrogate the X server about positions and sizes of
multiple screens. Specifications are a bit tricky to find -
http://sourceforge.net/projects/xinerama/ has some older specs and the
source code of the xorg project (libs & server code) has "definitive"
information.
** Python 2.5 fix (SF id: 1623900)
Bugfix to correct handling of XAuthority file parsing under Python 2.5
causing failed authentication.
* Version 0.13 6 Aug 2006 (trialed as 0.13pre1 on 22 Jul 2006)
A small release to incorporate a number of minor corrections and bug fixes, including small changes to keysym handling, .Xauthority parsing, several fixes to sending/receiving/flushing data, addition of WithdrawnState to WMHints. petli completed documentation for Display objects.
A small release to incorporate a number of minor corrections and bug
fixes, including small changes to keysym handling, .Xauthority parsing,
several fixes to sending/receiving/flushing data, addition of
WithdrawnState to WMHints. petli completed documentation for Display
objects.
* Version 0.12 29 Mar 2002
......
Metadata-Version: 1.0
Name: python-xlib
Version: 0.13pre1
Summary: Python X Library
Home-page: http://python-xlib.sourceforge.net/
Author: Peter Liljenberg
Author-email: petli@ctrl-c.liu.se
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
......@@ -17,7 +17,7 @@ details.
*** Requirements
The Python X Library requires Python 1.5.2 or newer. It has been
tested to various extents with Pythons 1.5.2, 2.0, 2.1 and 2.2.
tested to various extents with Pythons 1.5.2, 2.0 - 2.5.
*** Installation
......
2007-06-10 Mike Grant <mgg@nobodymuch.org>
* (many files): (mgg) Converted tabs to spaces throughout the
codebase, using reindent.py (SF id: 1559082)
2007-03-18 Mike Grant <mgg@nobodymuch.org>
* Xlib/display.py: (mgg) Added a get_atom alias that uses the
internal cache
* Xlib/xobject/drawable.py: (mgg) Added a raise_window() alias
to the Window class
2007-02-15 Mike Grant <mgg@nobodymuch.org>
* Xlib/xauth.py: (mgg) Python 2.5 didn't like the way the buffer
type was used, resulting in X authorisation failure, so
reverted to using slices
2006-11-22 Mike Grant <mgg@nobodymuch.org>
* Xlib/ext/record.py: Addition of RECORD extension by Alex Badea
<decampos@users.sourceforge.net>, SF patch id #1538663 (demo
program in python-xlib/examples/record_demo.py)
2006-09-20 Mike Meyer <mwm@mired.org>
* Xlib/ext/xinerama.py: (mwm) Addition of Xinerama extension
2006-07-22 Mike Grant <mgg@nobodymuch.org>
Various typo fixes, general updates.
......
# $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 @@ SelectionNotify = 31
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 @@ Button3Mask = (1<<10)
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
......
# $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,
......
# $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 @@ CAP_HEIGHT = 66
WM_CLASS = 67
WM_TRANSIENT_FOR = 68
LAST_PREDEFINED = 68
# $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 @@ IconPositionHint = (1 << 4)
IconMaskHint = (1 << 5)
WindowGroupHint = (1 << 6)
AllHints = (InputHint|StateHint|IconPixmapHint|IconWindowHint|
IconPositionHint|IconMaskHint|WindowGroupHint)
IconPositionHint|IconMaskHint|WindowGroupHint)
WithdrawnState = 0
NormalState = 1
IconicState = 3
......
# $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 @@ __all__ = [
# Explicitly exclude threaded, so that it isn't imported by
# from Xlib import *
]
This diff is collapsed.
# $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 @@ from Xlib.protocol import rq
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 @@ xerror_class = {
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
# $Id: __init__.py,v 1.2 2002/03/24 22:31:06 petli 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>
#
......@@ -25,7 +25,8 @@
__extensions__ = [
('XTEST', 'xtest'),
('SHAPE', 'shape'),
('XINERAMA', 'xinerama'),
('RECORD', 'record'),
]
__all__ = map(lambda x: x[1], __extensions__)
# $Id: record.py,v 1.2 2007/06/10 14:11:58 mggrant Exp $
#
# Xlib.ext.record -- RECORD extension module
#
# Copyright (C) 2006 Alex Badea <vamposdecampos@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from Xlib import X
from Xlib.protocol import rq
extname = 'RECORD'
FromServerTime = 0x01
FromClientTime = 0x02
FromClientSequence = 0x04
CurrentClients = 1
FutureClients = 2
AllClients = 3
FromServer = 0
FromClient = 1
ClientStarted = 2
ClientDied = 3
StartOfData = 4
EndOfData = 5
Record_Range8 = rq.Struct(
rq.Card8('first'),
rq.Card8('last'))
Record_Range16 = rq.Struct(
rq.Card16('first'),
rq.Card16('last'))
Record_ExtRange = rq.Struct(
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'))
Record_ClientInfo = rq.Struct(
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"""
structcode = None
def pack_value(self, val):
return val, len(val), None
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))
def get_version(self, major, 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))
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
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))
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)
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))
def unregister_clients(self, context, 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))
def get_context(self, 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