I am a beginner of vedo and I want to implement a 'play/pause' button in vedo. Here is my basic code:
import vedo
def test_handle_timer(event):
print('timer event triggered.')
plt = vedo.Plotter(axes=1)
timerevt = plt.add_callback('timer', test_handle_timer)
is_playing = False
timer_id = None
button = None
def button_fnc(obj, ename):
global is_playing, timer_id, button
if timer_id is not None:
plt.timer_callback("destroy", timer_id)
if not is_playing:
timer_id = plt.timer_callback("create", dt=100)
button.switch()
print('button clicked.')
is_playing = not is_playing
button = plt.add_button(button_fnc, states=["\u23F5 Play ","\u23F8 Pause"], size=32)
plt.interactive()
plt.close()
What I expect is when I click the button, I will get one 'button clicked' and many following 'time event triggered'. However, what I actually get is two 'button clicked' and only one 'time event triggered':
It seems like the button_fnc has been triggered twice, once when I click the button and once when I release.
I wonder what is the proper way to implement such button.
Hi marco.
I am a beginner of vedo and I want to implement a 'play/pause' button in vedo. Here is my basic code:
What I expect is when I click the button, I will get one 'button clicked' and many following 'time event triggered'. However, what I actually get is two 'button clicked' and only one 'time event triggered':
It seems like the
button_fnc
has been triggered twice, once when I click the button and once when I release.I wonder what is the proper way to implement such button.