Skip to content

Commit

Permalink
IMPROVEMENT: Move some functionality to the component editor base class
Browse files Browse the repository at this point in the history
The child class should do only validation
  • Loading branch information
amilcarlucas committed Jun 14, 2024
1 parent 04f3808 commit b1b3382
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
15 changes: 0 additions & 15 deletions MethodicConfigurator/frontend_tkinter_component_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ class ComponentEditorWindow(ComponentEditorWindowBase):
"""
def __init__(self, version, local_filesystem: LocalFilesystem=None):
ComponentEditorWindowBase.__init__(self, version, local_filesystem)
style = ttk.Style()
style.configure("comb_input_invalid.TCombobox", fieldbackground="red")
style.configure("comb_input_valid.TCombobox", fieldbackground="white")
style.configure("entry_input_invalid.TEntry", fieldbackground="red")
style.configure("entry_input_valid.TEntry", fieldbackground="white")

def update_json_data(self):
super().update_json_data()
Expand All @@ -89,16 +84,6 @@ def update_json_data(self):
if 'TOW max Kg' not in self.data['Components']['Frame']['Specifications']:
self.data['Components']['Frame']['Specifications']['TOW max Kg'] = 1

def set_component_value_and_update_ui(self, path: tuple, value: str):
data_path = self.data['Components']
for key in path[:-1]:
data_path = data_path[key]
data_path[path[-1]] = value
entry = self.entry_widgets[path]
entry.delete(0, tk.END)
entry.insert(0, value)
entry.config(state="disabled")

def set_vehicle_type_and_version(self, vehicle_type: str, version: str):
self.set_component_value_and_update_ui(('Flight Controller', 'Firmware', 'Type'), vehicle_type)
if version:
Expand Down
14 changes: 14 additions & 0 deletions MethodicConfigurator/frontend_tkinter_component_editor_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def __init__(self, version, local_filesystem: LocalFilesystem=None):

style = ttk.Style()
style.configure("bigger.TLabel", font=("TkDefaultFont", 14))
style.configure("comb_input_invalid.TCombobox", fieldbackground="red")
style.configure("comb_input_valid.TCombobox", fieldbackground="white")
style.configure("entry_input_invalid.TEntry", fieldbackground="red")
style.configure("entry_input_valid.TEntry", fieldbackground="white")

explanation_text = "Please configure all vehicle component properties in this window.\n"
explanation_text += "Scroll down and make sure you do not miss a property.\n"
Expand Down Expand Up @@ -108,6 +112,16 @@ def update_json_data(self): # should be overwritten in child classes
if 'Format version' not in self.data:
self.data['Format version'] = 1

def _set_component_value_and_update_ui(self, path: tuple, value: str):
data_path = self.data['Components']
for key in path[:-1]:
data_path = data_path[key]
data_path[path[-1]] = value
entry = self.entry_widgets[path]
entry.delete(0, tk.END)
entry.insert(0, value)
entry.config(state="disabled")

def __populate_frames(self):
"""
Populates the ScrollFrame with widgets based on the JSON data.
Expand Down

0 comments on commit b1b3382

Please sign in to comment.