Skip to content

Commit

Permalink
BUGFIX: cope with un-existing vehicle_components.json file
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Apr 30, 2024
1 parent 27b4c8d commit 80f326f
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions MethodicConfigurator/frontend_tkinter_parameter_editor_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,26 @@ def __create_new_value_entry(self, param_name, param, # pylint: disable=too-man

present_as_forced = False
if file_info and 'forced_parameters' in file_info and param_name in file_info['forced_parameters']:
present_as_forced = True
if "New Value" in file_info['forced_parameters'][param_name] and \
param.value != file_info['forced_parameters'][param_name]["New Value"]:
param.value = file_info['forced_parameters'][param_name]["New Value"]
self.at_least_one_param_edited = True
if "New Value" in file_info['forced_parameters'][param_name]:
present_as_forced = True
if param.value != file_info['forced_parameters'][param_name]["New Value"]:
param.value = file_info['forced_parameters'][param_name]["New Value"]
self.at_least_one_param_edited = True
if file_info and 'derived_parameters' in file_info and param_name in file_info['derived_parameters']:
present_as_forced = True
if "New Value" in file_info['derived_parameters'][param_name]:
# Prepare a dictionary that maps variable names to their values
local_vars = {
'vehicle_components': self.local_filesystem.vehicle_components['Components'],
'fc_parameters': self.local_filesystem.file_parameters[self.current_file],
# Add any other variables you want to make accessible within the eval expression
}
eval_result = eval(file_info['derived_parameters'][param_name]["New Value"], # pylint: disable=eval-used
{}, local_vars)
if param.value != eval_result:
param.value = eval_result
self.at_least_one_param_edited = True
if 'Components' in self.local_filesystem.vehicle_components:
present_as_forced = True
# Prepare a dictionary that maps variable names to their values
local_vars = {
'vehicle_components': self.local_filesystem.vehicle_components['Components'],
'fc_parameters': self.local_filesystem.file_parameters[self.current_file],
# Add any other variables you want to make accessible within the eval expression
}
eval_result = eval(file_info['derived_parameters'][param_name]["New Value"], # pylint: disable=eval-used
{}, local_vars)
if param.value != eval_result:
param.value = eval_result
self.at_least_one_param_edited = True

new_value_entry = tk.Entry(self.view_port, width=10, justify=tk.RIGHT)
ParameterEditorTable.__update_new_value_entry_text(new_value_entry, param.value, param_default)
Expand Down Expand Up @@ -274,17 +275,17 @@ def __create_change_reason_entry(self, param_name, param, new_value_entry, file_

present_as_forced = False
if file_info and 'forced_parameters' in file_info and param_name in file_info['forced_parameters']:
present_as_forced = True
if "Change Reason" in file_info['forced_parameters'][param_name] and \
param.comment != file_info['forced_parameters'][param_name]["Change Reason"]:
param.comment = file_info['forced_parameters'][param_name]["Change Reason"]
self.at_least_one_param_edited = True
if "Change Reason" in file_info['forced_parameters'][param_name]:
present_as_forced = True
if param.comment != file_info['forced_parameters'][param_name]["Change Reason"]:
param.comment = file_info['forced_parameters'][param_name]["Change Reason"]
self.at_least_one_param_edited = True
if file_info and 'derived_parameters' in file_info and param_name in file_info['derived_parameters']:
present_as_forced = True
if "Change Reason" in file_info['derived_parameters'][param_name] and \
param.comment != file_info['derived_parameters'][param_name]["Change Reason"]:
param.comment = file_info['derived_parameters'][param_name]["Change Reason"]
self.at_least_one_param_edited = True
if "Change Reason" in file_info['derived_parameters'][param_name]:
present_as_forced = True
if param.comment != file_info['derived_parameters'][param_name]["Change Reason"]:
param.comment = file_info['derived_parameters'][param_name]["Change Reason"]
self.at_least_one_param_edited = True

change_reason_entry = tk.Entry(self.view_port, background="white")
change_reason_entry.insert(0, "" if param.comment is None else param.comment)
Expand Down

0 comments on commit 80f326f

Please sign in to comment.