From 3a115842ff7068cb6336307d40c937c9a803d1cd Mon Sep 17 00:00:00 2001 From: "Dr.-Ing. Amilcar do Carmo Lucas" Date: Mon, 20 May 2024 21:16:44 +0200 Subject: [PATCH] FEATURE: add option to allow editing template files directly --- MethodicConfigurator/ardupilot_methodic_configurator.py | 2 +- MethodicConfigurator/backend_filesystem.py | 7 ++++++- MethodicConfigurator/frontend_tkinter_component_editor.py | 2 +- .../frontend_tkinter_component_editor_base.py | 2 +- .../frontend_tkinter_directory_selection.py | 4 ++-- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/MethodicConfigurator/ardupilot_methodic_configurator.py b/MethodicConfigurator/ardupilot_methodic_configurator.py index b1f11d5..70f6b97 100755 --- a/MethodicConfigurator/ardupilot_methodic_configurator.py +++ b/MethodicConfigurator/ardupilot_methodic_configurator.py @@ -84,7 +84,7 @@ def main(): vehicle_type = "ArduCopter" logging_warning("Could not detect vehicle type. Defaulting to ArduCopter.") - local_filesystem = LocalFilesystem(args.vehicle_dir, vehicle_type) + local_filesystem = LocalFilesystem(args.vehicle_dir, vehicle_type, args.allow_editing_template_files) # Get the list of intermediate parameter files files that will be processed sequentially files = list(local_filesystem.file_parameters.keys()) diff --git a/MethodicConfigurator/backend_filesystem.py b/MethodicConfigurator/backend_filesystem.py index 9da0aaf..f8b89a8 100644 --- a/MethodicConfigurator/backend_filesystem.py +++ b/MethodicConfigurator/backend_filesystem.py @@ -91,10 +91,11 @@ class LocalFilesystem(VehicleComponents, ConfigurationSteps): # pylint: disable param_default_dict (dict): A dictionary of default parameter values. doc_dict (dict): A dictionary containing documentation for each parameter. """ - def __init__(self, vehicle_dir: str, vehicle_type: str): + def __init__(self, vehicle_dir: str, vehicle_type: str, allow_editing_template_files: bool = False): self.file_parameters = None VehicleComponents.__init__(self) ConfigurationSteps.__init__(self, vehicle_dir, vehicle_type) + self.allow_editing_template_files = allow_editing_template_files if vehicle_dir is not None: self.re_init(vehicle_dir, vehicle_type) @@ -631,4 +632,8 @@ def add_argparse_arguments(parser): 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.') return parser diff --git a/MethodicConfigurator/frontend_tkinter_component_editor.py b/MethodicConfigurator/frontend_tkinter_component_editor.py index 5d048b7..041d47a 100644 --- a/MethodicConfigurator/frontend_tkinter_component_editor.py +++ b/MethodicConfigurator/frontend_tkinter_component_editor.py @@ -365,6 +365,6 @@ def validate_data(self): # pylint: disable=too-many-branches logging_basicConfig(level=logging_getLevelName(args.loglevel), format='%(asctime)s - %(levelname)s - %(message)s') - filesystem = LocalFilesystem(args.vehicle_dir, args.vehicle_type) + filesystem = LocalFilesystem(args.vehicle_dir, args.vehicle_type, args.allow_editing_template_files) app = ComponentEditorWindow(VERSION, filesystem) app.root.mainloop() diff --git a/MethodicConfigurator/frontend_tkinter_component_editor_base.py b/MethodicConfigurator/frontend_tkinter_component_editor_base.py index 44ce252..ae6a8ad 100644 --- a/MethodicConfigurator/frontend_tkinter_component_editor_base.py +++ b/MethodicConfigurator/frontend_tkinter_component_editor_base.py @@ -193,6 +193,6 @@ def add_argparse_arguments(parser): logging_basicConfig(level=logging_getLevelName(args.loglevel), format='%(asctime)s - %(levelname)s - %(message)s') - filesystem = LocalFilesystem(args.vehicle_dir, args.vehicle_type) + filesystem = LocalFilesystem(args.vehicle_dir, args.vehicle_type, args.allow_editing_template_files) app = ComponentEditorWindowBase(VERSION, filesystem) app.root.mainloop() diff --git a/MethodicConfigurator/frontend_tkinter_directory_selection.py b/MethodicConfigurator/frontend_tkinter_directory_selection.py index 50881a0..ee998bb 100644 --- a/MethodicConfigurator/frontend_tkinter_directory_selection.py +++ b/MethodicConfigurator/frontend_tkinter_directory_selection.py @@ -150,7 +150,7 @@ def __init__(self, parent: tk, parent_frame: tk.Frame, # pylint: disable=too-ma def on_select_directory(self): # Call the base class method to open the directory selection dialog if super().on_select_directory(): - if "vehicle_templates" in self.directory: + if "vehicle_templates" in self.directory and not self.local_filesystem.allow_editing_template_files: show_error_message("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") @@ -350,7 +350,7 @@ def main(): 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) + local_filesystem = LocalFilesystem(args.vehicle_dir, args.vehicle_type, args.allow_editing_template_files) # Get the list of intermediate parameter files files that will be processed sequentially files = list(local_filesystem.file_parameters.keys())