Wed, 19 May 2021 19:53:36 +0200
Continued porting eric to PyQt6.
7352 | 1 | # -*- coding: utf-8 -*- |
2 | ||
7923
91e843545d9a
Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7595
diff
changeset
|
3 | # Copyright (c) 2019 - 2021 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 | |
16 | from E5Gui.E5PathPicker import E5PathPickerModes | |
17 | ||
18 | from .Ui_EspBackupRestoreFirmwareDialog import ( | |
19 | Ui_EspBackupRestoreFirmwareDialog | |
20 | ) | |
21 | ||
22 | ||
23 | class EspBackupRestoreFirmwareDialog(QDialog, | |
24 | Ui_EspBackupRestoreFirmwareDialog): | |
25 | """ | |
26 | Class implementing a dialog to select the ESP chip type and the backup and | |
27 | restore parameters. | |
28 | """ | |
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
|
29 | 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
|
30 | ("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
|
31 | ("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
|
32 | ("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
|
33 | ("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
|
34 | ] |
7352 | 35 | FlashSizes = { |
36 | "ESP32": [ | |
37 | (" 1 MB", "0x100000"), | |
38 | (" 2 MB", "0x200000"), | |
39 | (" 4 MB", "0x400000"), | |
40 | (" 8 MB", "0x800000"), | |
41 | ("16 MB", "0x1000000"), | |
42 | ], | |
43 | "ESP8266": [ | |
44 | ("256 KB", "0x40000"), | |
45 | ("512 KB", "0x80000"), | |
46 | (" 1 MB", "0x100000"), | |
47 | (" 2 MB", "0x200000"), | |
48 | (" 4 MB", "0x400000"), | |
49 | (" 8 MB", "0x800000"), | |
50 | ("16 MB", "0x1000000"), | |
51 | ], | |
52 | } | |
53 | ||
54 | def __init__(self, backupMode=True, parent=None): | |
55 | """ | |
56 | Constructor | |
57 | ||
58 | @param backupMode flag indicating parameters for a firmware backup are | |
59 | requested | |
60 | @type bool | |
61 | @param parent reference to the parent widget | |
62 | @type QWidget | |
63 | """ | |
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
|
64 | super().__init__(parent) |
7352 | 65 | self.setupUi(self) |
66 | ||
67 | self.__isBackupMode = backupMode | |
68 | ||
69 | self.espComboBox.addItems(["", "ESP32", "ESP8266"]) | |
70 | ||
71 | self.firmwarePicker.setFilters( | |
72 | self.tr("Firmware Files (*.img);;All Files (*)")) | |
73 | if self.__isBackupMode: | |
74 | self.firmwarePicker.setMode( | |
8327
666c2b81cbb7
Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
75 | E5PathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE) |
7352 | 76 | self.modeComboBox.setEnabled(False) |
77 | self.setWindowTitle(self.tr("Backup Firmware")) | |
78 | else: | |
8327
666c2b81cbb7
Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
79 | self.firmwarePicker.setMode(E5PathPickerModes.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
|
80 | 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
|
81 | self.modeComboBox.addItem(text, mode) |
7352 | 82 | self.setWindowTitle(self.tr("Restore Firmware")) |
83 | ||
84 | msh = self.minimumSizeHint() | |
85 | self.resize(max(self.width(), msh.width()), msh.height()) | |
86 | ||
87 | def __updateOkButton(self): | |
88 | """ | |
89 | Private method to update the state of the OK button. | |
90 | """ | |
91 | firmwareFile = self.firmwarePicker.text() | |
92 | enable = (bool(self.espComboBox.currentText()) and | |
93 | bool(firmwareFile)) | |
94 | if self.__isBackupMode: | |
95 | enable &= bool(self.sizeComboBox.currentText()) | |
96 | else: | |
97 | enable &= os.path.exists(firmwareFile) | |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
98 | self.buttonBox.button( |
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
99 | QDialogButtonBox.StandardButton.Ok).setEnabled(enable) |
7352 | 100 | |
101 | @pyqtSlot(str) | |
102 | def on_espComboBox_currentTextChanged(self, chip): | |
103 | """ | |
104 | Private slot to handle the selection of a chip type. | |
105 | ||
106 | @param chip selected chip type | |
107 | @type str | |
108 | """ | |
109 | selectedSize = self.sizeComboBox.currentText() | |
110 | self.sizeComboBox.clear() | |
111 | if chip and chip in self.FlashSizes: | |
112 | self.sizeComboBox.addItem("") | |
113 | for text, data in self.FlashSizes[chip]: | |
114 | self.sizeComboBox.addItem(text, data) | |
115 | ||
116 | self.sizeComboBox.setCurrentText(selectedSize) | |
117 | ||
118 | self.__updateOkButton() | |
119 | ||
120 | @pyqtSlot(str) | |
121 | def on_firmwarePicker_textChanged(self, firmware): | |
122 | """ | |
123 | Private slot handling a change of the firmware path. | |
124 | ||
125 | @param firmware path to the firmware | |
126 | @type str | |
127 | """ | |
128 | self.__updateOkButton() | |
129 | ||
130 | def getData(self): | |
131 | """ | |
132 | Public method to get the entered data. | |
133 | ||
134 | @return tuple containing the selected chip type, the firmware size, | |
135 | the flash mode and the path of the firmware file | |
136 | @rtype tuple of (str, str, str, str) | |
137 | """ | |
138 | return ( | |
139 | self.espComboBox.currentText().lower(), | |
140 | self.sizeComboBox.currentData(), | |
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
|
141 | self.modeComboBox.currentData(), |
7352 | 142 | self.firmwarePicker.text(), |
143 | ) |