From 99017c50ac52a9ed2946ffee888ac2235f835bbd Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 8 Jan 2021 10:47:02 +0100 Subject: Trivial PyQt 6 changes See #5395 --- qutebrowser/app.py | 2 +- qutebrowser/browser/browsertab.py | 2 +- qutebrowser/browser/network/pac.py | 2 +- qutebrowser/browser/webkit/webview.py | 2 +- qutebrowser/components/misccommands.py | 2 +- qutebrowser/config/configinit.py | 2 +- qutebrowser/mainwindow/prompt.py | 6 +++--- qutebrowser/misc/backendproblem.py | 6 +++--- qutebrowser/misc/crashsignal.py | 2 +- qutebrowser/misc/earlyinit.py | 2 +- qutebrowser/misc/msgbox.py | 2 +- qutebrowser/misc/sql.py | 2 +- qutebrowser/utils/error.py | 2 +- qutebrowser/utils/qtutils.py | 6 +++--- scripts/dev/misc_checks.py | 16 ++++++++++++++++ scripts/keytester.py | 2 +- scripts/testbrowser/testbrowser_webengine.py | 2 +- scripts/testbrowser/testbrowser_webkit.py | 2 +- tests/unit/misc/test_msgbox.py | 2 +- tests/unit/utils/test_qtutils.py | 6 +++--- 20 files changed, 43 insertions(+), 27 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index d2e9468aa..32dbfe0cf 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -136,7 +136,7 @@ def qt_mainloop(): WARNING: misc/crashdialog.py checks the stacktrace for this function name, so if this is changed, it should be changed there as well! """ - return q_app.exec_() + return q_app.exec() def init(*, args: argparse.Namespace) -> None: diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 42ad89e7c..dda7c7720 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -259,7 +259,7 @@ class AbstractPrinting: diag = QPrintDialog(self._tab) if utils.is_mac: # For some reason we get a segfault when using open() on macOS - ret = diag.exec_() + ret = diag.exec() if ret == QDialog.Accepted: do_print() else: diff --git a/qutebrowser/browser/network/pac.py b/qutebrowser/browser/network/pac.py index 3b5686a03..891c5687b 100644 --- a/qutebrowser/browser/network/pac.py +++ b/qutebrowser/browser/network/pac.py @@ -301,7 +301,7 @@ class PACFetcher(QObject): if self._manager is not None: loop = qtutils.EventLoop() self.finished.connect(loop.quit) - loop.exec_() + loop.exec() def fetch_error(self): """Check if PAC script is successfully fetched. diff --git a/qutebrowser/browser/webkit/webview.py b/qutebrowser/browser/webkit/webview.py index 428e66744..f2c610d32 100644 --- a/qutebrowser/browser/webkit/webview.py +++ b/qutebrowser/browser/webkit/webview.py @@ -179,7 +179,7 @@ class WebView(QWebView): self.shutting_down.connect(menu.close) mm = modeman.instance(self.win_id) mm.entered.connect(menu.close) - menu.exec_(e.globalPos()) + menu.exec(e.globalPos()) def showEvent(self, e): """Extend showEvent to set the page visibility state to visible. diff --git a/qutebrowser/components/misccommands.py b/qutebrowser/components/misccommands.py index f553fce3b..85598f56a 100644 --- a/qutebrowser/components/misccommands.py +++ b/qutebrowser/components/misccommands.py @@ -80,7 +80,7 @@ def _print_preview(tab: apitypes.Tab) -> None: Qt.WindowMinimizeButtonHint) diag.paintRequested.connect(functools.partial( tab.printing.to_printer, callback=print_callback)) - diag.exec_() + diag.exec() def _print_pdf(tab: apitypes.Tab, filename: str) -> None: diff --git a/qutebrowser/config/configinit.py b/qutebrowser/config/configinit.py index 2951b5292..f0feb8af1 100644 --- a/qutebrowser/config/configinit.py +++ b/qutebrowser/config/configinit.py @@ -130,7 +130,7 @@ def late_init(save_manager: savemanager.SaveManager) -> None: text=_init_errors.to_html(), icon=QMessageBox.Warning, plain_text=False) - errbox.exec_() + errbox.exec() if _init_errors.fatal: sys.exit(usertypes.Exit.err_init) diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index 42b6c3d97..85363a3fc 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -194,11 +194,11 @@ class PromptQueue(QObject): loop.destroyed.connect(lambda: self._loops.remove(loop)) question.completed.connect(loop.quit) question.completed.connect(loop.deleteLater) - log.prompt.debug("Starting loop.exec_() for {}".format(question)) + log.prompt.debug("Starting loop.exec() for {}".format(question)) flags = cast(QEventLoop.ProcessEventsFlags, QEventLoop.ExcludeSocketNotifiers) - loop.exec_(flags) - log.prompt.debug("Ending loop.exec_() for {}".format(question)) + loop.exec(flags) + log.prompt.debug("Ending loop.exec() for {}".format(question)) log.prompt.debug("Restoring old question {}".format(old_question)) self._question = old_question diff --git a/qutebrowser/misc/backendproblem.py b/qutebrowser/misc/backendproblem.py index e459d81c1..aaa0e89fc 100644 --- a/qutebrowser/misc/backendproblem.py +++ b/qutebrowser/misc/backendproblem.py @@ -180,7 +180,7 @@ class _BackendProblemChecker: dialog = _Dialog(*args, **kwargs) - status = dialog.exec_() + status = dialog.exec() self._save_manager.save_all(is_exit=True) if status in [_Result.quit, QDialog.Rejected]: @@ -338,7 +338,7 @@ class _BackendProblemChecker: text="Could not initialize SSL support.", icon=QMessageBox.Critical, plain_text=False) - errbox.exec_() + errbox.exec() sys.exit(usertypes.Exit.err_init) assert not fatal @@ -364,7 +364,7 @@ class _BackendProblemChecker: text=text, icon=QMessageBox.Critical, plain_text=False) - errbox.exec_() + errbox.exec() sys.exit(usertypes.Exit.err_init) elif objects.backend == usertypes.Backend.QtWebKit: if imports.webkit_available: diff --git a/qutebrowser/misc/crashsignal.py b/qutebrowser/misc/crashsignal.py index d07d8e49c..1eaa608ba 100644 --- a/qutebrowser/misc/crashsignal.py +++ b/qutebrowser/misc/crashsignal.py @@ -295,7 +295,7 @@ class CrashHandler(QObject): self._crash_dialog = crashdialog.ExceptionCrashDialog( self._args.debug, info.pages, info.cmd_history, exc, info.objects) - ret = self._crash_dialog.exec_() + ret = self._crash_dialog.exec() if ret == crashdialog.Result.restore: self._quitter.restart(info.pages) diff --git a/qutebrowser/misc/earlyinit.py b/qutebrowser/misc/earlyinit.py index d742a6706..8027ad69a 100644 --- a/qutebrowser/misc/earlyinit.py +++ b/qutebrowser/misc/earlyinit.py @@ -95,7 +95,7 @@ def _die(message, exception=None): message) msgbox.setTextFormat(Qt.RichText) msgbox.resize(msgbox.sizeHint()) - msgbox.exec_() + msgbox.exec() app.quit() sys.exit(1) diff --git a/qutebrowser/misc/msgbox.py b/qutebrowser/misc/msgbox.py index f06eccd92..bf126da13 100644 --- a/qutebrowser/misc/msgbox.py +++ b/qutebrowser/misc/msgbox.py @@ -31,7 +31,7 @@ class DummyBox: """A dummy QMessageBox returned when --no-err-windows is used.""" - def exec_(self): + def exec(self): pass diff --git a/qutebrowser/misc/sql.py b/qutebrowser/misc/sql.py index 50ae0a251..8863ff25d 100644 --- a/qutebrowser/misc/sql.py +++ b/qutebrowser/misc/sql.py @@ -211,7 +211,7 @@ class Query: self._bind_values(values) log.sql.debug('query bindings: {}'.format(self.bound_values())) - ok = self.query.exec_() + ok = self.query.exec() self._check_ok('exec', ok) return self diff --git a/qutebrowser/utils/error.py b/qutebrowser/utils/error.py index 4cba06a10..a49798021 100644 --- a/qutebrowser/utils/error.py +++ b/qutebrowser/utils/error.py @@ -71,4 +71,4 @@ def handle_fatal_exc(exc: BaseException, if post_text: msg_text += '\n\n{}'.format(post_text) msgbox = QMessageBox(QMessageBox.Critical, title, msg_text) - msgbox.exec_() + msgbox.exec() diff --git a/qutebrowser/utils/qtutils.py b/qutebrowser/utils/qtutils.py index cd6ea2b32..6be2ff1bb 100644 --- a/qutebrowser/utils/qtutils.py +++ b/qutebrowser/utils/qtutils.py @@ -450,14 +450,14 @@ class EventLoop(QEventLoop): """A thin wrapper around QEventLoop. - Raises an exception when doing exec_() multiple times. + Raises an exception when doing exec() multiple times. """ def __init__(self, parent: QObject = None) -> None: super().__init__(parent) self._executing = False - def exec_( + def exec( self, flags: QEventLoop.ProcessEventsFlags = cast(QEventLoop.ProcessEventsFlags, QEventLoop.AllEvents) @@ -466,7 +466,7 @@ class EventLoop(QEventLoop): if self._executing: raise AssertionError("Eventloop is already running!") self._executing = True - status = super().exec_(flags) + status = super().exec(flags) self._executing = False return status diff --git a/scripts/dev/misc_checks.py b/scripts/dev/misc_checks.py index 4b5699086..5c654235c 100644 --- a/scripts/dev/misc_checks.py +++ b/scripts/dev/misc_checks.py @@ -198,6 +198,22 @@ def check_spelling(args: argparse.Namespace) -> Optional[bool]: "Don't use monkeypatch.setattr('obj.attr', value), use " "setattr(obj, 'attr', value) instead.", ), + ( + re.compile(r'(exec|print)_\('), + ".exec_()/.print_() are removed in PyQt 6, use .exec()/.print() instead.", + ), + ( + re.compile(r'qApp'), + "qApp is removed in PyQt 6, use QApplication.instance() instead.", + ), + ( + re.compile(r'PYQT_CONFIGURATION'), + "PYQT_CONFIGURATION is removed in PyQt 6", + ), + ( + re.compile(r'Q_(ENUM|FLAG)'), + "Q_ENUM and Q_FLAG are removed in PyQt 6", + ), ] # Files which should be ignored, e.g. because they come from another diff --git a/scripts/keytester.py b/scripts/keytester.py index 027dcbc59..7aa1fbe49 100644 --- a/scripts/keytester.py +++ b/scripts/keytester.py @@ -30,4 +30,4 @@ from qutebrowser.misc import miscwidgets app = QApplication([]) w = miscwidgets.KeyTesterWidget() w.show() -app.exec_() +app.exec() diff --git a/scripts/testbrowser/testbrowser_webengine.py b/scripts/testbrowser/testbrowser_webengine.py index 0a8dd0ac3..bfad90055 100755 --- a/scripts/testbrowser/testbrowser_webengine.py +++ b/scripts/testbrowser/testbrowser_webengine.py @@ -48,4 +48,4 @@ if __name__ == '__main__': wv.load(QUrl.fromUserInput(args.url)) wv.show() - app.exec_() + app.exec() diff --git a/scripts/testbrowser/testbrowser_webkit.py b/scripts/testbrowser/testbrowser_webkit.py index 39e2b991d..44112921a 100755 --- a/scripts/testbrowser/testbrowser_webkit.py +++ b/scripts/testbrowser/testbrowser_webkit.py @@ -53,4 +53,4 @@ if __name__ == '__main__': wv.load(QUrl.fromUserInput(args.url)) wv.show() - app.exec_() + app.exec() diff --git a/tests/unit/misc/test_msgbox.py b/tests/unit/misc/test_msgbox.py index 74422ea45..e2ea48fff 100644 --- a/tests/unit/misc/test_msgbox.py +++ b/tests/unit/misc/test_msgbox.py @@ -95,7 +95,7 @@ def test_information(qtbot): def test_no_err_windows(fake_args, capsys): fake_args.no_err_windows = True box = msgbox.information(parent=None, title='foo', text='bar') - box.exec_() # should do nothing + box.exec() # should do nothing out, err = capsys.readouterr() assert not out assert err == 'Message box: foo; bar\n' diff --git a/tests/unit/utils/test_qtutils.py b/tests/unit/utils/test_qtutils.py index 2e54fb42e..816cd8621 100644 --- a/tests/unit/utils/test_qtutils.py +++ b/tests/unit/utils/test_qtutils.py @@ -920,14 +920,14 @@ class TestEventLoop: def _double_exec(self): """Slot which gets called from timers to assert double-exec fails.""" with pytest.raises(AssertionError): - self.loop.exec_() + self.loop.exec() def test_normal_exec(self): """Test exec_ without double-executing.""" self.loop = qtutils.EventLoop() QTimer.singleShot(100, self._assert_executing) QTimer.singleShot(200, self.loop.quit) - self.loop.exec_() + self.loop.exec() assert not self.loop._executing def test_double_exec(self): @@ -937,7 +937,7 @@ class TestEventLoop: QTimer.singleShot(200, self._double_exec) QTimer.singleShot(300, self._assert_executing) QTimer.singleShot(400, self.loop.quit) - self.loop.exec_() + self.loop.exec() assert not self.loop._executing -- cgit v1.2.3-54-g00ecf