Merge branch 'Yatekii-master'

This commit is contained in:
Florian Bruhin 2016-05-24 21:37:02 +02:00
commit f692d34d94
3 changed files with 48 additions and 7 deletions

View File

@ -213,6 +213,7 @@ Contributors, sorted by the number of commits in descending order:
* Thiago Barroso Perrotta
* Sorokin Alexei
* Samuel Loury
* Noah Huesser
* Matthias Lisin
* Marcel Schilling
* Johannes Martinsson

View File

@ -31,7 +31,7 @@ import atexit
import datetime
import tokenize
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtGui import QDesktopServices, QPixmap, QIcon, QCursor, QWindow
from PyQt5.QtCore import (pyqtSlot, qInstallMessageHandler, QTimer, QUrl,
@ -343,18 +343,18 @@ def _save_version():
@pyqtSlot('QWidget*', 'QWidget*')
def on_focus_changed(_old, new):
"""Register currently focused main window in the object registry."""
if new is None:
window = None
else:
window = new.window()
if window is None or not isinstance(window, mainwindow.MainWindow):
if not isinstance(new, QWidget):
log.misc.debug("on_focus_changed called with non-QWidget {!r}".format(
new))
if new is None or not isinstance(new, mainwindow.MainWindow):
try:
objreg.delete('last-focused-main-window')
except KeyError:
pass
qApp.restoreOverrideCursor()
else:
objreg.register('last-focused-main-window', window, update=True)
objreg.register('last-focused-main-window', new.window(), update=True)
_maybe_hide_mouse_cursor()

40
tests/unit/test_app.py Normal file
View File

@ -0,0 +1,40 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""Tests for the qutebrowser.app module."""
from PyQt5.QtCore import QBuffer
from qutebrowser import app
def test_on_focus_changed_issue1484(monkeypatch, qapp, caplog):
"""Check what happens when on_focus_changed is called with wrong args.
For some reason, Qt sometimes calls on_focus_changed() with a QBuffer as
argument. Let's make sure we handle that gracefully.
"""
monkeypatch.setattr(app, 'qApp', qapp)
buf = QBuffer()
app.on_focus_changed(buf, buf)
assert len(caplog.records) == 1
record = caplog.records[0]
expected = "on_focus_changed called with non-QWidget {!r}".format(buf)
assert record.message == expected