Debian Codegraph @

examples/IPython Kernel/gui/gui-qt.py

raw
1 #!/usr/bin/env python
2 """Simple Qt4 example to manually test event loop integration.
3
4 This is meant to run tests manually in ipython as:
5
6 In [5]: %gui qt
7
8 In [6]: %run gui-qt.py
9
10 Ref: Modified from http://zetcode.com/tutorials/pyqt4/firstprograms/
11 """
12
13 from PyQt4 import QtGui, QtCore
14
15 class SimpleWindow(QtGui.QWidget):
16 def __init__(self, parent=None):
17 QtGui.QWidget.__init__(self, parent)
18
19 self.setGeometry(300, 300, 200, 80)
20 self.setWindowTitle('Hello World')
21
22 quit = QtGui.QPushButton('Close', self)
23 quit.setGeometry(10, 10, 60, 35)
24
25 self.connect(quit, QtCore.SIGNAL('clicked()'),
26 self, QtCore.SLOT('close()'))
27
28 if __name__ == '__main__':
29 app = QtCore.QCoreApplication.instance()
30 if app is None:
31 app = QtGui.QApplication([])
32
33 sw = SimpleWindow()
34 sw.show()
35
36 try:
37 from IPython.lib.guisupport import start_event_loop_qt4
38 start_event_loop_qt4(app)
39 except ImportError:
40 app.exec_()