From 6e4bec1ace98014f4bb8afcd3740a1c9ec01773b Mon Sep 17 00:00:00 2001 From: Tianfu He Date: Wed, 6 Jul 2016 22:42:16 +0800 Subject: [PATCH 1/3] Windows qtconsole without cmd window --- start_jupyter_cm/windows.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/start_jupyter_cm/windows.py b/start_jupyter_cm/windows.py index 86d1188..8c45729 100755 --- a/start_jupyter_cm/windows.py +++ b/start_jupyter_cm/windows.py @@ -28,6 +28,7 @@ WPSCRIPTS_FOLDER = "Scripts" + def remove_jupyter_here(): for env in ('qtconsole', 'notebook'): try: @@ -69,8 +70,22 @@ def add_jupyter_here(): "env.bat") script += " & jupyter-%s" % env else: - script = os.path.join( - sys.prefix, 'Scripts', "jupyter-%s.exe" % env) + if env == "notebook": + script = os.path.join( + sys.prefix, 'Scripts', "jupyter-%s.exe" % env) + else: + # Leveraging pythonw.exe to hide ugly back-end CMD window. + # Notebook is left as it was, because it needs a CMD window to + # log service info. + pyw_path = os.path.join(sys.prefix, 'pythonw.exe') + jpt_path = os.path.join( + sys.prefix, 'Scripts', 'jupyter-script.py') + if os.path.exists(jpt_path): + # alternate jupyter with ipython for older version + # releases. + jpt_path = os.path.join( + sys.prefix, 'Scripts', 'ipython-script.py') + script = ' '.join([pyw_path, jpt_path, 'qtconsole']) shell_script = script + ' --notebook-dir "%1"' if env == "notebook"\ else script From 1c8adb130bcc0d4a11121e8ae682f11f6b6b873a Mon Sep 17 00:00:00 2001 From: Tianfu He Date: Thu, 7 Jul 2016 11:11:31 +0800 Subject: [PATCH 2/3] For WINPython --- start_jupyter_cm/windows.py | 46 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/start_jupyter_cm/windows.py b/start_jupyter_cm/windows.py index 8c45729..55a03fd 100755 --- a/start_jupyter_cm/windows.py +++ b/start_jupyter_cm/windows.py @@ -26,7 +26,14 @@ import _winreg as winreg from win32com.shell import shell +PYTHON_PATH = os.environ["WINPYDIR"] if "WINPYDIR" in os.environ else sys.prefix WPSCRIPTS_FOLDER = "Scripts" +QTCONSOLE_SCRIPT = """from qtconsole.qtconsoleapp import main + + +if __name__ == '__main__': + main() +""" def remove_jupyter_here(): @@ -48,6 +55,8 @@ def remove_jupyter_here(): winreg.HKEY_CLASSES_ROOT, r'Directory\Background\shell\jupyter_%s_here' % env) + # remove sjc-jupyter-qtconsole-script.py when un-installing + os.remove(os.path.join(PYTHON_PATH, 'Scripts', 'sjc-jupyter-qtconsole-script.py')) print("Jupyter %s here context menu entry removed." % env) except: # If this fails it is because it was not installed, so nothing to @@ -61,31 +70,22 @@ def add_jupyter_here(): os.path.dirname(__file__), 'icons')) logos = {'qtconsole': os.path.join(logo_path, 'jupyter-qtconsole.ico'), 'notebook': os.path.join(logo_path, 'jupyter.ico')} + + # Here I need to create a script for pythonw + scr_fw = open(os.path.join(PYTHON_PATH, 'Scripts', 'sjc-jupyter-qtconsole-script.py'), 'w') + scr_fw.write(QTCONSOLE_SCRIPT) + scr_fw.close() + for env in ('qtconsole', 'notebook'): - if "WINPYDIR" in os.environ: - # Calling from WinPython - # Paths are relative, so we have to set the env first - script = os.path.join(os.environ["WINPYDIR"], "..", - WPSCRIPTS_FOLDER, - "env.bat") - script += " & jupyter-%s" % env - else: - if env == "notebook": - script = os.path.join( - sys.prefix, 'Scripts', "jupyter-%s.exe" % env) + if env == 'notebook': + if "WINPYDIR" in os.environ: + # Calling from WinPython + # Paths are relative, so we have to set the env first + script = os.path.join(PYTHON_PATH, "..", WPSCRIPTS_FOLDER, "env.bat") + " & jupyter-notebook" else: - # Leveraging pythonw.exe to hide ugly back-end CMD window. - # Notebook is left as it was, because it needs a CMD window to - # log service info. - pyw_path = os.path.join(sys.prefix, 'pythonw.exe') - jpt_path = os.path.join( - sys.prefix, 'Scripts', 'jupyter-script.py') - if os.path.exists(jpt_path): - # alternate jupyter with ipython for older version - # releases. - jpt_path = os.path.join( - sys.prefix, 'Scripts', 'ipython-script.py') - script = ' '.join([pyw_path, jpt_path, 'qtconsole']) + script = os.path.join(PYTHON_PATH, 'Scripts', 'jupyter-notebook.exe') + else: + script = os.path.join(PYTHON_PATH, 'pythonw.exe')+ ' ' +os.path.join(PYTHON_PATH, 'Scripts', 'sjc-jupyter-qtconsole-script.py') shell_script = script + ' --notebook-dir "%1"' if env == "notebook"\ else script From bace8d950d3779e1fef7fe530ab5c0ba7076e510 Mon Sep 17 00:00:00 2001 From: Tianfu He Date: Thu, 7 Jul 2016 11:25:26 +0800 Subject: [PATCH 3/3] For WinPython --- start_jupyter_cm/windows.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/start_jupyter_cm/windows.py b/start_jupyter_cm/windows.py index 55a03fd..3fbf17e 100755 --- a/start_jupyter_cm/windows.py +++ b/start_jupyter_cm/windows.py @@ -26,7 +26,8 @@ import _winreg as winreg from win32com.shell import shell -PYTHON_PATH = os.environ["WINPYDIR"] if "WINPYDIR" in os.environ else sys.prefix +PYTHON_PATH = os.environ[ + "WINPYDIR"] if "WINPYDIR" in os.environ else sys.prefix WPSCRIPTS_FOLDER = "Scripts" QTCONSOLE_SCRIPT = """from qtconsole.qtconsoleapp import main @@ -56,7 +57,8 @@ def remove_jupyter_here(): r'Directory\Background\shell\jupyter_%s_here' % env) # remove sjc-jupyter-qtconsole-script.py when un-installing - os.remove(os.path.join(PYTHON_PATH, 'Scripts', 'sjc-jupyter-qtconsole-script.py')) + os.remove(os.path.join(PYTHON_PATH, 'Scripts', + 'sjc-jupyter-qtconsole-script.py')) print("Jupyter %s here context menu entry removed." % env) except: # If this fails it is because it was not installed, so nothing to @@ -70,22 +72,26 @@ def add_jupyter_here(): os.path.dirname(__file__), 'icons')) logos = {'qtconsole': os.path.join(logo_path, 'jupyter-qtconsole.ico'), 'notebook': os.path.join(logo_path, 'jupyter.ico')} - + # Here I need to create a script for pythonw - scr_fw = open(os.path.join(PYTHON_PATH, 'Scripts', 'sjc-jupyter-qtconsole-script.py'), 'w') + scr_fw = open(os.path.join(PYTHON_PATH, 'Scripts', + 'sjc-jupyter-qtconsole-script.py'), 'w') scr_fw.write(QTCONSOLE_SCRIPT) scr_fw.close() - + for env in ('qtconsole', 'notebook'): if env == 'notebook': if "WINPYDIR" in os.environ: # Calling from WinPython # Paths are relative, so we have to set the env first - script = os.path.join(PYTHON_PATH, "..", WPSCRIPTS_FOLDER, "env.bat") + " & jupyter-notebook" + script = os.path.join( + PYTHON_PATH, "..", WPSCRIPTS_FOLDER, "env.bat") + " & jupyter-notebook" else: - script = os.path.join(PYTHON_PATH, 'Scripts', 'jupyter-notebook.exe') + script = os.path.join( + PYTHON_PATH, 'Scripts', 'jupyter-notebook.exe') else: - script = os.path.join(PYTHON_PATH, 'pythonw.exe')+ ' ' +os.path.join(PYTHON_PATH, 'Scripts', 'sjc-jupyter-qtconsole-script.py') + script = os.path.join(PYTHON_PATH, 'pythonw.exe') + ' ' + os.path.join( + PYTHON_PATH, 'Scripts', 'sjc-jupyter-qtconsole-script.py') shell_script = script + ' --notebook-dir "%1"' if env == "notebook"\ else script