-
Hi, Is there a way I could send an interrupt signal to a callback? Or would I have to implement my own thread management somehow? How would you go about it? import time
import dearpygui.dearpygui as dpg
dpg.create_context()
dpg.create_viewport(title='Custom Title', width=600, height=300)
def run(sender, app_data, user_data):
dpg.configure_item("cancel_btn", show=True)
dpg.set_value("progress", 0.0)
for i in range(user_data):
dpg.set_value("progress", i/user_data)
dpg.configure_item("pbar", overlay=f"{i}/{user_data}")
# Here would be a call to function, whose individual runtime could be a couple
# of seconds, in total some hundreds to thousands of loops.
time.sleep(0.5)
dpg.set_value("progress", 1.0)
dpg.configure_item("pbar", overlay="Ready!")
dpg.configure_item("cancel_btn", show=False)
def cancel_run(sender, app_data):
# This is not run until the first callback ends
print("Hello")
...
with dpg.value_registry():
dpg.add_float_value(tag="progress", default_value=0.0)
with dpg.window(label="Example Window", width=400):
dpg.add_progress_bar(tag="pbar", source="progress", width=-1)
with dpg.group(horizontal=True):
dpg.add_button(label="Start", callback=run, user_data=10)
dpg.add_button(label="Cancel", tag="cancel_btn", show=False, callback=cancel_run)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context() |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hmm. At the moment, we do not provide a standard way to handle this, so its on the user in the current version. However, I do see this as an easy add on our part to help. I will part this as an improvement we can add soon! |
Beta Was this translation helpful? Give feedback.
-
Hi guys, is there a solution now to this problem ? I added a counter in the callback and every 500 frames I could check for other events, on other frameworks I would issue a root.update() and that would allow for an interrupt if needed.. Here I could not find something similar.. |
Beta Was this translation helpful? Give feedback.
-
Hi! I suppose you could run the callback in a separate thread with a killswitch and have a button to set it. In the loop you would have: if killswitch.is_set():
# stop calculation You will have to wait one whole iteration before it stops though, which if you say
doesn't seem too bad. |
Beta Was this translation helpful? Give feedback.
Hmm. At the moment, we do not provide a standard way to handle this, so its on the user in the current version. However, I do see this as an easy add on our part to help. I will part this as an improvement we can add soon!