From 74be2fa4b98526e360662d5583ea517895b31000 Mon Sep 17 00:00:00 2001 From: pkill9 Date: Sun, 5 Mar 2017 07:26:13 +0000 Subject: [PATCH 1/2] Add command to close all messages. --- qutebrowser/mainwindow/mainwindow.py | 2 ++ qutebrowser/mainwindow/messageview.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 732b7a688..8038663e1 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -185,6 +185,8 @@ class MainWindow(QWidget): self._keyhint = keyhintwidget.KeyHintView(self.win_id, self) self._add_overlay(self._keyhint, self._keyhint.update_geometry) self._messageview = messageview.MessageView(parent=self) + objreg.register('messageview', self._messageview, + scope='window', window=self.win_id) self._add_overlay(self._messageview, self._messageview.update_geometry) self._prompt_container = prompt.PromptContainer(self.win_id, self) diff --git a/qutebrowser/mainwindow/messageview.py b/qutebrowser/mainwindow/messageview.py index 86178716f..dfcdaa540 100644 --- a/qutebrowser/mainwindow/messageview.py +++ b/qutebrowser/mainwindow/messageview.py @@ -25,6 +25,7 @@ from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QSizePolicy from qutebrowser.config import config, style from qutebrowser.utils import usertypes, objreg +from qutebrowser.commands import cmdutils class Message(QLabel): @@ -82,7 +83,7 @@ class MessageView(QWidget): self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self._clear_timer = QTimer() - self._clear_timer.timeout.connect(self._clear_messages) + self._clear_timer.timeout.connect(self.clear_messages) self._set_clear_timer_interval() objreg.get('config').changed.connect(self._set_clear_timer_interval) @@ -101,7 +102,8 @@ class MessageView(QWidget): self._clear_timer.setInterval(config.get('ui', 'message-timeout')) @pyqtSlot() - def _clear_messages(self): + @cmdutils.register(instance='messageview', scope="window", hide=True) + def clear_messages(self): """Hide and delete all messages.""" for widget in self._messages: self._vbox.removeWidget(widget) From d3b16bbd075f9e8c8656a402975d776088c2dab8 Mon Sep 17 00:00:00 2001 From: pkill9 Date: Tue, 7 Mar 2017 16:40:05 +0000 Subject: [PATCH 2/2] Add command to clear messages - cleaner --- qutebrowser/mainwindow/mainwindow.py | 4 ++-- qutebrowser/mainwindow/messageview.py | 2 -- qutebrowser/misc/utilcmds.py | 6 ++++++ qutebrowser/utils/message.py | 1 + 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 8038663e1..9858abf7d 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -185,8 +185,6 @@ class MainWindow(QWidget): self._keyhint = keyhintwidget.KeyHintView(self.win_id, self) self._add_overlay(self._keyhint, self._keyhint.update_geometry) self._messageview = messageview.MessageView(parent=self) - objreg.register('messageview', self._messageview, - scope='window', window=self.win_id) self._add_overlay(self._messageview, self._messageview.update_geometry) self._prompt_container = prompt.PromptContainer(self.win_id, self) @@ -440,6 +438,8 @@ class MainWindow(QWidget): message.global_bridge.show_message.connect( self._messageview.show_message) message.global_bridge.flush() + message.global_bridge.clear_messages.connect( + self._messageview.clear_messages) message_bridge.s_set_text.connect(status.set_text) message_bridge.s_maybe_reset_text.connect(status.txt.maybe_reset_text) diff --git a/qutebrowser/mainwindow/messageview.py b/qutebrowser/mainwindow/messageview.py index dfcdaa540..6565a2a44 100644 --- a/qutebrowser/mainwindow/messageview.py +++ b/qutebrowser/mainwindow/messageview.py @@ -25,7 +25,6 @@ from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QSizePolicy from qutebrowser.config import config, style from qutebrowser.utils import usertypes, objreg -from qutebrowser.commands import cmdutils class Message(QLabel): @@ -102,7 +101,6 @@ class MessageView(QWidget): self._clear_timer.setInterval(config.get('ui', 'message-timeout')) @pyqtSlot() - @cmdutils.register(instance='messageview', scope="window", hide=True) def clear_messages(self): """Hide and delete all messages.""" for widget in self._messages: diff --git a/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py index 893e11342..e617c1af2 100644 --- a/qutebrowser/misc/utilcmds.py +++ b/qutebrowser/misc/utilcmds.py @@ -137,6 +137,12 @@ def message_warning(text): message.warning(text) +@cmdutils.register(hide=True) +def clear_messages(): + """Clear all message notifications.""" + message.global_bridge.clear_messages.emit() + + @cmdutils.register(debug=True) @cmdutils.argument('typ', choices=['exception', 'segfault']) def debug_crash(typ='exception'): diff --git a/qutebrowser/utils/message.py b/qutebrowser/utils/message.py index b39e2ab49..bb758d78a 100644 --- a/qutebrowser/utils/message.py +++ b/qutebrowser/utils/message.py @@ -194,6 +194,7 @@ class GlobalMessageBridge(QObject): prompt_done = pyqtSignal(usertypes.KeyMode) ask_question = pyqtSignal(usertypes.Question, bool) mode_left = pyqtSignal(usertypes.KeyMode) + clear_messages = pyqtSignal() def __init__(self, parent=None): super().__init__(parent)