Note that there are some explanatory texts on larger screens.

plurals
  1. POCython callback works correctly for function, but not for bound method
    primarykey
    data
    text
    <p>I am implementing a cython-based interface to a C++ library. I implemented a callback system that works with normal functions but fails strangely when passing in bound methods. Here is a portion of my cython code:</p> <pre><code>cdef extern from "VolumeHapticTool.h": cdef cppclass HDButtonEvent: bool isPressed() unsigned int getButtonId() Vec3[float] getPosition() ctypedef void (*HDButtonCallback)(HDButtonEvent, void *) cdef extern from "Scene.h": cdef cppclass Scene: Scene() void setDrillButtonCallback( HDButtonCallback, void*) cdef void pyHDButtonCallback(HDButtonEvent e, void *user_data): print &lt;object&gt;user_data (&lt;object&gt;user_data)( (e.isPressed(), e.getButtonId(), topy_vec3f(e.getPosition())) ) cdef class pyScene: cdef Scene * m_scene def __init__(self): self.m_scene = new Scene() def __del__(self): del self.m_scene def setDrillButtonCallback(self, func): print func self.m_scene.setDrillButtonCallback(pyHDButtonCallback, &lt;void*&gt;func) </code></pre> <p>And here is how I'm trying to call it:</p> <pre><code>class RenderCanvas(GLCanvas): def __init__(self, parent): self.scene = cybraincase.pyScene() self.scene.setDrillButtonCallback(self.OnDrillButtonPress) def OnDrillButtonPress(self, event): print event </code></pre> <p>When this code is run initially, this is printed: <code>&lt;bound method RenderCanvas.OnDrillButtonPress of &lt;UI.RenderCanvas; proxy of &lt;Swig Object of type 'wxGLCanvas *' at 0x42b70a8&gt; &gt;&gt;</code></p> <p>That seems right. The problem is when the callback is triggered, this is printed: <code>&lt;bound method Shell.readline of &lt;wx.py.shell.Shell; proxy of &lt;Swig Object of type 'wxStyledTextCtrl *' at 0x3a12348&gt; &gt;&gt;</code></p> <p>A totally different bound method is being called. However, when I make <code>OnDrillButtonPress</code> a static method, <code>&lt;function OnDrillButtonPress at 0x042FC570&gt;</code> is printed both on initialization and triggering calls.</p> <p>Is there an incompatibility with saving bound methods as void*? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload