|
| 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") |
0 commit comments