Skip to content

Commit

Permalink
new lib python to call python scripts from ahk
Browse files Browse the repository at this point in the history
  • Loading branch information
ewerybody committed Jun 9, 2022
1 parent 254772a commit eacbc88
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
56 changes: 56 additions & 0 deletions lib/Autohotkey/lib/python.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
; a2 Autohotkey python lib

python_get_output(py_file, args := "") {
py_exe := python_get_console_path()
cmd = "%py_exe%" "%py_file%" %args%
shell := ComObjCreate("WScript.Shell")
exec := shell.Exec(cmd)
errors := exec.StdErr.ReadAll()
if (errors)
msgbox_error(errors, "python_get_output-ERROR")
else {
result := exec.StdOut.ReadAll()
return result
}
}

python_get_console_path() {
exe_type := {filename: "python.exe", reg_name: "ExecutablePath"}
return _py_get_path(exe_type)
}

python_get_path() {
exe_type := {filename: "pythonw.exe", reg_name: "WindowedExecutablePath"}
return _py_get_path(exe_type)
}

_py_get_path(exe_type) {
pypath := python_check_registry(exe_type)
if (pypath != "")
Return pypath

versions_string := string_join(python_supported_versions)
MsgBox, 16, No Matching Python Version!, Could not find a Python installation!`nSupported versions include: %versions_string%!
}


python_check_registry(exe_type) {
reg_name := exe_type["reg_name"]
for i, version in python_supported_versions
{
py_key = HKEY_CURRENT_USER\Software\Python\PythonCore\%version%\InstallPath
RegRead, pypath, %py_key%, %reg_name%

if !string_endswith(pypath, exe_type.filename)
{
py_key = HKEY_LOCAL_MACHINE\Software\Python\PythonCore\%version%\InstallPath
RegRead, pypath, %py_key%, %reg_name%
}

IfExist, %pypath%
{
global a2_PY_VERSION_SHORT := version
Return, pypath
}
}
}
1 change: 1 addition & 0 deletions lib/a2_globals.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ global WIN_10 := 10.0

global WEB_TLDS := ["html", "com", "de", "net", "org", "co.uk"]
global A_AppDataLocal := path_join(path_dirname(A_AppData), "Local")
global PYTHON_SUPPORTED_VERSIONS := ["3.10", "3.9", "3.8", "3.7", "3.6"]

; groups for explorer classes
GroupAdd, ExplorerGroup, ahk_class ExploreWClass
Expand Down

0 comments on commit eacbc88

Please sign in to comment.