feat(ui): improve device session management, update data directory paths, and add session clearing functionality.

This commit is contained in:
jack
2026-06-15 11:28:28 -07:00
parent 7e584e08e8
commit 2e4763510d
7 changed files with 173 additions and 42 deletions
@@ -1,10 +1,4 @@
"""QML-exposed controller for wafer device communication.
Bridges DeviceService (serialcomm) to QML via @Slot methods and signals.
All hardware operations run synchronously on the main thread (matching
C# Form1.cs per-operation open/close pattern). For long operations
(erase ~15s, read up to 120s) the caller should show a loading state.
"""
"""QML-exposed controller for wafer device communication."""
from __future__ import annotations
@@ -67,9 +61,8 @@ class DeviceController(QObject):
self._operation_in_progress = False
self._activity_log: list[str] = getattr(settings, 'activity_log', [])
self._raw_bytes: Optional[bytes] = None
# Default save dir lives next to the settings file (~/Documents/isc_data/csv)
from pathlib import Path
self._save_data_dir: str = getattr(settings, 'save_data_dir', str(Path.home() / "Documents" / "isc_data" / "csv"))
self._save_data_dir: str = getattr(settings, 'save_data_dir', "") or str(Path(self._data_dir) / "csv")
self._last_wafer_info: dict[str, Any] = getattr(settings, 'last_wafer_info', {})
self._last_csv_path: str = getattr(settings, 'last_csv_path', "")
self._selected_port: str = getattr(settings, 'selected_port', "")
@@ -209,6 +202,28 @@ class DeviceController(QObject):
self._activity_log = self._activity_log[-200:]
self.activityLogUpdated.emit("\n".join(self._activity_log))
@Slot()
def clearActivityLog(self) -> None:
"""Clear the activity log."""
self._activity_log.clear()
self.activityLogUpdated.emit("")
self._save_status()
@Slot()
def clearSession(self) -> None:
"""Clear the current session state, allowing a clean detect."""
self._connection_status = "Disconnected"
self._selected_port = ""
self._last_wafer_info = {}
self._data_row_count = 0
self._data_col_count = 0
self._raw_bytes = None
self._operation_in_progress = False
self.detectResult.emit(None)
self.portsUpdated.emit(self.availablePorts)
self._append_log("Session refreshed/cleared")
self._save_status()
def _set_operation_progress(self, in_progress: bool) -> None:
"""Set operation progress state and notify QML.
@@ -424,12 +439,10 @@ class DeviceController(QObject):
return
if not self._save_data_dir:
self._append_log("No save data directory set")
self.parsedDataReady.emit({
"success": False,
"error": "No save data directory set",
})
return
from pathlib import Path
self._save_data_dir = str(Path(self._data_dir) / "csv")
self._append_log(f"Auto-set save directory to: {self._save_data_dir}")
self._save_status()
fc = family_code or (
self._last_wafer_info.get("familyCode", "")
@@ -509,7 +522,7 @@ class DeviceController(QObject):
self._settings.last_csv_path = self._last_csv_path
# Save to disk
LocalSettings.save_settings(str(LocalSettings._settings_path(self._data_dir)), self._settings)
LocalSettings.save_settings(self._data_dir, self._settings)
# ---- Helpers ----
@@ -52,7 +52,7 @@ class LocalSettingsModel(QObject):
QStandardPaths.DocumentsLocation
)
base_dir = Path(documents_dir) if documents_dir else (Path.home() / "Documents")
return base_dir / "isc_data"
return base_dir / "ISC_DATA"
def _new_defaults(self) -> dict[str, Any]:
return {