Skip to content

Commit b1b3382

Browse files
committed
IMPROVEMENT: Move some functionality to the component editor base class
The child class should do only validation
1 parent 04f3808 commit b1b3382

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

MethodicConfigurator/frontend_tkinter_component_editor.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ class ComponentEditorWindow(ComponentEditorWindowBase):
6262
"""
6363
def __init__(self, version, local_filesystem: LocalFilesystem=None):
6464
ComponentEditorWindowBase.__init__(self, version, local_filesystem)
65-
style = ttk.Style()
66-
style.configure("comb_input_invalid.TCombobox", fieldbackground="red")
67-
style.configure("comb_input_valid.TCombobox", fieldbackground="white")
68-
style.configure("entry_input_invalid.TEntry", fieldbackground="red")
69-
style.configure("entry_input_valid.TEntry", fieldbackground="white")
7065

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

92-
def set_component_value_and_update_ui(self, path: tuple, value: str):
93-
data_path = self.data['Components']
94-
for key in path[:-1]:
95-
data_path = data_path[key]
96-
data_path[path[-1]] = value
97-
entry = self.entry_widgets[path]
98-
entry.delete(0, tk.END)
99-
entry.insert(0, value)
100-
entry.config(state="disabled")
101-
10287
def set_vehicle_type_and_version(self, vehicle_type: str, version: str):
10388
self.set_component_value_and_update_ui(('Flight Controller', 'Firmware', 'Type'), vehicle_type)
10489
if version:

MethodicConfigurator/frontend_tkinter_component_editor_base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ def __init__(self, version, local_filesystem: LocalFilesystem=None):
7474

7575
style = ttk.Style()
7676
style.configure("bigger.TLabel", font=("TkDefaultFont", 14))
77+
style.configure("comb_input_invalid.TCombobox", fieldbackground="red")
78+
style.configure("comb_input_valid.TCombobox", fieldbackground="white")
79+
style.configure("entry_input_invalid.TEntry", fieldbackground="red")
80+
style.configure("entry_input_valid.TEntry", fieldbackground="white")
7781

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

115+
def _set_component_value_and_update_ui(self, path: tuple, value: str):
116+
data_path = self.data['Components']
117+
for key in path[:-1]:
118+
data_path = data_path[key]
119+
data_path[path[-1]] = value
120+
entry = self.entry_widgets[path]
121+
entry.delete(0, tk.END)
122+
entry.insert(0, value)
123+
entry.config(state="disabled")
124+
111125
def __populate_frames(self):
112126
"""
113127
Populates the ScrollFrame with widgets based on the JSON data.

0 commit comments

Comments
 (0)