Fix connect dialog: button order and cancel-during-connection cleanup

Swap Connect/Cancel button order so Connect is the default (leftmost).
Guard background thread against cancelled state so a cancelled connect
does not leave the app in live mode. Cancel during connection now
disconnects the session cleanly in a cleanup thread.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-12 09:41:21 +03:00
co-authored by Claude Opus 4.6
parent 0674f32637
commit b4a504e57d
2 changed files with 22 additions and 4 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ so later rebinding would only ever be seen by the module that did it.
import configparser
import os
VERSION = "0.0.0.080"
VERSION = "0.0.0.081"
PROPERTIES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "editor.properties")
DEFAULT_GRID_SIZE = 10
DEFAULT_ADD_TIMESTAMP = True
+21 -3
View File
@@ -64,12 +64,12 @@ class ConnectDialog:
btn_frame = ttk.Frame(frame)
btn_frame.grid(row=row, column=0, columnspan=3, sticky="e", pady=(8, 0))
self._btn_connect = ttk.Button(btn_frame, text="Connect", command=self._do_connect)
self._btn_connect.pack(side=tk.RIGHT, padx=(8, 0))
self._btn_cancel = ttk.Button(btn_frame, text="Cancel", command=self._do_cancel)
self._btn_cancel.pack(side=tk.RIGHT)
self._btn_connect = ttk.Button(btn_frame, text="Connect", command=self._do_connect)
self._btn_connect.pack(side=tk.RIGHT, padx=(0, 8))
self._host_entry.focus_set()
self._dlg.bind("<Return>", lambda e: self._do_connect())
self._dlg.bind("<Escape>", lambda e: self._do_cancel())
@@ -110,8 +110,12 @@ class ConnectDialog:
def _connect_worker(self, host, port, user, password):
try:
result = self._callback(host, port, user, password)
if self._cancelled:
return
self._result = ("ok", result, host, port, user)
except Exception as e:
if self._cancelled:
return
self._result = ("error", str(e), host, port, user)
def _poll_connect(self):
@@ -133,6 +137,20 @@ class ConnectDialog:
def _do_cancel(self):
self._cancelled = True
if self._thread is not None and self._thread.is_alive():
# Connection attempt in progress — clean up after it finishes
import app_state as _as
def _cleanup():
self._thread.join(timeout=5)
if _as.device_session is not None and _as.live_mode:
try:
_as.device_session.disconnect()
except Exception:
pass
_as.live_mode = False
_as.device_session = None
_as.connection_status = "offline"
threading.Thread(target=_cleanup, daemon=True).start()
self._dlg.destroy()