def main(): parser = argparse.ArgumentParser(description=__doc__) # These two commands are aliases. parser.add_argument('-d', '--devices', '-t', '--target', action='append', type=str, default=[]) parser.add_argument('--max-receive-bytes', default=48, type=int) moteus.make_transport_args(parser) args = parser.parse_args() app = QtWidgets.QApplication(sys.argv) loop = asyncqt.QEventLoop(app) asyncio.set_event_loop(loop) # To work around https://bugreports.qt.io/browse/PYSIDE-88 app.aboutToQuit.connect(lambda: os._exit(0)) tv = TviewMainWindow(args) tv.show() app.exec_()
def loop(request, application): lp = asyncqt.QEventLoop(application) asyncio.set_event_loop(lp) additional_exceptions = [] def fin(): sys.excepthook = orig_excepthook try: lp.close() finally: asyncio.set_event_loop(None) for exc in additional_exceptions: if (os.name == 'nt' and isinstance(exc['exception'], WindowsError) and exc['exception'].winerror == 6): # ignore Invalid Handle Errors continue raise exc['exception'] def except_handler(loop, ctx): additional_exceptions.append(ctx) def excepthook(type, *args): lp.stop() orig_excepthook(type, *args) orig_excepthook = sys.excepthook sys.excepthook = excepthook lp.set_exception_handler(except_handler) request.addfinalizer(fin) return lp
def _setup_asyncio_event_loop(): if ida_qtconsole.is_using_pyqt5() and kernel.is_using_ipykernel_5(): from PyQt5.QtWidgets import QApplication import asyncqt import asyncio qapp = QApplication.instance() loop = asyncqt.QEventLoop(qapp) asyncio.set_event_loop(loop)
def create_loop(app: QtWidgets.QApplication) -> asyncio.AbstractEventLoop: os.environ['QT_API'] = "PySide2" import asyncqt loop: asyncio.AbstractEventLoop = asyncqt.QEventLoop(app) asyncio.set_event_loop(loop) sys.excepthook = catch_exceptions loop.set_exception_handler(catch_exceptions_async) return loop
def run(args): QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True) app = QApplication(sys.argv) os.environ['QT_API'] = "PySide2" import asyncqt loop = asyncqt.QEventLoop(app) asyncio.set_event_loop(loop) sys.excepthook = catch_exceptions target_window = getattr(args, "window", None) if target_window == "data-editor": show_data_editor(app) elif target_window == "tracker": show_tracker(app) else: show_main_window(app, getattr(args, "preview", False)) with loop: sys.exit(loop.run_forever())
def run(args): QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True) app = QApplication(sys.argv) preview: bool = getattr(args, "preview", False) os.environ['QT_API'] = "PySide2" import asyncqt loop = asyncqt.QEventLoop(app) asyncio.set_event_loop(loop) sys.excepthook = catch_exceptions app.game_connection = GameConnection() if getattr(args, "debug_game_backend", False): backend = DebugBackendWindow() backend.show() else: backend = DolphinBackend() app.game_connection.set_backend(backend) @asyncClose async def _on_last_window_closed(): await app.game_connection.stop() app.lastWindowClosed.connect(_on_last_window_closed, Qt.QueuedConnection) target_window = getattr(args, "window", None) if target_window == "data-editor": show_data_editor(app) elif target_window == "tracker": show_tracker(app) else: show_main_window(app, preview) with loop: loop.create_task(app.game_connection.start()) sys.exit(loop.run_forever())
def main(): parser = argparse.ArgumentParser() parser.parse_args() app = QCoreApplication(sys.argv) os.environ['QT_API'] = "PySide2" import asyncqt loop = asyncqt.QEventLoop(app) asyncio.set_event_loop(loop) def catch_exceptions(t, val, tb): global should_quit should_quit = True old_hook(t, val, tb) sys.excepthook = catch_exceptions with loop: try: asyncio.get_event_loop().run_until_complete(worker(app)) finally: app.quit()
self.goFileBtn.clicked.connect(self.performRandomLatinLetter) self.quitBtn = qw.QPushButton('Quit', self) self.quitBtn.move(50, 150) self.quitBtn.clicked.connect(self.close) @asyncSlot(bool) async def performRandomNumber(self, evt): self.goBtn.setEnabled(False) c = random.randint(1, 1000000) print("Random number from 1 to 1000000: ", c) self.goBtn.setEnabled(True) @asyncSlot(bool) async def performRandomLatinLetter(self, evt): alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' d = random.randint(0, 25) e = alphabet[d] print("Random latin letter: ", e) if __name__ == '__main__': app = qw.QApplication(sys.argv) loop = asyncqt.QEventLoop(app) asyncio.set_event_loop(loop) w = MainWindow() w.show() with loop: sys.exit(loop.run_forever())
def main(): parser = argparse.ArgumentParser() parser.add_argument( "--nintendont", help="Connect to the given IP via the Nintendont protocol instead.") args = parser.parse_args() app = QCoreApplication(sys.argv) os.environ['QT_API'] = "PySide2" import asyncqt loop = asyncqt.QEventLoop(app) asyncio.set_event_loop(loop) logging.config.dictConfig({ 'version': 1, 'formatters': { 'default': { 'format': '[%(asctime)s] [%(levelname)s] [%(name)s] %(funcName)s: %(message)s', } }, 'handlers': { 'default': { 'level': 'DEBUG', 'formatter': 'default', 'class': 'logging.StreamHandler', 'stream': 'ext://sys.stdout', # Default is stderr }, }, 'loggers': {}, 'root': { 'level': 'DEBUG', 'handlers': ['default'], }, }) def catch_exceptions(t, val, tb): global should_quit should_quit = True old_hook(t, val, tb) def catch_exceptions_async(loop, context): if 'future' in context: future: asyncio.Future = context['future'] logging.exception(context["message"], exc_info=future.exception()) else: logging.critical(str(context)) sys.excepthook = catch_exceptions loop.set_exception_handler(catch_exceptions_async) if args.nintendont is not None: backend = NintendontBackend(args.nintendont) else: backend = DolphinBackend() with loop: try: asyncio.get_event_loop().run_until_complete(worker(app, backend)) finally: app.quit()
def test_can_function_as_context_manager(application): """Verify that a QEventLoop can function as its own context manager.""" with asyncqt.QEventLoop(application) as loop: assert isinstance(loop, asyncqt.QEventLoop) loop.call_soon(loop.stop) loop.run_forever()