added --browser option to notebook

now you can specify --browser=firefox when starting ipython notebook
This commit is contained in:
Paul Ivanov 2012-02-13 19:15:32 -08:00
parent 7b9099041d
commit 407c8ee6d7

View File

@ -208,6 +208,7 @@ aliases.update({
'keyfile': 'NotebookApp.keyfile',
'certfile': 'NotebookApp.certfile',
'notebook-dir': 'NotebookManager.notebook_dir',
'browser': 'NotebookApp.browser',
})
# remove ipkernel flags that are singletons, and don't make sense in
@ -280,22 +281,22 @@ class NotebookApp(BaseIPythonApplication):
The string should be of the form type:salt:hashed-password.
"""
)
open_browser = Bool(True, config=True,
help="""Whether to open in a browser after starting.
The specific browser used is platform dependent and
determined by the python standard library `webbrowser`
module, which allows setting of the BROWSER
environment variable to override it. As a one-time
change, you can start the notebook using:
BROWSER=firefox ipython notebook
To make the change more permanent, modify your
~/.bashrc you can include a line like the following:
export BROWSER=firefox
module, unless it is overridden using the --browser
(NotebookApp.browser) configuration option.
""")
browser = Unicode(u'', config=True,
help="""Specify which browser to use when opening the
notebook. If not specified, the default browser will be
determined by the `webbrowser` standard library module,
which allows setting of the BROWSER environment variable
to override it.
""")
read_only = Bool(False, config=True,
help="Whether to prevent editing/execution of notebooks."
@ -440,7 +441,11 @@ class NotebookApp(BaseIPythonApplication):
if self.open_browser:
ip = self.ip or '127.0.0.1'
b = lambda : webbrowser.open("%s://%s:%i%s" % (proto, ip, self.port,
if len(self.browser) == 0:
browser = webbrowser.get()
else:
browser = webbrowser.get(self.browser)
b = lambda : browser.open("%s://%s:%i%s" % (proto, ip, self.port,
self.base_project_url),
new=2)
threading.Thread(target=b).start()