From 3c955eba0697db36493fc6df154f5b7baff6ab0a Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Mon, 8 Jan 2024 00:15:38 -0500 Subject: [PATCH] Initial commit of cluster_c.pyx --- py/hexagram/cluster_c.pyx | 41 +++++++++++++++++++++++++++++++++++++++ setup.py | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 py/hexagram/cluster_c.pyx diff --git a/py/hexagram/cluster_c.pyx b/py/hexagram/cluster_c.pyx new file mode 100644 index 0000000..ffa38b9 --- /dev/null +++ b/py/hexagram/cluster_c.pyx @@ -0,0 +1,41 @@ +from cpython.ref cimport PyObject, PyTypeObject, Py_INCREF + +from hexagram.cluster import Cluster + +cdef extern from "linux/can.h": + cdef struct can_frame: + pass + +cdef extern from "cairo.h": + ctypedef struct cairo_t: + pass + +cdef extern from "py3cairo.h": + cdef PyObject *PycairoContext_FromContext(cairo_t *ctx, PyTypeObject *type, PyObject *base) + + ctypedef struct Pycairo_CAPI_t: + pass + + cdef extern Pycairo_CAPI_t *Pycairo_CAPI + +cdef extern from *: + """ + #define ctx_type (Pycairo_CAPI->Context_Type) + """ + cdef extern PyTypeObject *ctx_type + +cdef class hexagram_cluster_py: + cdef object _obj + + def __cinit__(self, double rpm_min, double rpm_redline, double rpm_max): + self._obj = Cluster(rpm_min, rpm_redline, rpm_max) + + cdef draw_bg(self, cairo_t *cr): + ctx = PycairoContext_FromContext(cr, ctx_type, NULL) + + self._obj.draw_bg(ctx) + + cdef draw_fg(self, cairo_t *cr): + ctx = PycairoContext_FromContext(cr, ctx_type, NULL) + + self._obj.draw_fg(ctx) diff --git a/setup.py b/setup.py index cf6e8c5..73a52b1 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( ext_modules = cythonize( Extension( "*", ["py/hexagram/*.pyx"], - include_dirs = ["./include", "/usr/include/cairo"] + include_dirs = ["./include", "/usr/include/cairo", "/usr/include/pycairo"] ), language_level = 3, ) )