|
63 | 63 | import numpy as np |
64 | 64 |
|
65 | 65 | from qtpy import QtCore |
66 | | -from qtpy.QtCore import Qt, QPoint, QItemSelection, QItemSelectionModel, Signal, QSize, QModelIndex |
| 66 | +from qtpy.QtCore import (Qt, QPoint, QItemSelection, QItemSelectionModel, |
| 67 | + Signal, QSize, QModelIndex, QTimer) |
67 | 68 | from qtpy.QtGui import (QDoubleValidator, QIntValidator, QKeySequence, QFontMetrics, QCursor, QPixmap, QPainter, QIcon, |
68 | 69 | QWheelEvent, QMouseEvent) |
69 | 70 | from qtpy.QtWidgets import (QApplication, QTableView, QItemDelegate, QLineEdit, QCheckBox, |
@@ -1290,6 +1291,8 @@ def get_numbers_width(self, int_digits, frac_digits=0, need_sign=False, scientif |
1290 | 1291 |
|
1291 | 1292 | class ArrayEditorWidget(QWidget): |
1292 | 1293 | dataChanged = Signal(list) |
| 1294 | + # milliseconds between a scroll event and updating cell sizes |
| 1295 | + UPDATE_SIZES_FROM_CONTENT_DELAY = 100 |
1293 | 1296 |
|
1294 | 1297 | def __init__(self, parent, data=None, readonly=False, attributes=None, bg_gradient='blue-red', |
1295 | 1298 | minvalue=None, maxvalue=None, digits=None): |
@@ -1512,6 +1515,12 @@ def hidden_vscroll_range_changed(min_value: int, max_value: int): |
1512 | 1515 | self._updating_vlabels_row_heights = False |
1513 | 1516 | self._updating_axes_row_heights = False |
1514 | 1517 |
|
| 1518 | + update_timer = QTimer(self) |
| 1519 | + update_timer.setSingleShot(True) |
| 1520 | + update_timer.setInterval(self.UPDATE_SIZES_FROM_CONTENT_DELAY) |
| 1521 | + update_timer.timeout.connect(self.update_cell_sizes_from_content) |
| 1522 | + self.update_cell_sizes_timer = update_timer |
| 1523 | + |
1515 | 1524 | def visible_cols(self, include_partial=True): |
1516 | 1525 | """number of visible columns *including* partially visible ones""" |
1517 | 1526 |
|
@@ -1650,20 +1659,24 @@ def visible_vscroll_changed(self, value): |
1650 | 1659 | model_data.set_v_offset(new_v_offset) |
1651 | 1660 | self.model_vlabels.set_v_offset(new_v_offset) |
1652 | 1661 | self._update_selection(model_data.h_offset, new_v_offset) |
1653 | | - # TODO: scrolling feels *much* snappier (especially for in-memory |
1654 | | - # datasets) without these, but not having them at all is |
1655 | | - # annoying. Can we make that faster? |
1656 | | - # * Would computing the sizeHint ourselves help? |
1657 | | - # * For many in-memory (especially numerical) containers, |
1658 | | - # it would be cheaper to compute that once for the |
1659 | | - # whole array instead |
1660 | | - self._update_hlabels_column_widths_from_content() |
1661 | | - # we do not need to update axes cell size on scroll but vlabels |
1662 | | - # width can change on scroll (and they are linked to axes widths) |
1663 | | - self._update_axes_column_widths_from_content() |
1664 | | - self._update_vlabels_row_heights_from_content() |
| 1662 | + self.update_cell_sizes_timer.start() |
| 1663 | + |
1665 | 1664 | hidden_vscroll.setValue(new_hidden_offset) |
1666 | 1665 |
|
| 1666 | + def update_cell_sizes_from_content(self): |
| 1667 | + logger.debug("ArrayEditorWidget.update_cell_sizes_from_content()") |
| 1668 | + # TODO: having this in a timer alleviates the scrolling speed issue |
| 1669 | + # but we could also try to make this faster: |
| 1670 | + # * Would computing the sizeHint ourselves help? |
| 1671 | + # * For many in-memory (especially numerical) containers, |
| 1672 | + # it would be cheaper to compute that once for the |
| 1673 | + # whole array instead of after each scroll |
| 1674 | + self._update_hlabels_column_widths_from_content() |
| 1675 | + # we do not need to update axes cell size on scroll but vlabels |
| 1676 | + # width can change on scroll (and they are linked to axes widths) |
| 1677 | + self._update_axes_column_widths_from_content() |
| 1678 | + self._update_vlabels_row_heights_from_content() |
| 1679 | + |
1667 | 1680 | def visible_hscroll_changed(self, value): |
1668 | 1681 | # 'value' will be the first visible column |
1669 | 1682 | assert value >= 0, f"value must be >= 0 but is {value!r}" |
@@ -1715,11 +1728,7 @@ def visible_hscroll_changed(self, value): |
1715 | 1728 | model_data.set_h_offset(new_h_offset) |
1716 | 1729 | self.model_hlabels.set_h_offset(new_h_offset) |
1717 | 1730 | self._update_selection(new_h_offset, model_data.v_offset) |
1718 | | - self._update_hlabels_column_widths_from_content() |
1719 | | - # we do not need to update axes cell size on scroll but vlabels |
1720 | | - # width can change on scroll (and they are linked to axes widths) |
1721 | | - self._update_axes_column_widths_from_content() |
1722 | | - self._update_vlabels_row_heights_from_content() |
| 1731 | + self.update_cell_sizes_timer.start() |
1723 | 1732 | hidden_hscroll.setValue(new_hidden_offset) |
1724 | 1733 |
|
1725 | 1734 | def on_axes_column_resized(self, logical_index, old_size, new_size): |
|
0 commit comments