Show More
@@ -0,0 +1,41 b'' | |||||
|
1 | from IPython.embedded.ipkernel import EmbeddedKernel | |||
|
2 | from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget | |||
|
3 | from IPython.frontend.qt.embedded_kernelmanager import QtEmbeddedKernelManager | |||
|
4 | from IPython.lib import guisupport | |||
|
5 | ||||
|
6 | ||||
|
7 | def main(): | |||
|
8 | app = guisupport.get_app_qt4() | |||
|
9 | ||||
|
10 | # Create a kernel and populate the namespace. | |||
|
11 | kernel = EmbeddedKernel() | |||
|
12 | kernel.shell.push({'x': 0, 'y': 1, 'z': 2}) | |||
|
13 | ||||
|
14 | # Create a kernel manager for the frontend and register it with the kernel. | |||
|
15 | km = QtEmbeddedKernelManager(kernel=kernel) | |||
|
16 | km.start_channels() | |||
|
17 | kernel.frontends.append(km) | |||
|
18 | ||||
|
19 | # Create the Qt console frontend. | |||
|
20 | control = RichIPythonWidget() | |||
|
21 | control.exit_requested.connect(app.quit) | |||
|
22 | control.kernel_manager = km | |||
|
23 | control.show() | |||
|
24 | ||||
|
25 | # Execute some code directly. Note where the output appears. | |||
|
26 | kernel.shell.run_cell('print "x=%r, y=%r, z=%r" % (x,y,z)') | |||
|
27 | ||||
|
28 | # Execute some code through the frontend (once the event loop is | |||
|
29 | # running). Again, note where the output appears. | |||
|
30 | do_later(control.execute, '%who') | |||
|
31 | ||||
|
32 | guisupport.start_event_loop_qt4(app) | |||
|
33 | ||||
|
34 | ||||
|
35 | def do_later(func, *args, **kwds): | |||
|
36 | from IPython.external.qt import QtCore | |||
|
37 | QtCore.QTimer.singleShot(0, lambda: func(*args, **kwds)) | |||
|
38 | ||||
|
39 | ||||
|
40 | if __name__ == '__main__': | |||
|
41 | main() |
General Comments 0
You need to be logged in to leave comments.
Login now