From b3630014f20fb01fca6024d728f0abd8c920c203 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Tue, 23 Apr 2024 11:23:06 +0200 Subject: [PATCH 1/2] PICARD-2873: Fetch Search dialog cover art images after it was resized - create a new `resized` signal emitted every second - call `AlbumSearchDialog.fetch_coverarts()` when it happens --- picard/ui/searchdialog/album.py | 1 + picard/ui/tablebaseddialog.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/picard/ui/searchdialog/album.py b/picard/ui/searchdialog/album.py index 85b5aedbc9..23eba9b03b 100644 --- a/picard/ui/searchdialog/album.py +++ b/picard/ui/searchdialog/album.py @@ -168,6 +168,7 @@ def __init__(self, parent, force_advanced_search=None, existing_album=None): self.cover_cells = [] self.fetching = False self.scrolled.connect(self.fetch_coverarts) + self.resized.connect(self.fetch_coverarts) @staticmethod def show_releasegroup_search(releasegroup_id, existing_album=None): diff --git a/picard/ui/tablebaseddialog.py b/picard/ui/tablebaseddialog.py index 0c899b6ceb..3cf54baba6 100644 --- a/picard/ui/tablebaseddialog.py +++ b/picard/ui/tablebaseddialog.py @@ -52,6 +52,7 @@ class ResultTable(QtWidgets.QTableWidget): def __init__(self, parent): super().__init__(parent) + self._parent_dialog = parent self.setSelectionMode(QtWidgets.QAbstractItemView.SelectionMode.ExtendedSelection) self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectionBehavior.SelectRows) self.setEditTriggers(QtWidgets.QAbstractItemView.EditTrigger.NoEditTriggers) @@ -73,6 +74,14 @@ def prepare(self, headers): self.setRowCount(0) self.setSortingEnabled(False) + @throttle(1000) # only emit resized signal once per second + def emit_resized(self): + self._parent_dialog.resized.emit() + + def resizeEvent(self, event): + self.emit_resized() + super().resizeEvent(event) + class SortableTableWidgetItem(QtWidgets.QTableWidgetItem): @@ -88,6 +97,7 @@ class TableBasedDialog(PicardDialog): defaultsize = QtCore.QSize(720, 360) scrolled = pyqtSignal() + resized = pyqtSignal() def __init__(self, parent): super().__init__(parent) From 18c9ba592d05e4260e6bc83fd89db46a89a905b0 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Wed, 24 Apr 2024 09:55:39 +0200 Subject: [PATCH 2/2] ResultTable: explicitely pass parent_dialog Revamp signal emitters a bit to make it easier to override by a subclass --- picard/ui/tablebaseddialog.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/picard/ui/tablebaseddialog.py b/picard/ui/tablebaseddialog.py index 3cf54baba6..b51f3e8cb3 100644 --- a/picard/ui/tablebaseddialog.py +++ b/picard/ui/tablebaseddialog.py @@ -50,9 +50,9 @@ class ResultTable(QtWidgets.QTableWidget): - def __init__(self, parent): - super().__init__(parent) - self._parent_dialog = parent + def __init__(self, parent=None, parent_dialog=None): + super().__init__(parent=parent) + self.parent_dialog = parent_dialog self.setSelectionMode(QtWidgets.QAbstractItemView.SelectionMode.ExtendedSelection) self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectionBehavior.SelectRows) self.setEditTriggers(QtWidgets.QAbstractItemView.EditTrigger.NoEditTriggers) @@ -60,11 +60,8 @@ def __init__(self, parent): self.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.ResizeMode.Stretch) self.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.ResizeMode.Interactive) - @throttle(1000) # only emit scrolled signal once per second - def emit_scrolled(x): - parent.scrolled.emit() - self.horizontalScrollBar().valueChanged.connect(emit_scrolled) - self.verticalScrollBar().valueChanged.connect(emit_scrolled) + self.horizontalScrollBar().valueChanged.connect(self.emit_scrolled) + self.verticalScrollBar().valueChanged.connect(self.emit_scrolled) self.setHorizontalScrollMode(QtWidgets.QAbstractItemView.ScrollMode.ScrollPerPixel) def prepare(self, headers): @@ -74,9 +71,15 @@ def prepare(self, headers): self.setRowCount(0) self.setSortingEnabled(False) + @throttle(1000) # only emit scrolled signal once per second + def emit_scrolled(self, value): + if self.parent_dialog: + self.parent_dialog.scrolled.emit() + @throttle(1000) # only emit resized signal once per second def emit_resized(self): - self._parent_dialog.resized.emit() + if self.parent_dialog: + self.parent_dialog.resized.emit() def resizeEvent(self, event): self.emit_resized() @@ -165,7 +168,7 @@ def add_widget_to_center_layout(self, widget): widget.show() def create_table_obj(self): - return ResultTable(self) + return ResultTable(parent_dialog=self) def create_table(self): self.table = self.create_table_obj()