[vtkusers] 'vtkCommonCorePython.vtkCallbackCommand' object has no attribute 'SetCallback'
Andrew Maclean
andrew.amaclean at gmail.com
Mon Jul 9 18:25:29 EDT 2018
This example should give you some ideas about how to set up callbacks:
https://lorensen.github.io/VTKExamples/site/Python/Interaction/CallBack/
Also look at:
https://lorensen.github.io/VTKExamples/site/Python/VisualizationAlgorithms/StreamlinesWithLineWidget/
https://lorensen.github.io/VTKExamples/site/Python/Interaction/MouseEventsObserver/
https://lorensen.github.io/VTKExamples/site/Python/Infovis/SelectedGraphIDs/
Regards
Andrew
> ---------- Forwarded message ----------
> From:
>
> Jean-Christophe Fillion-Robin <
>
> jchris.fillionr at kitware.com>
> To: "J." <babybishops at gmail.com>
> Cc: vtkusers at public.kitware.com
> Bcc:
> Date: Mon, 9 Jul 2018 11:58:32 -0400
> Subject: Re: [vtkusers] 'vtkCommonCorePython.vtkCallbackCommand' object
> has no attribute 'SetCallback'
> 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
> _______________________________________________
> 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
>
--
___________________________________________
Andrew J. P. Maclean
___________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180710/b63ea118/attachment.html>
More information about the vtkusers
mailing list