From 2f991da6ead93b1540f670da2bcd6e71c1899e2e Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Mon, 19 Apr 2021 21:00:38 +0100 Subject: [PATCH] Handle window closes better --- app/musicmuster.py | 34 +++++++++++++++++----------------- app/playlists.py | 4 +++- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/app/musicmuster.py b/app/musicmuster.py index a853b2f..8afc859 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -58,23 +58,6 @@ class Window(QMainWindow, Ui_MainWindow): self.timer.start(Config.TIMER_MS) - def __del__(self): - record = Settings.get_int("mainwindow_height") - if record.f_int != self.height(): - record.update({'f_int': self.height()}) - - record = Settings.get_int("mainwindow_width") - if record.f_int != self.width(): - record.update({'f_int': self.width()}) - - record = Settings.get_int("mainwindow_x") - if record.f_int != self.x(): - record.update({'f_int': self.x()}) - - record = Settings.get_int("mainwindow_y") - if record.f_int != self.y(): - record.update({'f_int': self.y()}) - def add_file(self): dlg = QFileDialog() dlg.setFileMode(QFileDialog.ExistingFile) @@ -96,6 +79,23 @@ class Window(QMainWindow, Ui_MainWindow): # TODO notify user else: DEBUG("closeEvent() accepted") + + record = Settings.get_int("mainwindow_height") + if record.f_int != self.height(): + record.update({'f_int': self.height()}) + + record = Settings.get_int("mainwindow_width") + if record.f_int != self.width(): + record.update({'f_int': self.width()}) + + record = Settings.get_int("mainwindow_x") + if record.f_int != self.x(): + record.update({'f_int': self.x()}) + + record = Settings.get_int("mainwindow_y") + if record.f_int != self.y(): + record.update({'f_int': self.y()}) + event.accept() def connect_signals_slots(self): diff --git a/app/playlists.py b/app/playlists.py index 48c6e6e..69fb186 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -70,7 +70,7 @@ class Playlist(QTableWidget): self.previous_track_position = None self.played_tracks = [] - def __del__(self): + def closeEvent(self, event): "Save column widths" for column in range(self.columnCount()): @@ -80,6 +80,8 @@ class Playlist(QTableWidget): if record.f_int != self.columnWidth(column): record.update({'f_int': width}) + event.accept() + def eventFilter(self, source, event): "Used to process context (right-click) menu"