Disconnect from the device when opening a file or closing the app

Opening a file now drops the live connection once a file is chosen, without
asking. File > Exit and the window close box go through quit_app, which
closes the Sox session properly instead of leaving it for the device to
time out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-03 23:45:12 +03:00
co-authored by Claude Opus 5.5
parent 85b6fa62f3
commit dbeeb78916
3 changed files with 42 additions and 15 deletions
+14 -13
View File
@@ -31,6 +31,15 @@ def set_tree_filled_callback(callback):
_tree_filled = callback
_disconnect_device = None
def set_disconnect_device_callback(callback):
"""Registers how to drop the live device session before a file takes its place."""
global _disconnect_device
_disconnect_device = callback
def parse_xml_to_tree(treeview, parent_node, xml_element):
"""Recursively traverses XML elements and adds <comp> tags to the Treeview."""
for child in xml_element:
@@ -132,19 +141,6 @@ def open_file():
messagebox.showwarning("Action Blocked", "Cannot load SAX profiles because 'Sedona home folder' configuration is missing or empty.")
return
if app_state.live_mode:
answer = messagebox.askyesnocancel(
"Device Connected",
"A live device connection is active.\n\n"
"Disconnect from the device and open a file?\n\n"
"Choose Yes to disconnect and open, No to cancel.",
)
if not answer:
return
# Import here to avoid circular import at module level
from main import do_device_disconnect
do_device_disconnect()
file_path = filedialog.askopenfilename(
title="Select SAX File",
filetypes=[("SAX Files", "*.sax"), ("XML Files", "*.xml"), ("All Files", "*.*")],
@@ -152,6 +148,11 @@ def open_file():
if not file_path:
return
# A session is a file or a device, never both. The device goes only once a file has
# actually been chosen, so cancelling the dialog leaves the connection as it was.
if app_state.device_session is not None and _disconnect_device is not None:
_disconnect_device()
canvas = app_state.canvas
tree = app_state.tree