Changeset 4408 for libcaca/trunk


Ignore:
Timestamp:
Jun 21, 2010, 8:06:26 PM (9 years ago)
Author:
Alex Foulon
Message:
  • Add optional pointer argument to Canvas class.
  • get_canvas method now return Python Canvas object.
Location:
libcaca/trunk/python/caca
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/python/caca/canvas.py

    r4405 r4408  
    5757        first parameter.
    5858    """
    59     def __init__(self, width=0, height=0):
     59    def __init__(self, width=0, height=0, pointer=None):
    6060        """ Canvas constructor.
    6161
    6262            width   -- the desired canvas width
    6363            height  -- the desired canvas height
     64            cv      -- pointer to libcaca canvas
    6465        """
    6566        _lib.caca_create_canvas.argtypes = [ctypes.c_int, ctypes.c_int]
    6667
    67         self._cv = _lib.caca_create_canvas(width, height)
    68         if self._cv == 0:
    69             raise CanvasError, "Failed to create canvas"
     68        if cv is not None:
     69            self._cv = _lib.caca_create_canvas(width, height)
     70            if self._cv == 0:
     71                raise CanvasError, "Failed to create canvas"
     72        else:
     73            self._cv = cv
    7074
    7175    def manage(self, *args, **kw):
     
    941945                ctypes.c_char_p, p_size_t
    942946        ]
    943         _lib.caca_export_area_to_memory.restype  = ctypes.c_void_p
     947        _lib.caca_export_area_to_memory.restype  = ctypes.POINTER(ctypes.c_char_p)
    944948
    945949        p = ctypes.c_size_t()
  • libcaca/trunk/python/caca/display.py

    r4398 r4408  
    1818
    1919from caca import _lib
    20 from caca.canvas import _Canvas
     20from caca.canvas import _Canvas, Canvas
    2121
    2222class _Display(object):
     
    6464            self._dp = _lib.caca_create_display_with_driver(cv, driver)
    6565
     66        if self._dp == 0:
     67            raise DisplayError, "Failed to create display"
     68
    6669    def get_driver(self):
    6770        """ Return the caca graphical context's current output driver.
     
    9093        """
    9194        _lib.caca_get_canvas.argtypes = [_Display]
    92 
    93         return _lib.caca_get_canvas(self)
     95        _lib.caca_get_canvas.restype  = ctypes.POINTER(ctypes.c_char_p)
     96
     97        return Canvas(pointer=_lib.caca_get_canvas(self))
    9498
    9599    def refresh(self):
     
    195199        return _lib.caca_get_mouse_y(self)
    196200
     201class DisplayError(Exception):
     202    pass
     203
    197204class Event(ctypes.Structure):
    198205    """ Object to store libcaca event.
Note: See TracChangeset for help on using the changeset viewer.