* get_canvas method now return Python Canvas object.tags/v0.99.beta18
@@ -56,17 +56,21 @@ class Canvas(_Canvas): | |||||
""" Canvas object, methods are libcaca functions with canvas_t as | """ Canvas object, methods are libcaca functions with canvas_t as | ||||
first parameter. | first parameter. | ||||
""" | """ | ||||
def __init__(self, width=0, height=0): | |||||
def __init__(self, width=0, height=0, pointer=None): | |||||
""" Canvas constructor. | """ Canvas constructor. | ||||
width -- the desired canvas width | width -- the desired canvas width | ||||
height -- the desired canvas height | height -- the desired canvas height | ||||
cv -- pointer to libcaca canvas | |||||
""" | """ | ||||
_lib.caca_create_canvas.argtypes = [ctypes.c_int, ctypes.c_int] | _lib.caca_create_canvas.argtypes = [ctypes.c_int, ctypes.c_int] | ||||
self._cv = _lib.caca_create_canvas(width, height) | |||||
if self._cv == 0: | |||||
raise CanvasError, "Failed to create canvas" | |||||
if cv is not None: | |||||
self._cv = _lib.caca_create_canvas(width, height) | |||||
if self._cv == 0: | |||||
raise CanvasError, "Failed to create canvas" | |||||
else: | |||||
self._cv = cv | |||||
def manage(self, *args, **kw): | def manage(self, *args, **kw): | ||||
""" Not implemented. | """ Not implemented. | ||||
@@ -940,7 +944,7 @@ class Canvas(_Canvas): | |||||
_Canvas, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, | _Canvas, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, | ||||
ctypes.c_char_p, p_size_t | ctypes.c_char_p, p_size_t | ||||
] | ] | ||||
_lib.caca_export_area_to_memory.restype = ctypes.c_void_p | |||||
_lib.caca_export_area_to_memory.restype = ctypes.POINTER(ctypes.c_char_p) | |||||
p = ctypes.c_size_t() | p = ctypes.c_size_t() | ||||
ret = _lib.caca_export_area_to_memory(self, x, y, width, height, fmt, p) | ret = _lib.caca_export_area_to_memory(self, x, y, width, height, fmt, p) | ||||
@@ -17,7 +17,7 @@ | |||||
import ctypes | import ctypes | ||||
from caca import _lib | from caca import _lib | ||||
from caca.canvas import _Canvas | |||||
from caca.canvas import _Canvas, Canvas | |||||
class _Display(object): | class _Display(object): | ||||
""" Model for Display objects. | """ Model for Display objects. | ||||
@@ -63,6 +63,9 @@ class Display(_Display): | |||||
] | ] | ||||
self._dp = _lib.caca_create_display_with_driver(cv, driver) | self._dp = _lib.caca_create_display_with_driver(cv, driver) | ||||
if self._dp == 0: | |||||
raise DisplayError, "Failed to create display" | |||||
def get_driver(self): | def get_driver(self): | ||||
""" Return the caca graphical context's current output driver. | """ Return the caca graphical context's current output driver. | ||||
""" | """ | ||||
@@ -89,8 +92,9 @@ class Display(_Display): | |||||
""" Get the canvas attached to a caca graphical context. | """ Get the canvas attached to a caca graphical context. | ||||
""" | """ | ||||
_lib.caca_get_canvas.argtypes = [_Display] | _lib.caca_get_canvas.argtypes = [_Display] | ||||
_lib.caca_get_canvas.restype = ctypes.POINTER(ctypes.c_char_p) | |||||
return _lib.caca_get_canvas(self) | |||||
return Canvas(pointer=_lib.caca_get_canvas(self)) | |||||
def refresh(self): | def refresh(self): | ||||
""" Flush pending changes and redraw the screen. | """ Flush pending changes and redraw the screen. | ||||
@@ -194,6 +198,9 @@ class Display(_Display): | |||||
return _lib.caca_get_mouse_y(self) | return _lib.caca_get_mouse_y(self) | ||||
class DisplayError(Exception): | |||||
pass | |||||
class Event(ctypes.Structure): | class Event(ctypes.Structure): | ||||
""" Object to store libcaca event. | """ Object to store libcaca event. | ||||
""" | """ | ||||