Skip to content

Instantly share code, notes, and snippets.

@harvimt
Created January 17, 2015 22:22
Show Gist options
  • Save harvimt/2d4b4228b89ae472ed79 to your computer and use it in GitHub Desktop.
Save harvimt/2d4b4228b89ae472ed79 to your computer and use it in GitHub Desktop.
Quamash Mintest
import sys
from PyQt4.QtGui import *
import asyncio
from quamash import QEventLoop
class ClientController:
def __init__(self, server = None, loop=None):
self.server = server[0]
self.port = server[1]
self.loop = loop
@asyncio.coroutine
def startClient(self):
asyncio.set_event_loop(self.loop)
asyncio.async(self.loop.create_connection(_TCPClient, self.server, self.port))
class _TCPClient(asyncio.Protocol):
def __init__(self):
print('TCP init')
def connection_made(self, transport):
print('connection_made')
self.transport = transport
def data_received(self, data):
print('data received {}'.format(data))
def connection_lost(self, exc):
print('connection lost')
class App(QApplication):
def __init__(self):
server = ('localhost', 6667)
QApplication.__init__(self, sys.argv)
loop = QEventLoop(self)
asyncio.set_event_loop(loop) # NEW must set the event loop
self.clientController = ClientController(server, loop)
loop.create_task(self.clientController.startClient())
self.MainWindow = QMainWindow()
self.MainWindow.setWindowTitle("Ircbot")
self.MainWindow.show()
# self.MainWindow.connect(self.MainWindow.changeEvent, self.change)
loop.run_forever()
sys.exit(0)
if __name__ == '__main__':
App()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment