Skip to content

Commit

Permalink
FEATURE: use comboboxes where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Jun 17, 2024
1 parent a31420c commit 1e50bf9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
7 changes: 7 additions & 0 deletions MethodicConfigurator/backend_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ def __extend_and_reformat_parameter_documentation_metadata(self): # pylint: dis
key, value = item.split(':')
param_info['Bitmask'][int(key.strip())] = value.strip()

if 'values' in param_info and param_info['values']:
try:
param_info['Values'] = {int(k): v for k, v in param_info['values'].items()}
except ValueError:
param_info['Values'] = {float(k): v for k, v in param_info['values'].items()}
# print(param_info['Values'])

prefix_parts = [
f"{param_info['humanName']}",
]
Expand Down
14 changes: 11 additions & 3 deletions MethodicConfigurator/frontend_tkinter_connection_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,17 @@ class PairTupleCombobox(ttk.Combobox): # pylint: disable=too-many-ancestors
def process_list_pair_tuple(self, list_pair_tuple):
r_list_keys = []
r_list_shows = []
for tpl in list_pair_tuple:
r_list_keys.append(tpl[0])
r_list_shows.append(tpl[1])
if isinstance(list_pair_tuple, list):
for tpl in list_pair_tuple:
r_list_keys.append(tpl[0])
r_list_shows.append(tpl[1])
elif isinstance(list_pair_tuple, dict):
for key, value in list_pair_tuple.items():
r_list_keys.append(key)
r_list_shows.append(value)
else:
logging_critical("list_pair_tuple must be a tuple or a dictionary, not %s", type(list_pair_tuple))
sys_exit(1)
return r_list_keys, r_list_shows

def __init__(self, container, list_pair_tuple, selected_element, cb_name, *args, **kwargs):
Expand Down
29 changes: 23 additions & 6 deletions MethodicConfigurator/frontend_tkinter_parameter_editor_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
from MethodicConfigurator.frontend_tkinter_base import show_tooltip
#from MethodicConfigurator.frontend_tkinter_base import AutoResizeCombobox
from MethodicConfigurator.frontend_tkinter_base import ScrollFrame
from MethodicConfigurator.frontend_tkinter_base import get_font_family

from MethodicConfigurator.frontend_tkinter_connection_selection import PairTupleCombobox

from MethodicConfigurator.annotate_params import Par

Expand Down Expand Up @@ -219,8 +222,8 @@ def __create_flightcontroller_value(self, fc_parameters, param_name, param_defau
@staticmethod
def __update_new_value_entry_text(new_value_entry: ttk.Entry, value: float, param_default):
new_value_entry.delete(0, tk.END)
text = format(value, '.6f').rstrip('0').rstrip('.')
new_value_entry.insert(0, text)
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)
Expand All @@ -244,9 +247,20 @@ def __create_new_value_entry(self, param_name, param, # pylint: disable=too-man
param.value = self.local_filesystem.derived_parameters[self.current_file][param_name].value
self.at_least_one_param_edited = True

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)
bitmask_dict = param_metadata.get('Bitmask', None) if param_metadata else None
bitmask_dict = None
value_str = format(param.value, '.6f').rstrip('0').rstrip('.')
if 'values' in param_metadata and param_metadata['values'] and \
value_str in param_metadata['values']:
selected_value = param_metadata['values'].get(value_str, None)
new_value_entry = PairTupleCombobox(self.view_port, param_metadata['values'],
value_str, param_name)
new_value_entry.set(selected_value)
new_value_entry.config(state='readonly', width=9, font=(get_font_family(new_value_entry), 9))
new_value_entry.config(background='white') # does not work when done together with state='readonly'
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)
bitmask_dict = param_metadata.get('Bitmask', None) if param_metadata else None
try:
old_value = self.local_filesystem.file_parameters[self.current_file][param_name].value
except KeyError as e:
Expand Down Expand Up @@ -405,7 +419,10 @@ def __on_parameter_add(self, fc_parameters):

def __on_parameter_value_change(self, event, current_file, param_name):
# Get the new value from the Entry widget
new_value = event.widget.get()
if isinstance(event.widget, PairTupleCombobox):
new_value = event.widget.get_selected_key()
else:
new_value = event.widget.get()
try:
old_value = self.local_filesystem.file_parameters[current_file][param_name].value
except KeyError as e:
Expand Down

0 comments on commit 1e50bf9

Please sign in to comment.