summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2021-01-14 20:10:38 +0100
committerFlorian Bruhin <me@the-compiler.org>2021-01-14 20:10:38 +0100
commitfd4f0663e76e9ff9f8e11ac6a8c3b40e4c700bc2 (patch)
tree6aae2481fbe95087388576c46b7d5ca7e4193ce3
parentf1b925e37fea016939a35126bfc29a0c3e2d547b (diff)
downloadqutebrowser-fd4f0663e76e9ff9f8e11ac6a8c3b40e4c700bc2.tar.gz
qutebrowser-fd4f0663e76e9ff9f8e11ac6a8c3b40e4c700bc2.zip
Revert "history: Simplify HistoryProgress"
Seems to cause random dialogs This reverts commit f1b925e37fea016939a35126bfc29a0c3e2d547b.
-rw-r--r--qutebrowser/browser/history.py21
-rw-r--r--tests/unit/browser/test_history.py51
2 files changed, 47 insertions, 25 deletions
diff --git a/qutebrowser/browser/history.py b/qutebrowser/browser/history.py
index 7a9dd7fe8..eaeb274f3 100644
--- a/qutebrowser/browser/history.py
+++ b/qutebrowser/browser/history.py
@@ -46,11 +46,15 @@ class HistoryProgress:
"""
def __init__(self):
- self._progress = QProgressDialog()
+ self._reset()
+
+ def _reset(self):
+ self._progress = None
self._value = 0
def start(self, text):
"""Start showing a progress dialog."""
+ self._progress = QProgressDialog()
self._progress.setMaximum(0) # unknown
self._progress.setMinimumDuration(0)
self._progress.setLabelText(text)
@@ -67,13 +71,18 @@ class HistoryProgress:
def tick(self):
"""Increase the displayed progress value."""
self._value += 1
- self._progress.setValue(self._value)
- QApplication.processEvents()
+ if self._progress is not None:
+ self._progress.setValue(self._value)
+ QApplication.processEvents()
def finish(self):
- """Finish showing the progress dialog."""
- self._progress.hide()
- self._progress.deleteLater()
+ """Finish showing the progress dialog.
+
+ After this is called, the object can be reused.
+ """
+ if self._progress is not None:
+ self._progress.hide()
+ self._reset()
class CompletionMetaInfo(sql.SqlTable):
diff --git a/tests/unit/browser/test_history.py b/tests/unit/browser/test_history.py
index 1aa873503..876ffb9bc 100644
--- a/tests/unit/browser/test_history.py
+++ b/tests/unit/browser/test_history.py
@@ -498,22 +498,35 @@ class TestCompletionMetaInfo:
assert metainfo['excluded_patterns'] == value
-def test_history_progress(qtbot):
- progress = history.HistoryProgress()
- progress.start("Hello World")
- dialog = progress._progress
- qtbot.add_widget(dialog)
- progress.tick()
-
- assert dialog.isVisible()
- assert dialog.labelText() == "Hello World"
- assert dialog.minimum() == 0
- assert dialog.value() == 1
- assert dialog.minimumDuration() == 0
-
- assert dialog.maximum() == 0
- progress.set_maximum(42)
- assert dialog.maximum() == 42
-
- progress.finish()
- assert not dialog.isVisible()
+class TestHistoryProgress:
+
+ @pytest.fixture
+ def progress(self):
+ return history.HistoryProgress()
+
+ def test_no_start(self, progress):
+ """Test calling tick/finish without start."""
+ progress.tick()
+ assert progress._value == 1
+ progress.finish()
+ assert progress._progress is None
+ assert progress._value == 0
+
+ def test_gui(self, qtbot, progress):
+ progress.start("Hello World")
+ dialog = progress._progress
+ qtbot.add_widget(dialog)
+ progress.tick()
+
+ assert dialog.isVisible()
+ assert dialog.labelText() == "Hello World"
+ assert dialog.minimum() == 0
+ assert dialog.value() == 1
+ assert dialog.minimumDuration() == 0
+
+ assert dialog.maximum() == 0
+ progress.set_maximum(42)
+ assert dialog.maximum() == 42
+
+ progress.finish()
+ assert not dialog.isVisible()