From 8922d59b95348c4740228085e47966654379dfc8 Mon Sep 17 00:00:00 2001 From: Pakobbix Date: Sun, 14 May 2023 12:24:15 +0200 Subject: [PATCH] Fixed Linux Terminal output. --- StartUI.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/StartUI.py b/StartUI.py index fe944d1..65c9bf1 100644 --- a/StartUI.py +++ b/StartUI.py @@ -33,12 +33,32 @@ def run_cmd_with_conda(cmd, env=None): # Open a separate terminal window and execute the command subprocess.Popen(['start', 'cmd', '/k', full_cmd], shell=True, env=env) elif platform.system() == 'Linux': - # For Linux, activate the Conda environment using the conda command - activate_cmd = f"conda activate {conda_env_path} && " - full_cmd = f"source ./installer_files/conda/etc/profile.d/conda.sh && conda run -p {conda_env_path} {cmd}" + # Define the necessary variables from the bash script + install_dir = os.path.dirname(os.path.abspath(__file__)) + conda_root_prefix = os.path.join(install_dir, "installer_files", "conda") + install_env_dir = os.path.join(install_dir, "installer_files", "env") - # Open a separate terminal window and execute the command - process = subprocess.Popen(['gnome-terminal', '--', 'bash', '-c', full_cmd], env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + # For Linux, activate the Conda environment + activate_cmd = f"source {os.path.join(conda_root_prefix, 'etc', 'profile.d', 'conda.sh')} && conda activate {install_env_dir}" + + # Check for available terminal emulators + terminal_emulators = ['xdg-terminal', 'gnome-terminal', 'konsole', 'xfce4-terminal', 'mate-terminal', 'lxterminal', 'termite', 'tilix', 'xterm'] + terminal_cmd = None + + for emulator in terminal_emulators: + try: + subprocess.run([emulator, '--version'], check=True) + terminal_cmd = emulator + break + except FileNotFoundError: + continue + + if terminal_cmd is None: + raise RuntimeError("No compatible terminal emulator found.") + + # Execute the command within the Conda environment in a separate terminal + print(cmd) + subprocess.Popen([terminal_cmd, '--', 'bash', '-c', f"{activate_cmd} && {cmd}"], env=env) class MainWindow(QMainWindow): def __init__(self):