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

**URL:** https://discourse.vtk.org/t/how-can-i-make-my-interactor-stop-queuing-events-while-an-event-is-being-carried-out/12404
**Category:** Support
**Tags:** rendering, python
**Created:** [October 3, 2023, 10:09am UTC](https://discourse.vtk.org/t/how-can-i-make-my-interactor-stop-queuing-events-while-an-event-is-being-carried-out/12404 "2023-10-03T10:09:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![user12345](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/u/bcef8e/32.png) [@user12345](https://discourse.vtk.org/u/user12345)
#### Post date: [October 3, 2023, 10:09am UTC](https://discourse.vtk.org/t/how-can-i-make-my-interactor-stop-queuing-events-while-an-event-is-being-carried-out/12404/1 "2023-10-03T10:09:00Z")

</div>

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.

```auto
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”.

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [October 3, 2023, 7:05pm UTC](https://discourse.vtk.org/t/how-can-i-make-my-interactor-stop-queuing-events-while-an-event-is-being-carried-out/12404/2 "2023-10-03T19:05:04Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![user12345](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/u/bcef8e/32.png) [@user12345](https://discourse.vtk.org/u/user12345)
#### Post date: [October 4, 2023, 7:55am UTC](https://discourse.vtk.org/t/how-can-i-make-my-interactor-stop-queuing-events-while-an-event-is-being-carried-out/12404/3 "2023-10-04T07:55:51Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [October 4, 2023, 4:15pm UTC](https://discourse.vtk.org/t/how-can-i-make-my-interactor-stop-queuing-events-while-an-event-is-being-carried-out/12404/4 "2023-10-04T16:15:53Z")

</div>

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`.

---

<div class="post-metadata">

### Author: ![user12345](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/u/bcef8e/32.png) [@user12345](https://discourse.vtk.org/u/user12345)
#### Post date: [October 5, 2023, 9:03am UTC](https://discourse.vtk.org/t/how-can-i-make-my-interactor-stop-queuing-events-while-an-event-is-being-carried-out/12404/5 "2023-10-05T09:03:34Z")

</div>

> [@Jens\_Munk\_Hansen](#):
>
> `vtkCameraInterpolator`

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