aboutsummaryrefslogtreecommitdiffstats
path: root/sb_builder/mainwindow.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-20 12:34:04 +0200
committerDanilo M. <danix@danix.xyz>2026-10-20 12:34:04 +0200
commitf2bc23df84907a361e7d9fa20bf1bc8f7a916037 (patch)
tree60135956d7e3d98397ad80cdafa643446e231f2a /sb_builder/mainwindow.py
parenteaeeb7349504d83cd3251daba4c557854c46cd00 (diff)
downloadsb-builder-f2bc23df84907a361e7d9fa20bf1bc8f7a916037.tar.gz
sb-builder-f2bc23df84907a361e7d9fa20bf1bc8f7a916037.zip
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 <noreply@anthropic.com>
Diffstat (limited to 'sb_builder/mainwindow.py')
-rw-r--r--sb_builder/mainwindow.py39
1 files changed, 35 insertions, 4 deletions
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: