Skip to content

Commit f82baa0

Browse files
committed
feat(param editor): Warn the users when they try to edit non-editable parameters
1 parent ba84d46 commit f82baa0

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

ardupilot_methodic_configurator/frontend_tkinter_parameter_editor_table.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ def __create_new_value_entry( # pylint: disable=too-many-arguments, too-many-po
306306
) -> Union[PairTupleCombobox, ttk.Entry]:
307307
is_bitmask = param_metadata and "Bitmask" in param_metadata
308308
present_as_forced = False
309+
present_as_derived = False
309310
if (
310311
self.current_file in self.local_filesystem.forced_parameters
311312
and param_name in self.local_filesystem.forced_parameters[self.current_file]
@@ -319,7 +320,7 @@ def __create_new_value_entry( # pylint: disable=too-many-arguments, too-many-po
319320
self.current_file in self.local_filesystem.derived_parameters
320321
and param_name in self.local_filesystem.derived_parameters[self.current_file]
321322
):
322-
present_as_forced = True
323+
present_as_derived = True
323324
new_value = self.local_filesystem.derived_parameters[self.current_file][param_name].value
324325
if (is_bitmask and param.value != new_value) or not is_within_tolerance(param.value, new_value):
325326
param.value = new_value
@@ -342,7 +343,7 @@ def __create_new_value_entry( # pylint: disable=too-many-arguments, too-many-po
342343
value_str,
343344
param_name,
344345
style="TCombobox"
345-
if present_as_forced
346+
if present_as_forced or present_as_derived
346347
else "default_v.TCombobox"
347348
if has_default_value
348349
else "readonly.TCombobox",
@@ -365,8 +366,30 @@ def __create_new_value_entry( # pylint: disable=too-many-arguments, too-many-po
365366
except KeyError as e:
366367
logging_critical(_("Parameter %s not found in the %s file: %s"), param_name, self.current_file, e, exc_info=True)
367368
sys_exit(1)
368-
if present_as_forced:
369+
370+
# Store error messages for forced and derived parameters
371+
forced_error_msg = _(
372+
"This parameter already has the correct value for this configuration step.\n"
373+
"You must not change it, as this would defeat the purpose of this configuration step.\n\n"
374+
"Add it to other configuration step and change it there if you have a good reason to."
375+
)
376+
derived_error_msg = _(
377+
"This parameter value has been derived from information you entered in the component editor window.\n"
378+
"You need to change the information on that window to update the value here.\n"
379+
)
380+
381+
# Function to show the appropriate error message
382+
def show_parameter_error(_event: tk.Event) -> None: # pylint: disable=unused-argument
383+
if present_as_forced:
384+
messagebox.showerror(_("Forced Parameter"), forced_error_msg)
385+
elif present_as_derived:
386+
messagebox.showerror(_("Derived Parameter"), derived_error_msg)
387+
388+
if present_as_forced or present_as_derived:
369389
new_value_entry.config(state="disabled", background="light grey")
390+
new_value_entry.bind("<Button-1>", show_parameter_error)
391+
# Also bind to right-click for completeness
392+
new_value_entry.bind("<Button-3>", show_parameter_error)
370393
elif bitmask_dict:
371394
new_value_entry.bind(
372395
"<Double-Button>",
@@ -636,9 +659,9 @@ def __on_parameter_value_change(self, event: tk.Event, current_file: str, param_
636659
try:
637660
p = float(new_value) # type: ignore[arg-type] # workaround a mypy bug
638661
changed = not is_within_tolerance(old_value, p)
639-
param_metadata = self.local_filesystem.doc_dict.get(param_name, None)
640-
p_min = param_metadata.get("min", None) if param_metadata else None
641-
p_max = param_metadata.get("max", None) if param_metadata else None
662+
param_metadata = self.local_filesystem.doc_dict.get(param_name, {})
663+
p_min = param_metadata.get("min", None)
664+
p_max = param_metadata.get("max", None)
642665
if changed:
643666
if p_min and p < p_min:
644667
msg = _("The value for {param_name} {p} should be greater than {p_min}\n")

0 commit comments

Comments
 (0)