From f2bc23df84907a361e7d9fa20bf1bc8f7a916037 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Tue, 20 Oct 2026 12:34:04 +0200 Subject: Keep column widths, splitters and window size across runs QSettings in state.conf next to config.toml, saved on close: every table header (widths, sort column) and splitter of the tabs, and the window geometry. Tests point it at a temp file, never the user's own. Co-Authored-By: Claude Opus 5.5 --- sb_builder/__main__.py | 1 - sb_builder/mainwindow.py | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) (limited to 'sb_builder') diff --git a/sb_builder/__main__.py b/sb_builder/__main__.py index 7571bd6..239b405 100644 --- a/sb_builder/__main__.py +++ b/sb_builder/__main__.py @@ -34,7 +34,6 @@ def main(): app.setDesktopFileName("sb-builder") # Wayland: match sb-builder.desktop cfg, err = config.load() w = MainWindow(cfg, Remote(cfg)) - w.resize(1100, 700) w.show() if err: QMessageBox.warning(w, "Config error", f"{err}\nUsing defaults.") diff --git a/sb_builder/mainwindow.py b/sb_builder/mainwindow.py index c6ea02e..f63a4ba 100644 --- a/sb_builder/mainwindow.py +++ b/sb_builder/mainwindow.py @@ -16,13 +16,14 @@ """Main window: tabs, status bar, connection polling, VM control, notifications.""" +import os import time -from PyQt6.QtCore import QMetaType, QObject, QSize, Qt, QTimer, pyqtSignal, pyqtSlot +from PyQt6.QtCore import QSettings, QMetaType, QObject, QSize, Qt, QTimer, pyqtSignal, pyqtSlot from PyQt6.QtDBus import QDBusArgument, QDBusConnection, QDBusInterface, QDBusMessage from PyQt6.QtGui import QIcon, QKeySequence, QShortcut -from PyQt6.QtWidgets import (QLabel, QMainWindow, QMessageBox, QPushButton, QStyle, QTabWidget, - QToolBar, QToolButton) +from PyQt6.QtWidgets import (QHeaderView, QLabel, QMainWindow, QMessageBox, QPushButton, QSplitter, + QStyle, QTabWidget, QToolBar, QToolButton) from . import VERSION, config from .dashboard import Dashboard @@ -79,8 +80,11 @@ class Notifier(QObject): class MainWindow(QMainWindow): - def __init__(self, cfg, remote, notifier=None): + def __init__(self, cfg, remote, notifier=None, state=None): super().__init__() + # window size, column widths, splitters: kept across runs, apart from config.toml + self.state = QSettings(state or os.path.join(os.path.dirname(config.path()), "state.conf"), + QSettings.Format.IniFormat) self.cfg, self.remote = cfg, remote self.notifier = notifier or Notifier(self) self.notifier.clicked.connect(self.open_job) @@ -156,6 +160,8 @@ class MainWindow(QMainWindow): self.stats_timer = QTimer(self, timeout=self.poll_slow) self._start_timers() QTimer.singleShot(0, self.poll_jobs) + self.resize(1100, 700) + self._restore_view() # ── polling ───────────────────────────────────────────────────────────── @@ -400,6 +406,31 @@ class MainWindow(QMainWindow): if jid: self.open_jobs().select(jid) + # ── view state ────────────────────────────────────────────────────────── + + def _views(self): + """(key, widget) of every table header and splitter in the tabs.""" + # ponytail: keyed by tab class and creation order; a reordered layout + # restores the wrong widths once, then saves the right ones + for tab in (self.dashboard, self.packages_tab, self.hints_tab, self.results_tab, self.jobs_tab): + for kind in (QHeaderView, QSplitter): + for n, w in enumerate(tab.findChildren(kind)): + yield f"{type(tab).__name__}/{kind.__name__}{n}", w + + def _restore_view(self): + if self.state.value("geometry"): + self.restoreGeometry(self.state.value("geometry")) + for key, w in self._views(): + if self.state.value(key): + w.restoreState(self.state.value(key)) + + def closeEvent(self, event): + self.state.setValue("geometry", self.saveGeometry()) + for key, w in self._views(): + self.state.setValue(key, w.saveState()) + self.state.sync() + super().closeEvent(event) + def reload_config(self): cfg, err = config.load() if err: -- cgit v1.2.3