summaryrefslogtreecommitdiff
path: root/qutebrowser/mainwindow
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2021-03-20 16:38:25 +0100
committerFlorian Bruhin <me@the-compiler.org>2021-03-23 12:39:25 +0100
commit7f693f75a0e0812b7c788ec257608ed324cb3cc2 (patch)
tree5fa7d2dd7c23969c1d5528059c0ba704c9a192a8 /qutebrowser/mainwindow
parent045dda0f2795b7d7cfb69f30bfbab7dceaeb9eb9 (diff)
downloadqutebrowser-7f693f75a0e0812b7c788ec257608ed324cb3cc2.tar.gz
qutebrowser-7f693f75a0e0812b7c788ec257608ed324cb3cc2.zip
More sophisticated replacing for messages
Every message now takes a replace='...' ID, similar to what "dunstify --replace" does. This allows messages to be replaced even if another message was shown in the meantime (or with process live output, if another process was spawned).
Diffstat (limited to 'qutebrowser/mainwindow')
-rw-r--r--qutebrowser/mainwindow/messageview.py30
1 files changed, 24 insertions, 6 deletions
diff --git a/qutebrowser/mainwindow/messageview.py b/qutebrowser/mainwindow/messageview.py
index dedc311ee..58fcb3683 100644
--- a/qutebrowser/mainwindow/messageview.py
+++ b/qutebrowser/mainwindow/messageview.py
@@ -19,7 +19,7 @@
"""Showing messages above the statusbar."""
-from typing import MutableSequence
+from typing import MutableSequence, Optional
from PyQt5.QtCore import pyqtSlot, pyqtSignal, QTimer, Qt
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QSizePolicy
@@ -32,9 +32,16 @@ class Message(QLabel):
"""A single error/warning/info message."""
- def __init__(self, level, text, replace, parent=None):
+ def __init__(
+ self,
+ level: usertypes.MessageLevel,
+ text: str,
+ replace: Optional[str],
+ parent: QWidget = None,
+ ) -> None:
super().__init__(text, parent)
self.replace = replace
+ self.level = level
self.setAttribute(Qt.WA_StyledBackground, True)
self.setWordWrap(True)
qss = """
@@ -112,14 +119,25 @@ class MessageView(QWidget):
self.hide()
self._clear_timer.stop()
- @pyqtSlot(usertypes.MessageLevel, str, bool)
- def show_message(self, level, text, replace=False):
+ @pyqtSlot(usertypes.MessageLevel, str, str)
+ def show_message(
+ self,
+ level: usertypes.MessageLevel,
+ text: str,
+ replace: str = None,
+ ) -> None:
"""Show the given message with the given MessageLevel."""
if text == self._last_text:
return
- if replace and self._messages and self._messages[-1].replace:
- self._remove_message(self._messages.pop())
+ if replace: # None -> QString() -> ''
+ existing = [msg for msg in self._messages if msg.replace == replace]
+ if existing:
+ assert len(existing) == 1, existing
+ assert existing[0].level == level, (existing, level)
+ existing[0].setText(text)
+ self.update_geometry.emit()
+ return
widget = Message(level, text, replace=replace, parent=self)
self._vbox.addWidget(widget)