From ff88ae072f42f71b4f0a9b10196762280a262a2a Mon Sep 17 00:00:00 2001 From: wordofglass Date: Tue, 7 Mar 2017 22:28:52 +0100 Subject: [PATCH 1/2] Add 'new_browser_window' config option On startup, this optionally opens the notebook in a new browser window instead of a new tab. --- notebook/notebookapp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/notebook/notebookapp.py b/notebook/notebookapp.py index 498405a6d..ddfd659b1 100755 --- a/notebook/notebookapp.py +++ b/notebook/notebookapp.py @@ -678,6 +678,10 @@ class NotebookApp(JupyterApp): standard library module, which allows setting of the BROWSER environment variable to override it. """) + new_browser_window = Bool(False, config=True, + help="""Whether to open the notebook in a new + browser window. The default is to use a new tab. + """) webapp_settings = Dict(config=True, help="DEPRECATED, use tornado_settings" @@ -1387,7 +1391,7 @@ class NotebookApp(JupyterApp): uri = url_concat(uri, {'token': self.one_time_token}) if browser: b = lambda : browser.open(url_path_join(self.connection_url, uri), - new=2) + new=1 if self.new_browser_window else 2) threading.Thread(target=b).start() if self.token and self._token_generated: From f1253c460fe938c4d8080c6fdb84798c2b0f5feb Mon Sep 17 00:00:00 2001 From: wordofglass Date: Wed, 8 Mar 2017 20:46:04 +0100 Subject: [PATCH 2/2] Directly expose the `webbrowser.open` new argument. Suggested by minrk. Also, amend the corresponding documentation in order to mention dependence on browser support. --- notebook/notebookapp.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/notebook/notebookapp.py b/notebook/notebookapp.py index ddfd659b1..5dc0d6756 100755 --- a/notebook/notebookapp.py +++ b/notebook/notebookapp.py @@ -678,11 +678,18 @@ class NotebookApp(JupyterApp): standard library module, which allows setting of the BROWSER environment variable to override it. """) - new_browser_window = Bool(False, config=True, - help="""Whether to open the notebook in a new - browser window. The default is to use a new tab. - """) - + + webbrowser_open_new = Integer(2, config=True, + help="""Specify Where to open the notebook on startup. This is the + `new` argument passed to the standard library method `webbrowser.open`. + The behaviour is not guaranteed, but depends on browser support. Valid + values are: + 2 opens a new tab, + 1 opens a new window, + 0 opens in an existing window. + See the `webbrowser.open` documentation for details. + """) + webapp_settings = Dict(config=True, help="DEPRECATED, use tornado_settings" ) @@ -1391,7 +1398,7 @@ class NotebookApp(JupyterApp): uri = url_concat(uri, {'token': self.one_time_token}) if browser: b = lambda : browser.open(url_path_join(self.connection_url, uri), - new=1 if self.new_browser_window else 2) + new=self.webbrowser_open_new) threading.Thread(target=b).start() if self.token and self._token_generated: