Skip to content

Commit

Permalink
bindings/python: Rename __getCanvas to _getCanvas for cython 3.0 compat
Browse files Browse the repository at this point in the history
In cython 3.0, names with two underscores can't be used in derived
classes. For more details refer to the Cython 3.0 migration guide:

  https://cython.readthedocs.io/en/latest/src/userguide/migrating_to_cy30.html
  • Loading branch information
neuschaefer committed Jul 9, 2024
1 parent cdb2785 commit 47d9c4d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bindings/python/rgbmatrix/core.pxd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from . cimport cppinc

cdef class Canvas:
cdef cppinc.Canvas *__getCanvas(self) except +
cdef cppinc.Canvas *_getCanvas(self) except +

cdef class FrameCanvas(Canvas):
cdef cppinc.FrameCanvas *__canvas
Expand Down
27 changes: 13 additions & 14 deletions bindings/python/rgbmatrix/core.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

from libcpp cimport bool
from libc.stdint cimport uint8_t, uint32_t, uintptr_t
from PIL import Image
import cython

cdef class Canvas:
cdef cppinc.Canvas* __getCanvas(self) except +:
cdef cppinc.Canvas* _getCanvas(self) except +:
raise Exception("Not implemented")

def SetImage(self, image, int offset_x = 0, int offset_y = 0, unsafe=True):
Expand Down Expand Up @@ -34,7 +33,7 @@ cdef class Canvas:
@cython.boundscheck(False)
@cython.wraparound(False)
def SetPixelsPillow(self, int xstart, int ystart, int width, int height, image):
cdef cppinc.FrameCanvas* my_canvas = <cppinc.FrameCanvas*>self.__getCanvas()
cdef cppinc.FrameCanvas* my_canvas = <cppinc.FrameCanvas*>self._getCanvas()
cdef int frame_width = my_canvas.width()
cdef int frame_height = my_canvas.height()
cdef int row, col
Expand All @@ -58,34 +57,34 @@ cdef class FrameCanvas(Canvas):
if <void*>self.__canvas != NULL:
self.__canvas = NULL

cdef cppinc.Canvas* __getCanvas(self) except *:
cdef cppinc.Canvas* _getCanvas(self) except *:
if <void*>self.__canvas != NULL:
return self.__canvas
raise Exception("Canvas was destroyed or not initialized, you cannot use this object anymore")

def Fill(self, uint8_t red, uint8_t green, uint8_t blue):
(<cppinc.FrameCanvas*>self.__getCanvas()).Fill(red, green, blue)
(<cppinc.FrameCanvas*>self._getCanvas()).Fill(red, green, blue)

def Clear(self):
(<cppinc.FrameCanvas*>self.__getCanvas()).Clear()
(<cppinc.FrameCanvas*>self._getCanvas()).Clear()

def SetPixel(self, int x, int y, uint8_t red, uint8_t green, uint8_t blue):
(<cppinc.FrameCanvas*>self.__getCanvas()).SetPixel(x, y, red, green, blue)
(<cppinc.FrameCanvas*>self._getCanvas()).SetPixel(x, y, red, green, blue)


property width:
def __get__(self): return (<cppinc.FrameCanvas*>self.__getCanvas()).width()
def __get__(self): return (<cppinc.FrameCanvas*>self._getCanvas()).width()

property height:
def __get__(self): return (<cppinc.FrameCanvas*>self.__getCanvas()).height()
def __get__(self): return (<cppinc.FrameCanvas*>self._getCanvas()).height()

property pwmBits:
def __get__(self): return (<cppinc.FrameCanvas*>self.__getCanvas()).pwmbits()
def __set__(self, pwmBits): (<cppinc.FrameCanvas*>self.__getCanvas()).SetPWMBits(pwmBits)
def __get__(self): return (<cppinc.FrameCanvas*>self._getCanvas()).pwmbits()
def __set__(self, pwmBits): (<cppinc.FrameCanvas*>self._getCanvas()).SetPWMBits(pwmBits)

property brightness:
def __get__(self): return (<cppinc.FrameCanvas*>self.__getCanvas()).brightness()
def __set__(self, val): (<cppinc.FrameCanvas*>self.__getCanvas()).SetBrightness(val)
def __get__(self): return (<cppinc.FrameCanvas*>self._getCanvas()).brightness()
def __set__(self, val): (<cppinc.FrameCanvas*>self._getCanvas()).SetBrightness(val)


cdef class RGBMatrixOptions:
Expand Down Expand Up @@ -216,7 +215,7 @@ cdef class RGBMatrix(Canvas):
self.__matrix.Clear()
del self.__matrix

cdef cppinc.Canvas* __getCanvas(self) except *:
cdef cppinc.Canvas* _getCanvas(self) except *:
if <void*>self.__matrix != NULL:
return self.__matrix
raise Exception("Canvas was destroyed or not initialized, you cannot use this object anymore")
Expand Down
8 changes: 4 additions & 4 deletions bindings/python/rgbmatrix/graphics.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cdef class Font:
raise Exception("Couldn't load font " + file)

def DrawGlyph(self, core.Canvas c, int x, int y, Color color, uint32_t char):
return self.__font.DrawGlyph(c.__getCanvas(), x, y, color.__color, char)
return self.__font.DrawGlyph(c._getCanvas(), x, y, color.__color, char)

property height:
def __get__(self): return self.__font.height()
Expand All @@ -41,13 +41,13 @@ cdef class Font:
def __get__(self): return self.__font.baseline()

def DrawText(core.Canvas c, Font f, int x, int y, Color color, text):
return cppinc.DrawText(c.__getCanvas(), f.__font, x, y, color.__color, text.encode('utf-8'))
return cppinc.DrawText(c._getCanvas(), f.__font, x, y, color.__color, text.encode('utf-8'))

def DrawCircle(core.Canvas c, int x, int y, int r, Color color):
cppinc.DrawCircle(c.__getCanvas(), x, y, r, color.__color)
cppinc.DrawCircle(c._getCanvas(), x, y, r, color.__color)

def DrawLine(core.Canvas c, int x1, int y1, int x2, int y2, Color color):
cppinc.DrawLine(c.__getCanvas(), x1, y1, x2, y2, color.__color)
cppinc.DrawLine(c._getCanvas(), x1, y1, x2, y2, color.__color)

# Local Variables:
# mode: python
Expand Down

0 comments on commit 47d9c4d

Please sign in to comment.