eric6/MicroPython/EspBackupRestoreFirmwareDialog.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
child 8143
2c730d5fd177
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

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

eric ide

mercurial