Skip to content

Commit 1bd7867

Browse files
committed
Add new function: get_launch_method()
1 parent d263f69 commit 1bd7867

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

src/HwCodecDetect/run_tests.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,34 @@ def launch_gui(args):
806806
root.mainloop()
807807

808808

809+
def get_launch_method():
810+
if PSUTIL_AVAILABLE:
811+
try:
812+
current_process = psutil.Process(os.getpid())
813+
parent = current_process.parent()
814+
if parent is None:
815+
return "unknown"
816+
parent_name = parent.name().lower()
817+
shell_procs = ["cmd.exe", "powershell.exe", "pwsh.exe", "windows terminal", "wt.exe"]
818+
if parent_name == "explorer.exe":
819+
return "double_click"
820+
elif any(shell in parent_name for shell in shell_procs):
821+
return "terminal"
822+
else:
823+
return f"other ({parent_name})"
824+
except Exception as e:
825+
return f"error: {e}"
826+
else:
827+
import ctypes
828+
kernel32 = ctypes.windll.kernel32
829+
h_std_out = kernel32.GetStdHandle(-11)
830+
pids = (ctypes.c_uint * 10)()
831+
count = kernel32.GetConsoleProcessList(pids, 10)
832+
if count <= 1:
833+
return "double_click"
834+
return "terminal"
835+
836+
809837
def main():
810838
"""Parses arguments and runs the test suite."""
811839

@@ -868,7 +896,7 @@ def main():
868896
parser.add_argument(
869897
"-ui", "--ui",
870898
action="store_true",
871-
default=True,
899+
default=(get_launch_method() == "double_click"),
872900
help="Launch GUI"
873901
)
874902

0 commit comments

Comments
 (0)