Skip to content

Commit 512ebd8

Browse files
committed
Update look&feel, disable fields dynamically
1 parent 9e0cd08 commit 512ebd8

File tree

1 file changed

+70
-30
lines changed

1 file changed

+70
-30
lines changed

configure.py

Lines changed: 70 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class TuringConfigWindow:
6868
def __init__(self):
6969
self.window = Tk()
7070
self.window.title('Turing System Monitor configuration')
71-
self.window.geometry("720x450")
71+
self.window.geometry("730x480")
7272
self.window.iconphoto(True, PhotoImage(file="res/icons/monitor-icon-17865/64.png"))
7373
# When window gets focus again, reload theme preview in case it has been updated by theme editor
7474
self.window.bind("<FocusIn>", self.on_theme_change)
@@ -77,75 +77,76 @@ def __init__(self):
7777
sv_ttk.set_theme("light")
7878

7979
self.theme_preview_img = None
80-
self.theme_preview = Label(self.window)
80+
self.theme_preview = ttk.Label(self.window)
8181
self.theme_preview.place(x=10, y=10)
8282

83-
sysmon_label = Label(self.window, text='System Monitor configuration', font='bold')
83+
sysmon_label = ttk.Label(self.window, text='System Monitor configuration', font='bold')
8484
sysmon_label.place(x=320, y=0)
8585

86-
self.theme_label = Label(self.window, text='Theme')
87-
self.theme_label.place(x=320, y=30)
86+
self.theme_label = ttk.Label(self.window, text='Theme')
87+
self.theme_label.place(x=320, y=35)
8888
self.theme_cb = ttk.Combobox(self.window, values=get_themes(), state='readonly')
8989
self.theme_cb.place(x=500, y=30, width=210)
9090
self.theme_cb.bind('<<ComboboxSelected>>', self.on_theme_change)
9191

92-
self.hwlib_label = Label(self.window, text='Hardware monitoring')
93-
self.hwlib_label.place(x=320, y=70)
92+
self.hwlib_label = ttk.Label(self.window, text='Hardware monitoring')
93+
self.hwlib_label.place(x=320, y=75)
9494
self.hwlib_cb = ttk.Combobox(self.window, values=list(hw_lib_map.values()), state='readonly')
9595
self.hwlib_cb.place(x=500, y=70, width=210)
96+
self.hwlib_cb.bind('<<ComboboxSelected>>', self.on_hwlib_change)
9697

97-
self.eth_label = Label(self.window, text='Ethernet interface')
98-
self.eth_label.place(x=320, y=110)
98+
self.eth_label = ttk.Label(self.window, text='Ethernet interface')
99+
self.eth_label.place(x=320, y=115)
99100
self.eth_cb = ttk.Combobox(self.window, values=get_net_if(), state='readonly')
100101
self.eth_cb.place(x=500, y=110, width=210)
101102

102-
self.wl_label = Label(self.window, text='Wi-Fi interface')
103-
self.wl_label.place(x=320, y=150)
103+
self.wl_label = ttk.Label(self.window, text='Wi-Fi interface')
104+
self.wl_label.place(x=320, y=155)
104105
self.wl_cb = ttk.Combobox(self.window, values=get_net_if(), state='readonly')
105106
self.wl_cb.place(x=500, y=150, width=210)
106107

107-
sysmon_label = Label(self.window, text='Display configuration', font='bold')
108+
sysmon_label = ttk.Label(self.window, text='Display configuration', font='bold')
108109
sysmon_label.place(x=320, y=190)
109110

110-
self.com_label = Label(self.window, text='COM port')
111-
self.com_label.place(x=320, y=230)
111+
self.com_label = ttk.Label(self.window, text='COM port')
112+
self.com_label.place(x=320, y=235)
112113
self.com_cb = ttk.Combobox(self.window, values=get_com_ports(), state='readonly')
113114
self.com_cb.place(x=500, y=230, width=210)
114115

115-
self.model_label = Label(self.window, text='Smart screen model')
116-
self.model_label.place(x=320, y=270)
116+
self.model_label = ttk.Label(self.window, text='Smart screen model')
117+
self.model_label.place(x=320, y=275)
117118
self.model_cb = ttk.Combobox(self.window, values=list(revision_map.values()), state='readonly')
119+
self.model_cb.bind('<<ComboboxSelected>>', self.on_model_change)
118120
self.model_cb.place(x=500, y=270, width=210)
119121

120-
self.orient_label = Label(self.window, text='Orientation')
121-
self.orient_label.place(x=320, y=310)
122+
self.orient_label = ttk.Label(self.window, text='Orientation')
123+
self.orient_label.place(x=320, y=315)
122124
self.orient_cb = ttk.Combobox(self.window, values=list(reverse_map.values()), state='readonly')
123125
self.orient_cb.place(x=500, y=310, width=210)
124126

125127
self.brightness_string = StringVar()
126-
self.brightness_label = Label(self.window, text='Brightness')
127-
self.brightness_label.place(x=320, y=350)
128+
self.brightness_label = ttk.Label(self.window, text='Brightness')
129+
self.brightness_label.place(x=320, y=355)
128130
self.brightness_slider = ttk.Scale(self.window, from_=0, to=100, orient=HORIZONTAL,
129-
command=self.update_brightness_label)
131+
command=self.on_brightness_change)
130132
self.brightness_slider.place(x=550, y=350, width=160)
131-
self.brightness_val_label = Label(self.window, textvariable=self.brightness_string)
132-
self.brightness_val_label.place(x=500, y=350)
133+
self.brightness_val_label = ttk.Label(self.window, textvariable=self.brightness_string)
134+
self.brightness_val_label.place(x=500, y=355)
135+
self.brightness_warning_label = ttk.Label(self.window, text="⚠ Turing / rev. A displays can get hot at high brightness!", foreground='#f00')
136+
self.brightness_warning_label.place(x=320, y=390)
133137

134138
self.edit_theme_btn = ttk.Button(self.window, text="Edit theme", command=lambda: self.on_theme_editor_click())
135-
self.edit_theme_btn.place(x=310, y=390, height=50, width=130)
139+
self.edit_theme_btn.place(x=310, y=420, height=50, width=130)
136140

137141
self.save_btn = ttk.Button(self.window, text="Save settings", command=lambda: self.on_save_click())
138-
self.save_btn.place(x=450, y=390, height=50, width=130)
142+
self.save_btn.place(x=450, y=420, height=50, width=130)
139143

140144
self.save_run_btn = ttk.Button(self.window, text="Save and run", command=lambda: self.on_saverun_click())
141-
self.save_run_btn.place(x=590, y=390, height=50, width=130)
145+
self.save_run_btn.place(x=590, y=420, height=50, width=130)
142146

143147
self.config = None
144148
self.load_config_values()
145149

146-
def update_brightness_label(self, e=None):
147-
self.brightness_string.set(str(int(self.brightness_slider.get())) + "%")
148-
149150
def run(self):
150151
self.window.mainloop()
151152

@@ -185,6 +186,12 @@ def load_config_values(self):
185186
self.orient_cb.set(reverse_map[self.config['display']['DISPLAY_REVERSE']])
186187
self.brightness_slider.set(int(self.config['display']['BRIGHTNESS']))
187188

189+
# Reload content on screen
190+
self.on_model_change()
191+
self.on_theme_change()
192+
self.on_brightness_change()
193+
self.on_hwlib_change()
194+
188195
def save_config_values(self):
189196
self.config['config']['THEME'] = self.theme_cb.get()
190197
self.config['config']['HW_SENSORS'] = [k for k, v in hw_lib_map.items() if v == self.hwlib_cb.get()][0]
@@ -207,7 +214,7 @@ def save_config_values(self):
207214
with open("config.yaml", "w") as file:
208215
ruamel.yaml.YAML().dump(self.config, file)
209216

210-
def on_theme_change(self, event):
217+
def on_theme_change(self, e=None):
211218
self.load_theme_preview()
212219

213220
def on_theme_editor_click(self):
@@ -221,6 +228,39 @@ def on_saverun_click(self):
221228
subprocess.Popen(os.path.join(os.getcwd(), "main.py"), shell=True)
222229
self.window.destroy()
223230

231+
def on_brightness_change(self, e=None):
232+
self.brightness_string.set(str(int(self.brightness_slider.get())) + "%")
233+
self.show_hide_brightness_warning()
234+
235+
def on_model_change(self, e=None):
236+
self.show_hide_brightness_warning()
237+
if [k for k, v in revision_map.items() if v == self.model_cb.get()][0] == "SIMU":
238+
self.com_cb.configure(state="disabled", foreground="#C0C0C0")
239+
self.orient_cb.configure(state="disabled", foreground="#C0C0C0")
240+
self.brightness_slider.configure(state="disabled")
241+
self.brightness_val_label.configure(foreground="#C0C0C0")
242+
else:
243+
self.com_cb.configure(state="readonly", foreground="#000")
244+
self.orient_cb.configure(state="readonly", foreground="#000")
245+
self.brightness_slider.configure(state="normal")
246+
self.brightness_val_label.configure(foreground="#000")
247+
248+
def on_hwlib_change(self, e=None):
249+
hwlib = [k for k, v in hw_lib_map.items() if v == self.hwlib_cb.get()][0]
250+
if hwlib == "STUB" or hwlib == "STATIC":
251+
self.eth_cb.configure(state="disabled", foreground="#C0C0C0")
252+
self.wl_cb.configure(state="disabled", foreground="#C0C0C0")
253+
else:
254+
self.eth_cb.configure(state="readonly", foreground="#000")
255+
self.wl_cb.configure(state="readonly", foreground="#000")
256+
257+
def show_hide_brightness_warning(self, e=None):
258+
if int(self.brightness_slider.get()) > 50 and [k for k, v in revision_map.items() if v == self.model_cb.get()][0] == "A":
259+
# Show warning for Turing Smart screen with high brightness
260+
self.brightness_warning_label.place(x=320, y=390)
261+
else:
262+
self.brightness_warning_label.place_forget()
263+
224264

225265
if __name__ == "__main__":
226266
configurator = TuringConfigWindow()

0 commit comments

Comments
 (0)