From b7507d95ac270bbd470bb0ba664611eef17e2a37 Mon Sep 17 00:00:00 2001 From: VALLONGOL Date: Mon, 22 Dec 2025 12:40:06 +0100 Subject: [PATCH] sistemati editing di campi numeri --- pybusmonitor1553/gui/monitor.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/pybusmonitor1553/gui/monitor.py b/pybusmonitor1553/gui/monitor.py index afde5e5..2b16b97 100644 --- a/pybusmonitor1553/gui/monitor.py +++ b/pybusmonitor1553/gui/monitor.py @@ -146,6 +146,7 @@ class MonitorApp(tk.Frame): self.detail_selected_label = getattr(self, 'detail_selected_label', None) self.detail_accessors = getattr(self, 'detail_accessors', {}) self._flash_items = getattr(self, '_flash_items', {}) + self._fields_being_edited = set() # Track fields being edited to prevent refresh overwrite self._last_detail_update = 0.0 try: self.detail_tree.tag_configure('changed', background='lightyellow') @@ -524,9 +525,11 @@ class MonitorApp(tk.Frame): except Exception: pass else: - # Add instant callback for editable entries (on Return key or focus loss) - ent.bind('', lambda e, path=full: self._on_field_changed(path)) - ent.bind('', lambda e, path=full: self._on_field_changed(path)) + # Add instant callbacks for editable entries + # Mark as being edited when focused, apply when done + ent.bind('', lambda e, path=full: self._on_entry_focus_in(path)) + ent.bind('', lambda e, path=full: self._on_entry_finished(path)) + ent.bind('', lambda e, path=full: self._on_entry_finished(path)) ent.pack(side=tk.RIGHT, fill=tk.X, expand=True) widget = ('entry', ent) @@ -537,6 +540,23 @@ class MonitorApp(tk.Frame): except Exception: pass + def _on_entry_focus_in(self, field_path): + """Mark entry as being edited to prevent refresh from overwriting user input.""" + try: + self._fields_being_edited.add(field_path) + except Exception: + pass + + def _on_entry_finished(self, field_path): + """Entry editing finished - apply value and allow refresh again.""" + try: + # Apply the change first + self._on_field_changed(field_path) + # Remove from editing set so refresh can update it again + self._fields_being_edited.discard(field_path) + except Exception: + pass + def _on_field_changed(self, field_path): """Callback when user changes a field value - apply change immediately to message.""" try: @@ -1546,6 +1566,10 @@ class MonitorApp(tk.Frame): for full, widget in list(self.form_widgets.items()): try: + # Skip fields that are currently being edited by user + if full in getattr(self, '_fields_being_edited', set()): + continue + # resolve the value from msg val = None try: