Merge commit '13677d3563dbd01ae188a2b1a79c7dd840a5dc5e' into pkill-nine/upstream-master-close_message_on_click

This commit is contained in:
Florian Bruhin 2017-03-26 14:59:08 +02:00
commit 2181e1ddc4
2 changed files with 30 additions and 0 deletions

View File

@ -130,3 +130,10 @@ class MessageView(QWidget):
self._last_text = text
self.show()
self.update_geometry.emit()
def mousePressEvent(self, e):
"""Clear messages when they are clicked on."""
criteria = [Qt.LeftButton, Qt.MiddleButton, Qt.RightButton]
if e.button() in criteria:
self.clear_messages()

View File

@ -19,6 +19,9 @@
import pytest
from PyQt5.QtTest import QTest
from PyQt5.QtCore import Qt
from qutebrowser.mainwindow import messageview
from qutebrowser.utils import usertypes
@ -114,3 +117,23 @@ def test_replaced_messages(view, replace1, replace2, length):
view.show_message(usertypes.MessageLevel.info, 'test', replace=replace1)
view.show_message(usertypes.MessageLevel.info, 'test 2', replace=replace2)
assert len(view._messages) == length
def test_click_messages(qtbot, view):
"""Messages should dissappear when we click on them."""
view.show_message(usertypes.MessageLevel.info, 'test mouse left click')
QTest.mousePress(view, Qt.LeftButton)
assert not view._messages
view.show_message(usertypes.MessageLevel.info, 'test mouse middle click')
QTest.mousePress(view, Qt.MiddleButton)
assert not view._messages
view.show_message(usertypes.MessageLevel.info, 'test mouse right click')
QTest.mousePress(view, Qt.RightButton)
assert not view._messages
# Test mouse back button - This shouldn't clear messages.
view.show_message(usertypes.MessageLevel.info, 'test mouse back button')
QTest.mousePress(view, Qt.BackButton)
assert len(view._messages) == 1