<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2016-06-16 17:33 GMT+02:00 David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Thu, Jun 16, 2016 at 9:08 AM, Elvis Stansvik <span dir="ltr"><<a href="mailto:elvis.stansvik@orexplore.com" target="_blank">elvis.stansvik@orexplore.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>2016-06-16 16:08 GMT+02:00 Elvis Stansvik <span dir="ltr"><<a href="mailto:elvis.stansvik@orexplore.com" target="_blank">elvis.stansvik@orexplore.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>2016-06-16 15:52 GMT+02:00 Elvis Stansvik <span dir="ltr"><<a href="mailto:elvis.stansvik@orexplore.com" target="_blank">elvis.stansvik@orexplore.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div><div>The MouseEvents.py example [1] currently does:<br><br>class MyInteractorStyle(vtk.vtkInteractorStyleTrackballCamera):<br> <br> def __init__(self,parent=None):<br> self.AddObserver("MiddleButtonPressEvent",self.middleButtonPressEvent)<br> self.AddObserver("MiddleButtonReleaseEvent",self.middleButtonReleaseEvent)<br> <br> def middleButtonPressEvent(self,obj,event):<br> print("Middle Button pressed")<br> self.OnMiddleButtonDown()<br> return<br> <br> def middleButtonReleaseEvent(self,obj,event):<br> print("Middle Button released")<br> self.OnMiddleButtonUp()<br> return<br><br>But I don't understand the reason for calling e.g. self.OnMiddleButtonDown() ? Since this is not an override of a virtual function (which is not possible in Python), but simply adding another observer, I don't think it is needed? (..and I would think it would mean OnMiddleButtonDown is called twice, right?).<br></div></div></div></div></div></blockquote><div><br></div></span><div>Sorry, I realize I wasn't really clear here: What I mean is that, if the interactor style above is used, the behavior of vtkInteractorStyleTrackballCamera (the base class) will still be there, even if the call to self.OnMiddleButtonDown() is removed, since the base class will observe the interactor. That's why I don't understand the need for the self.OnMiddleButtonDown() call in the example.<br><br></div><div>This ties in to my other question (another mail), since what I want to do is to actually override the behavior of the base interactor style (similar to how you can in C++, but I need to find some other mechanism to do so, overriding of virtual functions won't work from Python).<span><font color="#888888"><br></font></span></div></div></div></div></blockquote><div><br></div></span><div>Sorry, I confused myself with all my mails, it actually was in the original mail in this thread I brought up this question.<br><br></div><div>Perhaps I should tell a little more about my goal. I'm building an application with VTK, and in some cases I expect that I want to make use of VTKs interactor + interactor style machinery, and leverage the built-in interactor styles (such as <span>vtkInteractorStyleTrackballCamera), but at the same time I might want to override behavior, and also be able to decide whether I want to override a particular event or not at runtime, when handling the event. I also suspect that I might want to modify the event information before passing it on.<br><br></span></div><div><span>E.g. in C++ I would just override the virtual method, and in my override I'd be able decide whether I want to do something special or call the base class implementation.<br><br></span></div><div><span>It seem there's no easy way of doing the equivalent in Python? At least I haven't found any. I've found some mentions in the vtkCommand docs about being able to stop propagation of an event to observers with lower priority. But I haven't found any exampels of this in Python, and it also seems that the docs in vtkCommand about callData are not applicable to Python? And also, with that solution, I'd have to install observers directly on the interactor, like the interactor style does, in order to end up in the same event propagation chain so to speak.<br><br></span></div><div><span>I'd love to hear how others have solved the problem of custom interaction behavior in Python, while still being able to leverage (parts of) the functionality provided by the built-in interactor styles.</span></div></div></div></div></blockquote><div><br></div></span><div>In C++, a callback can return "true" to stop event propagation:</div><div><br></div><div> // Description:</div><div> // This method invokes an event and return whether the event was</div><div> // aborted or not. If the event was aborted, the return value is 1,</div><div> // otherwise it is 0.</div><div> int InvokeEvent(unsigned long event, void *callData);</div><div> int InvokeEvent(unsigned long event);</div><div><br></div><div>When this feature was added for C++, it wasn't added to vtkPythonCommand.cxx (an oversight), so vtkPythonCommand.cxx would have to be modified to add this behavior for Python.</div><div><br></div><div>Regarding calldata, see the following merge request (now merged):</div><div><a href="https://gitlab.kitware.com/vtk/vtk/merge_requests/1543/commits" target="_blank">https://gitlab.kitware.com/vtk/vtk/merge_requests/1543/commits</a><br></div><div>If Hasting happens to be reading this, please note that commit messages should be a wee bit more descriptive...</div><div><br></div><div>I can't say much about the rest. The interactors aren't my favorite part of VTK.</div></div></div></div></blockquote><div><br></div><div>I'm also curious, if you don't mind me asking: Have you used a lot of PyQt+VTK? If so, did you use the interactor style system or did you forego using it completely?<br><br></div><div>Elvis<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="HOEnZb"><font color="#888888"><div><br></div><div> - David</div></font></span></div></div></div>
</blockquote></div><br></div></div>