Я хочу запустить свой редактор при двойном щелчке.
Моя идея состоит Мой редактор, если параметры не передаются, и запустите его с помощью пусковой установки Python, если он имеет параметры.
Я не могу заставить его полностью работать. Но при открытии командного окна редактора создается, которое не закрывается автоматически. < /P>
Код: Выделить всё
test drag.pyКод: Выделить всё
import sys
import os
if __name__ == "__main__":
test_file_name = os.path.join(os.path.split(sys.argv[0])[0], "test.txt")
if len(sys.argv) > 1:
with open(test_file_name, 'w', newline='\n') as f:
f.write("file names:")
f.write("\n")
for file_path in sys.argv[1:]:
f.write(file_path)
f.write("\n")
else:
with open(test_file_name, 'w', newline='\n') as f:
f.write("no file names")
f.write("\n")
< /code>
C:\drag\python_drag.cmdКод: Выделить всё
@echo off
if not "%~2"=="" (
:: Arguments detected, so files were dragged on it. Calling it with python.
START /B python.exe %*
) else (
:: No arguments detected, so double clicked. Opening it with editor (vscode)
START /B code %1
)
< /code>
Open command key is updated via command line:
reg add "HKEY_CLASSES_ROOT\Python.File\shell\open\command" /ve /t REG_EXPAND_SZ /d "\"C:\drag\python_drag.cmd\" \"%L\" %*" /f
< /code>
Set drophandler if needed (if installing latest python version with py launcher it should be set). enable_python_drag_and_drop.regWindows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Python.File\shellex\DropHandler]
@="{60254CA5-953B-11CF-8C96-00AA00B8708C}"
< /code>
When starting python a window briefly opens (you can only see the outline) and then it closes automaticallt.
When starting VSCODE it opens an additional window that doesn't close. How to fix it?
Подробнее здесь: https://stackoverflow.com/questions/793 ... ython-file