Implement saving and restoring window state (size, position, last selected tab) using QSettings in PyQt5
This commit is contained in:
parent
50b90bcf9c
commit
de63ffc509
15
frontend.py
15
frontend.py
@ -11,7 +11,7 @@ from PyQt5.QtWidgets import (
|
|||||||
QComboBox, QTextEdit, QDialogButtonBox, QAction, QFileDialog, QMessageBox,
|
QComboBox, QTextEdit, QDialogButtonBox, QAction, QFileDialog, QMessageBox,
|
||||||
QInputDialog, QApplication, QAbstractItemView, QSizePolicy, QHeaderView
|
QInputDialog, QApplication, QAbstractItemView, QSizePolicy, QHeaderView
|
||||||
)
|
)
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt, QSettings
|
||||||
from PyQt5.QtGui import QColor, QIcon
|
from PyQt5.QtGui import QColor, QIcon
|
||||||
from backend import AnimeBackend
|
from backend import AnimeBackend
|
||||||
|
|
||||||
@ -136,6 +136,7 @@ class CustomTableWidget(QTableWidget):
|
|||||||
class AnimeTracker(QMainWindow):
|
class AnimeTracker(QMainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
self.settings = QSettings("xAI", "AnimeBacklogTracker")
|
||||||
self.setWindowTitle("Anime Backlog Tracker")
|
self.setWindowTitle("Anime Backlog Tracker")
|
||||||
self.resize(800, 600)
|
self.resize(800, 600)
|
||||||
self.backend = AnimeBackend()
|
self.backend = AnimeBackend()
|
||||||
@ -143,6 +144,15 @@ class AnimeTracker(QMainWindow):
|
|||||||
self.setCentralWidget(self.tab_widget)
|
self.setCentralWidget(self.tab_widget)
|
||||||
self.create_menu()
|
self.create_menu()
|
||||||
self.load_tabs()
|
self.load_tabs()
|
||||||
|
self.restoreGeometry(self.settings.value("geometry", self.saveGeometry()))
|
||||||
|
last_tab = self.settings.value("lastTab", None)
|
||||||
|
if last_tab is not None:
|
||||||
|
self.set_current_tab_by_identifier(last_tab)
|
||||||
|
|
||||||
|
def closeEvent(self, event):
|
||||||
|
self.settings.setValue("geometry", self.saveGeometry())
|
||||||
|
self.settings.setValue("lastTab", self.get_current_tab_identifier())
|
||||||
|
super().closeEvent(event)
|
||||||
|
|
||||||
def create_menu(self):
|
def create_menu(self):
|
||||||
menubar = self.menuBar()
|
menubar = self.menuBar()
|
||||||
@ -200,6 +210,9 @@ class AnimeTracker(QMainWindow):
|
|||||||
if t.startswith(str(identifier) + " ("):
|
if t.startswith(str(identifier) + " ("):
|
||||||
self.tab_widget.setCurrentIndex(i)
|
self.tab_widget.setCurrentIndex(i)
|
||||||
return
|
return
|
||||||
|
# If the year no longer exists, default to first tab
|
||||||
|
if self.tab_widget.count() > 0:
|
||||||
|
self.tab_widget.setCurrentIndex(0)
|
||||||
|
|
||||||
def load_tabs(self):
|
def load_tabs(self):
|
||||||
self.tab_widget.clear()
|
self.tab_widget.clear()
|
||||||
|
Loading…
Reference in New Issue
Block a user