Skip to content

Commit 14218a0

Browse files
committed
Complete high-level interface implemented.
1 parent e47469c commit 14218a0

13 files changed

Lines changed: 726 additions & 199 deletions

File tree

README

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22
The Python X Library
33

4-
Version 0.1, 21 Jul 2000
4+
Version 0.2, 8 Aug 2000
55

66

77
*** Copyright
88

9-
The Python X Library is released under GPL, see file COPYING for
9+
The Python X Library is released under GPL, see the file COPYING for
1010
details.
1111

1212

@@ -21,6 +21,9 @@ Make sure that that directory exists before copying.
2121
Alternatively, you can run programs from the distribution directory,
2222
or changing the module path in programs.
2323

24+
There are a simple example program, implemented twice using both the
25+
high-level interface and the low-level protocol.
26+
2427

2528
*** Introduction
2629

@@ -40,60 +43,45 @@ library:
4043

4144
* Integration: The library can make use of the wonderful object
4245
system in Python, providing an easy-to-use class hierarchy.
43-
44-
* Portability: The library will be usable on any computer which have
45-
Python installed. A C interface could be problematic to port to
46-
non-Unix systems, such as MS Windows or OpenVMS.
46+
47+
* Portability: The library will be usable on (almost) any computer
48+
which have Python installed. A C interface could be problematic to
49+
port to non-Unix systems, such as MS Windows or OpenVMS.
4750

4851
* Maintainability: It is much easier to develop and debug native
4952
Python modules than modules written in C.
5053

5154

5255
*** Project status
5356

54-
Currently only the basic protocol interface is implemented. This
55-
includes the network communication code for TCP/IP and Unix sockets
56-
and definitions of all requests, events and errors in X11R6.
57-
58-
Client programs can be written using this, but that is quite awkward
59-
(see examples/draw.py for a simple application).
60-
61-
There aren't any documentation for this yet except of the code and the
62-
example program.
57+
The low-level protocol and a rudimentary object oriented interface is
58+
complete, implementing client-side X11R6. This should be usable for
59+
writing applications. It runs at least on Linux using XFree86 as the
60+
server, but should run on most Unices at least.
6361

64-
There are probably bugs. The code handling network traffic and
65-
packing/unpacking requests, events and errors have been well
66-
tested and seems correct, but there is probably a few errors in the
67-
definition of the requests and the events, as not all of these have
68-
been tested yet.
62+
There are most likely bugs, as only a rather small subset of all the
63+
requests and methods have been tested. The code is released anyway to
64+
let other interested Python hackers have a look (and hopefully help
65+
out with debugging and coding :).
6966

70-
The next step, except for further testing and documentation, is to
71-
write the real client interface. This will consist of classes
72-
representing windows, fonts, graphic contexts, etc, which wraps the
73-
basic protocol code in higher-level methods.
74-
75-
Somewhere threading support should be added. Currently the code is
76-
only thread safe if only one of the threads use the library.
77-
78-
When all that is done, we will have a complete and usable X library.
79-
Although not very usable yet, the code is released anyway to let
80-
interested Python hackers have a peek. Please report or fix any bugs
81-
you find, or get in contact if you want to help with the development
82-
in any way.
67+
There aren't any documentation for this yet except of the code, the
68+
example programs and the standard X11 documentation.
8369

70+
See the file TODO for a detailed list of what is missing,
71+
approximately ordered by importance.
8472

8573

8674
*** Contact information
8775

8876
Mailing list: <python-xlib@ctrl-c.liu.se>
8977

9078
To subscribe, send a message to <python-xlib-request@ctrl-c.liu.se>
91-
with the body "SUBSCRIBE".
79+
with the body "SUBSCRIBE". The subject line is ignored, and can be
80+
blank.
9281

9382

9483
Author email: Peter Liljenberg <petli@ctrl-c.liu.se>
9584

9685

9786
There isn't any real web page yet, although new versions can be
9887
downloaded from http://www.cendio.se/~petli/python-xlib/.
99-

Xlib/display.py

Lines changed: 216 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: display.py,v 1.2 2000-08-07 10:30:19 petli Exp $
1+
# $Id: display.py,v 1.3 2000-08-08 09:47:45 petli Exp $
22
#
33
# Xlib.display -- high level display object
44
#
@@ -26,11 +26,10 @@
2626
import protocol.display
2727
from protocol import request
2828

29-
# Xlib.xoobjects modules
29+
# Xlib.xobjects modules
3030
import xobject.resource
3131
import xobject.drawable
32-
import xobject.font
33-
import xobject.gc
32+
import xobject.fontable
3433
import xobject.colormap
3534
import xobject.cursor
3635

@@ -40,8 +39,8 @@ class _BaseDisplay(protocol.display.Display):
4039
'drawable': xobject.drawable.Drawable,
4140
'window': xobject.drawable.Window,
4241
'pixmap': xobject.drawable.Pixmap,
43-
'font': xobject.font.Font,
44-
'gc': xobject.gc.GC,
42+
'font': xobject.fontable.Font,
43+
'gc': xobject.fontable.GC,
4544
'colormap': xobject.colormap.Colormap,
4645
'cursor': xobject.cursor.Cursor,
4746
}
@@ -60,11 +59,21 @@ def flush(self):
6059
self.display.flush()
6160

6261
def next_event(self):
63-
self.display.next_event()
62+
return self.display.next_event()
6463

6564
def pending_events(self):
66-
self.display.pending_events()
67-
65+
return self.display.pending_events()
66+
67+
###
68+
### display information retrieval
69+
###
70+
71+
def screen(self, sno = None):
72+
if sno is None
73+
return self.display.info.roots[self.display.default_screen]
74+
else:
75+
return self.display.info.roots[sno]
76+
6877
###
6978
### X requests
7079
###
@@ -79,8 +88,205 @@ def get_atom_name(self, atom):
7988
r = request.GetAtomName(display = self.display,
8089
atom = atom)
8190
return r.name
82-
91+
92+
def get_selection_owner(self, selection):
93+
r = request.GetSelectionOwner(display = self.display,
94+
selection = selection)
95+
return r.owner
96+
97+
def send_event(self, destination, event, propagate = 0, event_mask = 0):
98+
request.SendEvent(display = self.display,
99+
propagate = propagate,
100+
destination = destination,
101+
event_mask = event_mask,
102+
event = event)
103+
104+
def ungrab_pointer(self, time):
105+
request.UngrabPointer(display = self.display,
106+
time = time)
107+
108+
def change_active_pointer_grab(self, event_mask, cursor, time):
109+
request.ChangeActivePointerGrab(display = self.display,
110+
cursor = cursor,
111+
time = time,
112+
event_mask = event_mask)
113+
114+
def ungrab_keyboard(self, time):
115+
request.UngrabKeyboard(display = self.display,
116+
time = time)
117+
118+
def allow_events(self, mode, time):
119+
request.AllowEvents(display = self.display,
120+
mode = mode,
121+
time = time)
122+
123+
def grab_server(self):
124+
request.GrabServer(display = self.display)
125+
126+
def ungrab_server(self):
127+
request.UngrabServer(display = self.display)
128+
129+
def warp_pointer(self, x, y, src_window = 0, src_x = 0, src_y = 0,
130+
src_width = 0, src_height = 0):
131+
132+
request.WarpPointer(display = self.display,
133+
src_window = src_window,
134+
dst_window = X.NONE,
135+
src_x = src_x,
136+
src_y = src_y,
137+
src_width = src_width,
138+
src_height = src_height,
139+
dst_x = x,
140+
dst_y = y)
141+
142+
def set_input_focus(self, focus, revert_to, time):
143+
request.SetInputFocus(display = self.display,
144+
revert_to = revert_to,
145+
focus = focus,
146+
time = time)
147+
148+
def get_input_focus(self):
149+
return request.GetInputFocus(display = self.display)
150+
151+
def query_keymap(self):
152+
r = request.QueryKeymap(display = self.display)
153+
return r.map
154+
155+
def open_font(self, name):
156+
fid = self.display.allocate_resource_id()
157+
request.OpenFont(display = self.display,
158+
fid = fid,
159+
name = name)
160+
161+
return fontable.Font(self.display, fid, owner = 1)
162+
163+
def list_fonts(self, pattern, max_names):
164+
r = request.ListFonts(display = self.display,
165+
max_names = max_names,
166+
pattern = pattern)
167+
return r.fonts
168+
169+
def list_fonts_with_info(self, pattern, max_names):
170+
return request.ListFontsWithInfo(display = self.display,
171+
max_names = max_names,
172+
pattern = pattern)
173+
174+
def set_font_path(self, path):
175+
request.SetFontPath(display = self.display,
176+
path = path)
177+
178+
def get_font_path(self):
179+
r = request.GetFontPath(display = self.display)
180+
return r.paths
181+
182+
def query_extension(self, name):
183+
r = request.QueryExtension(display = self.display,
184+
name = name)
185+
if r.present:
186+
return r
187+
else:
188+
return None
189+
190+
def list_extensions(self):
191+
r = request.ListExtensions(display = self.display)
192+
return r.names
193+
194+
def change_keyboard_mapping(self, first_keycode, keysyms):
195+
request.ChangeKeyboardMapping(display = self.display,
196+
first_keycode = first_keycode,
197+
keysyms = keysyms)
198+
199+
def get_keyboard_mapping(self, first_keycode, count):
200+
r = request.GetKeyboardMapping(display = self.display,
201+
first_keycode = first_keycode,
202+
count = count)
203+
return r.keysyms
204+
205+
def change_keyboard_control(self, **keys):
206+
request.ChangeKeyboardControl(display = self.display,
207+
attrs = keys)
208+
209+
def get_keyboard_control(self):
210+
return request.GetKeyboardControl(display = self.display)
211+
83212
def bell(self, percent = 0):
84213
request.Bell(display = self.display,
85214
percent = percent)
86215

216+
def change_pointer_control(self, accel = None, threshold = None):
217+
218+
if accel is None:
219+
do_accel = 0
220+
accel_num = 0
221+
accel_denum = 0
222+
else:
223+
do_accel = 1
224+
accel_num, accel_denum = accel
225+
226+
if threshold is None:
227+
do_threshold = 0
228+
else:
229+
do_threshold = 1
230+
231+
request.ChangePointerControl(display = self.display,
232+
do_accel = do_accel,
233+
do_thres = do_threshold,
234+
accel_num = accel_num,
235+
accel_denum = accel_denum,
236+
threshold = threshold)
237+
238+
def get_pointer_control(self):
239+
return request.GetPointerControl(display = self.display)
240+
241+
def set_screen_saver(self, timeout, interval, prefer_blank, allow_exposures):
242+
request.SetScreenSaver(display = self.display,
243+
timeout = timeout,
244+
interval = interval,
245+
prefer_blank = prefer_blank,
246+
allow_exposures = allow_exposures)
247+
248+
def get_screen_saver(self):
249+
return request.GetScreenSaver(display = self.display)
250+
251+
def change_hosts(self, mode, host_family, host):
252+
request.ChangeHosts(display = self.display,
253+
mode = mode,
254+
host_family = host_family,
255+
host = host)
256+
257+
def list_hosts(self):
258+
return request.ListHosts(display = self.display)
259+
260+
def set_access_control(self, mode):
261+
request.SetAccessControl(display = self.display,
262+
mode = mode)
263+
264+
def set_close_down_mode(self, mode):
265+
request.SetCloseDownMode(display = self.display,
266+
mode = mode)
267+
268+
def force_screen_saver(self, mode):
269+
request.ForceScreenSaver(display = self.display,
270+
mode = mode)
271+
272+
def set_pointer_mapping(self, map):
273+
r = request.SetPointerMapping(display = self.display,
274+
map = map)
275+
return r.status
276+
277+
def get_pointer_mapping(self):
278+
r = request.GetPointerMapping(display = self.display)
279+
return r.map
280+
281+
def set_modifier_mapping(self, keycodes):
282+
r = request.SetModifierMapping(display = self.display,
283+
keycodes = keycodes)
284+
return r.status
285+
286+
def get_modifier_mapping(self):
287+
r = request.GetModifierMapping(display = self.display)
288+
return r.keycodes
289+
290+
def no_operation(self):
291+
request.NoOperation(self)
292+

Xlib/protocol/display.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: display.py,v 1.2 2000-08-07 10:30:19 petli Exp $
1+
# $Id: display.py,v 1.3 2000-08-08 09:47:45 petli Exp $
22
#
33
# Xlib.protocol.display -- core display communication
44
#
@@ -215,21 +215,20 @@ def allocate_resource_id(self):
215215
def free_resource_id(self, rid):
216216
"""d.free_resource_id(rid)
217217
218-
Free resource id RID.
219-
220-
Raises ResourceIDError if RID is not allocated.
218+
Free resource id RID. Attempts to free a resource id which
219+
isn't allocated by us are ignored.
221220
"""
222221

223222
i = rid & self.info.resource_id_mask
224223

225224
# Attempting to free a resource id outside our range
226225
if rid - i != self.info.resource_id_base:
227-
raise error.ResourceIDError('resource id 0x%08x is not in our range' % rid)
226+
return None
228227

229228
try:
230229
del self.resource_ids[i]
231230
except KeyError:
232-
raise error.ResourceIDError('resouce id 0x%08x is not allocated' % rid)
231+
pass
233232

234233

235234

0 commit comments

Comments
 (0)