[vtkusers] SetClientData in python
David Gobbi
david.gobbi at gmail.com
Fri Nov 10 13:17:26 EST 2017
Hi Serge,
The way to do this in Python is to add attributes to your callback function.
def DummyFunc(obj, ev, data):
print(ev, data)
DummyFunc.CallData = whatever
interactor.AddObserver('LeftButtonPressEvent', DummyFunc)
So the vtkCallbackCommand really isn't needed in Python (and, as you have
noticed, it really can't be used in Python anyway).
- David
On Fri, Nov 10, 2017 at 10:32 AM, Serge K. <skab12 at gmail.com> wrote:
> Hi All,
>
> I am playing with MouseEventObserver.py example and I would like to add a
> ClientData on my callback function. There are many examples in C++ like
> this one: https://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/ClientData
>
> However, I do not know how to do that in Python.
>
> Indeed, if I create a vtkCallbackCommand , SetCallBack function does not
> exist.
>
> Any Idea? Thanks for your answer.
>
> Serge
>
> ps: python36 - vtk 7.1.1
>
>
> #!/usr/bin/env pythonfrom __future__ import print_function
> import vtksource = vtk.vtkSphereSource()source.SetCenter(0, 0, 0)source.SetRadius(1)source.Update()
> mapper = vtk.vtkPolyDataMapper()mapper.SetInputConnection(source.GetOutputPort())
> actor = vtk.vtkActor()actor.SetMapper(mapper)
> renderer = vtk.vtkRenderer()renderer.SetBackground(1, 1, 1)renderer.AddActor(actor)
> renwin = vtk.vtkRenderWindow()renwin.AddRenderer(renderer)
> interactor = vtk.vtkRenderWindowInteractor()interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())interactor.SetRenderWindow(renwin)
> def DummyFunc(obj, ev, my_obj_2):
> print(obj, my_obj_2)
>
> # obj_2 = vtk.whatever()# How do I pass my obj_2 ? interactor.AddObserver('LeftButtonPressEvent', DummyFunc)interactor.Initialize()interactor.Start()
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20171110/8b99cf58/attachment.html>
More information about the vtkusers
mailing list