Skip to content

Commit

Permalink
IMPROVEMENT: Display parameter read errors to the user before exiting
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Jun 1, 2024
1 parent 02f5a16 commit d29e3b3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
12 changes: 9 additions & 3 deletions MethodicConfigurator/ardupilot_methodic_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from MethodicConfigurator.backend_filesystem import LocalFilesystem
from MethodicConfigurator.backend_flightcontroller import FlightController

from MethodicConfigurator.frontend_tkinter_base import show_error_message

from MethodicConfigurator.frontend_tkinter_connection_selection import ConnectionSelectionWindow

from MethodicConfigurator.frontend_tkinter_flightcontroller_info import FlightControllerInfoWindow
Expand Down Expand Up @@ -60,7 +62,7 @@ def argument_parser():
return add_common_arguments_and_parse(parser)


def main():
def main(): # pylint: disable=too-many-branches
args = argument_parser()

logging_basicConfig(level=logging_getLevelName(args.loglevel), format='%(asctime)s - %(levelname)s - %(message)s')
Expand Down Expand Up @@ -90,7 +92,11 @@ def main():
if flight_controller.master is not None:
FlightControllerInfoWindow(flight_controller)

local_filesystem = LocalFilesystem(args.vehicle_dir, vehicle_type, args.allow_editing_template_files)
try:
local_filesystem = LocalFilesystem(args.vehicle_dir, vehicle_type, args.allow_editing_template_files)
except SystemExit as exp:
show_error_message("Fatal error reading parameter files", f"{exp}")
raise

# Get the list of intermediate parameter files files that will be processed sequentially
files = list(local_filesystem.file_parameters.keys())
Expand Down Expand Up @@ -119,7 +125,7 @@ def main():
flight_controller.fc_parameters)
if error_message:
logging_error(error_message)
#messagebox.showerror("Error in derived parameters", error_msg)
show_error_message("Error in derived parameters", error_message)
sys_exit(1)

# Call the GUI function with the starting intermediate parameter file
Expand Down
30 changes: 22 additions & 8 deletions MethodicConfigurator/frontend_tkinter_directory_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,13 @@ def on_select_directory(self):
"as those are used as a template for new vehicles")
return
self.local_filesystem.vehicle_dir = self.directory
self.local_filesystem.re_init(self.directory, self.local_filesystem.vehicle_type)

try:
self.local_filesystem.re_init(self.directory, self.local_filesystem.vehicle_type)
except SystemExit as exp:
show_error_message("Fatal error reading parameter files", f"{exp}")
raise

files = list(self.local_filesystem.file_parameters.keys())
if files:
LocalFilesystem.store_recently_used_vehicle_dir(self.directory)
Expand Down Expand Up @@ -291,7 +297,7 @@ def create_option3_widgets(self, last_vehicle_dir: str):
show_tooltip(open_last_vehicle_directory_button,
"Directly open the last used vehicle directory for configuring the vehicle")

def create_new_vehicle_from_template(self): # pylint: disable=too-many-return-statements
def create_new_vehicle_from_template(self):
# Get the selected template directory and new vehicle directory name
template_dir = self.template_dir.get_selected_directory()
new_base_dir = self.new_base_dir.get_selected_directory()
Expand All @@ -300,10 +306,6 @@ def create_new_vehicle_from_template(self): # pylint: disable=too-many-return-s
if template_dir == "":
show_error_message("Vehicle template directory", "Vehicle template directory cannot be empty")
return
if not LocalFilesystem.valid_directory_name(template_dir):
show_error_message("Vehicle template directory",
"Vehicle template directory name must not contain invalid characters")
return
if not LocalFilesystem.directory_exists(template_dir):
show_error_message("Vehicle template directory", "Vehicle template directory does not exist")
return
Expand All @@ -328,7 +330,13 @@ def create_new_vehicle_from_template(self): # pylint: disable=too-many-return-s

# Update the local_filesystem with the new vehicle directory
self.local_filesystem.vehicle_dir = new_vehicle_dir
self.local_filesystem.re_init(new_vehicle_dir, self.local_filesystem.vehicle_type)

try:
self.local_filesystem.re_init(new_vehicle_dir, self.local_filesystem.vehicle_type)
except SystemExit as exp:
show_error_message("Fatal error reading parameter files", f"{exp}")
raise

files = list(self.local_filesystem.file_parameters.keys())
if files:
LocalFilesystem.store_recently_used_template_dirs(template_dir, new_base_dir)
Expand All @@ -347,7 +355,13 @@ def open_last_vehicle_directory(self, last_vehicle_dir: str):
if last_vehicle_dir:
# If a last opened directory is found, proceed as if the user had manually selected it
self.local_filesystem.vehicle_dir = last_vehicle_dir
self.local_filesystem.re_init(last_vehicle_dir, self.local_filesystem.vehicle_type)

try:
self.local_filesystem.re_init(last_vehicle_dir, self.local_filesystem.vehicle_type)
except SystemExit as exp:
show_error_message("Fatal error reading parameter files", f"{exp}")
raise

files = list(self.local_filesystem.file_parameters.keys())
if files:
self.root.destroy()
Expand Down
6 changes: 5 additions & 1 deletion MethodicConfigurator/frontend_tkinter_parameter_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,11 @@ def __do_tempcal_imu(self, selected_file:str):
IMUfit(filename, tempcal_imu_result_param_fullpath, False, False, False, False,
self.local_filesystem.vehicle_dir, self.tempcal_imu_progress_window.update_progress_bar_300_pct)
self.tempcal_imu_progress_window.destroy()
self.local_filesystem.file_parameters = self.local_filesystem.read_params_from_files()
try:
self.local_filesystem.file_parameters = self.local_filesystem.read_params_from_files()
except SystemExit as exp:
messagebox.showerror("Fatal error reading parameter files", f"{exp}")
raise
self.parameter_editor_table.set_at_least_one_param_edited(True) # force writing doc annotations to file

def __should_copy_fc_values_to_file(self, selected_file: str):
Expand Down

0 comments on commit d29e3b3

Please sign in to comment.