diff --git a/python/caca/canvas.py b/python/caca/canvas.py index 292ab87..4373e0e 100644 --- a/python/caca/canvas.py +++ b/python/caca/canvas.py @@ -56,17 +56,21 @@ class Canvas(_Canvas): """ Canvas object, methods are libcaca functions with canvas_t as first parameter. """ - def __init__(self, width=0, height=0): + def __init__(self, width=0, height=0, pointer=None): """ Canvas constructor. width -- the desired canvas width height -- the desired canvas height + cv -- pointer to libcaca canvas """ _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): """ Not implemented. @@ -940,7 +944,7 @@ class Canvas(_Canvas): _Canvas, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, 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() ret = _lib.caca_export_area_to_memory(self, x, y, width, height, fmt, p) diff --git a/python/caca/display.py b/python/caca/display.py index 451b40a..8bdd887 100644 --- a/python/caca/display.py +++ b/python/caca/display.py @@ -17,7 +17,7 @@ import ctypes from caca import _lib -from caca.canvas import _Canvas +from caca.canvas import _Canvas, Canvas class _Display(object): """ Model for Display objects. @@ -63,6 +63,9 @@ class Display(_Display): ] self._dp = _lib.caca_create_display_with_driver(cv, driver) + if self._dp == 0: + raise DisplayError, "Failed to create display" + def get_driver(self): """ 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. """ _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): """ Flush pending changes and redraw the screen. @@ -194,6 +198,9 @@ class Display(_Display): return _lib.caca_get_mouse_y(self) +class DisplayError(Exception): + pass + class Event(ctypes.Structure): """ Object to store libcaca event. """