Show More
@@ -1,88 +1,93 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | |
|
3 | 3 | """ A minimal application using the Qt console-style IPython frontend. |
|
4 | 4 | """ |
|
5 | 5 | |
|
6 | 6 | # Systemm library imports |
|
7 | 7 | from PyQt4 import QtCore, QtGui |
|
8 | 8 | |
|
9 | 9 | # Local imports |
|
10 | 10 | from IPython.external.argparse import ArgumentParser |
|
11 | 11 | from IPython.frontend.qt.console.frontend_widget import FrontendWidget |
|
12 | 12 | from IPython.frontend.qt.console.ipython_widget import IPythonWidget |
|
13 | 13 | from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget |
|
14 | 14 | from IPython.frontend.qt.kernelmanager import QtKernelManager |
|
15 | 15 | |
|
16 | 16 | # Constants |
|
17 | 17 | LOCALHOST = '127.0.0.1' |
|
18 | 18 | |
|
19 | 19 | |
|
20 | 20 | def main(): |
|
21 | 21 | """ Entry point for application. |
|
22 | 22 | """ |
|
23 | 23 | # Parse command line arguments. |
|
24 | 24 | parser = ArgumentParser() |
|
25 | parser.add_argument('-r', '--rich', action='store_true', | |
|
26 | help='use a rich text frontend') | |
|
27 | parser.add_argument('-t', '--tab-simple', action='store_true', | |
|
28 | help='do tab completion ala a Unix terminal') | |
|
29 | ||
|
30 | parser.add_argument('--existing', action='store_true', | |
|
25 | kgroup = parser.add_argument_group('kernel options') | |
|
26 | kgroup.add_argument('-e', '--existing', action='store_true', | |
|
31 | 27 | help='connect to an existing kernel') |
|
32 |
|
|
|
28 | kgroup.add_argument('--ip', type=str, default=LOCALHOST, | |
|
33 | 29 | help='set the kernel\'s IP address [default localhost]') |
|
34 |
|
|
|
30 | kgroup.add_argument('--xreq', type=int, metavar='PORT', default=0, | |
|
35 | 31 | help='set the XREQ channel port [default random]') |
|
36 |
|
|
|
32 | kgroup.add_argument('--sub', type=int, metavar='PORT', default=0, | |
|
37 | 33 | help='set the SUB channel port [default random]') |
|
38 |
|
|
|
34 | kgroup.add_argument('--rep', type=int, metavar='PORT', default=0, | |
|
39 | 35 | help='set the REP channel port [default random]') |
|
40 | 36 | |
|
41 |
group = |
|
|
42 | group.add_argument('--pure', action='store_true', help = \ | |
|
37 | egroup = kgroup.add_mutually_exclusive_group() | |
|
38 | egroup.add_argument('--pure', action='store_true', help = \ | |
|
43 | 39 | 'use a pure Python kernel instead of an IPython kernel') |
|
44 | group.add_argument('--pylab', action='store_true', | |
|
40 | egroup.add_argument('--pylab', action='store_true', | |
|
45 | 41 | help='use a kernel with PyLab enabled') |
|
46 | 42 | |
|
43 | wgroup = parser.add_argument_group('widget options') | |
|
44 | wgroup.add_argument('--paging', type=str, default='inside', | |
|
45 | choices = ['inside', 'hsplit', 'vsplit', 'none'], | |
|
46 | help='set the paging style [default inside]') | |
|
47 | wgroup.add_argument('--rich', action='store_true', | |
|
48 | help='enable rich text support') | |
|
49 | wgroup.add_argument('--tab-simple', action='store_true', | |
|
50 | help='do tab completion ala a Unix terminal') | |
|
51 | ||
|
47 | 52 | args = parser.parse_args() |
|
48 | 53 | |
|
49 | 54 | # Don't let Qt or ZMQ swallow KeyboardInterupts. |
|
50 | 55 | import signal |
|
51 | 56 | signal.signal(signal.SIGINT, signal.SIG_DFL) |
|
52 | 57 | |
|
53 | 58 | # Create a KernelManager and start a kernel. |
|
54 | 59 | kernel_manager = QtKernelManager(xreq_address=(args.ip, args.xreq), |
|
55 | 60 | sub_address=(args.ip, args.sub), |
|
56 | 61 | rep_address=(args.ip, args.rep)) |
|
57 | 62 | if args.ip == LOCALHOST and not args.existing: |
|
58 | 63 | if args.pure: |
|
59 | 64 | kernel_manager.start_kernel(ipython=False) |
|
60 | 65 | elif args.pylab: |
|
61 | 66 | if args.rich: |
|
62 | 67 | kernel_manager.start_kernel(pylab='payload-svg') |
|
63 | 68 | else: |
|
64 | 69 | kernel_manager.start_kernel(pylab='qt4') |
|
65 | 70 | else: |
|
66 | 71 | kernel_manager.start_kernel() |
|
67 | 72 | kernel_manager.start_channels() |
|
68 | 73 | |
|
69 | 74 | # Create the widget. |
|
70 | 75 | app = QtGui.QApplication([]) |
|
71 | 76 | if args.pure: |
|
72 | 77 | kind = 'rich' if args.rich else 'plain' |
|
73 | widget = FrontendWidget(kind=kind) | |
|
78 | widget = FrontendWidget(kind=kind, paging=args.paging) | |
|
74 | 79 | elif args.rich: |
|
75 | widget = RichIPythonWidget() | |
|
80 | widget = RichIPythonWidget(paging=args.paging) | |
|
76 | 81 | else: |
|
77 | widget = IPythonWidget() | |
|
82 | widget = IPythonWidget(paging=args.paging) | |
|
78 | 83 | widget.gui_completion = not args.tab_simple |
|
79 | 84 | widget.kernel_manager = kernel_manager |
|
80 | 85 | widget.setWindowTitle('Python' if args.pure else 'IPython') |
|
81 | 86 | widget.show() |
|
82 | 87 | |
|
83 | 88 | # Start the application main loop. |
|
84 | 89 | app.exec_() |
|
85 | 90 | |
|
86 | 91 | |
|
87 | 92 | if __name__ == '__main__': |
|
88 | 93 | main() |
General Comments 0
You need to be logged in to leave comments.
Login now