src/eric7/MicroPython/EspBackupRestoreFirmwareDialog.py

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

eric ide

mercurial