##// END OF EJS Templates
Add ability to open the notebook in a browser when it starts.
Thomas Kluyver -
Show More
@@ -22,6 +22,7 b' import os'
22 import signal
22 import signal
23 import socket
23 import socket
24 import sys
24 import sys
25 import webbrowser
25
26
26 import zmq
27 import zmq
27
28
@@ -51,7 +52,7 b' from IPython.zmq.ipkernel import ('
51 aliases as ipkernel_aliases,
52 aliases as ipkernel_aliases,
52 IPKernelApp
53 IPKernelApp
53 )
54 )
54 from IPython.utils.traitlets import Dict, Unicode, Int, List, Enum
55 from IPython.utils.traitlets import Dict, Unicode, Int, List, Enum, Bool
55
56
56 #-----------------------------------------------------------------------------
57 #-----------------------------------------------------------------------------
57 # Module globals
58 # Module globals
@@ -111,11 +112,15 b' class NotebookWebApplication(web.Application):'
111 #-----------------------------------------------------------------------------
112 #-----------------------------------------------------------------------------
112
113
113 flags = dict(ipkernel_flags)
114 flags = dict(ipkernel_flags)
115 flags['no-browser']=(
116 {'IPythonNotebookApp' : {'open_browser' : False}},
117 "Don't open the notebook in a browser after startup."
118 )
114
119
115 # the flags that are specific to the frontend
120 # the flags that are specific to the frontend
116 # these must be scrubbed before being passed to the kernel,
121 # these must be scrubbed before being passed to the kernel,
117 # or it will raise an error on unrecognized flags
122 # or it will raise an error on unrecognized flags
118 notebook_flags = []
123 notebook_flags = ['no-browser']
119
124
120 aliases = dict(ipkernel_aliases)
125 aliases = dict(ipkernel_aliases)
121
126
@@ -195,6 +200,9 b' class IPythonNotebookApp(BaseIPythonApplication):'
195 password = Unicode(u'', config=True,
200 password = Unicode(u'', config=True,
196 help="""Password to use for web authentication"""
201 help="""Password to use for web authentication"""
197 )
202 )
203
204 open_browser = Bool(True, config=True,
205 help="Whether to open in a browser after starting.")
198
206
199 def get_ws_url(self):
207 def get_ws_url(self):
200 """Return the WebSocket URL for this server."""
208 """Return the WebSocket URL for this server."""
@@ -291,6 +299,9 b' class IPythonNotebookApp(BaseIPythonApplication):'
291 self.log.info("The IPython Notebook is running at: %s://%s:%i" % (proto,
299 self.log.info("The IPython Notebook is running at: %s://%s:%i" % (proto,
292 ip,
300 ip,
293 self.port))
301 self.port))
302 if self.open_browser:
303 ip = self.ip or '127.0.0.1'
304 webbrowser.open("%s://%s:%i" % (proto, ip, self.port), new=2)
294 ioloop.IOLoop.instance().start()
305 ioloop.IOLoop.instance().start()
295
306
296 #-----------------------------------------------------------------------------
307 #-----------------------------------------------------------------------------
General Comments 0
You need to be logged in to leave comments. Login now