[vtkusers] 'vtkCommonCorePython.vtkCallbackCommand' object has no attribute 'SetCallback'

Jean-Christophe Fillion-Robin jchris.fillionr at kitware.com
Mon Jul 9 11:58:32 EDT 2018


Hi,

Thanks for reaching out.

In python, you shouldn't have to create a vtkCallbackCommand object. You
can directly pass a python function to the AddObserver function.

Looking at this test should help give more details:
https://github.com/Kitware/VTK/blob/90f7e9a4590922d159ed3c599d0e363edcad3ed5/Common/Core/Testing/Python/TestInvokeEvent.py


To more easily manage the connections, you could also create a
VTKObservationMixin
<https://github.com/Slicer/Slicer/blob/3ea26dae3e461899f8ecf51ec7ae02f7bab10d15/Base/Python/slicer/util.py#L932>
class.

More detail about the mixin looking at these:
*
https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#How_can_I_access_callData_argument_in_a_VTK_object_observer_callback_function
*
https://github.com/Slicer/Slicer/blob/3ea26dae3e461899f8ecf51ec7ae02f7bab10d15/Base/Python/slicer/tests/test_slicer_util_VTKObservationMixin.py


Hth
Jc


On Mon, Jul 9, 2018 at 7:08 AM, J. <babybishops at gmail.com> wrote:

> According to the tutorials and example code, you can create a
> vtkCallbackCommand() object and then call SetCallback on it with a callback
> function, as in:
>
>   vtkSmartPointer<vtkCallbackCommand> keypressCallback =
>       vtkSmartPointer<vtkCallbackCommand>::New();
>   keypressCallback->SetCallback ( func );
>
> However, when I try this with Python, I get*
> 'vtkCommonCorePython.vtkCallbackCommand' object has no attribute
> 'SetCallback'*. I'm using vtk 8:
>
> def onClick():
>     print("Hello, World!")
>
> onClickCallback = vtk.vtkCallbackCommand()
> onClickCallback.SetCallback(onClick)
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers
>
>


-- 
+1 919 869 8849
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180709/7eb91b91/attachment.html>


More information about the vtkusers mailing list