From 3ed9af072250137e89fa6640d825bb56eb729d97 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Wed, 24 Apr 2024 09:55:39 +0200 Subject: [PATCH] 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 3cf54baba6e..b51f3e8cb30 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()