|
78 | 78 | from PyQt5.QtCore import pyqtSlot as Slot |
79 | 79 |
|
80 | 80 | QApplication = QtWidgets.QApplication |
| 81 | + AllEvents = QtCore.QEventLoop.ProcessEventsFlags(0x00) |
81 | 82 |
|
82 | 83 | elif QtModuleName == "PyQt6": |
83 | 84 | from PyQt6 import QtWidgets |
84 | 85 | from PyQt6.QtCore import pyqtSlot as Slot |
85 | 86 |
|
86 | 87 | QApplication = QtWidgets.QApplication |
| 88 | + AllEvents = QtCore.QEventLoop.ProcessEventsFlag(0x00) |
87 | 89 |
|
88 | 90 | elif QtModuleName == "PySide2": |
89 | 91 | from PySide2 import QtWidgets |
90 | 92 | from PySide2.QtCore import Slot |
91 | 93 |
|
92 | 94 | QApplication = QtWidgets.QApplication |
| 95 | + AllEvents = QtCore.QEventLoop.ProcessEventsFlags(0x00) |
93 | 96 |
|
94 | 97 | elif QtModuleName == "PySide6": |
95 | 98 | from PySide6 import QtWidgets |
96 | 99 | from PySide6.QtCore import Slot |
97 | 100 |
|
98 | 101 | QApplication = QtWidgets.QApplication |
| 102 | + AllEvents = QtCore.QEventLoop.ProcessEventsFlags(0x00) |
99 | 103 |
|
100 | 104 | from ._common import with_logger # noqa |
101 | 105 |
|
@@ -234,7 +238,7 @@ def __exit__(self, *args): |
234 | 238 |
|
235 | 239 | def _format_handle(handle: asyncio.Handle): |
236 | 240 | cb = getattr(handle, "_callback", None) |
237 | | - if isinstance(getattr(cb, '__self__', None), asyncio.tasks.Task): |
| 241 | + if isinstance(getattr(cb, "__self__", None), asyncio.tasks.Task): |
238 | 242 | return repr(cb.__self__) |
239 | 243 | return str(handle) |
240 | 244 |
|
@@ -292,7 +296,11 @@ def timerEvent(self, event): # noqa: N802 |
292 | 296 | handle._run() |
293 | 297 | dt = time.time() - t0 |
294 | 298 | if dt >= loop.slow_callback_duration: |
295 | | - self._logger.warning('Executing %s took %.3f seconds', _format_handle(handle), dt) |
| 299 | + self._logger.warning( |
| 300 | + "Executing %s took %.3f seconds", |
| 301 | + _format_handle(handle), |
| 302 | + dt, |
| 303 | + ) |
296 | 304 | finally: |
297 | 305 | loop._current_handle = None |
298 | 306 | else: |
@@ -338,7 +346,7 @@ class _QEventLoop: |
338 | 346 | ... await asyncio.sleep(.1) |
339 | 347 | >>> |
340 | 348 | >>> asyncio.run(xplusy(2, 2), loop_factory=lambda:QEventLoop(app)) |
341 | | - |
| 349 | +
|
342 | 350 | If the event loop shall be used with an existing and already running QApplication |
343 | 351 | it must be specified in the constructor via already_running=True |
344 | 352 | In this case the user is responsible for loop cleanup with stop() and close() |
@@ -420,7 +428,9 @@ def stop(*args): |
420 | 428 | self.run_forever() |
421 | 429 | finally: |
422 | 430 | future.remove_done_callback(stop) |
423 | | - self.__app.processEvents() # run loop one last time to process all the events |
| 431 | + self.__app.eventDispatcher().processEvents( |
| 432 | + AllEvents |
| 433 | + ) # run loop one last time to process all the events |
424 | 434 | if not future.done(): |
425 | 435 | raise RuntimeError("Event loop stopped before Future completed.") |
426 | 436 |
|
|
0 commit comments