Created
September 18, 2012 06:21
-
-
Save jamiesun/3741546 to your computer and use it in GitHub Desktop.
pyqt and gevent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""The user interface for our app""" | |
import os,sys | |
import gevent | |
# Import Qt modules | |
from PyQt4 import QtCore,QtGui | |
# Import the compiled UI module | |
from windowUi import Ui_MainWindow | |
# Create a class for our main window | |
class Main(QtGui.QMainWindow): | |
def __init__(self): | |
QtGui.QMainWindow.__init__(self) | |
# This is always the same | |
self.ui=Ui_MainWindow() | |
self.ui.setupUi(self) | |
def mainloop(app): | |
while True: | |
app.processEvents() | |
while app.hasPendingEvents(): | |
app.processEvents() | |
gevent.sleep() | |
gevent.sleep() # don't appear to get here but cooperate again | |
def testprint(): | |
print 'this is running' | |
gevent.spawn_later(1, testprint) | |
def main(): | |
# Again, this is boilerplate, it's going to be the same on | |
# almost every app you write | |
app = QtGui.QApplication(sys.argv) | |
window=Main() | |
window.show() | |
# It's exec_ because exec is a reserved word in Python | |
#sys.exit(app.exec_()) | |
gevent.joinall([gevent.spawn(testprint), gevent.spawn(mainloop, app)]) | |
print 'done' | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment