feat(api): Add GUI state manipulation hooks with thread-safe queueing

This commit is contained in:
2026-02-23 12:21:18 -05:00
parent 03db4190d7
commit 5f9bc193cb
3 changed files with 48 additions and 0 deletions

25
gui.py
View File

@@ -473,6 +473,10 @@ class App:
self._pending_history_adds: list[dict] = []
self._pending_history_adds_lock = threading.Lock()
# API GUI Hooks Queue
self._pending_gui_tasks: list[dict] = []
self._pending_gui_tasks_lock = threading.Lock()
# Blink state
self._trigger_blink = False
self._is_blinking = False
@@ -2085,6 +2089,27 @@ class App:
# Force scroll to bottom using a very large number
dpg.set_y_scroll("disc_scroll", 99999)
# Process queued API GUI tasks
with self._pending_gui_tasks_lock:
gui_tasks = self._pending_gui_tasks[:]
self._pending_gui_tasks.clear()
for task in gui_tasks:
try:
action = task.get("action")
if action == "set_value":
item = task.get("item")
val = task.get("value")
if item and dpg.does_item_exist(item):
dpg.set_value(item, val)
elif action == "click":
item = task.get("item")
if item and dpg.does_item_exist(item):
cb = dpg.get_item_callback(item)
if cb:
cb()
except Exception as e:
print(f"Error executing GUI hook task: {e}")
# Handle retro arcade blinking effect
if self._trigger_script_blink:
self._trigger_script_blink = False