src/eric7/MicroPython/Devices/EspDialogs/EspBackupRestoreFirmwareDialog.py

branch
eric7
changeset 9756
9854647c8c5c
parent 9653
e67609152c5e
child 10439
21c28b0f9e41
equal deleted inserted replaced
9755:1a09700229e7 9756:9854647c8c5c
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2019 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
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
13 from PyQt6.QtCore import pyqtSlot
14 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
15
16 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes
17
18 from .Ui_EspBackupRestoreFirmwareDialog import Ui_EspBackupRestoreFirmwareDialog
19
20
21 class EspBackupRestoreFirmwareDialog(QDialog, Ui_EspBackupRestoreFirmwareDialog):
22 """
23 Class implementing a dialog to select the ESP chip type and the backup and
24 restore parameters.
25 """
26
27 Chips = (
28 ("", ""),
29 ("ESP32", "esp32"),
30 ("ESP32-C3", "esp32c3"),
31 ("ESP32-S2", "esp32s2"),
32 ("ESP32-S3", "esp32s3"),
33 ("ESP8266", "esp8266"),
34 )
35
36 FlashModes = [
37 ("", ""),
38 ("Quad I/O", "qio"),
39 ("Quad Output", "qout"),
40 ("Dual I/O", "dio"),
41 ("Dual Output", "dout"),
42 ]
43
44 FlashSizes = {
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": [
53 (" 1 MB", "0x100000"),
54 (" 2 MB", "0x200000"),
55 (" 4 MB", "0x400000"),
56 (" 8 MB", "0x800000"),
57 ("16 MB", "0x1000000"),
58 ],
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": [
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 }
83
84 def __init__(self, backupMode=True, parent=None):
85 """
86 Constructor
87
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 """
94 super().__init__(parent)
95 self.setupUi(self)
96
97 self.__isBackupMode = backupMode
98
99 for text, chip in self.Chips:
100 self.espComboBox.addItem(text, chip)
101
102 self.baudRateComboBox.addItems(
103 ["74.880", "115.200", "230.400", "460.800", "921.600", "1.500.000"]
104 )
105 self.baudRateComboBox.setCurrentIndex(3)
106
107 self.firmwarePicker.setFilters(self.tr("Firmware Files (*.img);;All Files (*)"))
108 if self.__isBackupMode:
109 self.firmwarePicker.setMode(
110 EricPathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE
111 )
112 self.sizeInfoLabel.clear()
113 self.modeComboBox.setEnabled(False)
114 self.modeInfoLabel.setEnabled(False)
115 self.setWindowTitle(self.tr("Backup Firmware"))
116 else:
117 self.firmwarePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
118 for text, mode in self.FlashModes:
119 self.modeComboBox.addItem(text, mode)
120 self.setWindowTitle(self.tr("Restore Firmware"))
121
122 msh = self.minimumSizeHint()
123 self.resize(max(self.width(), msh.width()), msh.height())
124
125 def __updateOkButton(self):
126 """
127 Private method to update the state of the OK button.
128 """
129 firmwareFile = self.firmwarePicker.text()
130 enable = bool(self.espComboBox.currentText()) and bool(firmwareFile)
131 if self.__isBackupMode:
132 enable &= bool(self.sizeComboBox.currentText())
133 else:
134 enable &= os.path.exists(firmwareFile)
135 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(enable)
136
137 @pyqtSlot(str)
138 def on_espComboBox_currentTextChanged(self, chip):
139 """
140 Private slot to handle the selection of a chip type.
141
142 @param chip selected chip type
143 @type str
144 """
145 selectedSize = self.sizeComboBox.currentText()
146 self.sizeComboBox.clear()
147 chipType = self.espComboBox.currentData()
148 if chipType and chipType in self.FlashSizes:
149 self.sizeComboBox.addItem("")
150 for text, data in self.FlashSizes[chipType]:
151 self.sizeComboBox.addItem(text, data)
152
153 self.sizeComboBox.setCurrentText(selectedSize)
154
155 self.__updateOkButton()
156
157 @pyqtSlot(str)
158 def on_sizeComboBox_currentTextChanged(self, size):
159 """
160 Private slot handling a change of the selected firmware size.
161
162 @param size selected size text
163 @type str
164 """
165 self.__updateOkButton()
166
167 @pyqtSlot(str)
168 def on_firmwarePicker_textChanged(self, firmware):
169 """
170 Private slot handling a change of the firmware path.
171
172 @param firmware path to the firmware
173 @type str
174 """
175 self.__updateOkButton()
176
177 def getData(self):
178 """
179 Public method to get the entered data.
180
181 @return tuple containing the selected chip type, the firmware size,
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)
185 """
186 flashSize = (
187 self.sizeComboBox.currentData()
188 if self.__isBackupMode
189 else self.sizeComboBox.currentText().replace(" ", "")
190 )
191
192 return (
193 self.espComboBox.currentData(),
194 flashSize,
195 self.baudRateComboBox.currentText().replace(".", ""),
196 self.modeComboBox.currentData(),
197 self.firmwarePicker.text(),
198 )

eric ide

mercurial