|
1
|
|
|
"""This module focuses on improvements to the Python libtcod API. |
|
2
|
|
|
""" |
|
3
|
|
|
from __future__ import absolute_import as _ |
|
4
|
|
|
|
|
5
|
|
|
import os as _os |
|
|
|
|
|
|
6
|
|
|
import sys as _sys |
|
7
|
|
|
|
|
8
|
|
|
import platform as _platform |
|
|
|
|
|
|
9
|
|
|
import weakref as _weakref |
|
10
|
|
|
import functools as _functools |
|
11
|
|
|
|
|
12
|
|
|
from tcod.libtcod import lib, ffi, BKGND_DEFAULT, BKGND_SET |
|
13
|
|
|
|
|
14
|
|
|
def _unpack_char_p(char_p): |
|
|
|
|
|
|
15
|
|
|
if char_p == ffi.NULL: |
|
|
|
|
|
|
16
|
|
|
return '' |
|
17
|
|
|
return ffi.string(char_p).decode() |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
def _int(int_or_str): |
|
20
|
|
|
'return an integer where a single character string may be expected' |
|
21
|
|
|
if isinstance(int_or_str, str): |
|
22
|
|
|
return ord(int_or_str) |
|
23
|
|
|
if isinstance(int_or_str, bytes): |
|
24
|
|
|
return int_or_str[0] |
|
25
|
|
|
return int(int_or_str) # check for __count__ |
|
26
|
|
|
|
|
27
|
|
|
def _cdata(cdata): |
|
28
|
|
|
"""covert value into a cffi.CData instance""" |
|
29
|
|
|
try: # first check for _CDataWrapper |
|
30
|
|
|
cdata = cdata.cdata |
|
31
|
|
|
except AttributeError: # assume cdata is valid |
|
|
|
|
|
|
32
|
|
|
pass |
|
33
|
|
|
except KeyError: |
|
|
|
|
|
|
34
|
|
|
pass |
|
35
|
|
|
if cdata is None or cdata == 0: # convert None to NULL |
|
36
|
|
|
cdata = ffi.NULL |
|
|
|
|
|
|
37
|
|
|
return cdata |
|
38
|
|
|
|
|
39
|
|
|
if _sys.version_info[0] == 2: # Python 2 |
|
40
|
|
|
def _bytes(string): |
|
|
|
|
|
|
41
|
|
|
if isinstance(string, unicode): |
|
|
|
|
|
|
42
|
|
|
return string.encode() |
|
43
|
|
|
return string |
|
44
|
|
|
|
|
45
|
|
|
def _unicode(string): |
|
|
|
|
|
|
46
|
|
|
if not isinstance(string, unicode): |
|
|
|
|
|
|
47
|
|
|
return string.decode() |
|
48
|
|
|
return string |
|
49
|
|
|
|
|
50
|
|
|
else: # Python 3 |
|
51
|
|
|
def _bytes(string): |
|
|
|
|
|
|
52
|
|
|
if isinstance(string, str): |
|
53
|
|
|
return string.encode() |
|
54
|
|
|
return string |
|
55
|
|
|
|
|
56
|
|
|
def _unicode(string): |
|
|
|
|
|
|
57
|
|
|
if isinstance(string, bytes): |
|
58
|
|
|
return string.decode() |
|
59
|
|
|
return string |
|
60
|
|
|
|
|
61
|
|
|
def _fmt_bytes(string): |
|
|
|
|
|
|
62
|
|
|
return _bytes(string).replace(b'%', b'%%') |
|
63
|
|
|
|
|
64
|
|
|
def _fmt_unicode(string): |
|
|
|
|
|
|
65
|
|
|
return _unicode(string).replace(u'%', u'%%') |
|
66
|
|
|
|
|
67
|
|
|
class _PropagateException(): |
|
68
|
|
|
""" context manager designed to propagate exceptions outside of a cffi |
|
69
|
|
|
callback context. normally cffi suppresses the exception |
|
70
|
|
|
|
|
71
|
|
|
when propagate is called this class will hold onto the error until the |
|
72
|
|
|
control flow leaves the context, then the error will be raised |
|
73
|
|
|
|
|
74
|
|
|
with _PropagateException as propagate: |
|
75
|
|
|
# give propagate as onerror parameter for ffi.def_extern |
|
76
|
|
|
""" |
|
77
|
|
|
|
|
78
|
|
|
def __init__(self): |
|
79
|
|
|
self.exc_info = None # (exception, exc_value, traceback) |
|
80
|
|
|
|
|
81
|
|
|
def propagate(self, *exc_info): |
|
82
|
|
|
""" set an exception to be raised once this context exits |
|
83
|
|
|
|
|
84
|
|
|
if multiple errors are caught, only keep the first exception raised |
|
85
|
|
|
""" |
|
86
|
|
|
if not self.exc_info: |
|
87
|
|
|
self.exc_info = exc_info |
|
88
|
|
|
|
|
89
|
|
|
def __enter__(self): |
|
90
|
|
|
""" once in context, only the propagate call is needed to use this |
|
91
|
|
|
class effectively |
|
92
|
|
|
""" |
|
93
|
|
|
return self.propagate |
|
94
|
|
|
|
|
95
|
|
|
def __exit__(self, type, value, traceback): |
|
|
|
|
|
|
96
|
|
|
""" if we're holding on to an exception, raise it now |
|
97
|
|
|
|
|
98
|
|
|
prefers our held exception over any current raising error |
|
99
|
|
|
|
|
100
|
|
|
self.exc_info is reset now in case of nested manager shenanigans |
|
101
|
|
|
""" |
|
102
|
|
|
if self.exc_info: |
|
103
|
|
|
type, value, traceback = self.exc_info |
|
|
|
|
|
|
104
|
|
|
self.exc_info = None |
|
105
|
|
|
if type: |
|
106
|
|
|
# Python 2/3 compatible throw |
|
107
|
|
|
exception = type(value) |
|
108
|
|
|
exception.__traceback__ = traceback |
|
109
|
|
|
raise exception |
|
110
|
|
|
|
|
111
|
|
|
class _CDataWrapper(object): |
|
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
def __init__(self, *args, **kargs): |
|
114
|
|
|
self.cdata = self._get_cdata_from_args(*args, **kargs) |
|
115
|
|
|
if self.cdata == None: |
|
116
|
|
|
self.cdata = ffi.NULL |
|
|
|
|
|
|
117
|
|
|
super(_CDataWrapper, self).__init__() |
|
118
|
|
|
|
|
119
|
|
|
def _get_cdata_from_args(self, *args, **kargs): |
|
|
|
|
|
|
120
|
|
|
if len(args) == 1 and isinstance(args[0], ffi.CData) and not kargs: |
|
|
|
|
|
|
121
|
|
|
return args[0] |
|
122
|
|
|
else: |
|
123
|
|
|
return None |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
def __hash__(self): |
|
127
|
|
|
return hash(self.cdata) |
|
128
|
|
|
|
|
129
|
|
|
def __eq__(self, other): |
|
130
|
|
|
try: |
|
131
|
|
|
return self.cdata == other.cdata |
|
132
|
|
|
except AttributeError: |
|
133
|
|
|
return NotImplemented |
|
134
|
|
|
|
|
135
|
|
|
def __getattr__(self, attr): |
|
136
|
|
|
if 'cdata' in self.__dict__: |
|
137
|
|
|
return getattr(self.__dict__['cdata'], attr) |
|
138
|
|
|
raise AttributeError(attr) |
|
139
|
|
|
|
|
140
|
|
|
def __setattr__(self, attr, value): |
|
141
|
|
|
if hasattr(self, 'cdata') and hasattr(self.cdata, attr): |
|
142
|
|
|
setattr(self.cdata, attr, value) |
|
143
|
|
|
else: |
|
144
|
|
|
super(_CDataWrapper, self).__setattr__(attr, value) |
|
145
|
|
|
|
|
146
|
|
|
def _assert_cdata_is_not_null(func): |
|
147
|
|
|
"""Any BSP methods which use a cdata object in a TCOD call need to have |
|
148
|
|
|
a sanity check, otherwise it may end up passing a NULL pointer""" |
|
149
|
|
|
if __debug__: |
|
150
|
|
|
@_functools.wraps(func) |
|
151
|
|
|
def check_sanity(*args, **kargs): |
|
|
|
|
|
|
152
|
|
|
assert self.cdata != ffi.NULL and self.cdata is not None, \ |
|
|
|
|
|
|
153
|
|
|
'cannot use function, cdata is %r' % self.cdata |
|
|
|
|
|
|
154
|
|
|
return func(*args, **kargs) |
|
155
|
|
|
return func |
|
156
|
|
|
|
|
157
|
|
|
class BSP(_CDataWrapper): |
|
158
|
|
|
""" |
|
159
|
|
|
|
|
160
|
|
|
|
|
161
|
|
|
Attributes: |
|
162
|
|
|
x (int): Rectangle left coordinate. |
|
163
|
|
|
y (int): Rectangle top coordinate. |
|
164
|
|
|
w (int): Rectangle width. |
|
165
|
|
|
h (int): Rectangle height. |
|
166
|
|
|
|
|
167
|
|
|
Args: |
|
168
|
|
|
x (int): Rectangle left coordinate. |
|
169
|
|
|
y (int): Rectangle top coordinate. |
|
170
|
|
|
w (int): Rectangle width. |
|
171
|
|
|
h (int): Rectangle height. |
|
172
|
|
|
|
|
173
|
|
|
.. versionchanged:: 2.0 |
|
174
|
|
|
You can create BSP's with this class contructor instead of using |
|
175
|
|
|
:any:`bsp_new_with_size`. |
|
176
|
|
|
""" |
|
177
|
|
|
|
|
178
|
|
|
def __init__(self, *args, **kargs): |
|
179
|
|
|
self._reference = None # to prevent garbage collection |
|
180
|
|
|
self._children = _weakref.WeakSet() # used by _invalidate_children |
|
181
|
|
|
super(BSP, self).__init__(*args, **kargs) |
|
182
|
|
|
if self._get_cdata_from_args(*args, **kargs) is None: |
|
183
|
|
|
self._init(*args, **kargs) |
|
184
|
|
|
|
|
185
|
|
|
def _init(self, x, y, w, h): |
|
|
|
|
|
|
186
|
|
|
self.cdata = ffi.gc(lib.TCOD_bsp_new_with_size(x, y, w, h), |
|
|
|
|
|
|
187
|
|
|
lib.TCOD_bsp_delete) |
|
|
|
|
|
|
188
|
|
|
|
|
189
|
|
|
def _pass_reference(self, reference): |
|
|
|
|
|
|
190
|
|
|
self._reference = reference |
|
191
|
|
|
self._reference._children.add(self) |
|
192
|
|
|
return self |
|
193
|
|
|
|
|
194
|
|
|
def _invalidate_children(self): |
|
195
|
|
|
"""Invalidates BSP instances known to be based off of this one.""" |
|
196
|
|
|
for child in self._children: |
|
197
|
|
|
child._reference = None |
|
198
|
|
|
child._invalidate_children() |
|
199
|
|
|
child.cdata = ffi.NULL |
|
|
|
|
|
|
200
|
|
|
self._children.clear() |
|
201
|
|
|
|
|
202
|
|
|
def __str__(self): |
|
203
|
|
|
"""Provide a useful readout when printed.""" |
|
204
|
|
|
if not self.cdata: |
|
205
|
|
|
return '<%s NULL!>' % self.__class__.__name__ |
|
206
|
|
|
|
|
207
|
|
|
status = 'leaf' |
|
208
|
|
|
if not self.is_leaf(): |
|
209
|
|
|
status = ('split at dicision=%i,orientation=%r' % |
|
210
|
|
|
(self.get_division(), self.get_orientation())) |
|
211
|
|
|
|
|
212
|
|
|
return ('<%s(x=%i,y=%i,w=%i,h=%i)depth=%i,%s>' % |
|
213
|
|
|
(self.__class__.__name__, |
|
214
|
|
|
self.x, self.y, self.w, self.h, self.get_depth(), status)) |
|
215
|
|
|
|
|
216
|
|
|
def get_depth(self): |
|
217
|
|
|
"""Return the depth of this node. |
|
218
|
|
|
|
|
219
|
|
|
Returns: |
|
220
|
|
|
int: This nodes depth. |
|
221
|
|
|
|
|
222
|
|
|
.. versionadded:: 2.0 |
|
223
|
|
|
""" |
|
224
|
|
|
return self.cdata.level |
|
225
|
|
|
|
|
226
|
|
|
def get_division(self): |
|
227
|
|
|
"""Return the point where this node was divided into parts. |
|
228
|
|
|
|
|
229
|
|
|
Returns: |
|
230
|
|
|
Optional[int]: The integer of where the node was split or None. |
|
231
|
|
|
|
|
232
|
|
|
.. versionadded:: 2.0 |
|
233
|
|
|
""" |
|
234
|
|
|
if self.is_leaf(): |
|
235
|
|
|
return None |
|
236
|
|
|
return self.cdata.position |
|
237
|
|
|
|
|
238
|
|
|
def get_orientation(self): |
|
239
|
|
|
"""Return this nodes split orientation. |
|
240
|
|
|
|
|
241
|
|
|
Returns: |
|
242
|
|
|
Optional[Text]: 'horizontal', 'vertical', or None |
|
243
|
|
|
|
|
244
|
|
|
.. versionadded:: 2.0 |
|
245
|
|
|
""" |
|
246
|
|
|
if self.is_leaf(): |
|
247
|
|
|
return None |
|
248
|
|
|
elif self.cdata.horizontal: |
|
249
|
|
|
return 'horizontal' |
|
250
|
|
|
else: |
|
251
|
|
|
return 'vertical' |
|
252
|
|
|
|
|
253
|
|
|
@_assert_cdata_is_not_null |
|
254
|
|
|
def split_once(self, orientation, position): |
|
255
|
|
|
""" |
|
256
|
|
|
|
|
257
|
|
|
.. versionadded:: 2.0 |
|
258
|
|
|
""" |
|
259
|
|
|
# orientation = horz |
|
260
|
|
|
if orientation[:1].lower() == 'h': |
|
261
|
|
|
lib.TCOD_bsp_split_once(self.cdata, True, position) |
|
|
|
|
|
|
262
|
|
|
elif orientation[:1].lower() == 'v': |
|
263
|
|
|
lib.TCOD_bsp_split_once(self.cdata, False, position) |
|
|
|
|
|
|
264
|
|
|
else: |
|
265
|
|
|
raise ValueError("orientation must be 'horizontal' or 'vertical'" |
|
266
|
|
|
"\nNot %r" % orientation) |
|
267
|
|
|
|
|
268
|
|
|
@_assert_cdata_is_not_null |
|
269
|
|
|
def split_recursive(self, depth, min_width, min_height, |
|
270
|
|
|
max_horz_ratio, max_vert_raito, random=None): |
|
271
|
|
|
""" |
|
272
|
|
|
|
|
273
|
|
|
.. versionadded:: 2.0 |
|
274
|
|
|
""" |
|
275
|
|
|
lib.TCOD_bsp_split_recursive(self.cdata, random or ffi.NULL, |
|
|
|
|
|
|
276
|
|
|
depth, min_width, min_height, |
|
277
|
|
|
max_horz_ratio, max_vert_raito) |
|
278
|
|
|
|
|
279
|
|
|
@_assert_cdata_is_not_null |
|
280
|
|
|
def resize(self, x, y, w, h): |
|
281
|
|
|
"""Resize this BSP to the provided rectangle. |
|
282
|
|
|
|
|
283
|
|
|
Args: |
|
284
|
|
|
x (int): Rectangle left coordinate. |
|
285
|
|
|
y (int): Rectangle top coordinate. |
|
286
|
|
|
w (int): Rectangle width. |
|
287
|
|
|
h (int): Rectangle height. |
|
288
|
|
|
|
|
289
|
|
|
.. versionadded:: 2.0 |
|
290
|
|
|
""" |
|
291
|
|
|
lib.TCOD_bsp_resize(self.cdata, x, y, w, h) |
|
|
|
|
|
|
292
|
|
|
|
|
293
|
|
|
@_assert_cdata_is_not_null |
|
294
|
|
|
def get_left(self): |
|
295
|
|
|
"""Return this BSP's 'left' child. |
|
296
|
|
|
|
|
297
|
|
|
Returns None if this BSP is a leaf node. |
|
298
|
|
|
|
|
299
|
|
|
Returns: |
|
300
|
|
|
Optional[BSP]: This nodes left/top child or None. |
|
301
|
|
|
|
|
302
|
|
|
.. versionadded:: 2.0 |
|
303
|
|
|
""" |
|
304
|
|
|
if self.is_leaf(): |
|
305
|
|
|
return None |
|
306
|
|
|
return BSP(lib.TCOD_bsp_left(self.cdata))._pass_reference(self) |
|
|
|
|
|
|
307
|
|
|
|
|
308
|
|
|
@_assert_cdata_is_not_null |
|
309
|
|
|
def get_right(self): |
|
310
|
|
|
"""Return this BSP's 'right' child. |
|
311
|
|
|
|
|
312
|
|
|
Returns None if this BSP is a leaf node. |
|
313
|
|
|
|
|
314
|
|
|
Returns: |
|
315
|
|
|
Optional[BSP]: This nodes right/bottom child or None. |
|
316
|
|
|
|
|
317
|
|
|
.. versionadded:: 2.0 |
|
318
|
|
|
""" |
|
319
|
|
|
if self.is_leaf(): |
|
320
|
|
|
return None |
|
321
|
|
|
return BSP(lib.TCOD_bsp_right(self.cdata))._pass_reference(self) |
|
|
|
|
|
|
322
|
|
|
|
|
323
|
|
|
@_assert_cdata_is_not_null |
|
324
|
|
|
def get_parent(self): |
|
325
|
|
|
"""Return this BSP's parent node. |
|
326
|
|
|
|
|
327
|
|
|
Returns: |
|
328
|
|
|
Optional[BSP]: Returns the parent node as a BSP instance. |
|
329
|
|
|
Returns None if this BSP has no parent. |
|
330
|
|
|
|
|
331
|
|
|
.. versionadded:: 2.0 |
|
332
|
|
|
""" |
|
333
|
|
|
node = BSP(lib.TCOD_bsp_father(self.cdata))._pass_reference(self) |
|
|
|
|
|
|
334
|
|
|
if node.cdata == ffi.NULL: |
|
|
|
|
|
|
335
|
|
|
return None |
|
336
|
|
|
return node |
|
337
|
|
|
|
|
338
|
|
|
@_assert_cdata_is_not_null |
|
339
|
|
|
def get_children(self): |
|
340
|
|
|
"""Return this instances immediate children, if any. |
|
341
|
|
|
|
|
342
|
|
|
Returns: |
|
343
|
|
|
Optional[Tuple[BSP, BSP]]: |
|
344
|
|
|
Returns a tuple of (left, right) BSP instances. |
|
345
|
|
|
Returns None if this BSP has no children. |
|
346
|
|
|
|
|
347
|
|
|
.. versionadded:: 2.0 |
|
348
|
|
|
""" |
|
349
|
|
|
if self.is_leaf(): |
|
350
|
|
|
return None |
|
351
|
|
|
return (BSP(lib.TCOD_bsp_left(self.cdata))._pass_reference(self), |
|
|
|
|
|
|
352
|
|
|
BSP(lib.TCOD_bsp_right(self.cdata))._pass_reference(self)) |
|
|
|
|
|
|
353
|
|
|
|
|
354
|
|
|
@_assert_cdata_is_not_null |
|
355
|
|
|
def walk(self): |
|
356
|
|
|
"""Iterate over this BSP's hieracrhy. |
|
357
|
|
|
|
|
358
|
|
|
The iterator will include the instance which called it. |
|
359
|
|
|
It will traverse its own children and grandchildren, in no particular |
|
360
|
|
|
order. |
|
361
|
|
|
|
|
362
|
|
|
Returns: |
|
363
|
|
|
Iterator[BSP]: An iterator of BSP nodes. |
|
364
|
|
|
|
|
365
|
|
|
.. versionadded:: 2.0 |
|
366
|
|
|
""" |
|
367
|
|
|
children = self.get_children() or () |
|
368
|
|
|
for child in children: |
|
369
|
|
|
for grandchild in child.walk(): |
|
370
|
|
|
yield grandchild |
|
371
|
|
|
yield self |
|
372
|
|
|
|
|
373
|
|
|
@_assert_cdata_is_not_null |
|
374
|
|
|
def is_leaf(self): |
|
375
|
|
|
"""Returns True if this node is a leaf. |
|
376
|
|
|
|
|
377
|
|
|
Returns: |
|
378
|
|
|
bool: |
|
379
|
|
|
True if this node is a leaf. |
|
380
|
|
|
False when this node has children. |
|
381
|
|
|
|
|
382
|
|
|
.. versionadded:: 2.0 |
|
383
|
|
|
""" |
|
384
|
|
|
return bool(lib.TCOD_bsp_is_leaf(self.cdata)) |
|
|
|
|
|
|
385
|
|
|
|
|
386
|
|
|
@_assert_cdata_is_not_null |
|
387
|
|
|
def contains(self, x, y): |
|
388
|
|
|
"""Returns True if this node contains these coordinates. |
|
389
|
|
|
|
|
390
|
|
|
Args: |
|
391
|
|
|
x (int): X position to check. |
|
392
|
|
|
y (int): Y position to check. |
|
393
|
|
|
|
|
394
|
|
|
Returns: |
|
395
|
|
|
bool: True if this node contains these coordinates. |
|
396
|
|
|
Otherwise False. |
|
397
|
|
|
|
|
398
|
|
|
.. versionadded:: 2.0 |
|
399
|
|
|
""" |
|
400
|
|
|
return bool(lib.TCOD_bsp_contains(self.cdata, x, y)) |
|
|
|
|
|
|
401
|
|
|
|
|
402
|
|
|
@_assert_cdata_is_not_null |
|
403
|
|
|
def find_node(self, x, y): |
|
404
|
|
|
"""Return the deepest node which contains these coordinates. |
|
405
|
|
|
|
|
406
|
|
|
Returns: |
|
407
|
|
|
Optional[BSP]: BSP object or None. |
|
408
|
|
|
|
|
409
|
|
|
.. versionadded:: 2.0 |
|
410
|
|
|
""" |
|
411
|
|
|
node = BSP(lib.TCOD_bsp_find_node(self.cdata, |
|
|
|
|
|
|
412
|
|
|
x, y))._pass_reference(self) |
|
413
|
|
|
if node.cdata == ffi.NULL: |
|
|
|
|
|
|
414
|
|
|
node = None |
|
415
|
|
|
return node |
|
416
|
|
|
|
|
417
|
|
|
class HeightMap(_CDataWrapper): |
|
418
|
|
|
"""libtcod HeightMap instance |
|
419
|
|
|
""" |
|
420
|
|
|
|
|
421
|
|
|
def __init__(self, *args, **kargs): |
|
422
|
|
|
super(HeightMap, self).__init__(*args, **kargs) |
|
423
|
|
|
if not self.cdata: |
|
424
|
|
|
self._init(*args, **kargs) |
|
425
|
|
|
|
|
426
|
|
|
def _init(self, width, height): |
|
|
|
|
|
|
427
|
|
|
self.cdata = ffi.gc(lib.TCOD_heightmap_new(width, height), |
|
|
|
|
|
|
428
|
|
|
lib.TCOD_heightmap_delete) |
|
|
|
|
|
|
429
|
|
|
|
|
430
|
|
|
|
|
431
|
|
|
class Key(_CDataWrapper): |
|
432
|
|
|
"""Key Event instance |
|
433
|
|
|
|
|
434
|
|
|
Attributes: |
|
435
|
|
|
vk (int): TCOD_keycode_t key code |
|
436
|
|
|
c (int): character if vk == TCODK_CHAR else 0 |
|
437
|
|
|
text (Text): text[TCOD_KEY_TEXT_SIZE]; text if vk == TCODK_TEXT else text[0] == '\0' |
|
|
|
|
|
|
438
|
|
|
pressed (bool): does this correspond to a key press or key release event ? |
|
|
|
|
|
|
439
|
|
|
lalt (bool): True when left alt is held. |
|
440
|
|
|
lctrl (bool): True when left control is held. |
|
441
|
|
|
lmeta (bool): True when left meta key is held. |
|
442
|
|
|
ralt (bool): True when right alt is held. |
|
443
|
|
|
rctrl (bool): True when right control is held. |
|
444
|
|
|
rmeta (bool): True when right meta key is held. |
|
445
|
|
|
shift (bool): True when any shift is held. |
|
446
|
|
|
""" |
|
447
|
|
|
|
|
448
|
|
|
_BOOL_ATTRIBUTES = ('lalt', 'lctrl', 'lmeta', |
|
449
|
|
|
'ralt', 'rctrl', 'rmeta', 'pressed', 'shift') |
|
450
|
|
|
|
|
451
|
|
|
def __init__(self, *args, **kargs): |
|
452
|
|
|
super(Key, self).__init__(*args, **kargs) |
|
453
|
|
|
if self.cdata == ffi.NULL: |
|
|
|
|
|
|
454
|
|
|
self.cdata = ffi.new('TCOD_key_t*') |
|
|
|
|
|
|
455
|
|
|
|
|
456
|
|
|
def __getattr__(self, attr): |
|
457
|
|
|
if attr in self._BOOL_ATTRIBUTES: |
|
458
|
|
|
return bool(getattr(self.cdata, attr)) |
|
459
|
|
|
if attr == 'c': |
|
460
|
|
|
return ord(getattr(self.cdata, attr)) |
|
461
|
|
|
if attr == 'text': |
|
462
|
|
|
return _unpack_char_p(getattr(self.cdata, attr)) |
|
463
|
|
|
return super(Key, self).__getattr__(attr) |
|
464
|
|
|
|
|
465
|
|
|
class Mouse(_CDataWrapper): |
|
466
|
|
|
"""Mouse event instance |
|
467
|
|
|
|
|
468
|
|
|
Attributes: |
|
469
|
|
|
x (int): Absolute mouse position at pixel x. |
|
470
|
|
|
y (int): |
|
471
|
|
|
dx (int): Movement since last update in pixels. |
|
472
|
|
|
dy (int): |
|
473
|
|
|
cx (int): Cell coordinates in the root console. |
|
474
|
|
|
cy (int): |
|
475
|
|
|
dcx (int): Movement since last update in console cells. |
|
476
|
|
|
dcy (int): |
|
477
|
|
|
lbutton (bool): Left button status. |
|
478
|
|
|
rbutton (bool): Right button status. |
|
479
|
|
|
mbutton (bool): Middle button status. |
|
480
|
|
|
lbutton_pressed (bool): Left button pressed event. |
|
481
|
|
|
rbutton_pressed (bool): Right button pressed event. |
|
482
|
|
|
mbutton_pressed (bool): Middle button pressed event. |
|
483
|
|
|
wheel_up (bool): Wheel up event. |
|
484
|
|
|
wheel_down (bool): Wheel down event. |
|
485
|
|
|
""" |
|
486
|
|
|
|
|
487
|
|
|
def __init__(self, *args, **kargs): |
|
488
|
|
|
super(Mouse, self).__init__(*args, **kargs) |
|
489
|
|
|
if self.cdata == ffi.NULL: |
|
|
|
|
|
|
490
|
|
|
self.cdata = ffi.new('TCOD_mouse_t*') |
|
|
|
|
|
|
491
|
|
|
|
|
492
|
|
|
|
|
493
|
|
|
class Console(_CDataWrapper): |
|
494
|
|
|
""" |
|
495
|
|
|
Args: |
|
496
|
|
|
width (int): Width of the new Console. |
|
497
|
|
|
height (int): Height of the new Console. |
|
498
|
|
|
|
|
499
|
|
|
.. versionadded:: 2.0 |
|
500
|
|
|
""" |
|
501
|
|
|
|
|
502
|
|
|
def __init__(self, *args, **kargs): |
|
|
|
|
|
|
503
|
|
|
self.cdata = self._get_cdata_from_args(*args, **kargs) |
|
504
|
|
|
if self.cdata is None: |
|
505
|
|
|
self._init(*args, **kargs) |
|
506
|
|
|
|
|
507
|
|
|
def _init(self, width, height): |
|
|
|
|
|
|
508
|
|
|
self.cdata = ffi.gc(lib.TCOD_console_new(width, height), |
|
|
|
|
|
|
509
|
|
|
lib.TCOD_console_delete) |
|
|
|
|
|
|
510
|
|
|
|
|
511
|
|
|
def get_width(self): |
|
512
|
|
|
"""Return the width of this console. |
|
513
|
|
|
|
|
514
|
|
|
Returns: |
|
515
|
|
|
int: The width of a Console. |
|
516
|
|
|
""" |
|
517
|
|
|
return lib.TCOD_console_get_width(self.cdata) |
|
|
|
|
|
|
518
|
|
|
|
|
519
|
|
|
def get_height(self): |
|
520
|
|
|
"""Return the height of this console. |
|
521
|
|
|
|
|
522
|
|
|
Returns: |
|
523
|
|
|
int: The height of a Console. |
|
524
|
|
|
""" |
|
525
|
|
|
return lib.TCOD_console_get_height(self.cdata) |
|
|
|
|
|
|
526
|
|
|
|
|
527
|
|
|
def set_default_bg(self, color): |
|
528
|
|
|
"""Change the default backround color for this console. |
|
529
|
|
|
|
|
530
|
|
|
Args: |
|
531
|
|
|
color (Union[Tuple[int, int, int], Sequence[int]]): |
|
532
|
|
|
An (r, g, b) sequence or Color instance. |
|
533
|
|
|
""" |
|
534
|
|
|
lib.TCOD_console_set_default_background(self.cdata, color) |
|
|
|
|
|
|
535
|
|
|
|
|
536
|
|
|
def set_default_fg(self, color): |
|
537
|
|
|
"""Change the default foreground color for this console. |
|
538
|
|
|
|
|
539
|
|
|
Args: |
|
540
|
|
|
color (Union[Tuple[int, int, int], Sequence[int]]): |
|
541
|
|
|
An (r, g, b) sequence or Color instance. |
|
542
|
|
|
""" |
|
543
|
|
|
lib.TCOD_console_set_default_foreground(self.cdata, color) |
|
|
|
|
|
|
544
|
|
|
|
|
545
|
|
|
def clear(self): |
|
546
|
|
|
"""Reset this console to its default colors and the space character. |
|
547
|
|
|
""" |
|
548
|
|
|
lib.TCOD_console_clear(self.cdata) |
|
|
|
|
|
|
549
|
|
|
|
|
550
|
|
|
def put_char(self, x, y, ch, flag=BKGND_DEFAULT): |
|
551
|
|
|
"""Draw the character c at x,y using the default colors and a blend mode. |
|
|
|
|
|
|
552
|
|
|
|
|
553
|
|
|
Args: |
|
554
|
|
|
x (int): Character x position from the left. |
|
555
|
|
|
y (int): Character y position from the top. |
|
556
|
|
|
c (Union[int, AnyStr]): Character to draw, can be an integer or string. |
|
|
|
|
|
|
557
|
|
|
flag (int): Blending mode to use, defaults to BKGND_DEFAULT. |
|
558
|
|
|
""" |
|
559
|
|
|
lib.TCOD_console_put_char(self.cdata, x, y, _int(ch), flag) |
|
|
|
|
|
|
560
|
|
|
|
|
561
|
|
|
def put_char_ex(self, x, y, ch, fore, back): |
|
562
|
|
|
"""Draw the character c at x,y using the colors fore and back. |
|
563
|
|
|
|
|
564
|
|
|
Args: |
|
565
|
|
|
x (int): Character x position from the left. |
|
566
|
|
|
y (int): Character y position from the top. |
|
567
|
|
|
c (Union[int, AnyStr]): Character to draw, can be an integer or string. |
|
|
|
|
|
|
568
|
|
|
fore (Union[Tuple[int, int, int], Sequence[int]]): |
|
569
|
|
|
An (r, g, b) sequence or Color instance. |
|
570
|
|
|
back (Union[Tuple[int, int, int], Sequence[int]]): |
|
571
|
|
|
An (r, g, b) sequence or Color instance. |
|
572
|
|
|
""" |
|
573
|
|
|
lib.TCOD_console_put_char_ex(self.cdata, x, y, |
|
|
|
|
|
|
574
|
|
|
_int(ch), fore, back) |
|
575
|
|
|
|
|
576
|
|
|
def set_char_bg(self, x, y, col, flag=BKGND_SET): |
|
577
|
|
|
"""Change the background color of x,y to col using a blend mode. |
|
578
|
|
|
|
|
579
|
|
|
Args: |
|
580
|
|
|
x (int): Character x position from the left. |
|
581
|
|
|
y (int): Character y position from the top. |
|
582
|
|
|
col (Union[Tuple[int, int, int], Sequence[int]]): |
|
583
|
|
|
An (r, g, b) sequence or Color instance. |
|
584
|
|
|
flag (int): Blending mode to use, defaults to BKGND_SET. |
|
585
|
|
|
""" |
|
586
|
|
|
lib.TCOD_console_set_char_background(self.cdata, x, y, col, flag) |
|
|
|
|
|
|
587
|
|
|
|
|
588
|
|
|
def set_char_fg(self, x, y, col): |
|
589
|
|
|
"""Change the foreground color of x,y to col. |
|
590
|
|
|
|
|
591
|
|
|
Args: |
|
592
|
|
|
x (int): Character x position from the left. |
|
593
|
|
|
y (int): Character y position from the top. |
|
594
|
|
|
col (Union[Tuple[int, int, int], Sequence[int]]): |
|
595
|
|
|
An (r, g, b) sequence or Color instance. |
|
596
|
|
|
""" |
|
597
|
|
|
lib.TCOD_console_set_char_foreground(self.cdata, x, y, col) |
|
|
|
|
|
|
598
|
|
|
|
|
599
|
|
|
def set_char(self, x, y, ch): |
|
600
|
|
|
"""Change the character at x,y to c, keeping the current colors. |
|
601
|
|
|
|
|
602
|
|
|
Args: |
|
603
|
|
|
x (int): Character x position from the left. |
|
604
|
|
|
y (int): Character y position from the top. |
|
605
|
|
|
c (Union[int, AnyStr]): Character to draw, can be an integer or string. |
|
|
|
|
|
|
606
|
|
|
""" |
|
607
|
|
|
lib.TCOD_console_set_char(self.cdata, x, y, _int(ch)) |
|
|
|
|
|
|
608
|
|
|
|
|
609
|
|
|
def set_default_bg_blend(self, flag): |
|
610
|
|
|
"""Change the default blend mode for this console. |
|
611
|
|
|
|
|
612
|
|
|
Args: |
|
613
|
|
|
flag (int): Blend mode to use by default. |
|
614
|
|
|
""" |
|
615
|
|
|
lib.TCOD_console_set_background_flag(self.cdata, flag) |
|
|
|
|
|
|
616
|
|
|
|
|
617
|
|
|
def get_default_bg_blend(self): |
|
618
|
|
|
"""Return this consoles current blend mode. |
|
619
|
|
|
""" |
|
620
|
|
|
return lib.TCOD_console_get_background_flag(self.cdata) |
|
|
|
|
|
|
621
|
|
|
|
|
622
|
|
|
def set_alignment(self, alignment): |
|
623
|
|
|
"""Change this consoles current alignment mode. |
|
624
|
|
|
|
|
625
|
|
|
* tcod.LEFT |
|
626
|
|
|
* tcod.CENTER |
|
627
|
|
|
* tcod.RIGHT |
|
628
|
|
|
|
|
629
|
|
|
Args: |
|
630
|
|
|
alignment (int): |
|
631
|
|
|
""" |
|
632
|
|
|
lib.TCOD_console_set_alignment(self.cdata, alignment) |
|
|
|
|
|
|
633
|
|
|
|
|
634
|
|
|
def get_alignment(self): |
|
635
|
|
|
"""Return this consoles current alignment mode. |
|
636
|
|
|
""" |
|
637
|
|
|
return lib.TCOD_console_get_alignment(self.cdata) |
|
|
|
|
|
|
638
|
|
|
|
|
639
|
|
|
def print_str(self, x, y, fmt): |
|
640
|
|
|
"""Print a color formatted string on a console. |
|
641
|
|
|
|
|
642
|
|
|
Args: |
|
643
|
|
|
x (int): Character x position from the left. |
|
644
|
|
|
y (int): Character y position from the top. |
|
645
|
|
|
fmt (AnyStr): A unicode or bytes string optionaly using color codes. |
|
|
|
|
|
|
646
|
|
|
""" |
|
647
|
|
|
lib.TCOD_console_print_utf(self.cdata, x, y, _fmt_unicode(fmt)) |
|
|
|
|
|
|
648
|
|
|
|
|
649
|
|
|
def print_ex(self, x, y, flag, alignment, fmt): |
|
650
|
|
|
"""Print a string on a console using a blend mode and alignment mode. |
|
651
|
|
|
|
|
652
|
|
|
Args: |
|
653
|
|
|
x (int): Character x position from the left. |
|
654
|
|
|
y (int): Character y position from the top. |
|
655
|
|
|
""" |
|
656
|
|
|
lib.TCOD_console_print_ex_utf(self.cdata, x, y, |
|
|
|
|
|
|
657
|
|
|
flag, alignment, _fmt_unicode(fmt)) |
|
658
|
|
|
|
|
659
|
|
|
def print_rect(self, x, y, w, h, fmt): |
|
|
|
|
|
|
660
|
|
|
"""Print a string constrained to a rectangle. |
|
661
|
|
|
|
|
662
|
|
|
If h > 0 and the bottom of the rectangle is reached, |
|
663
|
|
|
the string is truncated. If h = 0, |
|
664
|
|
|
the string is only truncated if it reaches the bottom of the console. |
|
665
|
|
|
|
|
666
|
|
|
|
|
667
|
|
|
|
|
668
|
|
|
Returns: |
|
669
|
|
|
int: The number of lines of text once word-wrapped. |
|
670
|
|
|
""" |
|
671
|
|
|
return lib.TCOD_console_print_rect_utf( |
|
|
|
|
|
|
672
|
|
|
self.cdata, x, y, width, height, _fmt_unicode(fmt)) |
|
|
|
|
|
|
673
|
|
|
|
|
674
|
|
|
def print_rect_ex(self, x, y, w, h, flag, alignment, fmt): |
|
|
|
|
|
|
675
|
|
|
"""Print a string constrained to a rectangle with blend and alignment. |
|
676
|
|
|
|
|
677
|
|
|
Returns: |
|
678
|
|
|
int: The number of lines of text once word-wrapped. |
|
679
|
|
|
""" |
|
680
|
|
|
return lib.TCOD_console_print_rect_ex_utf(self.cdata, |
|
|
|
|
|
|
681
|
|
|
x, y, width, height, flag, alignment, _fmt_unicode(fmt)) |
|
|
|
|
|
|
682
|
|
|
|
|
683
|
|
|
def get_height_rect(self, x, y, width, height, fmt): |
|
684
|
|
|
"""Return the height of this text once word-wrapped into this rectangle. |
|
|
|
|
|
|
685
|
|
|
|
|
686
|
|
|
Returns: |
|
687
|
|
|
int: The number of lines of text once word-wrapped. |
|
688
|
|
|
""" |
|
689
|
|
|
return lib.TCOD_console_get_height_rect_utf( |
|
|
|
|
|
|
690
|
|
|
self.cdata, x, y, width, height, _fmt_unicode(fmt)) |
|
691
|
|
|
|
|
692
|
|
|
def rect(self, x, y, w, h, clr, flag=BKGND_DEFAULT): |
|
693
|
|
|
"""Draw a the background color on a rect optionally clearing the text. |
|
694
|
|
|
|
|
695
|
|
|
If clr is True the affected tiles are changed to space character. |
|
696
|
|
|
""" |
|
697
|
|
|
lib.TCOD_console_rect(self.cdata, x, y, w, h, clr, flag) |
|
|
|
|
|
|
698
|
|
|
|
|
699
|
|
|
def hline(self, x, y, width, flag=BKGND_DEFAULT): |
|
700
|
|
|
"""Draw a horizontal line on the console. |
|
701
|
|
|
|
|
702
|
|
|
This always uses the character 196, the horizontal line character. |
|
703
|
|
|
""" |
|
704
|
|
|
lib.TCOD_console_hline(self.cdata, x, y, width, flag) |
|
|
|
|
|
|
705
|
|
|
|
|
706
|
|
|
def vline(self, x, y, height, flag=BKGND_DEFAULT): |
|
707
|
|
|
"""Draw a vertical line on the console. |
|
708
|
|
|
|
|
709
|
|
|
This always uses the character 179, the vertical line character. |
|
710
|
|
|
""" |
|
711
|
|
|
lib.TCOD_console_vline(self.cdata, x, y, height, flag) |
|
|
|
|
|
|
712
|
|
|
|
|
713
|
|
|
def print_frame(self, x, y, w, h, clear=True, flag=BKGND_DEFAULT, fmt=b''): |
|
714
|
|
|
"""Draw a framed rectangle with optinal text. |
|
715
|
|
|
|
|
716
|
|
|
This uses the default background color and blend mode to fill the |
|
717
|
|
|
rectangle and the default foreground to draw the outline. |
|
718
|
|
|
|
|
719
|
|
|
fmt will be printed on the inside of the rectangle, word-wrapped. |
|
720
|
|
|
""" |
|
721
|
|
|
lib.TCOD_console_print_frame(self.cdata, x, y, w, h, clear, flag, |
|
|
|
|
|
|
722
|
|
|
_fmt_bytes(fmt)) |
|
723
|
|
|
|
|
724
|
|
|
def get_default_bg(self): |
|
725
|
|
|
"""Return this consoles default background color.""" |
|
726
|
|
|
return Color.from_cdata( |
|
|
|
|
|
|
727
|
|
|
lib.TCOD_console_get_default_background(self.cdata)) |
|
|
|
|
|
|
728
|
|
|
|
|
729
|
|
|
def get_default_fg(self): |
|
730
|
|
|
"""Return this consoles default foreground color.""" |
|
731
|
|
|
return Color.from_cdata( |
|
|
|
|
|
|
732
|
|
|
lib.TCOD_console_get_default_foreground(self.cdata)) |
|
|
|
|
|
|
733
|
|
|
|
|
734
|
|
|
def get_char_bg(self, x, y): |
|
735
|
|
|
"""Return the background color at the x,y of this console.""" |
|
736
|
|
|
return Color.from_cdata( |
|
|
|
|
|
|
737
|
|
|
lib.TCOD_console_get_char_background(self.cdata, x, y)) |
|
|
|
|
|
|
738
|
|
|
|
|
739
|
|
|
def get_char_fg(self, x, y): |
|
740
|
|
|
"""Return the foreground color at the x,y of this console.""" |
|
741
|
|
|
return Color.from_cdata( |
|
|
|
|
|
|
742
|
|
|
lib.TCOD_console_get_char_foreground(self.cdata, x, y)) |
|
|
|
|
|
|
743
|
|
|
|
|
744
|
|
|
def get_char(self, x, y): |
|
745
|
|
|
"""Return the character at the x,y of this console.""" |
|
746
|
|
|
return lib.TCOD_console_get_char(self.cdata, x, y) |
|
|
|
|
|
|
747
|
|
|
|
|
748
|
|
|
def blit(self, x, y, w, h, |
|
749
|
|
|
dest, dest_x, dest_y, fg_alpha=1, bg_alpha=1): |
|
|
|
|
|
|
750
|
|
|
"""Blit this console from x,y,w,h to the console dst at xdst,ydst.""" |
|
751
|
|
|
lib.TCOD_console_blit(self.cdata, x, y, w, h, |
|
|
|
|
|
|
752
|
|
|
_cdata(dst), dest_x, dest_y, fg_alpha, bg_alpha) |
|
|
|
|
|
|
753
|
|
|
|
|
754
|
|
|
def set_key_color(self, color): |
|
755
|
|
|
"""Set a consoles blit transparent color.""" |
|
756
|
|
|
lib.TCOD_console_set_key_color(self.cdata, color) |
|
|
|
|
|
|
757
|
|
|
|
|
758
|
|
|
def fill(self, ch=None, fg=None, bg=None): |
|
759
|
|
|
"""Fill this console with the given numpy array values. |
|
760
|
|
|
|
|
761
|
|
|
Args: |
|
762
|
|
|
ch (Optional[:any:`numpy.ndarray`]): |
|
763
|
|
|
A numpy integer array with a shape of (width, height) |
|
764
|
|
|
fg (Optional[:any:`numpy.ndarray`]): |
|
765
|
|
|
A numpy integer array with a shape of (width, height, 3) |
|
766
|
|
|
bg (Optional[:any:`numpy.ndarray`]): |
|
767
|
|
|
A numpy integer array with a shape of (width, height, 3) |
|
768
|
|
|
""" |
|
769
|
|
|
import numpy |
|
|
|
|
|
|
770
|
|
|
if ch: |
|
771
|
|
|
ch = numpy.ascontiguousarray(ch, dtype=numpy.intc) |
|
772
|
|
|
ch_array = ffi.cast('int *', ch.ctypes.data) |
|
|
|
|
|
|
773
|
|
|
lib.TCOD_console_fill_char(self.cdata, ch_array) |
|
|
|
|
|
|
774
|
|
View Code Duplication |
if fg: |
|
|
|
|
|
|
775
|
|
|
r = numpy.ascontiguousarray(fg[:,:,0], dtype=numpy.intc) |
|
|
|
|
|
|
776
|
|
|
g = numpy.ascontiguousarray(fg[:,:,1], dtype=numpy.intc) |
|
|
|
|
|
|
777
|
|
|
b = numpy.ascontiguousarray(fg[:,:,2], dtype=numpy.intc) |
|
|
|
|
|
|
778
|
|
|
cr = ffi.cast('int *', r.ctypes.data) |
|
|
|
|
|
|
779
|
|
|
cg = ffi.cast('int *', g.ctypes.data) |
|
|
|
|
|
|
780
|
|
|
cb = ffi.cast('int *', b.ctypes.data) |
|
|
|
|
|
|
781
|
|
|
lib.TCOD_console_fill_foreground(self.cdata, cr, cg, cb) |
|
|
|
|
|
|
782
|
|
View Code Duplication |
if bg: |
|
|
|
|
|
|
783
|
|
|
r = numpy.ascontiguousarray(bg[:,:,0], dtype=numpy.intc) |
|
|
|
|
|
|
784
|
|
|
g = numpy.ascontiguousarray(bg[:,:,1], dtype=numpy.intc) |
|
|
|
|
|
|
785
|
|
|
b = numpy.ascontiguousarray(bg[:,:,2], dtype=numpy.intc) |
|
|
|
|
|
|
786
|
|
|
cr = ffi.cast('int *', r.ctypes.data) |
|
|
|
|
|
|
787
|
|
|
cg = ffi.cast('int *', g.ctypes.data) |
|
|
|
|
|
|
788
|
|
|
cb = ffi.cast('int *', b.ctypes.data) |
|
|
|
|
|
|
789
|
|
|
lib.TCOD_console_fill_background(self.cdata, cr, cg, cb) |
|
|
|
|
|
|
790
|
|
|
|
|
791
|
|
|
|
|
792
|
|
|
class Image(_CDataWrapper): |
|
793
|
|
|
""" |
|
794
|
|
|
Args: |
|
795
|
|
|
width (int): Width of the new Image. |
|
796
|
|
|
height (int): Height of the new Image. |
|
797
|
|
|
|
|
798
|
|
|
.. versionadded:: 2.0 |
|
799
|
|
|
""" |
|
800
|
|
|
def __init__(self, *args, **kargs): |
|
801
|
|
|
super(Console, self).__init__(*args, **kargs) |
|
|
|
|
|
|
802
|
|
|
if not self.cdata: |
|
803
|
|
|
self._init(*args, **kargs) |
|
804
|
|
|
|
|
805
|
|
|
def _init(self, width, height): |
|
|
|
|
|
|
806
|
|
|
self.cdata = ffi.gc(lib.TCOD_image_new(width, height), |
|
|
|
|
|
|
807
|
|
|
lib.TCOD_image_delete) |
|
|
|
|
|
|
808
|
|
|
|
|
809
|
|
|
def clipboard_set(string): |
|
810
|
|
|
"""Set the clipboard contents to string. |
|
811
|
|
|
|
|
812
|
|
|
Args: |
|
813
|
|
|
string (AnyStr): The string to set the clipboard to. |
|
814
|
|
|
|
|
815
|
|
|
.. versionadded:: 2.0 |
|
816
|
|
|
""" |
|
817
|
|
|
lib.TCOD_sys_clipboard_set(_bytes(string)) |
|
|
|
|
|
|
818
|
|
|
|
|
819
|
|
|
def clipboard_get(): |
|
820
|
|
|
"""Return the current contents of the clipboard. |
|
821
|
|
|
|
|
822
|
|
|
Returns: |
|
823
|
|
|
Text: The clipboards current contents. |
|
824
|
|
|
|
|
825
|
|
|
.. versionadded:: 2.0 |
|
826
|
|
|
""" |
|
827
|
|
|
return _unpack_char_p(lib.TCOD_sys_clipboard_get()) |
|
|
|
|
|
|
828
|
|
|
|
|
829
|
|
|
@ffi.def_extern() |
|
830
|
|
|
def _pycall_bsp_callback(node, handle): |
|
831
|
|
|
"""static bool _pycall_bsp_callback(TCOD_bsp_t *node, void *userData);""" |
|
832
|
|
|
func, userData, propagate = ffi.from_handle(handle) |
|
|
|
|
|
|
833
|
|
|
try: |
|
834
|
|
|
return func(BSP(node), userData) |
|
835
|
|
|
except BaseException: |
|
836
|
|
|
propagate(*_sys.exc_info()) |
|
837
|
|
|
return False |
|
838
|
|
|
|
|
839
|
|
|
__all__ = [_name for _name in list(globals()) if _name[0] != '_'] |
|
840
|
|
|
|