Skip to content

Commit 4237244

Browse files
committed
ui refactoring
1 parent 734ea3f commit 4237244

File tree

7 files changed

+400
-324
lines changed

7 files changed

+400
-324
lines changed

ui/base_ui.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from logging import getLogger, debug, error
22
from platform import system
3-
from customtkinter import CTk, CTkFrame
3+
from customtkinter import CTk
44
from tkinter import Event
55
from config.application_configuration import TITLE
66
from config.os_configuration import OPERATING_SYSTEM
@@ -41,31 +41,6 @@ def __init__(self):
4141
self.grid_columnconfigure(1, weight=3)
4242
self.grid_rowconfigure((1, 2, 3), weight=1)
4343

44-
# Top Frame
45-
self._top_frame = CTkFrame(self)
46-
self._top_frame.grid(row=0, column=0, columnspan=2, pady=10, padx=10, sticky="ew")
47-
48-
# Left Top Frame
49-
self._left_top_frame = CTkFrame(self)
50-
self._left_top_frame.grid(row=1, column=0, padx=10, pady=5, sticky="nsew")
51-
self._left_top_frame.grid_columnconfigure(0, weight=1)
52-
53-
# Left Bottom Frame
54-
self._left_bottom_frame = CTkFrame(self)
55-
self._left_bottom_frame.grid(row=2, column=0, padx=10, pady=5, sticky="nsew")
56-
self._left_bottom_frame.grid_columnconfigure(0, weight=1)
57-
58-
# Right Frame
59-
self._right_frame = CTkFrame(self)
60-
self._right_frame.grid(row=1, column=1, rowspan=2, padx=10, pady=5, sticky="nsew")
61-
self._right_frame.grid_columnconfigure((0, 1, 2, 3, 4), weight=0)
62-
self._right_frame.grid_columnconfigure(5, weight=1)
63-
64-
# Bottom Frame
65-
self._bottom_frame = CTkFrame(self)
66-
self._bottom_frame.grid(row=3, column=0, columnspan=2, pady=10, padx=10, sticky="nsew")
67-
self._bottom_frame.grid_columnconfigure(0, weight=1)
68-
6944
@staticmethod
7045
def _block_text_input(event: Event) -> str:
7146
"""

ui/firmware_studio.py

Lines changed: 159 additions & 298 deletions
Large diffs are not rendered by default.

ui/frame_console.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from customtkinter import CTkFrame, CTkLabel, CTkTextbox
2+
3+
4+
class FrameConsole(CTkFrame):
5+
"""
6+
A specialized class designed to facilitate console output operations.
7+
"""
8+
9+
def __init__(self, master, *args, **kwargs):
10+
"""
11+
A custom frame designed with widgets for erasing flash. This frame
12+
is a child of the specified parent widget (master) and includes a
13+
Label and a Textbox with customizable UI features.
14+
"""
15+
super().__init__(master, *args, **kwargs)
16+
17+
self.grid(row=3, column=0, columnspan=2, pady=10, padx=10, sticky="nsew")
18+
self.grid_columnconfigure(0, weight=1)
19+
20+
self.label = CTkLabel(self, text='Console Output')
21+
self.label.pack(padx=10, pady=10)
22+
23+
self.console_text = CTkTextbox(self, width=800, height=300)
24+
self.console_text.pack(padx=10, pady=10, fill="both", expand=True)

ui/frame_device_information.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from customtkinter import CTkFrame, CTkLabel, CTkButton
2+
3+
4+
class FrameDeviceInformation(CTkFrame):
5+
"""
6+
A specialized class designed to facilitate device information operations.
7+
"""
8+
9+
def __init__(self, master, *args, **kwargs):
10+
"""
11+
A custom frame designed with widgets for erasing flash. This frame
12+
is a child of the specified parent widget (master) and includes a
13+
Label and Button with customizable UI features.
14+
"""
15+
super().__init__(master, *args, **kwargs)
16+
17+
self.grid(row=1, column=0, padx=10, pady=5, sticky="nsew")
18+
self.grid_columnconfigure(0, weight=1)
19+
20+
self.label = CTkLabel(self, text='Information')
21+
self.label.pack(padx=10, pady=10)
22+
23+
self.chip_info_btn = CTkButton(self, text='Chip ID')
24+
self.chip_info_btn.pack(padx=10, pady=5)
25+
26+
self.memory_info_btn = CTkButton(self, text='Flash ID')
27+
self.memory_info_btn.pack(padx=10, pady=5)
28+
29+
self.mac_info_btn = CTkButton(self, text='MAC Address')
30+
self.mac_info_btn.pack(padx=10, pady=5)
31+
32+
self.flash_status_btn = CTkButton(self, text='Flash Status')
33+
self.flash_status_btn.pack(padx=10, pady=5)
34+
35+
self.mp_version_btn = CTkButton(self, text='Version', fg_color='green')
36+
self.mp_version_btn.pack(padx=10, pady=5)
37+
38+
self.mp_structure_btn = CTkButton(self, text='File Structure', fg_color='green')
39+
self.mp_structure_btn.pack(padx=10, pady=5)

ui/frame_erase_device.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from customtkinter import CTkFrame, CTkLabel, CTkButton
2+
3+
4+
class FrameEraseDevice(CTkFrame):
5+
"""
6+
A specialized class designed to facilitate flash erasing operations.
7+
"""
8+
9+
def __init__(self, master, *args, **kwargs):
10+
"""
11+
A custom frame designed with widgets for erasing flash. This frame
12+
is a child of the specified parent widget (master) and includes a
13+
Label and a Button with customizable UI features.
14+
"""
15+
super().__init__(master, *args, **kwargs)
16+
17+
self.grid(row=2, column=0, padx=10, pady=5, sticky="nsew")
18+
self.grid_columnconfigure(0, weight=1)
19+
20+
self.label = CTkLabel(self, text='Erase')
21+
self.label.pack(padx=10, pady=10)
22+
23+
self.erase_btn = CTkButton(self, text='Erase Flash')
24+
self.erase_btn.pack(padx=10, pady=5)

ui/frame_firmware_flash.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
from customtkinter import CTkFrame, CTkLabel, CTkSwitch, CTkOptionMenu, CTkCheckBox, CTkButton, CTkEntry
2+
from tkinter import Canvas
3+
from config.application_configuration import LINK_OBJECT
4+
from config.device_configuration import (CONFIGURED_DEVICES, BAUDRATE_OPTIONS, FLASH_MODE_OPTIONS,
5+
FLASH_FREQUENCY_OPTIONS, FLASH_SIZE_OPTIONS)
6+
7+
8+
class FrameFirmwareFlash(CTkFrame):
9+
"""
10+
A specialized class designed to facilitate firmware flashing operations.
11+
"""
12+
13+
def __init__(self, master, *args, **kwargs):
14+
"""
15+
A custom frame designed with widgets for erasing flash. This frame
16+
is a child of the specified parent widget (master) and includes a
17+
Label, switch, OptionMenu, CheckBox, Button and Entry with
18+
customizable UI features.
19+
"""
20+
super().__init__(master, *args, **kwargs)
21+
22+
self.grid(row=1, column=1, rowspan=2, padx=10, pady=5, sticky="nsew")
23+
self.grid_columnconfigure((0, 1, 2, 3, 4), weight=0)
24+
self.grid_columnconfigure(5, weight=1)
25+
26+
self.label = CTkLabel(self, text='Flash Configuration')
27+
self.label.grid(row=0, column=0, columnspan=5, padx=10, pady=10, sticky="w")
28+
29+
self.expert_mode = CTkSwitch(self, text='Expert Mode')
30+
self.expert_mode.grid(row=0, column=5, padx=10, pady=5, sticky="e")
31+
32+
self.chip_label = CTkLabel(self, text='Step 1:')
33+
self.chip_label.grid(row=1, column=0, padx=10, pady=5, sticky="w")
34+
35+
chip_options = ["Select Chip"] + list(CONFIGURED_DEVICES.keys())
36+
self.chip_option = CTkOptionMenu(self, values=chip_options, width=150)
37+
self.chip_option.grid(row=1, column=1, padx=10, pady=5, sticky="w")
38+
39+
self.chip_checkbox = CTkCheckBox(self, text='', state='disabled', width=20)
40+
self.chip_checkbox.grid(row=1, column=2, padx=10, pady=5, sticky="w")
41+
42+
self.chip_info = CTkLabel(self, text='Choose the chip type to flash')
43+
self.chip_info.grid(row=1, column=3, columnspan=3, padx=10, pady=5, sticky="w")
44+
45+
self.firmware_label = CTkLabel(self, text='Step 2:')
46+
self.firmware_label.grid(row=2, column=0, padx=10, pady=5, sticky="w")
47+
48+
self.firmware_btn = CTkButton(self, text='Select Firmware', width=150)
49+
self.firmware_btn.grid(row=2, column=1, padx=10, pady=5, sticky="w")
50+
51+
self.firmware_checkbox = CTkCheckBox(self, text='', state='disabled', width=20)
52+
self.firmware_checkbox.grid(row=2, column=2, padx=10, pady=5, sticky="w")
53+
54+
self.link_label = CTkLabel(self, text='Browse', text_color=LINK_OBJECT, cursor="hand2")
55+
self.link_label.grid(row=2, column=3, padx=(10, 0), pady=5, sticky="w")
56+
57+
self.firmware_info = CTkLabel(self, text='and select the firmware file to upload')
58+
self.firmware_info.grid(row=2, column=4, columnspan=2, padx=(5, 10), pady=5, sticky="w")
59+
60+
self.baudrate_label = CTkLabel(self, text='Step 3:')
61+
self.baudrate_label.grid(row=3, column=0, padx=10, pady=5, sticky="w")
62+
63+
self.baudrate_option = CTkOptionMenu(self, values=BAUDRATE_OPTIONS, width=150)
64+
self.baudrate_option.grid(row=3, column=1, padx=10, pady=5, sticky="w")
65+
66+
self.baudrate_checkbox = CTkCheckBox(self, text='', state='disabled', width=20)
67+
self.baudrate_checkbox.grid(row=3, column=2, padx=10, pady=5, sticky="w")
68+
69+
self.baudrate_info = CTkLabel(self, text='Choose a communication speed')
70+
self.baudrate_info.grid(row=3, column=3, columnspan=3, padx=10, pady=5, sticky="w")
71+
72+
self.sector_label = CTkLabel(self, text='Step 4:')
73+
self.sector_label.grid(row=4, column=0, padx=10, pady=5, sticky="w")
74+
75+
self.sector_input = CTkEntry(self, width=150)
76+
self.sector_input.grid(row=4, column=1, padx=10, pady=5, sticky="w")
77+
78+
self.sector_checkbox = CTkCheckBox(self, text='', state='disabled', width=20)
79+
self.sector_checkbox.grid(row=4, column=2, padx=10, pady=5, sticky="w")
80+
81+
self.sector_info = CTkLabel(self, text='Set the starting address for firmware')
82+
self.sector_info.grid(row=4, column=3, columnspan=3, padx=10, pady=5, sticky="w")
83+
84+
self.flash_mode_label = CTkLabel(self, text='Step 5:')
85+
self.flash_mode_label.grid(row=5, column=0, padx=10, pady=5, sticky="w")
86+
87+
self.flash_mode_option = CTkOptionMenu(self, values=FLASH_MODE_OPTIONS, width=150)
88+
self.flash_mode_option.grid(row=5, column=1, padx=10, pady=5, sticky="w")
89+
90+
self.flash_mode_info = CTkLabel(self, text='Choose the data transfer mode for flashing')
91+
self.flash_mode_info.grid(row=5, column=3, columnspan=3, padx=10, pady=5, sticky="w")
92+
93+
self.flash_frequency_label = CTkLabel(self, text='Step 6:')
94+
self.flash_frequency_label.grid(row=6, column=0, padx=10, pady=5, sticky="w")
95+
96+
self.flash_frequency_option = CTkOptionMenu(self, values=FLASH_FREQUENCY_OPTIONS, width=150)
97+
self.flash_frequency_option.grid(row=6, column=1, padx=10, pady=5, sticky="w")
98+
99+
self.flash_frequency_info = CTkLabel(self, text='Set the clock speed during flash operations')
100+
self.flash_frequency_info.grid(row=6, column=3, columnspan=3, padx=10, pady=5, sticky="w")
101+
102+
self.flash_size_label = CTkLabel(self, text='Step 7:')
103+
self.flash_size_label.grid(row=7, column=0, padx=10, pady=5, sticky="w")
104+
105+
self.flash_size_option = CTkOptionMenu(self, values=FLASH_SIZE_OPTIONS, width=150)
106+
self.flash_size_option.grid(row=7, column=1, padx=10, pady=5, sticky="w")
107+
108+
self.flash_size_info = CTkLabel(self, text='Specify or detect the flash memory size')
109+
self.flash_size_info.grid(row=7, column=3, columnspan=3, padx=10, pady=5, sticky="w")
110+
111+
self.erase_before_label = CTkLabel(self, text='Step 8:')
112+
self.erase_before_label.grid(row=8, column=0, padx=10, pady=5, sticky="w")
113+
114+
self.erase_before_switch = CTkSwitch(self, text='')
115+
self.erase_before_switch.grid(row=8, column=1, padx=10, pady=5, sticky="w")
116+
117+
self.erase_before_info = CTkLabel(self, text='Erase flash before flashing firmware')
118+
self.erase_before_info.grid(row=8, column=3, columnspan=3, padx=10, pady=5, sticky="w")
119+
120+
self.separator_canvas = Canvas(self, height=1, highlightthickness=0, bg="white", bd=0)
121+
self.separator_canvas.grid(row=9, columnspan=6, sticky="ew", padx=10, pady=10)
122+
123+
self.flash_btn = CTkButton(self, text='Flash Firmware')
124+
self.flash_btn.grid(row=10, column=1, columnspan=5, padx=10, pady=5, sticky="w")

ui/frame_search_device.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from customtkinter import CTkFrame, CTkLabel, CTkImage, CTkButton, CTkOptionMenu
2+
from PIL import Image
3+
from config.application_configuration import FONT_PATH
4+
from config.application_configuration import RELOAD_ICON
5+
6+
7+
class FrameSearchDevice(CTkFrame):
8+
9+
def __init__(self, master, *args, **kwargs):
10+
"""
11+
A custom frame designed with widgets for select a device. This frame
12+
is a child of the specified parent widget (master) and includes an Label,
13+
Image, Button and an OptionMenu with customizable UI features.
14+
"""
15+
super().__init__(master, *args, **kwargs)
16+
17+
self.grid(row=0, column=0, columnspan=2, pady=10, padx=10, sticky="ew")
18+
19+
self.device_path_label = CTkLabel(self, text='Device Path:')
20+
self.device_path_label.pack(side="left", padx=10, pady=10)
21+
self.device_path_label.configure(font=FONT_PATH)
22+
23+
reload_img = CTkImage(light_image=Image.open(RELOAD_ICON))
24+
25+
self.refresh = CTkButton(self, image=reload_img, text='', width=30)
26+
self.refresh.pack(side="right", padx=10, pady=10)
27+
28+
self.device_option = CTkOptionMenu(self, width=150)
29+
self.device_option.pack(side="right", padx=10, pady=10)

0 commit comments

Comments
 (0)