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