Trivial PyQt 6 changes

See #5395
This commit is contained in:
Florian Bruhin 2021-01-08 10:47:02 +01:00
parent c628e1430c
commit 99017c50ac
20 changed files with 43 additions and 27 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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.

View File

@ -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.

View File

@ -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:

View File

@ -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)

View File

@ -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

View File

@ -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:

View File

@ -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)

View File

@ -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)

View File

@ -31,7 +31,7 @@ class DummyBox:
"""A dummy QMessageBox returned when --no-err-windows is used."""
def exec_(self):
def exec(self):
pass

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -30,4 +30,4 @@ from qutebrowser.misc import miscwidgets
app = QApplication([])
w = miscwidgets.KeyTesterWidget()
w.show()
app.exec_()
app.exec()

View File

@ -48,4 +48,4 @@ if __name__ == '__main__':
wv.load(QUrl.fromUserInput(args.url))
wv.show()
app.exec_()
app.exec()

View File

@ -53,4 +53,4 @@ if __name__ == '__main__':
wv.load(QUrl.fromUserInput(args.url))
wv.show()
app.exec_()
app.exec()

View File

@ -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'

View File

@ -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