Skip to content

Commit

Permalink
Merge pull request #2427 from zas/fix_cover_art_cells
Browse files Browse the repository at this point in the history
PICARD-2873: Fetch Search dialog cover art images after it was resized
  • Loading branch information
zas authored Apr 25, 2024
2 parents 055547b + 18c9ba5 commit 5f5b4e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions picard/ui/searchdialog/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
29 changes: 21 additions & 8 deletions picard/ui/tablebaseddialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,18 @@

class ResultTable(QtWidgets.QTableWidget):

def __init__(self, parent):
super().__init__(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)
self.horizontalHeader().setStretchLastSection(True)
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):
Expand All @@ -73,6 +71,20 @@ 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):
if self.parent_dialog:
self.parent_dialog.resized.emit()

def resizeEvent(self, event):
self.emit_resized()
super().resizeEvent(event)


class SortableTableWidgetItem(QtWidgets.QTableWidgetItem):

Expand All @@ -88,6 +100,7 @@ class TableBasedDialog(PicardDialog):

defaultsize = QtCore.QSize(720, 360)
scrolled = pyqtSignal()
resized = pyqtSignal()

def __init__(self, parent):
super().__init__(parent)
Expand Down Expand Up @@ -155,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()
Expand Down

0 comments on commit 5f5b4e4

Please sign in to comment.