sistemati editing di campi numeri

This commit is contained in:
VALLONGOL 2025-12-22 12:40:06 +01:00
parent 0c4c1e27ea
commit b7507d95ac

View File

@ -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('<Return>', lambda e, path=full: self._on_field_changed(path))
ent.bind('<FocusOut>', 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('<FocusIn>', lambda e, path=full: self._on_entry_focus_in(path))
ent.bind('<Return>', lambda e, path=full: self._on_entry_finished(path))
ent.bind('<FocusOut>', 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: