Call a function every n millisecond for an animation in an asynchronous/non-blocking way (event loop?)
See original GitHub issueI display a visualization with plot.show(interactive=True) and when the user clicks on some button, I want to play an animation. However I couldn’t find the proper mechanism for doing so. I tried using Threads or the scheduler module and then I tried a simple for loop like this:
for i in range(100):
some_function_that_moves_an_object()
plot.show()
# time.sleep(0.1) # Is this useful?
But this doesn’t work.
Is there a way to have an interactive view and to play an animation at the same time? I see in vedo examples in the tunelling effect demo that a simple for loop calls multiple times plot.show() but in my case there was an initial call to plot.show(interactive=True) so how do I quit this interactive mode to let the animation play, that is, if interactive and animation cannot happen at the same time?
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Event loops, building smooth UIs, and handling high server ...
Building smooth UIs. Most of the code an iOS/macOS developer writes is called from an event loop iteration. All gesture recognisers, sensors ...
Read more >javascript - Call a function each 100 milliseconds using ...
I want to execute a function every 100 milliseconds. it can be done using an interval like this: setInterval(function(){ console. log('done') } ...
Read more >️ JavaScript Visualized: Event Loop
Time for the event loop to do its only task: connecting the queue with the call stack! If the call stack is empty,...
Read more >libuv(1) - Arch manual pages
One can run multiple event loops as long as each runs in a different thread. ... This function is just a convenient way...
Read more >Calling function every n second javascript game
You can pass an optional time parameter to your window.requestAnimationFrame() callback ( loop() in this case), and it will pass in the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah, thanks for the comment. It helps to know it should be ExitCallback() Good idea to add this as an example to vedo.
I solved it. There’s some unwanted code in vedo like the “allowInteraction” part in settings. As I thought, vtk has an accessible internal event loop. I thought listening to TimerEvent was enough but you have to trigger a repeating timer (so the user actually controls it).
In a class, I use the following to have a button that plays an animation:
If
vedo.settings.allowInteraction = True
, then the code below kicks in (from vedo/plotter.py) and kills the app (!) if a TimerEvent is caught.