Qt reactor in cogen

20 April 2008 (updated 04 March 2015)

I've implemented a reactor to integrate the cogen loop in the qt main loop.

You whould use it like this:

from PyQt4 import QtGui

app = QtGui.QApplication([])
hello = QtGui.QPushButton( "Hello world!" )
hello.resize(100, 30)
hello.show()

from cogen.core import reactors, schedulers
m = schedulers.Scheduler(reactor=reactors.QtReactor)

def lorem_ipsum_app(environ, start_response):
    start_response('200 OK', [('Content-type','text/plain'), ('Content-Length','19')])
    return ['Lorem ipsum dolor..']

server = wsgi.WSGIServer(
    ('0.0.0.0', 9001),
    lorem_ipsum_app,
    m,
)
m.add(server.serve)
m.run()
# voila! this actualy runs the QApplication loop with the cogen hooks
Though the reactor isn't tested, well, unittested - I have a bunch of tests to keep the code sane.
The problem is that Qt is a big nasty monolithic framework, well, it's nice if you don't need to do any weird stuff - like running the main application loop in a second thread.

I just don't understand why they made this ugly limitation in qt: the application loop must run in the main thread. I'll fix those tests somehow, but in the meanwhile I'll just continue cursing Qt for making me feel miserable about my unittests.

This entry was tagged as cogen python qt