diff --git a/MethodicConfigurator/annotate_params.py b/MethodicConfigurator/annotate_params.py index b2231be..4b66ea7 100755 --- a/MethodicConfigurator/annotate_params.py +++ b/MethodicConfigurator/annotate_params.py @@ -24,6 +24,7 @@ from os import path as os_path from os import popen as os_popen +from MethodicConfigurator.internationalization import _ import glob import re @@ -51,8 +52,8 @@ def arg_parser(): - parser = argparse.ArgumentParser(description=_('Fetches on-line ArduPilot parameter documentation and adds it to the ') - _('specified file or to all *.param and *.parm files in the specified directory.')) + parser = argparse.ArgumentParser(description=_('Fetches on-line ArduPilot parameter documentation and adds it to the ' + 'specified file or to all *.param and *.parm files in the specified directory.')) parser.add_argument('target', help=_('The target file or directory.'), ) @@ -341,7 +342,7 @@ def get_xml_data(base_url: str, directory: str, filename: str, vehicle_type: str url = base_url + filename response = requests_get(url, timeout=5) if response.status_code != 200: - logging.warning_("Remote URL: %s"), url) + logging.warning_("Remote URL: %s"), url raise requests_exceptions.RequestException(_(f"HTTP status code {response.status_code}")) except requests_exceptions.RequestException as e: logging.warning(_("Unable to fetch XML data: %s", e)) diff --git a/MethodicConfigurator/ardupilot_methodic_configurator.py b/MethodicConfigurator/ardupilot_methodic_configurator.py index 3e89a3f..a45e8c9 100755 --- a/MethodicConfigurator/ardupilot_methodic_configurator.py +++ b/MethodicConfigurator/ardupilot_methodic_configurator.py @@ -16,7 +16,7 @@ #from logging import warning as logging_warning from logging import error as logging_error from sys import exit as sys_exit - +from MethodicConfigurator.internationalization import _ from MethodicConfigurator.backend_filesystem import LocalFilesystem from MethodicConfigurator.backend_flightcontroller import FlightController @@ -46,16 +46,16 @@ def argument_parser(): Returns: argparse.Namespace: An object containing the parsed arguments. """ - parser = argparse.ArgumentParser(description=_('ArduPilot methodic configurator is a simple GUI with a table that lists ') - _('parameters. The GUI reads intermediate parameter files from a directory and ') - _('displays their parameters in a table. Each row displays the parameter name, ') - _('its current value on the flight controller, its new value from the selected ') - _('intermediate parameter file, and an "Upload" checkbox. The GUI includes "Upload ') - _('selected params to FC" and "Skip" buttons at the bottom. ') - _('When "Upload Selected to FC" is clicked, it uploads the selected parameters to the ') - _('flight controller. ') - _('When "Skip" is pressed, it skips to the next intermediate parameter file. ') - _('The process gets repeated for each intermediate parameter file.')) + parser = argparse.ArgumentParser(description=_('ArduPilot methodic configurator is a simple GUI with a table that lists ' + 'parameters. The GUI reads intermediate parameter files from a directory and ' + 'displays their parameters in a table. Each row displays the parameter name, ' + 'its current value on the flight controller, its new value from the selected ' + 'intermediate parameter file, and an "Upload" checkbox. The GUI includes "Upload ' + 'selected params to FC" and "Skip" buttons at the bottom. ' + 'When "Upload Selected to FC" is clicked, it uploads the selected parameters to the ' + 'flight controller. ' + 'When "Skip" is pressed, it skips to the next intermediate parameter file. ' + 'The process gets repeated for each intermediate parameter file.')) parser = FlightController.add_argparse_arguments(parser) parser = LocalFilesystem.add_argparse_arguments(parser) parser = ComponentEditorWindow.add_argparse_arguments(parser) diff --git a/MethodicConfigurator/argparse_check_range.py b/MethodicConfigurator/argparse_check_range.py index 9e48197..4ae2ba9 100644 --- a/MethodicConfigurator/argparse_check_range.py +++ b/MethodicConfigurator/argparse_check_range.py @@ -16,7 +16,7 @@ from operator import ge from operator import lt from operator import le - +from MethodicConfigurator.internationalization import _ class CheckRange(Action): ''' diff --git a/MethodicConfigurator/backend_filesystem.py b/MethodicConfigurator/backend_filesystem.py index 6ac0353..8722afe 100644 --- a/MethodicConfigurator/backend_filesystem.py +++ b/MethodicConfigurator/backend_filesystem.py @@ -14,7 +14,7 @@ from os import rename as os_rename from platform import system as platform_system - +from MethodicConfigurator.internationalization import _ from shutil import copy2 as shutil_copy2 from shutil import copytree as shutil_copytree @@ -611,16 +611,16 @@ def add_argparse_arguments(parser): parser.add_argument('--vehicle-dir', type=str, default=os_getcwd(), - help=_('Directory containing vehicle-specific intermediate parameter files. ') - _('Defaults to the current working directory')) + help=_('Directory containing vehicle-specific intermediate parameter files. ' + 'Defaults to the current working directory')) parser.add_argument('--n', type=int, default=-1, - help=_('Start directly on the nth intermediate parameter file (skips previous files). ') - _('Default is to start on the file next to the last that you wrote to the flight controller.') - _('If the file does not exist, it will start on the first file.')) + help=_('Start directly on the nth intermediate parameter file (skips previous files). ' + 'Default is to start on the file next to the last that you wrote to the flight controller.' + 'If the file does not exist, it will start on the first file.')) parser.add_argument('--allow-editing-template-files', action='store_true', - help=_('Allow opening and editing template files directly. ') - _('Only for software developers that know what they are doing.')) + help=_('Allow opening and editing template files directly. ' + 'Only for software developers that know what they are doing.')) return parser diff --git a/MethodicConfigurator/backend_filesystem_configuration_steps.py b/MethodicConfigurator/backend_filesystem_configuration_steps.py index 14f3f3f..c8bca51 100644 --- a/MethodicConfigurator/backend_filesystem_configuration_steps.py +++ b/MethodicConfigurator/backend_filesystem_configuration_steps.py @@ -18,7 +18,7 @@ from json import load as json_load from json import JSONDecodeError - +from MethodicConfigurator.internationalization import _ from typing import Tuple from MethodicConfigurator.annotate_params import Par @@ -56,8 +56,8 @@ def re_init(self, vehicle_dir: str, vehicle_type: str): file_found = True if self.log_loaded_file: if i == 0: - logging_warning(_("Configuration steps '%s' loaded from %s ") \ - _("(overwriting default configuration steps)."), + logging_warning(_("Configuration steps '%s' loaded from %s " \ + "(overwriting default configuration steps)."), self.configuration_steps_filename, directory) if i == 1: logging_info(_("Configuration steps '%s' loaded from %s."), @@ -90,12 +90,12 @@ def __validate_parameters_in_configuration_steps(self, filename: str, file_info: return for parameter, parameter_info in file_info[parameter_type + '_parameters'].items(): if "New Value" not in parameter_info: - logging_error(_("Error in file '%s': '%s' %s parameter '%s'") - _(" 'New Value' attribute not found."), + logging_error(_("Error in file '%s': '%s' %s parameter '%s'" + " 'New Value' attribute not found."), self.configuration_steps_filename, filename, parameter_type, parameter) if "Change Reason" not in parameter_info: - logging_error(_("Error in file '%s': '%s' %s parameter '%s'") - _(" 'Change Reason' attribute not found."), + logging_error(_("Error in file '%s': '%s' %s parameter '%s'" + " 'Change Reason' attribute not found."), self.configuration_steps_filename, filename, parameter_type, parameter) def compute_parameters(self, filename: str, file_info: dict, parameter_type: str, variables: dict) -> str: @@ -112,8 +112,8 @@ def compute_parameters(self, filename: str, file_info: dict, parameter_type: str try: if ('fc_parameters' in str(parameter_info["New Value"])) and \ ('fc_parameters' not in variables or variables['fc_parameters'] == {}): - error_msg = f"In file '{self.configuration_steps_filename}': '{filename}' {parameter_type} " \ - _(f"parameter '{parameter}' could not be computed: 'fc_parameters' not found, is an FC connected?") + error_msg = _(f"In file '{self.configuration_steps_filename}': '{filename}' {parameter_type} " \ + f"parameter '{parameter}' could not be computed: 'fc_parameters' not found, is an FC connected?") if parameter_type == 'forced': logging_error(error_msg) return error_msg @@ -136,8 +136,8 @@ def compute_parameters(self, filename: str, file_info: dict, parameter_type: str destination[filename] = {} destination[filename][parameter] = Par(float(result), parameter_info["Change Reason"]) except (SyntaxError, NameError, KeyError, StopIteration) as e: - error_msg = f"In file '{self.configuration_steps_filename}': '{filename}' {parameter_type} " \ - _(f"parameter '{parameter}' could not be computed: {e}") + error_msg = _(f"In file '{self.configuration_steps_filename}': '{filename}' {parameter_type} " \ + f"parameter '{parameter}' could not be computed: {e}") if parameter_type == 'forced': logging_error(error_msg) return error_msg @@ -158,11 +158,11 @@ def get_documentation_text_and_url(self, selected_file: str, prefix_key: str) -> documentation = self.configuration_steps.get(selected_file, {}) if \ self.configuration_steps else None if documentation is None: - text = _(f"File '{self.configuration_steps_filename}' not found. ") \ - _("No intermediate parameter configuration steps available") + text = _(f"File '{self.configuration_steps_filename}' not found. " \ + "No intermediate parameter configuration steps available") url = None else: - text = documentation.get(prefix_key + "_text", _(f"No documentation available for {selected_file} in the ") - _(f"{self.configuration_steps_filename} file")) + text = documentation.get(prefix_key + "_text", _(f"No documentation available for {selected_file} in the " + f"{self.configuration_steps_filename} file")) url = documentation.get(prefix_key + "_url", None) return text, url diff --git a/MethodicConfigurator/backend_filesystem_program_settings.py b/MethodicConfigurator/backend_filesystem_program_settings.py index 5b3f1d4..89dff34 100644 --- a/MethodicConfigurator/backend_filesystem_program_settings.py +++ b/MethodicConfigurator/backend_filesystem_program_settings.py @@ -15,7 +15,7 @@ from re import match as re_match from re import escape as re_escape from re import sub as re_sub - +from MethodicConfigurator.internationalization import _ # from sys import exit as sys_exit from logging import error as logging_error diff --git a/MethodicConfigurator/backend_filesystem_vehicle_components.py b/MethodicConfigurator/backend_filesystem_vehicle_components.py index 1d420cd..fec7b19 100644 --- a/MethodicConfigurator/backend_filesystem_vehicle_components.py +++ b/MethodicConfigurator/backend_filesystem_vehicle_components.py @@ -16,7 +16,7 @@ #from logging import info as logging_info #from logging import warning as logging_warning from logging import error as logging_error - +from MethodicConfigurator.internationalization import _ from re import match as re_match from json import load as json_load diff --git a/MethodicConfigurator/backend_flightcontroller.py b/MethodicConfigurator/backend_flightcontroller.py index 9460d17..d0f6825 100644 --- a/MethodicConfigurator/backend_flightcontroller.py +++ b/MethodicConfigurator/backend_flightcontroller.py @@ -12,7 +12,7 @@ from logging import info as logging_info from logging import warning as logging_warning from logging import error as logging_error - +from MethodicConfigurator.internationalization import _ from time import sleep as time_sleep from time import time as time_time from os import path as os_path @@ -273,9 +273,9 @@ def __create_connection_with_retry(self, progress_callback, retries: int = 3, def __process_autopilot_version(self, m, banner_msgs) -> str: if m is None: - return _("No AUTOPILOT_VERSION MAVLink message received, connection failed.\n") \ - _("Only ArduPilot versions newer than 4.3.8 are supported.\n") \ - _("Make sure parameter SERIAL0_PROTOCOL is set to 2") + return _("No AUTOPILOT_VERSION MAVLink message received, connection failed.\n" \ + "Only ArduPilot versions newer than 4.3.8 are supported.\n" \ + "Make sure parameter SERIAL0_PROTOCOL is set to 2") self.info.set_capabilities(m.capabilities) self.info.set_flight_sw_version(m.flight_sw_version) self.info.set_board_version(m.board_version) @@ -538,6 +538,6 @@ def add_argparse_arguments(parser): max=50, action=CheckRange, default=7, - help=_('Flight controller reboot time. ') - _('Default is %(default)s')) + help=_('Flight controller reboot time. ' + 'Default is %(default)s')) return parser diff --git a/MethodicConfigurator/backend_mavftp.py b/MethodicConfigurator/backend_mavftp.py index 943a6d4..6f5af5d 100644 --- a/MethodicConfigurator/backend_mavftp.py +++ b/MethodicConfigurator/backend_mavftp.py @@ -19,7 +19,7 @@ import time import random import os - +from MethodicConfigurator.internationalization import _ from io import BytesIO as SIO import sys @@ -1332,14 +1332,14 @@ def argument_parser(): This function sets up an argument parser to handle the command-line arguments for the script. """ - parser = ArgumentParser(description=_('MAVFTP - MAVLink File Transfer Protocol https://mavlink.io/en/services/ftp.html') - _(' A tool to do file operations between a ground control station and a drone using the MAVLink') - _(' protocol.')) + parser = ArgumentParser(description=_('MAVFTP - MAVLink File Transfer Protocol https://mavlink.io/en/services/ftp.html' + ' A tool to do file operations between a ground control station and a drone using the MAVLink' + ' protocol.')) parser.add_argument("--baudrate", type=int, default=115200, help=_("master port baud rate. Defaults to %(default)s")) parser.add_argument("--device", type=str, default='', - help=_("serial device. For windows use COMx where x is the port number. ") - _("For Unix use /dev/ttyUSBx where x is the port number. Defaults to autodetection")) + help=_("serial device. For windows use COMx where x is the port number. " + "For Unix use /dev/ttyUSBx where x is the port number. Defaults to autodetection")) parser.add_argument("--source-system", type=int, default=250, help=_('MAVLink source system for this GCS. Defaults to %(default)s')) parser.add_argument("--loglevel", default="INFO", diff --git a/MethodicConfigurator/common_arguments.py b/MethodicConfigurator/common_arguments.py index bb43b22..638b1b5 100644 --- a/MethodicConfigurator/common_arguments.py +++ b/MethodicConfigurator/common_arguments.py @@ -9,7 +9,7 @@ ''' from MethodicConfigurator.version import VERSION - +from MethodicConfigurator.internationalization import _ def add_common_arguments_and_parse(parser): parser.add_argument('--loglevel', diff --git a/MethodicConfigurator/frontend_tkinter_base.py b/MethodicConfigurator/frontend_tkinter_base.py index 5123b98..e55abcc 100644 --- a/MethodicConfigurator/frontend_tkinter_base.py +++ b/MethodicConfigurator/frontend_tkinter_base.py @@ -21,7 +21,7 @@ from logging import error as logging_error from platform import system as platform_system - +from MethodicConfigurator.internationalization import _ from PIL import Image from PIL import ImageTk @@ -39,15 +39,15 @@ def show_error_message(title: str, message: str): def show_no_param_files_error(dirname: str): - error_message = _(f"No intermediate parameter files found in the selected '{dirname}' vehicle directory.\n") \ - _("Please select and step inside a vehicle directory containing valid ArduPilot intermediate parameter files.\n\n") \ - _("Make sure to step inside the directory (double-click) and not just select it.") + error_message = _(f"No intermediate parameter files found in the selected '{dirname}' vehicle directory.\n" \ + "Please select and step inside a vehicle directory containing valid ArduPilot intermediate parameter files.\n\n" \ + "Make sure to step inside the directory (double-click) and not just select it.") show_error_message(_("No Parameter Files Found"), error_message) def show_no_connection_error(error_string: str): - error_message = _(f"{error_string}\n\nPlease connect a flight controller to the PC,\n") \ - _("wait at least 7 seconds and retry.") + error_message = _(f"{error_string}\n\nPlease connect a flight controller to the PC,\n" \ + "wait at least 7 seconds and retry.") show_error_message(_("No Connection to the Flight Controller"), error_message) diff --git a/MethodicConfigurator/frontend_tkinter_component_editor.py b/MethodicConfigurator/frontend_tkinter_component_editor.py index 7f5fa79..53e6512 100644 --- a/MethodicConfigurator/frontend_tkinter_component_editor.py +++ b/MethodicConfigurator/frontend_tkinter_component_editor.py @@ -15,7 +15,7 @@ # from logging import debug as logging_debug #from logging import info as logging_info from logging import error as logging_error - +from MethodicConfigurator.internationalization import _ import tkinter as tk from tkinter import ttk from math import log2 @@ -45,8 +45,8 @@ def argument_parser(): Returns: argparse.Namespace: An object containing the parsed arguments. """ - parser = ArgumentParser(description=_('A GUI for editing JSON files that contain vehicle component configurations. ') - _('Not to be used directly, but through the main ArduPilot methodic configurator script.')) + parser = ArgumentParser(description=_('A GUI for editing JSON files that contain vehicle component configurations. ' + 'Not to be used directly, but through the main ArduPilot methodic configurator script.')) parser = LocalFilesystem.add_argparse_arguments(parser) parser = ComponentEditorWindow.add_argparse_arguments(parser) return add_common_arguments_and_parse(parser) @@ -548,8 +548,8 @@ def validate_combobox(self, event, path) -> bool: if value not in allowed_values: if event.type == "10": # FocusOut events - show_error_message(_("Error"), _(f"Invalid value '{value}' for {'>'.join(list(path))}\n") - _(f"Allowed values are: {', '.join(allowed_values)}")) + show_error_message(_("Error"), _(f"Invalid value '{value}' for {'>'.join(list(path))}\n" + f"Allowed values are: {', '.join(allowed_values)}")) combobox.configure(style="comb_input_invalid.TCombobox") return False @@ -592,25 +592,25 @@ def validate_cell_voltage(self, event, entry, path): # pylint: disable=too-many if is_focusout_event: entry.delete(0, tk.END) entry.insert(0, BatteryCell.limit_min_voltage(chemistry)) - raise VoltageTooLowError(_(f"is below the {chemistry} minimum limit of ") - f"{BatteryCell.limit_min_voltage(chemistry)}") + raise VoltageTooLowError(_(f"is below the {chemistry} minimum limit of " + f"{BatteryCell.limit_min_voltage(chemistry)}")) if voltage > BatteryCell.limit_max_voltage(chemistry): if is_focusout_event: entry.delete(0, tk.END) entry.insert(0, BatteryCell.limit_max_voltage(chemistry)) - raise VoltageTooHighError(_(f"is above the {chemistry} maximum limit of ") - f"{BatteryCell.limit_max_voltage(chemistry)}") + raise VoltageTooHighError(_(f"is above the {chemistry} maximum limit of " + f"{BatteryCell.limit_max_voltage(chemistry)}")) except (VoltageTooLowError, VoltageTooHighError) as e: if is_focusout_event: - show_error_message(_("Error"), _(f"Invalid value '{value}' for {'>'.join(list(path))}\n") - f"{e}") + show_error_message(_("Error"), _(f"Invalid value '{value}' for {'>'.join(list(path))}\n" + f"{e}")) else: entry.configure(style="entry_input_invalid.TEntry") return False except ValueError as e: if is_focusout_event: - show_error_message(_("Error"), _(f"Invalid value '{value}' for {'>'.join(list(path))}\n") - _(f"{e}\nWill be set to the recommended value.")) + show_error_message(_("Error"), _(f"Invalid value '{value}' for {'>'.join(list(path))}\n" + f"{e}\nWill be set to the recommended value.")) entry.delete(0, tk.END) if path[-1] == "Volt per cell max": entry.insert(0, str(BatteryCell.recommended_max_voltage(chemistry))) @@ -642,8 +642,8 @@ def validate_data(self): # pylint: disable=too-many-branches if path == ('ESC', 'FC Connection', 'Type'): self.update_esc_protocol_combobox_entries(value) if value not in entry.cget("values"): - show_error_message(_("Error"), _(f"Invalid value '{value}' for {'>'.join(list(path))}\n") - _(f"Allowed values are: {', '.join(entry.cget('values'))}")) + show_error_message(_("Error"), _(f"Invalid value '{value}' for {'>'.join(list(path))}\n" + f"Allowed values are: {', '.join(entry.cget('values'))}")) entry.configure(style="comb_input_invalid.TCombobox") invalid_values = True continue @@ -676,7 +676,7 @@ def validate_data(self): # pylint: disable=too-many-branches invalid_values = True if path == ('Battery', 'Specifications', 'Volt per cell low'): if value >= self.entry_widgets[('Battery', 'Specifications', 'Volt per cell max')].get(): - show_error_message_("Error"), _("Battery Cell Low voltage must be lower than max voltage")) + show_error_message_("Error"), _("Battery Cell Low voltage must be lower than max voltage") entry.configure(style="entry_input_invalid.TEntry") invalid_values = True if path == ('Battery', 'Specifications', 'Volt per cell crit'): diff --git a/MethodicConfigurator/frontend_tkinter_component_editor_base.py b/MethodicConfigurator/frontend_tkinter_component_editor_base.py index f1e764a..cf6d0d1 100644 --- a/MethodicConfigurator/frontend_tkinter_component_editor_base.py +++ b/MethodicConfigurator/frontend_tkinter_component_editor_base.py @@ -19,7 +19,7 @@ from tkinter import ttk from MethodicConfigurator.common_arguments import add_common_arguments_and_parse - +from MethodicConfigurator.internationalization import _ from MethodicConfigurator.backend_filesystem import LocalFilesystem from MethodicConfigurator.frontend_tkinter_base import show_tooltip @@ -39,8 +39,8 @@ def argument_parser(): Returns: argparse.Namespace: An object containing the parsed arguments. """ - parser = ArgumentParser(description=_('A GUI for editing JSON files that contain vehicle component configurations. ') - _('Not to be used directly, but through the main ArduPilot methodic configurator script.')) + parser = ArgumentParser(description=_('A GUI for editing JSON files that contain vehicle component configurations. ' + 'Not to be used directly, but through the main ArduPilot methodic configurator script.')) parser = LocalFilesystem.add_argparse_arguments(parser) parser = ComponentEditorWindowBase.add_argparse_arguments(parser) return add_common_arguments_and_parse(parser) diff --git a/MethodicConfigurator/frontend_tkinter_connection_selection.py b/MethodicConfigurator/frontend_tkinter_connection_selection.py index 79d43fb..39b6d39 100644 --- a/MethodicConfigurator/frontend_tkinter_connection_selection.py +++ b/MethodicConfigurator/frontend_tkinter_connection_selection.py @@ -17,7 +17,7 @@ from logging import debug as logging_debug from logging import warning as logging_warning from logging import critical as logging_critical - +from MethodicConfigurator.internationalization import _ import tkinter as tk from tkinter import ttk from tkinter import simpledialog @@ -121,8 +121,8 @@ def __init__(self, parent, parent_frame, flight_controller: FlightController, # state='readonly') self.conn_selection_combobox.bind("<>", self.on_select_connection_combobox_change) self.conn_selection_combobox.pack(side=tk.TOP, pady=(4, 0)) - show_tooltip(self.conn_selection_combobox, _("Select the flight controller connection\nYou can add a custom connection ") - _("to the existing ones")) + show_tooltip(self.conn_selection_combobox, _("Select the flight controller connection\nYou can add a custom connection " + "to the existing ones")) def on_select_connection_combobox_change(self, _event): selected_connection = self.conn_selection_combobox.get_selected_key() @@ -138,11 +138,11 @@ def on_select_connection_combobox_change(self, _event): def add_connection(self): # Open the connection selection dialog selected_connection = simpledialog.askstring(_("Flight Controller Connection"), - _("Enter the connection string to the flight controller. ") - _("Examples are:\n\nCOM4 (on windows)\n") + _("Enter the connection string to the flight controller. " + "Examples are:\n\nCOM4 (on windows)\n" "/dev/serial/by-id/usb-xxx (on linux)\n" "tcp:127.0.0.1:5761\n" - "udp:127.0.0.1:14551") + "udp:127.0.0.1:14551")) if selected_connection: logging_debug(_(f"Will add new connection: {selected_connection} if not duplicated")) self.flight_controller.add_connection(selected_connection) @@ -202,9 +202,9 @@ def __init__(self, flight_controller: FlightController, connection_result_string option1_label_frame = ttk.LabelFrame(self.main_frame, labelwidget=option1_label, borderwidth=2, relief="solid") option1_label_frame.pack(expand=False, fill=tk.X, padx=6, pady=6) option1_label = ttk.Label(option1_label_frame, anchor=tk.CENTER, justify=tk.CENTER, - text=_("Connect a flight controller to the PC,\n") - _("wait 7 seconds for it to fully boot and\n") - _("press the Auto-connect button below to connect to it") + text=_("Connect a flight controller to the PC,\n" + "wait 7 seconds for it to fully boot and\n" + "press the Auto-connect button below to connect to it")) option1_label.pack(expand=False, fill=tk.X, padx=6) autoconnect_button = ttk.Button(option1_label_frame, text=_("Auto-connect"), command=self.fc_autoconnect) autoconnect_button.pack(expand=False, fill=tk.X, padx=100, pady=6) @@ -215,9 +215,9 @@ def __init__(self, flight_controller: FlightController, connection_result_string option2_label_frame = ttk.LabelFrame(self.main_frame, labelwidget=option2_label, borderwidth=2, relief="solid") option2_label_frame.pack(expand=False, fill=tk.X, padx=6, pady=6) option2_label = ttk.Label(option2_label_frame, anchor=tk.CENTER, justify=tk.CENTER, - text=_("Connect a flight controller to the PC,\n") - _("wait 7 seconds for it to fully boot and\n") - _("manually select the fight controller connection or add a new one") + text=_("Connect a flight controller to the PC,\n" + "wait 7 seconds for it to fully boot and\n" + "manually select the fight controller connection or add a new one")) option2_label.pack(expand=False, fill=tk.X, padx=6) self.connection_selection_widgets = ConnectionSelectionWidgets(self, option2_label_frame, flight_controller, destroy_parent_on_connect=True, @@ -241,8 +241,8 @@ def __init__(self, flight_controller: FlightController, connection_result_string self.skip_fc_connection(flight_controller)) skip_fc_connection_button.pack(expand=False, fill=tk.X, padx=15, pady=6) show_tooltip(skip_fc_connection_button, - _("No parameter values will be fetched from the FC, default parameter values from disk will be used\n") - _("instead (if '00_default.param' file is present) and just edit the intermediate '.param' files on disk")) + _("No parameter values will be fetched from the FC, default parameter values from disk will be used\n" + "instead (if '00_default.param' file is present) and just edit the intermediate '.param' files on disk")) # Bind the close_connection_and_quit function to the window close event self.root.protocol("WM_DELETE_WINDOW", self.close_and_quit) @@ -269,8 +269,8 @@ def argument_parser(): Returns: argparse.Namespace: An object containing the parsed arguments. """ - parser = ArgumentParser(description=_('This main is for testing and development only. ') - _('Usually, the ConnectionSelectionWidgets is called from another script')) + parser = ArgumentParser(description=_('This main is for testing and development only. ' + 'Usually, the ConnectionSelectionWidgets is called from another script')) parser = FlightController.add_argparse_arguments(parser) return add_common_arguments_and_parse(parser) @@ -280,8 +280,8 @@ def main(): logging_basicConfig(level=logging_getLevelName(args.loglevel), format='%(asctime)s - %(levelname)s - %(message)s') - logging_warning(_("This main is for testing and development only, usually the ConnectionSelectionWindow is called from ") - _("another script")) + logging_warning(_("This main is for testing and development only, usually the ConnectionSelectionWindow is called from " + "another script")) flight_controller = FlightController(args.reboot_time) # Initialize your FlightController instance result = flight_controller.connect(device=args.device) # Connect to the flight controller diff --git a/MethodicConfigurator/frontend_tkinter_directory_selection.py b/MethodicConfigurator/frontend_tkinter_directory_selection.py index ae45939..7399545 100644 --- a/MethodicConfigurator/frontend_tkinter_directory_selection.py +++ b/MethodicConfigurator/frontend_tkinter_directory_selection.py @@ -25,7 +25,7 @@ from tkinter import messagebox from tkinter import ttk from tkinter import filedialog - +from MethodicConfigurator.internationalization import _ from MethodicConfigurator.version import VERSION from MethodicConfigurator.common_arguments import add_common_arguments_and_parse @@ -152,10 +152,10 @@ def __init__(self, parent: ttk, parent_frame: ttk.Frame, # pylint: disable=too- # Call the parent constructor with the necessary arguments super().__init__(parent, parent_frame, initial_dir, _("Vehicle configuration directory:"), False, - _("Vehicle-specific directory containing the intermediate\n") - _("parameter files to be uploaded to the flight controller"), - _("Select the vehicle-specific configuration directory containing the\n") - _("intermediate parameter files to be uploaded to the flight controller") \ + _("Vehicle-specific directory containing the intermediate\n" + "parameter files to be uploaded to the flight controller"), + _("Select the vehicle-specific configuration directory containing the\n" + "intermediate parameter files to be uploaded to the flight controller") \ if destroy_parent_on_open else '', False) self.local_filesystem = local_filesystem @@ -166,15 +166,15 @@ def on_select_directory(self): if super().on_select_directory(): if "vehicle_templates" in self.directory and not self.local_filesystem.allow_editing_template_files: messagebox.showerror(_("Invalid Vehicle Directory Selected"), - _("Please do not edit the files provided 'vehicle_templates' directory\n") - _("as those are used as a template for new vehicles")) + _("Please do not edit the files provided 'vehicle_templates' directory\n" + "as those are used as a template for new vehicles")) return self.local_filesystem.vehicle_dir = self.directory if not self.local_filesystem.vehicle_configuration_files_exist(self.directory): messagebox.showerror(_("Invalid Vehicle Directory Selected"), - _("Selected directory must contain files matching \\d\\d_*\\.param ") \ - _(f"and a {self.local_filesystem.vehicle_components_json_filename} file")) + _("Selected directory must contain files matching \\d\\d_*\\.param " \ + f"and a {self.local_filesystem.vehicle_components_json_filename} file")) return try: @@ -241,10 +241,10 @@ def create_option1_widgets(self, initial_template_dir: str, initial_base_dir: st option1_label = ttk.Label(text=_("New"), style="Bold.TLabel") option1_label_frame = ttk.LabelFrame(self.main_frame, labelwidget=option1_label, borderwidth=2, relief="solid") option1_label_frame.pack(expand=True, fill=tk.X, padx=6, pady=6) - template_dir_edit_tooltip = _("Existing vehicle template directory containing the intermediate\n") \ - _("parameter files to be copied to the new vehicle configuration directory") - template_dir_btn_tooltip = _("Select the existing vehicle template directory containing the intermediate\n") \ - _("parameter files to be copied to the new vehicle configuration directory") + template_dir_edit_tooltip = _("Existing vehicle template directory containing the intermediate\n" \ + "parameter files to be copied to the new vehicle configuration directory") + template_dir_btn_tooltip = _("Select the existing vehicle template directory containing the intermediate\n" \ + "parameter files to be copied to the new vehicle configuration directory") self.template_dir = DirectorySelectionWidgets(self, option1_label_frame, initial_template_dir, _("Source Template directory:"), False, @@ -257,9 +257,9 @@ def create_option1_widgets(self, initial_template_dir: str, initial_base_dir: st text=_("Use parameter values from connected FC, not from template files")) use_fc_params_checkbox.pack(anchor=tk.NW) show_tooltip(use_fc_params_checkbox, - _("Use the parameter values from the connected flight controller instead of the\n") \ - _("template files when creating a new vehicle configuration directory from a template.\n") \ - _("This option is only available when a flight controller is connected")) + _("Use the parameter values from the connected flight controller instead of the\n" \ + "template files when creating a new vehicle configuration directory from a template.\n" \ + "This option is only available when a flight controller is connected")) if not fc_connected: self.use_fc_params.set(False) use_fc_params_checkbox.config(state=tk.DISABLED) @@ -273,8 +273,8 @@ def create_option1_widgets(self, initial_template_dir: str, initial_base_dir: st new_base_dir_btn_tooltip, False) self.new_base_dir.container_frame.pack(expand=False, fill=tk.X, padx=3, pady=5, anchor=tk.NW) - new_dir_edit_tooltip = _("A new vehicle configuration directory with this name will be created at the ") \ - _("(destination) base directory") + new_dir_edit_tooltip = _("A new vehicle configuration directory with this name will be created at the " \ + "(destination) base directory") self.new_dir = DirectoryNameWidgets(option1_label_frame, initial_new_dir, _("Destination new vehicle name:"), new_dir_edit_tooltip) @@ -284,9 +284,9 @@ def create_option1_widgets(self, initial_template_dir: str, initial_base_dir: st command=self.create_new_vehicle_from_template) create_vehicle_directory_from_template_button.pack(expand=False, fill=tk.X, padx=20, pady=5, anchor=tk.CENTER) show_tooltip(create_vehicle_directory_from_template_button, - _("Create a new vehicle configuration directory on the (destination) base directory,\n") - _("copy the template files from the (source) template directory to it and\n") - _("load the newly created files into the application")) + _("Create a new vehicle configuration directory on the (destination) base directory,\n" + "copy the template files from the (source) template directory to it and\n" + "load the newly created files into the application")) def create_option2_widgets(self, initial_dir: str): # Option 2 - Use an existing vehicle configuration directory @@ -294,8 +294,8 @@ def create_option2_widgets(self, initial_dir: str): option2_label_frame = ttk.LabelFrame(self.main_frame, labelwidget=option2_label, borderwidth=2, relief="solid") option2_label_frame.pack(expand=True, fill=tk.X, padx=6, pady=6) option2_label = ttk.Label(option2_label_frame, anchor=tk.CENTER, justify=tk.CENTER, - text=_("Use an existing vehicle configuration directory with\n") \ - _("intermediate parameter files, apm.pdef.xml and vehicle_components.json")) + text=_("Use an existing vehicle configuration directory with\n" \ + "intermediate parameter files, apm.pdef.xml and vehicle_components.json")) option2_label.pack(expand=False, fill=tk.X, padx=6) self.connection_selection_widgets = VehicleDirectorySelectionWidgets(self, option2_label_frame, self.local_filesystem, @@ -401,8 +401,8 @@ def open_last_vehicle_directory(self, last_vehicle_dir: str): else: # If no last opened directory is found, display a message to the user messagebox.showerror(_("No Last Vehicle Directory Found"), - _("No last opened vehicle configuration directory was found.\n") \ - _("Please select a directory manually.")) + _("No last opened vehicle configuration directory was found.\n" \ + "Please select a directory manually.")) def argument_parser(): """ @@ -413,8 +413,8 @@ def argument_parser(): Returns: argparse.Namespace: An object containing the parsed arguments. """ - parser = ArgumentParser(description=_('This main is for testing and development only. ') - _('Usually, the VehicleDirectorySelectionWindow is called from another script')) + parser = ArgumentParser(description=_('This main is for testing and development only. ' + 'Usually, the VehicleDirectorySelectionWindow is called from another script')) parser = LocalFilesystem.add_argparse_arguments(parser) return add_common_arguments_and_parse(parser) @@ -424,8 +424,8 @@ def main(): logging_basicConfig(level=logging_getLevelName(args.loglevel), format='%(asctime)s - %(levelname)s - %(message)s') - logging_warning(_("This main is for testing and development only, usually the VehicleDirectorySelectionWindow is") - _(" called from another script")) + logging_warning(_("This main is for testing and development only, usually the VehicleDirectorySelectionWindow is" + " called from another script")) local_filesystem = LocalFilesystem(args.vehicle_dir, args.vehicle_type, None, args.allow_editing_template_files) diff --git a/MethodicConfigurator/frontend_tkinter_parameter_editor.py b/MethodicConfigurator/frontend_tkinter_parameter_editor.py index 148257e..f23888f 100644 --- a/MethodicConfigurator/frontend_tkinter_parameter_editor.py +++ b/MethodicConfigurator/frontend_tkinter_parameter_editor.py @@ -22,7 +22,7 @@ from logging import warning as logging_warning from logging import error as logging_error #from logging import critical as logging_critical - +from MethodicConfigurator.internationalization import _ from typing import List from typing import Tuple @@ -82,8 +82,8 @@ def __create_documentation_frame(self): descriptive_tooltips = [_("ArduPilot's forum Methodic configuration Blog post relevant for the current file"), _("ArduPilot's wiki page relevant for the current file"), _("External tool or documentation relevant for the current file"), - _("Mandatory level of the current file,\n 100% you MUST use this file to configure the ") - _("vehicle,\n 0% you can ignore this file if it does not apply to your vehicle")] + _("Mandatory level of the current file,\n 100% you MUST use this file to configure the " + "vehicle,\n 0% you can ignore this file if it does not apply to your vehicle")] for i, text in enumerate(descriptive_texts): # Create labels for the first column with static descriptive text label = ttk.Label(documentation_grid, text=text) @@ -139,10 +139,10 @@ def show_about_window(root, version: str): main_frame.pack(expand=True, fill=tk.BOTH) # Add the "About" message - about_message = _(f"ArduPilot Methodic Configurator Version: {version}\n\n") \ - _("A clear configuration sequence for ArduPilot vehicles.\n\n") \ - _("Copyright © 2024 Amilcar do Carmo Lucas and ArduPilot.org\n\n") \ - _("Licensed under the GNU General Public License v3.0") + about_message = _(f"ArduPilot Methodic Configurator Version: {version}\n\n" \ + "A clear configuration sequence for ArduPilot vehicles.\n\n" \ + "Copyright © 2024 Amilcar do Carmo Lucas and ArduPilot.org\n\n" \ + "Licensed under the GNU General Public License v3.0") about_label = ttk.Label(main_frame, text=about_message, wraplength=450) about_label.grid(column=0, row=0, padx=10, pady=10, columnspan=5) # Span across all columns @@ -255,10 +255,10 @@ def __create_conf_widgets(self, version: str): self.file_selection_combobox = AutoResizeCombobox(file_selection_frame, list(self.local_filesystem.file_parameters.keys()), self.current_file, - _("Select the intermediate parameter file from the list of available ") - _("files in the selected vehicle directory\nIt will automatically ") - _("advance to the next file once the current file is uploaded to the ") - _("fight controller"), + _("Select the intermediate parameter file from the list of available " + "files in the selected vehicle directory\nIt will automatically " + "advance to the next file once the current file is uploaded to the " + "fight controller"), state='readonly', width=45, style='readonly.TCombobox') self.file_selection_combobox.bind("<>", self.on_param_file_combobox_change) self.file_selection_combobox.pack(side=tk.TOP, anchor=tk.NW, pady=(4, 0)) @@ -319,31 +319,31 @@ def __create_parameter_area_widgets(self): variable=self.show_only_differences, command=self.on_show_only_changed_checkbox_change) only_changed_checkbox.pack(side=tk.TOP, anchor=tk.NW) - show_tooltip(only_changed_checkbox, _("Toggle to show only parameters that will change if/when uploaded to the flight ") - _("controller")) + show_tooltip(only_changed_checkbox, _("Toggle to show only parameters that will change if/when uploaded to the flight " + "controller")) annotate_params_checkbox = ttk.Checkbutton(checkboxes_frame, text=_("Annotate docs into .param files"), state='normal' if self.local_filesystem.doc_dict else 'disabled', variable=self.annotate_params_into_files) annotate_params_checkbox.pack(side=tk.TOP, anchor=tk.NW) - show_tooltip(annotate_params_checkbox, _("Annotate ArduPilot parameter documentation metadata into the intermediate ") - _("parameter files\n") - _("The files will be bigger, but all the existing parameter documentation will be included inside")) + show_tooltip(annotate_params_checkbox, _("Annotate ArduPilot parameter documentation metadata into the intermediate " + "parameter files\n" + "The files will be bigger, but all the existing parameter documentation will be included inside")) # Create upload button upload_selected_button = ttk.Button(buttons_frame, text=_("Upload selected params to FC, and advance to next param file"), command=self.on_upload_selected_click) upload_selected_button.configure(state='normal' if self.flight_controller.master else 'disabled') upload_selected_button.pack(side=tk.LEFT, padx=(8, 8)) # Add padding on both sides of the upload selected button - show_tooltip(upload_selected_button, _("Upload selected parameters to the flight controller and advance to the next ") - _("intermediate parameter file\nIf changes have been made to the current file it will ask if you want ") - _("to save them\nIt will reset the FC if necessary, re-download all parameters and validate their value")) + show_tooltip(upload_selected_button, _("Upload selected parameters to the flight controller and advance to the next " + "intermediate parameter file\nIf changes have been made to the current file it will ask if you want " + "to save them\nIt will reset the FC if necessary, re-download all parameters and validate their value")) # Create skip button skip_button = ttk.Button(buttons_frame, text=_("Skip parameter file"), command=self.on_skip_click) skip_button.pack(side=tk.RIGHT, padx=(8, 8)) # Add right padding to the skip button - show_tooltip(skip_button, _("Skip to the next intermediate parameter file without uploading any changes to the flight ") - _("controller\nIf changes have been made to the current file it will ask if you want to save them")) + show_tooltip(skip_button, _("Skip to the next intermediate parameter file without uploading any changes to the flight " + "controller\nIf changes have been made to the current file it will ask if you want to save them")) @staticmethod def __please_read_the_docs(parent: tk.Tk): @@ -398,15 +398,15 @@ def __do_tempcal_imu(self, selected_file:str): self.local_filesystem.tempcal_imu_result_param_tuple() if selected_file == tempcal_imu_result_param_filename: if messagebox.askyesno(_("IMU temperature calibration"), - _(f"If you proceed the {tempcal_imu_result_param_filename}\n") - _("will be overwritten with the new calibration results.\n") - _("Do you want to provide a .bin log file and\n") - _("run the IMU temperature calibration using it?")): + _(f"If you proceed the {tempcal_imu_result_param_filename}\n" + "will be overwritten with the new calibration results.\n" + "Do you want to provide a .bin log file and\n" + "run the IMU temperature calibration using it?")): # file selection dialog to select the *.bin file to be used in the IMUfit temperature calibration filename = filedialog.askopenfilename(filetypes=[(_("ArduPilot binary log files", ["*.bin", "*.BIN"]))]) if filename: - messagebox.showwarning(_("IMU temperature calibration"), _("Please wait, this can take a really long time and\n") - _("the GUI will be unresponsive until it finishes.")) + messagebox.showwarning(_("IMU temperature calibration"), _("Please wait, this can take a really long time and\n" + "the GUI will be unresponsive until it finishes.")) self.tempcal_imu_progress_window = ProgressWindow(self.main_frame, _("Reading IMU calibration messages"), _("Please wait, this can take a long time")) # Pass the selected filename to the IMUfit class @@ -424,10 +424,10 @@ def __should_copy_fc_values_to_file(self, selected_file: str): auto_changed_by = self.local_filesystem.auto_changed_by(selected_file) if auto_changed_by and self.flight_controller.fc_parameters: if messagebox.askyesno(_("Update file with values from FC?"), - _("This configuration step should be performed outside this tool by\n") + _("This configuration step should be performed outside this tool by\n" f"{auto_changed_by}\n" - _("and that should have changed the parameters on the FC.\n\n") - _(f"Should the FC values now be copied to the {selected_file} file?")): + "and that should have changed the parameters on the FC.\n\n" + f"Should the FC values now be copied to the {selected_file} file?")): relevant_fc_params = {key: value for key, value in self.flight_controller.fc_parameters.items() \ if key in self.local_filesystem.file_parameters[selected_file]} params_copied = self.local_filesystem.copy_fc_values_to_file(selected_file, relevant_fc_params) @@ -467,8 +467,8 @@ def __should_upload_file_to_fc(self, selected_file: str): if not self.flight_controller.upload_file(local_filename, remote_filename, self.file_upload_progress_window.update_progress_bar): messagebox.showerror(_("Upload failed"), - _(f"Failed to upload {local_filename} to {remote_filename},") \ - _(" please upload it manually")) + _(f"Failed to upload {local_filename} to {remote_filename}," \ + " please upload it manually")) self.file_upload_progress_window.destroy() else: logging_warning(_("No flight controller connection, will not upload any file")) @@ -563,8 +563,8 @@ def __reset_and_reconnect(self, fc_reset_required, fc_reset_unsure): if not fc_reset_required: if fc_reset_unsure: # Ask the user if they want to reset the ArduPilot - fc_reset_required = messagebox.askyesno(_("Possible reset required"), _(f"{(', ').join(fc_reset_unsure)} parameter") - _("(s) potentially require a reset\nDo you want to reset the ArduPilot?")) + fc_reset_required = messagebox.askyesno(_("Possible reset required"), _(f"{(', ').join(fc_reset_unsure)} parameter" + "(s) potentially require a reset\nDo you want to reset the ArduPilot?")) if fc_reset_required: self.reset_progress_window = ProgressWindow(self.main_frame, _("Resetting Flight Controller"), @@ -636,8 +636,8 @@ def upload_selected_params(self, selected_params): if param_upload_error: if messagebox.askretrycancel(_("Parameter upload error"), - _("Failed to upload the following parameters to the flight controller:\n") - f"{(', ').join(param_upload_error)}"): + _("Failed to upload the following parameters to the flight controller:\n" + f"{(', ').join(param_upload_error)}")): self.upload_selected_params(selected_params) else: logging_info(_("All parameters uploaded to the flight controller successfully")) @@ -688,14 +688,14 @@ def write_summary_files(self): nr_unchanged_params = len(annotated_fc_parameters) - len(non_default__read_only_params) - \ len(non_default__writable_calibrations) - len(non_default__writable_non_calibrations) # If there are no more files, present a summary message box - summary_message = _(f"Methodic configuration of {len(annotated_fc_parameters)} parameters complete:\n\n" )\ - _(f"{nr_unchanged_params} kept their default value\n\n") \ - _(f"{len(non_default__read_only_params)} non-default read-only parameters - ") \ - _("ignore these, you can not change them\n\n") \ - _(f"{len(non_default__writable_calibrations)} non-default writable sensor-calibrations - ") \ - _("non-reusable between vehicles\n\n") \ - _(f"{len(non_default__writable_non_calibrations)} non-default writable non-sensor-calibrations - ") \ - _("these can be reused between similar vehicles") + summary_message = _(f"Methodic configuration of {len(annotated_fc_parameters)} parameters complete:\n\n" \ + f"{nr_unchanged_params} kept their default value\n\n" \ + f"{len(non_default__read_only_params)} non-default read-only parameters - " \ + "ignore these, you can not change them\n\n" \ + f"{len(non_default__writable_calibrations)} non-default writable sensor-calibrations - " \ + "non-reusable between vehicles\n\n" \ + f"{len(non_default__writable_non_calibrations)} non-default writable non-sensor-calibrations - " \ + "these can be reused between similar vehicles") messagebox.showinfo(_("Last parameter file processed"), summary_message) wrote_complete = self.write_summary_file(annotated_fc_parameters, "complete.param", False) @@ -731,9 +731,9 @@ def write_zip_file(self, files_to_zip: List[Tuple[bool, str]]): _(f"{zip_file_path} file already exists.\nDo you want to overwrite it?")) if should_write_file: self.local_filesystem.zip_files(files_to_zip) - messagebox.showinfo(_("Parameter files zipped"), _("All relevant files have been zipped into the \n") - _(f"{zip_file_path} file.\n\nYou can now upload this file to the ArduPilot Methodic\n") - _("Configuration Blog post on discuss.ardupilot.org.")) + messagebox.showinfo(_("Parameter files zipped"), _("All relevant files have been zipped into the \n" + f"{zip_file_path} file.\n\nYou can now upload this file to the ArduPilot Methodic\n" + "Configuration Blog post on discuss.ardupilot.org.")) return should_write_file def close_connection_and_quit(self): @@ -745,8 +745,8 @@ def close_connection_and_quit(self): def add_argparse_arguments(parser): parser.add_argument('--skip-welcome-popup', action='store_true', - help=_('Skip the welcome popup window. Only use this if you already know how to use the software. ') - _('Default to false')) + help=_('Skip the welcome popup window. Only use this if you already know how to use the software. ' + 'Default to false')) return parser @@ -759,8 +759,8 @@ def argument_parser(): Returns: argparse.Namespace: An object containing the parsed arguments. """ - parser = ArgumentParser(description=_('A GUI for editing ArduPilot param files. ') - _('Not to be used directly, but through the main ArduPilot methodic configurator script.')) + parser = ArgumentParser(description=_('A GUI for editing ArduPilot param files. ' + 'Not to be used directly, but through the main ArduPilot methodic configurator script.')) parser = FlightController.add_argparse_arguments(parser) parser = LocalFilesystem.add_argparse_arguments(parser) parser = ParameterEditorWindow.add_argparse_arguments(parser) diff --git a/MethodicConfigurator/frontend_tkinter_parameter_editor_table.py b/MethodicConfigurator/frontend_tkinter_parameter_editor_table.py index 9f87674..a1a27cc 100644 --- a/MethodicConfigurator/frontend_tkinter_parameter_editor_table.py +++ b/MethodicConfigurator/frontend_tkinter_parameter_editor_table.py @@ -19,7 +19,7 @@ #from logging import warning as logging_warning #from logging import error as logging_error from logging import critical as logging_critical - +from MethodicConfigurator.internationalization import _ from platform import system as platform_system #from MethodicConfigurator.backend_filesystem import LocalFilesystem @@ -531,13 +531,13 @@ def __on_parameter_value_change(self, event, current_file, param_name): if changed: if p_min and p < p_min: if not messagebox.askyesno(_("Out-of-bounds Value"), - _(f"The value for {param_name} {p} should be greater than {p_min}\n") - _("Use out-of-bounds value?"), icon='warning'): + _(f"The value for {param_name} {p} should be greater than {p_min}\n" + "Use out-of-bounds value?"), icon='warning'): valid = False if p_max and p > p_max: if not messagebox.askyesno(_("Out-of-bounds Value"), - _(f"The value for {param_name} {p} should be smaller than {p_max}\n") - _("Use out-of-bounds value?"), icon='warning'): + _(f"The value for {param_name} {p} should be smaller than {p_max}\n" + "Use out-of-bounds value?"), icon='warning'): valid = False except ValueError: # Optionally, you can handle the invalid value here, for example, by showing an error message @@ -565,8 +565,8 @@ def __on_parameter_change_reason_change(self, event, current_file, param_name): new_value, e, exc_info=True) sys_exit(1) if changed and not self.at_least_one_param_edited: - logging_debug(_("Parameter %s change reason changed from %s to %s, will later ask if change(s) should be saved to ") - _("file."), + logging_debug(_("Parameter %s change reason changed from %s to %s, will later ask if change(s) should be saved to " + "file."), param_name, self.local_filesystem.file_parameters[current_file][param_name].comment, new_value) self.at_least_one_param_edited = changed or self.at_least_one_param_edited # Update the params dictionary with the new value diff --git a/MethodicConfigurator/frontend_tkinter_template_overview.py b/MethodicConfigurator/frontend_tkinter_template_overview.py index a5b556e..63e2368 100644 --- a/MethodicConfigurator/frontend_tkinter_template_overview.py +++ b/MethodicConfigurator/frontend_tkinter_template_overview.py @@ -14,7 +14,7 @@ import tkinter as tk from tkinter import ttk - +from MethodicConfigurator.internationalization import _ from MethodicConfigurator.middleware_template_overview import TemplateOverview from MethodicConfigurator.backend_filesystem_program_settings import ProgramSettings @@ -151,12 +151,12 @@ def argument_parser(): Returns: argparse.Namespace: An object containing the parsed arguments. """ - parser = argparse.ArgumentParser(description=_('ArduPilot methodic configurator is a GUI-based tool designed to simplify ') - _('the management and visualization of ArduPilot parameters. It enables users ') - _('to browse through various vehicle templates, edit parameter files, and ') - _('apply changes directly to the flight controller. The tool is built to ') - _('semi-automate the configuration process of ArduPilot for drones by ') - _('providing a clear and intuitive interface for parameter management.')) + parser = argparse.ArgumentParser(description=_('ArduPilot methodic configurator is a GUI-based tool designed to simplify ' + 'the management and visualization of ArduPilot parameters. It enables users ' + 'to browse through various vehicle templates, edit parameter files, and ' + 'apply changes directly to the flight controller. The tool is built to ' + 'semi-automate the configuration process of ArduPilot for drones by ' + 'providing a clear and intuitive interface for parameter management.')) return add_common_arguments_and_parse(parser) diff --git a/MethodicConfigurator/internationalization.py b/MethodicConfigurator/internationalization.py new file mode 100644 index 0000000..bee266a --- /dev/null +++ b/MethodicConfigurator/internationalization.py @@ -0,0 +1,14 @@ +import gettext + + +# Setup language +locale_path = 'locale' # directory of locale file +language = 'zh_CN' # select language + +# create translation +translation = gettext.translation('messages', localedir=locale_path, languages=[language], fallback=True) + +# set translation object as _() +_ = translation.gettext + + diff --git a/MethodicConfigurator/mavftp_example.py b/MethodicConfigurator/mavftp_example.py index c360a3e..b6960ff 100755 --- a/MethodicConfigurator/mavftp_example.py +++ b/MethodicConfigurator/mavftp_example.py @@ -12,7 +12,7 @@ from logging import basicConfig as logging_basicConfig from logging import getLevelName as logging_getLevelName - +from MethodicConfigurator.internationalization import _ from logging import debug as logging_debug from logging import info as logging_info from logging import error as logging_error @@ -39,8 +39,8 @@ def argument_parser(): parser.add_argument("--baudrate", type=int, default=115200, help=_("master port baud rate. Defaults to %(default)s")) parser.add_argument("--device", type=str, default='', - help=_("serial device. For windows use COMx where x is the port number. ") - _("For Unix use /dev/ttyUSBx where x is the port number. Defaults to autodetection")) + help=_("serial device. For windows use COMx where x is the port number. " + "For Unix use /dev/ttyUSBx where x is the port number. Defaults to autodetection")) parser.add_argument("--source-system", type=int, default=250, help=_('MAVLink source system for this GCS. Defaults to %(default)s')) parser.add_argument("--loglevel", default="INFO", diff --git a/MethodicConfigurator/param_pid_adjustment_update.py b/MethodicConfigurator/param_pid_adjustment_update.py index a27aa58..438e2f7 100755 --- a/MethodicConfigurator/param_pid_adjustment_update.py +++ b/MethodicConfigurator/param_pid_adjustment_update.py @@ -18,7 +18,7 @@ import subprocess from typing import List, Dict import re - +from MethodicConfigurator.internationalization import _ PARAM_NAME_REGEX = r'^[A-Z][A-Z_0-9]*$' PARAM_NAME_MAX_LEN = 16 VERSION = '1.0' @@ -43,8 +43,8 @@ def parse_arguments(): ) parser.add_argument("-a", "--adjustment_factor", type=ranged_type(float, 0.1, 0.8), default=0.5, - help=_("The adjustment factor to apply to the optimized parameters. ") - _("Must be in the interval 0.1 to 0.8. Defaults to 0.5."), + help=_("The adjustment factor to apply to the optimized parameters. " + "Must be in the interval 0.1 to 0.8. Defaults to 0.5."), ) parser.add_argument('-v', '--version', action='version', version=f'%(prog)s {VERSION}', help=_('Display version information and exit.'), @@ -120,7 +120,7 @@ def load_param_file_into_dict(param_file: str) -> Dict[str, 'Par']: except ValueError as exc: raise SystemExit(_(f"Invalid parameter value {value} in {param_file} line {n}")) from exc if parameter in parameter_dict: - raise SystemExit(_(f"Duplicated parameter {parameter} in {param_file} line {n}") + raise SystemExit(_(f"Duplicated parameter {parameter} in {param_file} line {n}")) parameter_dict[parameter] = Par(fvalue, comment) return parameter_dict, content