Skip to content

Commit bf41435

Browse files
committed
Bugfixes, documentation makefiles, and partial ICCCM support
1 parent 5c024b7 commit bf41435

15 files changed

Lines changed: 282 additions & 44 deletions

File tree

‎TODO‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,6 @@
66
hooks to PIL.
77

88

9-
*** Frameworks
10-
11-
* Multi-platform: the X library should be portable to other operating
12-
systems than Unix (it might even only work with XFree86 if the
13-
display is ":0" right now). There are two things which might be OS
14-
specific: finding out and parsing the display name for establishing
15-
a connection, and finding authoritative data.
16-
17-
* Thread support: Currently, it would suffice to make the lowlevel
18-
Xlib.protocol.display.Display thread-safe, as no parts of the
19-
high-level interface modify shared data. This should be done in
20-
such a way that one can still use the library without the thread
21-
support, for systems where the thread module is missing.
22-
23-
An attempt has been made, but it is not entirely correct. However,
24-
the framework is there.
25-
26-
27-
289
*** To be a real C Xlib replacement
2910

3011
* High-level functions: currently, there are only methods which

‎Xlib/display.py‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: display.py,v 1.8 2000-09-06 01:51:34 petli Exp $
1+
# $Id: display.py,v 1.9 2000-09-22 11:37:51 petli Exp $
22
#
33
# Xlib.display -- high level display object
44
#
@@ -265,12 +265,12 @@ def allow_events(self, mode, time, onerror = None):
265265
time = time)
266266

267267
def grab_server(self, onerror = None):
268-
request.GrabServer(display = self.display)
269-
onerror = onerror,
268+
request.GrabServer(display = self.display,
269+
onerror = onerror)
270270

271271
def ungrab_server(self, onerror = None):
272-
request.UngrabServer(display = self.display)
273-
onerror = onerror,
272+
request.UngrabServer(display = self.display,
273+
onerror = onerror)
274274

275275
def warp_pointer(self, x, y, src_window = 0, src_x = 0, src_y = 0,
276276
src_width = 0, src_height = 0, onerror = None):
@@ -314,7 +314,8 @@ def open_font(self, name):
314314
self.display.free_resource_id(fid)
315315
return None
316316
else:
317-
return xobject.fontable.Font(self.display, fid, owner = 1)
317+
cls = self.display.get_resource_class('font', xobject.fontable.Font)
318+
return cls(self.display, fid, owner = 1)
318319

319320
def list_fonts(self, pattern, max_names):
320321
r = request.ListFonts(display = self.display,

‎Xlib/protocol/display.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: display.py,v 1.6 2000-09-06 01:51:34 petli Exp $
1+
# $Id: display.py,v 1.7 2000-09-22 11:37:51 petli Exp $
22
#
33
# Xlib.protocol.display -- core display communication
44
#
@@ -251,14 +251,14 @@ def free_resource_id(self, rid):
251251

252252

253253

254-
def get_resource_class(self, class_name):
255-
"""class = d.get_resource_class(class_name)
254+
def get_resource_class(self, class_name, default = None):
255+
"""class = d.get_resource_class(class_name, default = None)
256256
257257
Return the class to be used for X resource objects of type
258-
CLASS_NAME, or None if no such class is set.
258+
CLASS_NAME, or DEFAULT if no such class is set.
259259
"""
260260

261-
return self.resource_classes.get(class_name, None)
261+
return self.resource_classes.get(class_name, default)
262262

263263
def set_extension_major(self, extname, major):
264264
self.extension_major_opcodes[extname] = major

‎Xlib/xobject/colormap.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: colormap.py,v 1.3 2000-08-21 10:03:46 petli Exp $
1+
# $Id: colormap.py,v 1.4 2000-09-22 11:37:51 petli Exp $
22
#
33
# Xlib.xobject.colormap -- colormap object
44
#
@@ -38,7 +38,8 @@ def copy_colormap_and_free(self, scr_cmap):
3838
mid = mid,
3939
src_cmap = src_cmap)
4040

41-
return Colormap(self.display, mid, owner = 1)
41+
cls = self.display.get_resource_class('colormap', Colormap)
42+
return cls(self.display, mid, owner = 1)
4243

4344
def install_colormap(self, onerror = None):
4445
request.InstallColormap(display = self.display,

‎Xlib/xobject/drawable.py‎

Lines changed: 112 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: drawable.py,v 1.4 2000-08-22 13:53:02 petli Exp $
1+
# $Id: drawable.py,v 1.5 2000-09-22 11:37:51 petli Exp $
22
#
33
# Xlib.xobject.drawable -- drawable objects (window and pixmap)
44
#
@@ -18,7 +18,9 @@
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
2020

21-
from Xlib import X
21+
import string
22+
23+
from Xlib import X, Xatom, Xutil
2224
from Xlib.protocol import request
2325

2426
# Other X resource objects
@@ -27,6 +29,9 @@
2729
import cursor
2830
import fontable
2931

32+
# Inter-client communication conventions
33+
import icccm
34+
3035
class Drawable(resource.Resource):
3136
__drawable__ = resource.Resource.__resource__
3237

@@ -43,7 +48,8 @@ def create_pixmap(self, width, height, depth):
4348
width = width,
4449
height = height)
4550

46-
return Pixmap(self.display, pid, owner = 1)
51+
cls = self.display.get_resource_class('pixmap', Pixmap)
52+
return cls(self.display, pid, owner = 1)
4753

4854
def create_gc(self, **keys):
4955
cid = self.display.allocate_resource_id()
@@ -52,7 +58,8 @@ def create_gc(self, **keys):
5258
drawable = self.id,
5359
attrs = keys)
5460

55-
return fontable.GC(self.display, cid, owner = 1)
61+
cls = self.display.get_resource_class('gc', fontable.GC)
62+
return cls(self.display, cid, owner = 1)
5663

5764
def copy_area(self, gc, src_drawable, src_x, src_y, width, height, dst_x, dst_y, onerror = None):
5865
request.CopyArea(display = self.display,
@@ -257,7 +264,9 @@ def create_window(self, x, y, width, height, border_width, depth,
257264
window_class = window_class,
258265
visual = visual,
259266
attrs = keys)
260-
return Window(self.display, wid, owner = 1)
267+
268+
cls = self.display.get_resource_class('window', Window)
269+
return cls(self.display, wid, owner = 1)
261270

262271
def change_attributes(self, onerror = None, **keys):
263272
request.ChangeWindowAttributes(display = self.display,
@@ -531,7 +540,8 @@ def create_colormap(self, visual, alloc):
531540
mid = mid,
532541
window = self.id,
533542
visual = visual)
534-
return colormap.Colormap(self.display, mid, owner = 1)
543+
cls = self.display.get_resource_class('colormap', colormap.Colormap)
544+
return cls(self.display, mid, owner = 1)
535545

536546
def list_installed_colormaps(self):
537547
r = request.ListInstalledColormaps(display = self.display,
@@ -545,6 +555,100 @@ def rotate_properties(self, properties, delta, onerror = None):
545555
delta = delta,
546556
properties = properties)
547557

558+
def set_wm_name(self, name, onerror = None):
559+
self.change_property(Xatom.WM_NAME, Xatom.STRING, 8, name,
560+
onerror = onerror)
561+
562+
def get_wm_name(self):
563+
d = self.get_full_property(Xatom.WM_NAME, Xatom.STRING)
564+
if d is None or d.format != 8:
565+
return None
566+
else:
567+
return d.value
568+
569+
def set_wm_icon_name(self, name, onerror = None):
570+
self.change_property(Xatom.WM_ICON_NAME, Xatom.STRING, 8, name,
571+
onerror = onerror)
572+
573+
def get_wm_icon_name(self):
574+
d = self.get_full_property(Xatom.WM_ICON_NAME, Xatom.STRING)
575+
if d is None or d.format != 8:
576+
return None
577+
else:
578+
return d.value
579+
580+
581+
def set_wm_class(self, inst, cls, onerror = None):
582+
self.change_property(Xatom.WM_CLASS, Xatom.STRING, 8,
583+
'%s\0%s\0' % (inst, cls),
584+
onerror = onerror)
585+
586+
def get_wm_class(self):
587+
d = self.get_full_property(Xatom.WM_CLASS, Xatom.STRING)
588+
if d is None or d.format != 8:
589+
return None
590+
else:
591+
parts = string.split(d.value, '\0')
592+
if len(parts) < 2:
593+
return None
594+
else:
595+
return parts[0], parts[1]
596+
597+
def set_wm_transient_for(self, window, onerror = None):
598+
self.change_property(Xatom.WM_TRANSIENT_FOR, Xatom.WINDOW,
599+
32, window.id,
600+
onerror = onerror)
601+
602+
def get_wm_transient_for(self):
603+
d = self.get_property(Xatom.WM_TRANSIENT_FOR, Xatom.WINDOW, 0, 1)
604+
if d is None or d.format != 32 or len(d.value) < 1:
605+
return None
606+
else:
607+
cls = self.display.get_resource_class('window', Window)
608+
return cls(self.display, d.value[0])
609+
610+
611+
def set_wm_protocols(self, protocols, onerror = None):
612+
self.change_property(self.display.get_atom('WM_PROTOCOLS'),
613+
Xatom.ATOM, 32, protocols,
614+
onerror = onerror)
615+
616+
def get_wm_protocols(self):
617+
d = self.get_full_property(self.display.get_atom('WM_PROTOCOLS'), Xatom.ATOM)
618+
if d is None or d.format != 32:
619+
return None
620+
else:
621+
return d.value
622+
623+
def set_wm_colormap_windows(self, windows, onerror = None):
624+
self.change_property(self.display.get_atom('WM_COLORMAP_WINDOWS'),
625+
Xatom.WINDOW, 32,
626+
map(lambda w: w.id, windows),
627+
onerror = onerror)
628+
629+
def get_wm_colormap_windows(self):
630+
d = self.get_full_property(self.display.get_atom('WM_COLORMAP_WINDOWS'),
631+
Xatom.WINDOW)
632+
if d is None or d.format != 32:
633+
return None
634+
else:
635+
cls = self.display.get_resource_class('window', Window)
636+
return map(lambda i, d = self.display, c = cls: c(d, i),
637+
d.value)
638+
639+
640+
def set_wm_client_machine(self, name, onerror = None):
641+
self.change_property(Xatom.WM_CLIENT_MACHINE, Xatom.STRING, 8, name,
642+
onerror = onerror)
643+
644+
def get_wm_client_machine(self):
645+
d = self.get_full_property(Xatom.WM_CLIENT_MACHINE, Xatom.STRING)
646+
if d is None or d.format != 8:
647+
return None
648+
else:
649+
return d.value
650+
651+
548652
class Pixmap(Drawable):
549653
__pixmap__ = resource.Resource.__resource__
550654

@@ -572,7 +676,8 @@ def create_cursor(self, mask,
572676
back_blue = back_blue,
573677
x = x,
574678
y = y)
575-
return cursor.Cursor(self.display, cid, owner = 1)
679+
cls = self.display.get_resource_class('cursor', cursor.Cursor)
680+
return cls(self.display, cid, owner = 1)
576681

577682

578683

‎Xlib/xobject/fontable.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: fontable.py,v 1.2 2000-08-21 10:03:46 petli Exp $
1+
# $Id: fontable.py,v 1.3 2000-09-22 11:37:51 petli Exp $
22
#
33
# Xlib.xobject.fontable -- fontable objects (GC, font)
44
#
@@ -104,6 +104,7 @@ def create_glyph_cursor(self, mask, source_char, mask_char,
104104
back_green = back_green,
105105
back_blue = back_blue)
106106

107-
return cursor.Cursor(self.display, cid, owner = 1)
107+
cls = self.display.get_resource_class('cursor', cursor.Cursor)
108+
return cls(self.display, cid, owner = 1)
108109

109110

‎Xlib/xobject/icccm.py‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# $Id: icccm.py,v 1.1 2000-09-22 11:37:51 petli Exp $
2+
#
3+
# Xlib.xobject.icccm -- ICCCM structures
4+
#
5+
# Copyright (C) 2000 Peter Liljenberg <petli@ctrl-c.liu.se>
6+
#
7+
# This program is free software; you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation; either version 2 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program; if not, write to the Free Software
19+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20+
21+
from Xlib import X, Xutil
22+
from Xlib.protocol import rq
23+
24+
Aspect = rq.Struct( rq.Int32('num'), rq.Int32('denum') )
25+
26+
WMNormalHints = rq.Struct( rq.Card32('flags'),
27+
rq.Pad(16),
28+
rq.Int32('min_width'),
29+
rq.Int32('min_height'),
30+
rq.Int32('max_width'),
31+
rq.Int32('max_height'),
32+
rq.Int32('width_inc'),
33+
rq.Int32('height_inc'),
34+
rq.Object('min_aspect', Aspect),
35+
rq.Object('max_aspect', Aspect),
36+
rq.Int32('base_width'),
37+
rq.Int32('base_height'),
38+
rq.Int32('win_gravity'),
39+
)
40+
41+
WMHints = rq.Struct( rq.Card32('flags'),
42+
rq.Card32('input'),
43+
rq.Set('initial_state', 4,
44+
( Xutil.NormalState, Xutil.IconicState )),
45+
rq.Pixmap('icon_pixmap'),
46+
rq.Window('icon_window'),
47+
rq.Int32('icon_x'),
48+
rq.Int32('icon_y'),
49+
rq.Pixmap('icon_mask'),
50+
rq.Window('window_group'),
51+
)
52+
53+
WMState = rq.Struct( rq.Set('state', 4,
54+
( Xutil.WithdrawnState,
55+
Xutil.NormalState,
56+
Xutil.IconicState )),
57+
rq.Window('icon', ( X.NONE, )),
58+
)
59+
60+
61+
WMIconSize = rq.Struct( rq.Card32('min_width'),
62+
rq.Card32('min_height'),
63+
rq.Card32('max_width'),
64+
rq.Card32('max_height'),
65+
rq.Card32('width_inc'),
66+
rq.Card32('height_inc'),
67+
)
68+

‎doc/Makefile‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Top-level makefile for Python Xlib documentation
2+
#
3+
# $Id: Makefile,v 1.1 2000-09-22 11:37:51 petli Exp $
4+
5+
FORMATS = info ps html
6+
7+
all: $(FORMATS)
8+
9+
info::
10+
(cd info; make)
11+
12+
ps::
13+
(cd ps; make)
14+
15+
html::
16+
(cd html; make)
17+
18+
clean:
19+
for f in $(FORMATS); do (cd $$f; make clean); done

‎doc/html/Makefile‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Make HTML documentation for Python Xlib
2+
#
3+
# $Id: Makefile,v 1.1 2000-09-22 11:37:51 petli Exp $
4+
5+
include ../src/defs
6+
7+
python-xlib_toc.html: $(SRCS)
8+
texi2html -splitnode -menu $(TOPSRC)
9+
ln -sf python-xlib_toc.html index.html
10+
11+
clean:
12+
rm -f *.html

0 commit comments

Comments
 (0)