Skip to content

Commit

Permalink
FEATURE: add option to allow editing template files directly
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed May 21, 2024
1 parent fadfce6 commit 3a11584
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion MethodicConfigurator/ardupilot_methodic_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
7 changes: 6 additions & 1 deletion MethodicConfigurator/backend_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion MethodicConfigurator/frontend_tkinter_component_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 2 additions & 2 deletions MethodicConfigurator/frontend_tkinter_directory_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 3a11584

Please sign in to comment.