diff options
author | Jay Kamat <jaygkamat@gmail.com> | 2018-09-29 12:25:49 -0700 |
---|---|---|
committer | Jay Kamat <jaygkamat@gmail.com> | 2018-09-29 12:26:42 -0700 |
commit | a5f9115b2f13305a31bc7e0e6236211d9696498e (patch) | |
tree | 26988b18465b268cb2de52606a65d39957841cf5 | |
parent | 3081d017ce692b48bb9ea42ca9fa40eb2e13ed86 (diff) | |
download | qutebrowser-a5f9115b2f13305a31bc7e0e6236211d9696498e.tar.gz qutebrowser-a5f9115b2f13305a31bc7e0e6236211d9696498e.zip |
Only apply visibility toggle if we have >10 tabs
-rw-r--r-- | qutebrowser/mainwindow/tabwidget.py | 39 | ||||
-rw-r--r-- | tests/unit/mainwindow/test_tabwidget.py | 6 |
2 files changed, 31 insertions, 14 deletions
diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index 928f1079a..69f0b1b92 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -21,6 +21,7 @@ import functools import enum +import contextlib import attr from PyQt5.QtCore import (pyqtSignal, pyqtSlot, Qt, QSize, QRect, QPoint, @@ -214,19 +215,35 @@ class TabWidget(QTabWidget): fields['scroll_pos'] = scroll_pos return fields + @contextlib.contextmanager + def _toggle_visibility(self, force_toggle=False): + """Toggle visibility while running. + + Every single call to setTabText calls the size hinting functions for + every single tab, which are slow. Since we know we are updating all + the tab's titles, we can delay this processing by making the tab + non-visible. To avoid flickering, disable repaint updates whlie we + work. + + Args: + force_toggle: Whether to always force the toggle, or only do it + if we have enough tabs for it to matter + """ + if self.count() > 10: + force_toggle = True + if force_toggle: + self.setUpdatesEnabled(False) + self.setVisible(False) + yield + if force_toggle: + self.setVisible(True) + self.setUpdatesEnabled(True) + def update_tab_titles(self): """Update all texts.""" - # Every single call to setTabText calls the size hinting functions for - # every single tab, which are slow. Since we know we are updating all - # the tab's titles, we can delay this processing by making the tab - # non-visible. To avoid flickering, disable repaint updates whlie we - # work. - self.setUpdatesEnabled(False) - self.setVisible(False) - for idx in range(self.count()): - self.update_tab_title(idx) - self.setVisible(True) - self.setUpdatesEnabled(True) + with self._toggle_visibility(): + for idx in range(self.count()): + self.update_tab_title(idx) def tabInserted(self, idx): """Update titles when a tab was inserted.""" diff --git a/tests/unit/mainwindow/test_tabwidget.py b/tests/unit/mainwindow/test_tabwidget.py index 2418a6d80..bc5ee9deb 100644 --- a/tests/unit/mainwindow/test_tabwidget.py +++ b/tests/unit/mainwindow/test_tabwidget.py @@ -24,7 +24,7 @@ import functools import pytest from PyQt5.QtGui import QIcon, QPixmap -from qutebrowser.mainwindow import tabwidget, tabbedbrowser +from qutebrowser.mainwindow import tabwidget from qutebrowser.utils import usertypes @@ -108,7 +108,7 @@ class TestTabWidget: assert first_size == widget.tabBar().tabSizeHint(i) assert first_size_min == widget.tabBar().minimumTabSizeHint(i) - @pytest.mark.parametrize("num_tabs", [4, 10]) + @pytest.mark.parametrize("num_tabs", [4, 10, 50, 100]) def test_update_tab_titles_benchmark(self, benchmark, widget, qtbot, fake_web_tab, num_tabs): """Benchmark for update_tab_titles.""" @@ -120,7 +120,7 @@ class TestTabWidget: benchmark(widget.update_tab_titles) - @pytest.mark.parametrize("num_tabs", [4, 10]) + @pytest.mark.parametrize("num_tabs", [4, 100]) @pytest.mark.parametrize("rev", [True, False]) def test_add_remove_tab_benchmark(self, benchmark, widget, qtbot, fake_web_tab, num_tabs, rev): |