From 299c66b82cd0bd237961bfd38c7f2a35b0e39be5 Mon Sep 17 00:00:00 2001 From: Noah Huesser Date: Mon, 23 May 2016 11:32:27 +0200 Subject: [PATCH 1/4] Possibly fixed issue: #1484 --- qutebrowser/app.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 459c2f76b..96fed4b5b 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -343,18 +343,14 @@ 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 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() From ea1d8902d5666f7b718cd5677e2b99dcd7cc282c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 24 May 2016 21:35:48 +0200 Subject: [PATCH 2/4] Add logging for #1484 --- qutebrowser/app.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index b7fbdfc0d..d422e1208 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -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,6 +343,10 @@ def _save_version(): @pyqtSlot('QWidget*', 'QWidget*') def on_focus_changed(_old, new): """Register currently focused main window in the object registry.""" + 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') From 846fe8b9439a8f5f69278bc5f4c97633da846d27 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 24 May 2016 21:36:09 +0200 Subject: [PATCH 3/4] Add a test for #1484 --- tests/unit/test_app.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/unit/test_app.py diff --git a/tests/unit/test_app.py b/tests/unit/test_app.py new file mode 100644 index 000000000..7f40cb891 --- /dev/null +++ b/tests/unit/test_app.py @@ -0,0 +1,40 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2016 Florian Bruhin (The Compiler) +# +# 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 . + +"""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 From 9ef12a0af8cbb36ef6251f22eeedad628f29d7d4 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 24 May 2016 21:36:47 +0200 Subject: [PATCH 4/4] Regenerate authors --- README.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/README.asciidoc b/README.asciidoc index f8fe1b31b..739cd9f4e 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -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