Skip to content

Commit

Permalink
BUGFIX: default highlight in light blue regression
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Jul 10, 2024
1 parent deb02cb commit a0f7fe8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
4 changes: 4 additions & 0 deletions MethodicConfigurator/frontend_tkinter_parameter_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ def __init__(self, current_file: str, flight_controller: FlightController,
style.map('readonly.TCombobox', fieldbackground=[('readonly', 'white')])
style.map('readonly.TCombobox', selectbackground=[('readonly', 'white')])
style.map('readonly.TCombobox', selectforeground=[('readonly', 'black')])
style.map('default_v.TCombobox', fieldbackground=[('readonly', 'light blue')])
style.map('default_v.TCombobox', selectbackground=[('readonly', 'light blue')])
style.map('default_v.TCombobox', selectforeground=[('readonly', 'black')])
style.configure('default_v.TEntry', fieldbackground="light blue")

self.__create_conf_widgets(version)

Expand Down
27 changes: 21 additions & 6 deletions MethodicConfigurator/frontend_tkinter_parameter_editor_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,26 @@ def __create_flightcontroller_value(self, fc_parameters, param_name, param_defau
show_tooltip(flightcontroller_value, doc_tooltip)
return flightcontroller_value

def __update_combobox_style_on_selection(self, combobox_widget, param_default):
try:
current_value = float(combobox_widget.get_selected_key())
has_default_value = param_default is not None and is_within_tolerance(current_value, param_default.value)
combobox_widget.configure(style='default_v.TCombobox' if has_default_value else 'readonly.TCombobox')
except ValueError:
logging_info(f'Could not solve the selected {combobox_widget} key to a float value.')
pass

@staticmethod
def __update_new_value_entry_text(new_value_entry: ttk.Entry, value: float, param_default):
if isinstance(new_value_entry, PairTupleCombobox):
return
new_value_entry.delete(0, tk.END)
value_str = format(value, '.6f').rstrip('0').rstrip('.')
new_value_entry.insert(0, value_str)
new_value_background = "light blue" if param_default is not None and \
is_within_tolerance(value, param_default.value) else "white"
new_value_entry.config(background=new_value_background)
if param_default is not None and is_within_tolerance(value, param_default.value):
new_value_entry.configure(style='default_v.TEntry')
else:
new_value_entry.configure(style='TEntry')

def __create_new_value_entry(self, param_name, param, # pylint: disable=too-many-arguments
param_metadata, param_default, doc_tooltip):
Expand All @@ -254,13 +266,17 @@ def __create_new_value_entry(self, param_name, param, # pylint: disable=too-man
if param_metadata and 'values' in param_metadata and param_metadata['values'] and \
value_str in param_metadata['values']:
selected_value = param_metadata['values'].get(value_str, None)
has_default_value = param_default is not None and is_within_tolerance(param.value, param_default.value)
new_value_entry = PairTupleCombobox(self.view_port, param_metadata['values'],
value_str, param_name,
style='TCombobox' if present_as_forced else 'readonly.TCombobox')
style='TCombobox' if present_as_forced else \
'default_v.TCombobox' if has_default_value else 'readonly.TCombobox')
new_value_entry.set(selected_value)
font = get_widget_font(new_value_entry)
font['size'] -= 2 if platform_system() == 'Windows' else 1
new_value_entry.config(state='readonly', width=9, font=(font['family'], font['size']))
new_value_entry.bind("<<ComboboxSelected>>",
lambda event: self.__update_combobox_style_on_selection(new_value_entry, param_default))
else:
new_value_entry = ttk.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 @@ -464,8 +480,7 @@ def __on_parameter_value_change(self, event, current_file, param_name):
else:
# Revert to the previous (valid) value
p = old_value
ParameterEditorTable.__update_new_value_entry_text(event.widget, p,
self.local_filesystem.param_default_dict.get(param_name, None))
self.__update_new_value_entry_text(event.widget, p, self.local_filesystem.param_default_dict.get(param_name, None))

def __on_parameter_change_reason_change(self, event, current_file, param_name):
# Get the new value from the Entry widget
Expand Down

0 comments on commit a0f7fe8

Please sign in to comment.