Skip to content

Commit

Permalink
Widgets: Debounce operations when resizing ElementsTable
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Oct 23, 2023
1 parent 85310f8 commit 7c7c396
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion spyder/widgets/elementstable.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from qtpy.QtCore import QAbstractTableModel, QModelIndex, QSize, Qt
from qtpy.QtGui import QIcon
from qtpy.QtWidgets import QAbstractItemView, QCheckBox, QHBoxLayout, QWidget
from superqt.utils import qdebounced

# Local imports
from spyder.api.config.fonts import SpyderFontsMixin, SpyderFontType
Expand Down Expand Up @@ -333,6 +334,18 @@ def _set_layout(self):
# changes row heights in unpredictable ways.
self.resizeRowsToContents()

_set_layout_debounced = qdebounced(_set_layout, timeout=40)
"""
Debounced version of _set_layout.
Notes
-----
* We need a different version of _set_layout so that we can use the regular
one in showEvent. That way users won't experience a visual glitch when
the widget is rendered for the first time.
* We use this version in resizeEvent, where that is not a problem.
"""

def _with_feature(self, feature_name: str) -> bool:
"""Check if it's necessary to build the table with `feature_name`."""
return len([e for e in self.elements if e.get(feature_name)]) > 0
Expand Down Expand Up @@ -369,7 +382,7 @@ def enterEvent(self, event):
def resizeEvent(self, event):
# This is necessary to readjust the layout when the parent widget is
# resized.
self._set_layout()
self._set_layout_debounced()
super().resizeEvent(event)


Expand Down

0 comments on commit 7c7c396

Please sign in to comment.