Hello!!
I’m using VTK 9.1 and Python 3.8 and I’m creating a custom InteractorStyle, derived from vtkInteractorStyleRubberBandPick, where I want to change some of the Events that drive view manipulation etc. to different events to match another application.
I’ve more or less figured out how this should work - BUT, I’m unable to override the default behaviors of the ‘r’ and ‘3’ KeyPressEvents (at least)
By default, ‘r’ invokes the rubber band widgets and ‘3’ invokes stereo mode viewing.
I have added my own KeyPressEvent observer and it correctly calls the command I associated it to - BUT - it ALSO goes on to call the default methods.
So I added a call to remove the existing KeyPressEvent - but it seems to have no effect on behavior…
Code snippet below…
# Define interaction style
class InteractorStyle(vtk.vtkInteractorStyleRubberBandPick):
def __init__(self, parent = None):
self.RemoveObservers("KeyPressEvent")
self.AddObserver("KeyPressEvent",self.OnKeyPress)
self.AddObserver("MiddleButtonPressEvent",self.OnMMBPressEvent)
self.camera = None
self.math = vtk.vtkMath()
def OnKeyPress(self,obj,event):
key = self.GetInteractor().GetKeySym()
self.camera=self.GetDefaultRenderer().GetActiveCamera()
if key == '1':
print("\nCamera details...")
self.print_camera_details()
elif key == '2':
self.camera.Roll(30.0)
print("\nRoll +30...")
self.print_camera_details()
elif key == '3':
self.camera.Pitch(30.0)
self.camera.OrthogonalizeViewUp()
print("\nPitch +30...")
self.print_camera_details()
How do I prevent the default methods from being called?
Thanks,
Doug