Преглед на файлове

* Add optional pointer argument to Canvas class.

* get_canvas method now return Python Canvas object.
tags/v0.99.beta18
Alex Foulon alxf преди 14 години
родител
ревизия
78a25b95bf
променени са 2 файла, в които са добавени 18 реда и са изтрити 7 реда
  1. +9
    -5
      python/caca/canvas.py
  2. +9
    -2
      python/caca/display.py

+ 9
- 5
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)


+ 9
- 2
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.
"""


Зареждане…
Отказ
Запис