From a2d680a1581621dff75d15e6a9bf228eb461c77e Mon Sep 17 00:00:00 2001 From: Fabien-B Date: Fri, 8 May 2026 18:09:59 +0200 Subject: [PATCH] [supervision] edit more reliable (#3654) --- sw/supervision/python/configuration_panel.py | 8 ++++++-- sw/supervision/python/utils.py | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/sw/supervision/python/configuration_panel.py b/sw/supervision/python/configuration_panel.py index e3ff2c555a..14683c26e0 100644 --- a/sw/supervision/python/configuration_panel.py +++ b/sw/supervision/python/configuration_panel.py @@ -7,7 +7,7 @@ from program_widget import ProgramWidget, TabProgramsState from conf import * from programs_conf import Tool import subprocess - +import os class ConfigurationPanel(QWidget, Ui_ConfigurationPanel): @@ -75,9 +75,13 @@ class ConfigurationPanel(QWidget, Ui_ConfigurationPanel): def edit_flightplan_gcs(self, path): if self.flight_plan_editor is not None: - cmd = [os.path.join(utils.PAPARAZZI_SRC, self.flight_plan_editor.command)] + if self.flight_plan_editor.command.startswith("$"): + cmd = [self.flight_plan_editor.command[1:]] + else: + cmd = [os.path.join(utils.PAPARAZZI_SRC, self.flight_plan_editor.command)] for arg in self.flight_plan_editor.args: cmd += arg.args() + cmd.append(os.path.join(utils.CONF_DIR, path)) subprocess.Popen(cmd) # self.launch_program(self.flight_plan_editor.name, cmd, self.flight_plan_editor.icon) diff --git a/sw/supervision/python/utils.py b/sw/supervision/python/utils.py index 41b311ae5b..47955f9313 100644 --- a/sw/supervision/python/utils.py +++ b/sw/supervision/python/utils.py @@ -6,7 +6,9 @@ from PyQt5.QtWidgets import * from typing import NamedTuple from PyQt5.QtCore import QSettings import subprocess +from shutil import which +EDITORS = ["gnome-text-editor", "kate"] class GConfEntry(NamedTuple): name: str @@ -36,9 +38,10 @@ def remove_suffix(s: str, suffix: str, /) -> str: # TODO: make it work with shell program such as vim. def edit_file(file_path, prefix=CONF_DIR): path = prefix + file_path - editor = get_settings().value("text_editor", "", str) - if editor == "": - editor = "gedit" + editor = "" + for editor in [get_settings().value("text_editor", "", str), *EDITORS]: + if which(editor) is not None: + break try: subprocess.Popen([editor, path]) except Exception as e: