Skip to content

Commit 4ef7a51

Browse files
committed
Started on high-level xlib
1 parent ffc9b5f commit 4ef7a51

3 files changed

Lines changed: 136 additions & 2 deletions

File tree

Xlib/display.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# $Id: display.py,v 1.1 2000-08-02 09:39:24 petli Exp $
2+
#
3+
# Xlib.display -- high level display object
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+
22+
# Xlib modules
23+
import error
24+
25+
# Xlib.protocol modules
26+
import protocol.display
27+
from protocol import request
28+
29+
30+
class Display:
31+
def __init__(self, display = None):
32+
self.display = protocol.display.Display(display)
33+
self.resource_ids = {}
34+
self.last_resource_id = 0
35+
36+
def fileno(self):
37+
return self.display.fileno()
38+
39+
def close(self):
40+
self.display.close()
41+
42+
43+
###
44+
### X requests
45+
###
46+
47+
def intern_atom(self, name, only_if_exists = 0):
48+
r = request.InternAtom(display = self.display,
49+
name = name,
50+
only_if_exists = only_if_exists)
51+
return r.atom
52+
53+
def get_atom_name(self, atom):
54+
r = request.GetAtomName(display = self.display,
55+
atom = atom)
56+
return r.name
57+
58+
def bell(self, percent = 0):
59+
request.Bell(display = self.display,
60+
percent = percent)
61+
62+
###
63+
### Private interface
64+
###
65+
66+
def allocate_resource_id(self):
67+
"""id = d.allocate_resource_id()
68+
69+
Allocate a new X resource id number ID.
70+
71+
Raises ResourceIDError if there are no free resource ids.
72+
"""
73+
74+
i = self.last_resource_id
75+
while self.resource_ids.has_key(i):
76+
i = i + 1
77+
if i > self.display.info.resource_id_mask:
78+
i = 0
79+
if i == self.last_resource_id:
80+
raise error.ResourceIDError('out of resource ids')
81+
82+
self.resource_ids[i] = None
83+
self.last_resource_id = i
84+
return self.info.resource_id_base | i
85+
86+
def free_resource_id(self, rid):
87+
"""d.free_resource_id(rid)
88+
89+
Free resource id RID.
90+
91+
Raises ResourceIDError if RID is not allocated.
92+
"""
93+
94+
i = rid & self.display.info.resource_id_mask
95+
96+
# Attempting to free a resource id outside our range
97+
if rid - i != self.display.info.resource_id_base:
98+
raise error.ResourceIDError('resource id 0x%08x is not in our range' % rid)
99+
100+
try:
101+
del self.resource_ids[i]
102+
except KeyError:
103+
raise error.ResourceIDError('resouce id 0x%08x is not allocated' % rid)
104+
105+

Xlib/error.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: error.py,v 1.1 2000-07-21 09:54:49 petli Exp $
1+
# $Id: error.py,v 1.2 2000-08-02 09:39:24 petli Exp $
22
#
33
# Xlib.error -- basic error classes
44
#
@@ -53,7 +53,11 @@ def __init__(self, whom):
5353

5454
def __str__(self):
5555
return 'Display connection closed by %s' % self.whom
56-
56+
57+
58+
class ResourceIDError(Exception): pass
59+
60+
5761
class XError(rq.GetAttrData, Exception):
5862
_fields = rq.Struct( rq.Card8('type'), # Always 0
5963
rq.Card8('code'),

Xlib/xobject/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# $Id: __init__.py,v 1.1 2000-08-02 09:39:24 petli Exp $
2+
#
3+
# Xlib.xobject.__init__ -- glue for Xlib.xobject package
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+
__all__ = [
22+
'font',
23+
'gc',
24+
'window',
25+
]

0 commit comments

Comments
 (0)