Skip to content

Commit

Permalink
ResultTable: explicitely pass parent_dialog
Browse files Browse the repository at this point in the history
Revamp signal emitters a bit to make it easier to override by a subclass
  • Loading branch information
zas committed Apr 24, 2024
1 parent b77fd16 commit 3ed9af0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions picard/ui/tablebaseddialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,18 @@

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)
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 @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 3ed9af0

Please sign in to comment.