How can I make my interactor stop queuing events while an event is being carried out?

In this minimal example that moves the camera aimed at the sphere when you right click, I want to have an interactor that moves the camera when I click. This takes some time, and during that time, I want the interactor to ignore user inputs instead of queuing them up. Right now, the interactor queues up clicks from the user while the camera is moving, so if you double tap the right mouse button, the camera moves twices, instead of just once.

import vtk
import numpy as np 


class MouseInteractorHighLightActor(vtk.vtkInteractorStyleTrackballCamera):

    def __init__(self, renderer=None, renwin=None, rwi=None, com=None):
        self.AddObserver("RightButtonPressEvent", self.rightButtonPressEvent)

        self.Renderer = renderer
        self.RenderWindow = renwin
        self.RenderWindowInteractor = rwi
        self.Camera = renderer.GetActiveCamera()
        self.com = com

    def rightButtonPressEvent(self, obj, event):
        print("event: " + str(event) + ", " + str(obj))

        pos = [np.array(self.com) + np.array([10 + i, 0, 0]) for i in range(50)]
        self.Camera.SetFocalPoint(self.com)
        
        step = 0
        while step < 50:
            #print(step)

            self.Camera.SetPosition(pos[step])
            self.Renderer.ResetCameraClippingRange()
            self.RenderWindowInteractor.GetRenderWindow().Render()
            step += 1
            
            
        self.OnRightButtonDown()
        return




if __name__ == '__main__':
    sphere_filter = vtk.vtkSphereSource()
    sphere_filter.Update()
    sphere = sphere_filter.GetOutput()
    
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(sphere)
    
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)

    renderer = vtk.vtkRenderer()

    renwin = vtk.vtkRenderWindow()
    renwin.AddRenderer(renderer)
    renwin.SetSize(1500, 1000)

    # An interactor
    rwi = vtk.vtkRenderWindowInteractor()
    rwi.Initialize()
    renwin.SetInteractor(rwi)
    
    # add the custom style
    style = MouseInteractorHighLightActor(renderer, renwin, rwi, sphere.GetCenter())
    style.SetDefaultRenderer(renderer)
    rwi.SetInteractorStyle(style)
    
    renderer.AddActor(actor)
    renderer.GetActiveCamera().SetFocalPoint(actor.GetCenter())
    renderer.ResetCameraClippingRange()
        
    # Start
    renwin.Render()
    rwi.Start()

I tried to disable the render window interactor (rwi.Disable()), set the interactor style enabled to 0 (self.SetEnabled(0) in MouseInteractorHighLightActor), and I put an if condition in the rightButtonPressEvent to only carry out the event if the style is “enabled”.

It is very nice with a deterministic rendering engine. Some of the never widgets support throtling i.e. concatening events. I would look into that.

Do you have an example of such a widget? And is that something that I could implement in an interactor style?

Sorry my bad. In your code, you are busy setting a position and enforcing a Render() calls, which is why it lacking like mad. Some of the widgets implement smooth motion, where positions are extrapolated and a request for moving the focus is made (unrelated to your specific code).

I you want move your camera a long a curve, look into vtkCameraInterpolator.

Thank you, that’s exactly the kind of thing I’m looking for!