wxPython 4 alternative for wxMemoryDC.this

I have a cython’ized render routine that writes into a wxMemoryDC. The code to begin this on older versions that used SWIG looks like this:

    def drawElements(self, dc, canvas, tick):
        """Draw elements in the list to the given dc
        """
        elements = canvas.GetDrawPairs() # Uses bounds
        xoff, yoff = canvas.GetRenderOffsets()
        background_brushes, reason_brushes = canvas.GetBrushes()

        cdef SwigPyObject* ptr = <SwigPyObject*>dc.this
        cdef wxDC* c_dc = <wxDC*?>ptr.ptr
        assert c_dc != NULL

        <and then we continue to do stuff with the pointer to the c++ wxDC>

I should also mention that dc is passed the results of wx.MemoryDC().

After the changeover to SIP, there is no longer a this attribute on instances of wxMemoryDC(). Can someone help me understand how I can get to the C++ internals of wxWidgets in my Cython with the 4.0+ version?

Thanks.

SIP has an extension module that can do low-level things with SIP-wrapped objects from Python code, like unwrapinstance. I’ve exposed this as the wx.siplib module. However I think that API is likely changing in SIP 5 so it’s probably not a good idea to spend much time working on doing things that way for now.

I also expose a set of C functions for some common things that I want to share across all modules. You can see the details in include/wxPython/wxpy_api.h, the wxPyConvertWrappedPtr function will probably do what you need. Everything in that header is declared explicitly or implicitly as inline and they will automatically import the struct of function pointers from wx._wxPyAPI the first time it is needed in any compilation unit.

Thanks Robin. I’m glad I asked because I was seeing the siplib stuff but hadn’t noticed wxpy_api.h yet. I’ll try using wxpy_api.h helpers for now and let you know how I make out.