From 0bc80c5ed9d7e21c3d4fe702c4eb018428d44b81 Mon Sep 17 00:00:00 2001 From: Luca Toniolo <10792599+grandixximo@users.noreply.github.com> Date: Mon, 17 Aug 2026 20:53:31 +0800 Subject: [PATCH] hal_glib: defer file-loaded when the interp is already running GSTAT only emits 'file-loaded' if the poll that first sees stat.file change finds the interp IDLE. A client doing program_open + AUTO_RUN back to back starts the program within ms, so every 100 ms poll sees the file with the interp busy, the remap guard swallows the change, and the signal is never emitted: gmoccapy sits at 'No Program loaded' with an empty editor and preview after an externally driven run, and whether it does depends on poll timing. Emit a skipped change on the first poll with the interp back at IDLE. Remap protection unchanged: merge() ignores the file name at call level != 0. --- lib/python/common/hal_glib.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/python/common/hal_glib.py b/lib/python/common/hal_glib.py index 864bf95b0ec..a157a3f47c0 100644 --- a/lib/python/common/hal_glib.py +++ b/lib/python/common/hal_glib.py @@ -330,6 +330,7 @@ def __init__(self, stat = None): self._status_active = False self.old = {} self.old['tool-prep-number'] = 0 + self._file_load_pending = False self.previous_mode = self.MANUAL try: self.stat.poll() @@ -677,6 +678,17 @@ def update(self): # a reload of the preview and sourceview widgets if self.stat.interp_state == linuxcnc.INTERP_IDLE and file_new != "": self.emit('file-loaded', file_new) + elif file_new != "": + # also defer a legit program that was opened and started + # before this poll saw it, or the GUI never shows it + self._file_load_pending = True + else: + self._file_load_pending = False + if self._file_load_pending and \ + self.stat.interp_state == linuxcnc.INTERP_IDLE and \ + self.old['file']: + self._file_load_pending = False + self.emit('file-loaded', self.old['file']) #ToDo : Find a way to avoid signal when the line changed due to # a remap procedure, because the signal do highlight a wrong