From 3c1b05c81e8ce00ed647001f7623c79f2612b770 Mon Sep 17 00:00:00 2001 From: Yashar Shahi Date: Mon, 10 Jul 2017 18:05:35 +0430 Subject: [PATCH 1/9] Show messages longer if there are multiple of them --- qutebrowser/mainwindow/messageview.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qutebrowser/mainwindow/messageview.py b/qutebrowser/mainwindow/messageview.py index 7d0d2b682..382853d11 100644 --- a/qutebrowser/mainwindow/messageview.py +++ b/qutebrowser/mainwindow/messageview.py @@ -100,6 +100,10 @@ class MessageView(QWidget): """Configure self._clear_timer according to the config.""" interval = config.get('ui', 'message-timeout') if interval != 0: + multimpy_by = len(self._messages) + 1 + if multimpy_by > 5: + multimpy_by = 5 + interval *= multimpy_by self._clear_timer.setInterval(interval) @pyqtSlot() @@ -128,6 +132,7 @@ class MessageView(QWidget): self._vbox.addWidget(widget) widget.show() if config.get('ui', 'message-timeout') != 0: + self._set_clear_timer_interval() self._clear_timer.start() self._messages.append(widget) self._last_text = text From 03c70f0421c728cd6be3c639d92d4d8161bd00d6 Mon Sep 17 00:00:00 2001 From: Yashar Shahi Date: Mon, 10 Jul 2017 18:58:45 +0430 Subject: [PATCH 2/9] An empty file to trigger travis. --- trigger_travis | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 trigger_travis diff --git a/trigger_travis b/trigger_travis new file mode 100644 index 000000000..e69de29bb From c015e9cc5df6e8eb11efa44c733e4b5be93f5081 Mon Sep 17 00:00:00 2001 From: Yashar Shahi Date: Mon, 10 Jul 2017 19:20:32 +0430 Subject: [PATCH 3/9] Revert "An empty file to trigger travis." This reverts commit 03c70f0421c728cd6be3c639d92d4d8161bd00d6. --- trigger_travis | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 trigger_travis diff --git a/trigger_travis b/trigger_travis deleted file mode 100644 index e69de29bb..000000000 From cb0bd2c52d93512e81cb41199bea1394833c7729 Mon Sep 17 00:00:00 2001 From: Yashar Shahi Date: Mon, 10 Jul 2017 19:21:35 +0430 Subject: [PATCH 4/9] Do not call _set_timer_interval() at constructor No need to call _set_timer_interval() at constructor since it's called every time timer is going to be started. --- qutebrowser/mainwindow/messageview.py | 1 - 1 file changed, 1 deletion(-) diff --git a/qutebrowser/mainwindow/messageview.py b/qutebrowser/mainwindow/messageview.py index 382853d11..04da214f7 100644 --- a/qutebrowser/mainwindow/messageview.py +++ b/qutebrowser/mainwindow/messageview.py @@ -83,7 +83,6 @@ class MessageView(QWidget): self._clear_timer = QTimer() self._clear_timer.timeout.connect(self.clear_messages) - self._set_clear_timer_interval() objreg.get('config').changed.connect(self._set_clear_timer_interval) self._last_text = None From a631c971d98784b2cbd61c5b73900802ddfec54e Mon Sep 17 00:00:00 2001 From: Yashar Shahi Date: Mon, 10 Jul 2017 20:52:42 +0430 Subject: [PATCH 5/9] Add tests for show messages longer Add tests for "Show messages longer if there are multiple of them." --- tests/unit/mainwindow/test_messageview.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/unit/mainwindow/test_messageview.py b/tests/unit/mainwindow/test_messageview.py index ebecc9398..7790d343e 100644 --- a/tests/unit/mainwindow/test_messageview.py +++ b/tests/unit/mainwindow/test_messageview.py @@ -104,6 +104,14 @@ def test_changing_timer_with_messages_shown(qtbot, view, config_stub): config_stub.set('ui', 'message-timeout', 100) +@pytest.mark.parametrize('count', [1, 2, 3, 4, 5, 6, 7]) +def test_show_messages_longer_when_there_are_multiple_of_them(view, config_stub, count): + """When there are multiple messages, messages should be shown longer than usual. but with an upper maximum of 5""" + for message_number in range(1, count+1): + view.show_message(usertypes.MessageLevel.info, 'test ' + str(message_number)) + assert view._clear_timer.interval() == min(5, count) * config_stub['ui']['message-timeout'] + + @pytest.mark.parametrize('replace1, replace2, length', [ (False, False, 2), # Two stacked messages (True, True, 1), # Two replaceable messages From 1cb23f1193e1664bb0e2de6e266f20d48b9de148 Mon Sep 17 00:00:00 2001 From: Yashar Shahi Date: Mon, 10 Jul 2017 21:11:38 +0430 Subject: [PATCH 6/9] Change timer interval after appending to _messages --- qutebrowser/mainwindow/messageview.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/qutebrowser/mainwindow/messageview.py b/qutebrowser/mainwindow/messageview.py index 04da214f7..36c778d12 100644 --- a/qutebrowser/mainwindow/messageview.py +++ b/qutebrowser/mainwindow/messageview.py @@ -99,10 +99,7 @@ class MessageView(QWidget): """Configure self._clear_timer according to the config.""" interval = config.get('ui', 'message-timeout') if interval != 0: - multimpy_by = len(self._messages) + 1 - if multimpy_by > 5: - multimpy_by = 5 - interval *= multimpy_by + interval *= min(5, len(self._messages)) self._clear_timer.setInterval(interval) @pyqtSlot() @@ -130,13 +127,13 @@ class MessageView(QWidget): widget = Message(level, text, replace=replace, parent=self) self._vbox.addWidget(widget) widget.show() - if config.get('ui', 'message-timeout') != 0: - self._set_clear_timer_interval() - self._clear_timer.start() self._messages.append(widget) self._last_text = text self.show() self.update_geometry.emit() + if config.get('ui', 'message-timeout') != 0: + self._set_clear_timer_interval() + self._clear_timer.start() def mousePressEvent(self, e): """Clear messages when they are clicked on.""" From 7da690885070fcc3708319ce52a07e6a194061fe Mon Sep 17 00:00:00 2001 From: Yashar Shahi Date: Mon, 10 Jul 2017 21:14:55 +0430 Subject: [PATCH 7/9] Check for interval being positive. Check for interval being positive instead of checking for it to be non-zero. So if somehow some unexpected thing happend and made message-timeout negative, the bug doesn't cascade. --- qutebrowser/mainwindow/messageview.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/mainwindow/messageview.py b/qutebrowser/mainwindow/messageview.py index 36c778d12..657835dba 100644 --- a/qutebrowser/mainwindow/messageview.py +++ b/qutebrowser/mainwindow/messageview.py @@ -98,7 +98,7 @@ class MessageView(QWidget): def _set_clear_timer_interval(self): """Configure self._clear_timer according to the config.""" interval = config.get('ui', 'message-timeout') - if interval != 0: + if interval > 0: interval *= min(5, len(self._messages)) self._clear_timer.setInterval(interval) From 1e58c87380b3140240fd207d0742d63f57698238 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 11 Jul 2017 09:25:53 +0200 Subject: [PATCH 8/9] Improve test for messageview timeout --- tests/unit/mainwindow/test_messageview.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/unit/mainwindow/test_messageview.py b/tests/unit/mainwindow/test_messageview.py index 7790d343e..782e38ae5 100644 --- a/tests/unit/mainwindow/test_messageview.py +++ b/tests/unit/mainwindow/test_messageview.py @@ -104,12 +104,17 @@ def test_changing_timer_with_messages_shown(qtbot, view, config_stub): config_stub.set('ui', 'message-timeout', 100) -@pytest.mark.parametrize('count', [1, 2, 3, 4, 5, 6, 7]) -def test_show_messages_longer_when_there_are_multiple_of_them(view, config_stub, count): - """When there are multiple messages, messages should be shown longer than usual. but with an upper maximum of 5""" +@pytest.mark.parametrize('count, expected', [(1, 100), (3, 300), + (5, 500), (7, 500)]) +def test_show_multiple_messages_longer(view, count, expected): + """When there are multiple messages, messages should be shown longer. + + There is an upper maximum to avoid messages never disappearing. + """ for message_number in range(1, count+1): - view.show_message(usertypes.MessageLevel.info, 'test ' + str(message_number)) - assert view._clear_timer.interval() == min(5, count) * config_stub['ui']['message-timeout'] + view.show_message(usertypes.MessageLevel.info, + 'test ' + str(message_number)) + assert view._clear_timer.interval() == expected @pytest.mark.parametrize('replace1, replace2, length', [ From 6f930be08e763b72b002ed8e53cff1e583238929 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 11 Jul 2017 09:26:36 +0200 Subject: [PATCH 9/9] Update docs --- CHANGELOG.asciidoc | 1 + README.asciidoc | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 6471d0b9f..6dd448d67 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -47,6 +47,7 @@ Changed - Upgrading qutebrowser with a version older than v0.4.0 still running now won't work properly anymore. - Using `:download` now uses the page's title as filename. +- When there are multiple messages shown, the timeout is increased. Fixes ~~~~~ diff --git a/README.asciidoc b/README.asciidoc index 65a04a200..b2cc291f5 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -192,6 +192,7 @@ Contributors, sorted by the number of commits in descending order: * Peter Vilim * Jacob Sword * knaggita +* Yashar Shahi * Oliver Caldwell * Nikolay Amiantov * Marius