From 407c8ee6d72e223b2c84f14aefcbe5d3ac547024 Mon Sep 17 00:00:00 2001 From: Paul Ivanov Date: Mon, 13 Feb 2012 19:15:32 -0800 Subject: [PATCH] added --browser option to notebook now you can specify --browser=firefox when starting ipython notebook --- IPython/frontend/html/notebook/notebookapp.py | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index 30bbeb544..bc0718e99 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -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()