<div dir="ltr"><div class="gmail_default" style="font-size:small">This example should give you some ideas about how to set up callbacks:</div><div class="gmail_default" style="font-size:small">
<div class="gmail_default" style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline"><a href="https://lorensen.github.io/VTKExamples/site/Python/Interaction/CallBack/">https://lorensen.github.io/VTKExamples/site/Python/Interaction/CallBack/</a></div><br></div><div class="gmail_default" style="font-size:small"><div class="gmail_default" style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline"><br></div></div><div class="gmail_default" style="font-size:small"><div class="gmail_default" style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline">Also look at:</div></div><div class="gmail_default"><div class="gmail_default" style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline"><a href="https://lorensen.github.io/VTKExamples/site/Python/VisualizationAlgorithms/StreamlinesWithLineWidget/">https://lorensen.github.io/VTKExamples/site/Python/VisualizationAlgorithms/StreamlinesWithLineWidget/</a><br></div></div><div class="gmail_default"><div class="gmail_default" style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline"><a href="https://lorensen.github.io/VTKExamples/site/Python/Interaction/MouseEventsObserver/">https://lorensen.github.io/VTKExamples/site/Python/Interaction/MouseEventsObserver/</a><br></div></div><div class="gmail_default"><div class="gmail_default" style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline"><a href="https://lorensen.github.io/VTKExamples/site/Python/Infovis/SelectedGraphIDs/">https://lorensen.github.io/VTKExamples/site/Python/Infovis/SelectedGraphIDs/</a><br></div></div><div class="gmail_default"><div class="gmail_default" style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline"><br></div></div><div class="gmail_default"><div class="gmail_default" style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline">Regards</div></div><div class="gmail_default"><div class="gmail_default" style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline"> Andrew</div></div><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>---------- Forwarded message ----------<br>From: <div class="gmail_default" style="font-size:small;display:inline"></div>Jean-Christophe Fillion-Robin <<a href="mailto:jchris.fillionr@kitware.com" target="_blank"><div class="gmail_default" style="font-size:small;display:inline"></div>jchris.fillionr@kitware.com</a>><br>To: "J." <<a href="mailto:babybishops@gmail.com" target="_blank">babybishops@gmail.com</a>><br>Cc: <a href="mailto:vtkusers@public.kitware.com" target="_blank">vtkusers@public.kitware.com</a><br>Bcc: <br>Date: Mon, 9 Jul 2018 11:58:32 -0400<br>Subject: Re: [vtkusers] 'vtkCommonCorePython.vtkCallbackCommand' object has no attribute 'SetCallback'<br><div dir="ltr"><div>Hi, <br></div><div><br></div><div>Thanks for reaching out.</div><div><br></div><div>In python, you shouldn't have to create a vtkCallbackCommand object. You can directly pass a python function to the AddObserver function.<br></div><div><br></div><div>Looking at this test should help give more details: <a href="https://github.com/Kitware/VTK/blob/90f7e9a4590922d159ed3c599d0e363edcad3ed5/Common/Core/Testing/Python/TestInvokeEvent.py" target="_blank">https://github.com/Kitware/VTK/blob/90f7e9a4590922d159ed3c599d0e363edcad3ed5/Common/Core/Testing/Python/TestInvokeEvent.py</a></div><div><br></div><div><br></div><div>To more easily manage the connections, you could also create a <a href="https://github.com/Slicer/Slicer/blob/3ea26dae3e461899f8ecf51ec7ae02f7bab10d15/Base/Python/slicer/util.py#L932" target="_blank">VTKObservationMixin</a> class.<br></div><div><br></div><div>More detail about the mixin looking at these:</div><div>* <a href="https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#How_can_I_access_callData_argument_in_a_VTK_object_observer_callback_function" target="_blank">https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#How_can_I_access_callData_argument_in_a_VTK_object_observer_callback_function</a></div><div>* <a href="https://github.com/Slicer/Slicer/blob/3ea26dae3e461899f8ecf51ec7ae02f7bab10d15/Base/Python/slicer/tests/test_slicer_util_VTKObservationMixin.py" target="_blank">https://github.com/Slicer/Slicer/blob/3ea26dae3e461899f8ecf51ec7ae02f7bab10d15/Base/Python/slicer/tests/test_slicer_util_VTKObservationMixin.py</a><br></div><div><br></div><div><br></div><div>Hth</div><div>Jc<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 9, 2018 at 7:08 AM, J. <span dir="ltr"><<a href="mailto:babybishops@gmail.com" target="_blank">babybishops@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>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:</div><div><br></div><div>
<pre class="gmail-m_-3636566572602915271m_-1533427813086379359gmail-de1"> vtkSmartPointer<span class="gmail-m_-3636566572602915271m_-1533427813086379359gmail-sy1"><</span>vtkCallbackCommand<span class="gmail-m_-3636566572602915271m_-1533427813086379359gmail-sy1">></span> keypressCallback <span class="gmail-m_-3636566572602915271m_-1533427813086379359gmail-sy1">=</span>
vtkSmartPointer<span class="gmail-m_-3636566572602915271m_-1533427813086379359gmail-sy1"><</span>vtkCallbackCommand<span class="gmail-m_-3636566572602915271m_-1533427813086379359gmail-sy1">></span><span class="gmail-m_-3636566572602915271m_-1533427813086379359gmail-sy4">::</span><span class="gmail-m_-3636566572602915271m_-1533427813086379359gmail-me2">New</span><span class="gmail-m_-3636566572602915271m_-1533427813086379359gmail-br0">(</span><span class="gmail-m_-3636566572602915271m_-1533427813086379359gmail-br0">)</span><span class="gmail-m_-3636566572602915271m_-1533427813086379359gmail-sy4">;</span>
keypressCallback<span class="gmail-m_-3636566572602915271m_-1533427813086379359gmail-sy2">-</span><span class="gmail-m_-3636566572602915271m_-1533427813086379359gmail-sy1">></span>SetCallback <span class="gmail-m_-3636566572602915271m_-1533427813086379359gmail-br0">(</span> func <span class="gmail-m_-3636566572602915271m_-1533427813086379359gmail-br0">)</span><span class="gmail-m_-3636566572602915271m_-1533427813086379359gmail-sy4">;</span></pre>
</div><div>However, when I try this with Python, I get<i> 'vtkCommonCorePython.vtkCallbackCommand' object has no attribute 'SetCallback'</i>. I'm using vtk 8:</div><div><br></div><div>
<div style="color:rgb(51,51,51);background-color:rgb(245,245,245);font-family:Consolas,"Courier New",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(122,62,157)">def</span><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(170,55,49);font-weight:bold">onClick</span><span style="color:rgb(119,119,119)">():</span></div><div><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(170,55,49);font-weight:bold">print</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(119,119,119)">"</span><span style="color:rgb(68,140,39)">Hello, World!</span><span style="color:rgb(119,119,119)">"</span><span style="color:rgb(119,119,119)">)</span></div><br><div><span style="color:rgb(51,51,51)">onClickCallback </span><span style="color:rgb(119,119,119)">=</span><span style="color:rgb(51,51,51)"> vtk</span><span style="color:rgb(119,119,119)">.</span><span style="color:rgb(51,51,51)">vtkCallbackCommand</span><span style="color:rgb(119,119,119)">()</span></div><div><span style="color:rgb(51,51,51)">onClickCallback</span><span style="color:rgb(119,119,119)">.</span><span style="color:rgb(51,51,51)">SetCallback</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(51,51,51)">onClick</span><span style="color:rgb(119,119,119)">)</span></div></div>
<br></div></div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">https://public.kitware.com/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail-m_-3636566572602915271gmail_signature">+1 919 869 8849<br></div>
</div>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">https://public.kitware.com/mailman/listinfo/vtkusers</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">___________________________________________<br>Andrew J. P. Maclean<br><br>___________________________________________</div></div>