# Copyright (C) 2008-2022 The Paparazzi Team # released under GNU GPLv2 or later. See COPYING file. import os import subprocess from PyQt5.QtWidgets import * from typing import NamedTuple from PyQt5.QtCore import QSettings import subprocess class GConfEntry(NamedTuple): name: str value: str application: str PAPARAZZI_SRC = os.getenv("PAPARAZZI_HOME") PAPARAZZI_HOME = os.getenv("PAPARAZZI_HOME", PAPARAZZI_SRC) CONF_DIR = os.path.join(PAPARAZZI_HOME, "conf/") def remove_prefix(string: str, prefix: str, /) -> str: if string.startswith(prefix): return string[len(prefix):] else: return string[:] def remove_suffix(s: str, suffix: str, /) -> str: if s.endswith(suffix): return s[:-len(suffix)] else: return s # 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" try: subprocess.Popen([editor, path]) except Exception as e: print(e) def make_line(parent: QWidget = None, vertical=False) -> QWidget: line = QFrame(parent) if vertical: line.setFrameShape(QFrame.VLine) else: line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) return line def get_version() -> str: run_version_exe = os.path.join(PAPARAZZI_HOME, "paparazzi_version") proc = subprocess.run(run_version_exe, cwd=PAPARAZZI_HOME, capture_output=True) return proc.stdout.decode().strip() def get_build_version() -> str: bv_path = os.path.join(PAPARAZZI_HOME, "var", "build_version.txt") with open(bv_path, 'r') as f: version = f.readline().strip() return version def get_shell(): p = subprocess.run(['getent', 'passwd', os.getenv('LOGNAME')], capture_output=True) shell = p.stdout.decode().strip().split(':')[6] return shell def open_terminal(wd): terminal_emulator = get_settings().value("terminal_emulator", "", str) if terminal_emulator == "": terminal_emulator = "x-terminal-emulator" shell = get_shell() subprocess.Popen([terminal_emulator, '-e', shell, '--rcfile', 'conf/system/term_init.sh'], cwd=wd) def get_settings() -> QSettings: return QSettings(os.path.join(CONF_DIR, "pprz_center_settings.ini"), QSettings.IniFormat) ABOUT_TEXT = \ """
The Paparazzi Center is the home application for Paparazzi UAV. Learn more about Paparazzi:
Copyright (C) 2008-2022 The Paparazzi Team
Paparazzi Center is part of the Paparazzi, released under GPLv2 or any later version.
See the file COPYING,
or the licence information at http://www.gnu.org/licenses/.
This software uses:
""".format(PAPARAZZI_HOME)