class App(QApplication): def __init__(self): QApplication.__init__(self, sys.argv) self.loop = QEventLoop(self) asyncio.set_event_loop(self.loop) self.client = Client(self.loop, f'user-{int(random()*10000)}') self.loop.create_task(self.start()) self.gui = MyWindow(self.loop, self.client) self.gui.show() self.loop.run_forever() async def start(self): clientConnection = self.loop.create_connection(lambda: self.client, '127.0.0.1', 8888) await asyncio.wait_for(clientConnection, 10000, loop=self.loop)
class App(QApplication): def __init__(self): QApplication.__init__(self, sys.argv) self.loop = QEventLoop(self) asyncio.set_event_loop(self.loop) self.userClient = EchoClientProtocol(self.loop, 'user') self.loop.create_task(self.start()) self.gui = Gui(self.loop, self.userClient) self.loop.run_forever() async def start(self): clientConnection = self.loop.create_connection(lambda: self.userClient, '127.0.0.1', 8888) await asyncio.wait_for(clientConnection, 1000) transport, protocol = clientConnection self.userClient.connection_made(transport)
class App(QApplication): def __init__(self): QApplication.__init__(self, sys.argv) self.loop = QEventLoop(self) asyncio.set_event_loop(self.loop) self.userClient = EchoClientProtocol(self.loop, 'user') self.loop.create_task(self.start()) self.window = MyWindow(self.loop, self.userClient) self.window.show() self.loop.run_forever() async def start(self): print('[START CLIENT]') clientConnection = self.loop.create_connection(lambda: self.userClient, '127.0.0.1', 8888) await asyncio.wait_for(clientConnection, 10000, loop=self.loop)
btn = get_btn(data) btn.move(0, label_height) btn.show() label_height += (label.height() + 10) def listen(): manager.reg_msg_handler('reg', on_reg) manager.reg_msg_handler('text', on_text) manager.listen() def send_msg(): data = get_text_from_editor() ui.textEdit.clear() manager.send_msg(data) def set_name(): name = ui.nameInput.toPlainText() manager.set_name(name or 'anonymous') ui.nameInput.textChanged.connect(set_name) ui.submit.clicked.connect(send_msg) listen() loop.create_task(manager.heartbeat(flush_user)) sys.exit(loop.run_forever())