Mon, 13 Feb 2023 17:49:52 +0100
Reorganized the MicroPython package.
7352 | 1 | # -*- coding: utf-8 -*- |
2 | ||
9653
e67609152c5e
Updated copyright for 2023.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
3 | # Copyright (c) 2019 - 2023 Detlev Offenbach <detlev@die-offenbachs.de> |
7352 | 4 | # |
5 | ||
6 | """ | |
7 | Module implementing a dialog to select the ESP chip type and the backup and | |
8 | restore parameters. | |
9 | """ | |
10 | ||
11 | import os | |
12 | ||
8318
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
13 | from PyQt6.QtCore import pyqtSlot |
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
14 | from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
7352 | 15 | |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
16 | from eric7.EricWidgets.EricPathPicker import EricPathPickerModes |
7352 | 17 | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
18 | from .Ui_EspBackupRestoreFirmwareDialog import Ui_EspBackupRestoreFirmwareDialog |
7352 | 19 | |
20 | ||
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
21 | class EspBackupRestoreFirmwareDialog(QDialog, Ui_EspBackupRestoreFirmwareDialog): |
7352 | 22 | """ |
23 | Class implementing a dialog to select the ESP chip type and the backup and | |
24 | restore parameters. | |
25 | """ | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
26 | |
8924 | 27 | Chips = ( |
28 | ("", ""), | |
29 | ("ESP32", "esp32"), | |
30 | ("ESP32-C3", "esp32c3"), | |
31 | ("ESP32-S2", "esp32s2"), | |
32 | ("ESP32-S3", "esp32s3"), | |
33 | ("ESP8266", "esp8266"), | |
34 | ) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
35 | |
7595
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
36 | FlashModes = [ |
8945 | 37 | ("", ""), |
7595
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
38 | ("Quad I/O", "qio"), |
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
39 | ("Quad Output", "qout"), |
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
40 | ("Dual I/O", "dio"), |
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
41 | ("Dual Output", "dout"), |
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
42 | ] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
43 | |
7352 | 44 | FlashSizes = { |
8924 | 45 | "esp32": [ |
46 | (" 1 MB", "0x100000"), | |
47 | (" 2 MB", "0x200000"), | |
48 | (" 4 MB", "0x400000"), | |
49 | (" 8 MB", "0x800000"), | |
50 | ("16 MB", "0x1000000"), | |
51 | ], | |
52 | "esp32c3": [ | |
7352 | 53 | (" 1 MB", "0x100000"), |
54 | (" 2 MB", "0x200000"), | |
55 | (" 4 MB", "0x400000"), | |
56 | (" 8 MB", "0x800000"), | |
57 | ("16 MB", "0x1000000"), | |
58 | ], | |
8924 | 59 | "esp32s2": [ |
60 | (" 1 MB", "0x100000"), | |
61 | (" 2 MB", "0x200000"), | |
62 | (" 4 MB", "0x400000"), | |
63 | (" 8 MB", "0x800000"), | |
64 | ("16 MB", "0x1000000"), | |
65 | ], | |
66 | "esp32s3": [ | |
67 | (" 1 MB", "0x100000"), | |
68 | (" 2 MB", "0x200000"), | |
69 | (" 4 MB", "0x400000"), | |
70 | (" 8 MB", "0x800000"), | |
71 | ("16 MB", "0x1000000"), | |
72 | ], | |
73 | "esp8266": [ | |
7352 | 74 | ("256 KB", "0x40000"), |
75 | ("512 KB", "0x80000"), | |
76 | (" 1 MB", "0x100000"), | |
77 | (" 2 MB", "0x200000"), | |
78 | (" 4 MB", "0x400000"), | |
79 | (" 8 MB", "0x800000"), | |
80 | ("16 MB", "0x1000000"), | |
81 | ], | |
82 | } | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
83 | |
7352 | 84 | def __init__(self, backupMode=True, parent=None): |
85 | """ | |
86 | Constructor | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
87 | |
7352 | 88 | @param backupMode flag indicating parameters for a firmware backup are |
89 | requested | |
90 | @type bool | |
91 | @param parent reference to the parent widget | |
92 | @type QWidget | |
93 | """ | |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8143
diff
changeset
|
94 | super().__init__(parent) |
7352 | 95 | self.setupUi(self) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
96 | |
7352 | 97 | self.__isBackupMode = backupMode |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
98 | |
8924 | 99 | for text, chip in self.Chips: |
100 | self.espComboBox.addItem(text, chip) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
101 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
102 | self.baudRateComboBox.addItems( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
103 | ["74.880", "115.200", "230.400", "460.800", "921.600", "1.500.000"] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
104 | ) |
8945 | 105 | self.baudRateComboBox.setCurrentIndex(3) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
106 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
107 | self.firmwarePicker.setFilters(self.tr("Firmware Files (*.img);;All Files (*)")) |
7352 | 108 | if self.__isBackupMode: |
109 | self.firmwarePicker.setMode( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
110 | EricPathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
111 | ) |
8945 | 112 | self.sizeInfoLabel.clear() |
7352 | 113 | self.modeComboBox.setEnabled(False) |
8945 | 114 | self.modeInfoLabel.setEnabled(False) |
7352 | 115 | self.setWindowTitle(self.tr("Backup Firmware")) |
116 | else: | |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8327
diff
changeset
|
117 | self.firmwarePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) |
7595
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
118 | for text, mode in self.FlashModes: |
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
119 | self.modeComboBox.addItem(text, mode) |
7352 | 120 | self.setWindowTitle(self.tr("Restore Firmware")) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
121 | |
7352 | 122 | msh = self.minimumSizeHint() |
123 | self.resize(max(self.width(), msh.width()), msh.height()) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
124 | |
7352 | 125 | def __updateOkButton(self): |
126 | """ | |
127 | Private method to update the state of the OK button. | |
128 | """ | |
129 | firmwareFile = self.firmwarePicker.text() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
130 | enable = bool(self.espComboBox.currentText()) and bool(firmwareFile) |
7352 | 131 | if self.__isBackupMode: |
132 | enable &= bool(self.sizeComboBox.currentText()) | |
133 | else: | |
134 | enable &= os.path.exists(firmwareFile) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
135 | self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(enable) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
136 | |
7352 | 137 | @pyqtSlot(str) |
138 | def on_espComboBox_currentTextChanged(self, chip): | |
139 | """ | |
140 | Private slot to handle the selection of a chip type. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
141 | |
7352 | 142 | @param chip selected chip type |
143 | @type str | |
144 | """ | |
145 | selectedSize = self.sizeComboBox.currentText() | |
146 | self.sizeComboBox.clear() | |
8924 | 147 | chipType = self.espComboBox.currentData() |
148 | if chipType and chipType in self.FlashSizes: | |
7352 | 149 | self.sizeComboBox.addItem("") |
8924 | 150 | for text, data in self.FlashSizes[chipType]: |
7352 | 151 | self.sizeComboBox.addItem(text, data) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
152 | |
7352 | 153 | self.sizeComboBox.setCurrentText(selectedSize) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
154 | |
7352 | 155 | self.__updateOkButton() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
156 | |
7352 | 157 | @pyqtSlot(str) |
8945 | 158 | def on_sizeComboBox_currentTextChanged(self, size): |
159 | """ | |
160 | Private slot handling a change of the selected firmware size. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
161 | |
8945 | 162 | @param size selected size text |
163 | @type str | |
164 | """ | |
165 | self.__updateOkButton() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
166 | |
8945 | 167 | @pyqtSlot(str) |
7352 | 168 | def on_firmwarePicker_textChanged(self, firmware): |
169 | """ | |
170 | Private slot handling a change of the firmware path. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
171 | |
7352 | 172 | @param firmware path to the firmware |
173 | @type str | |
174 | """ | |
175 | self.__updateOkButton() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
176 | |
7352 | 177 | def getData(self): |
178 | """ | |
179 | Public method to get the entered data. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
180 | |
7352 | 181 | @return tuple containing the selected chip type, the firmware size, |
8945 | 182 | the baud rate or flashing, the flash mode and the path of the |
183 | firmware file | |
184 | @rtype tuple of (str, str, str, str, str) | |
7352 | 185 | """ |
8955
202286fb4574
Fixed a code style issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8945
diff
changeset
|
186 | flashSize = ( |
202286fb4574
Fixed a code style issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8945
diff
changeset
|
187 | self.sizeComboBox.currentData() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
188 | if self.__isBackupMode |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
189 | else self.sizeComboBox.currentText().replace(" ", "") |
8955
202286fb4574
Fixed a code style issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8945
diff
changeset
|
190 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
191 | |
7352 | 192 | return ( |
8924 | 193 | self.espComboBox.currentData(), |
8945 | 194 | flashSize, |
195 | self.baudRateComboBox.currentText().replace(".", ""), | |
7595
5db6bfeff23e
MicroPython: added code to allow the user to select the flash mod for flashing the MicroPython firmware for ESP32/ESP8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
196 | self.modeComboBox.currentData(), |
7352 | 197 | self.firmwarePicker.text(), |
198 | ) |