eric6/MicroPython/EspBackupRestoreFirmwareDialog.py

changeset 7352
5f69f55b919f
child 7360
9190402e4505
equal deleted inserted replaced
7348:79ae0af9558a 7352:5f69f55b919f
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2019 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 PyQt5.QtCore import pyqtSlot
14 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
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 """
29 FlashModes = ["qio", "qout", "dio", "dout"]
30 FlashSizes = {
31 "ESP32": [
32 (" 1 MB", "0x100000"),
33 (" 2 MB", "0x200000"),
34 (" 4 MB", "0x400000"),
35 (" 8 MB", "0x800000"),
36 ("16 MB", "0x1000000"),
37 ],
38 "ESP8266": [
39 ("256 KB", "0x40000"),
40 ("512 KB", "0x80000"),
41 (" 1 MB", "0x100000"),
42 (" 2 MB", "0x200000"),
43 (" 4 MB", "0x400000"),
44 (" 8 MB", "0x800000"),
45 ("16 MB", "0x1000000"),
46 ],
47 }
48
49 def __init__(self, backupMode=True, parent=None):
50 """
51 Constructor
52
53 @param backupMode flag indicating parameters for a firmware backup are
54 requested
55 @type bool
56 @param parent reference to the parent widget
57 @type QWidget
58 """
59 super(EspBackupRestoreFirmwareDialog, self).__init__(parent)
60 self.setupUi(self)
61
62 self.__isBackupMode = backupMode
63
64 self.espComboBox.addItems(["", "ESP32", "ESP8266"])
65
66 self.firmwarePicker.setFilters(
67 self.tr("Firmware Files (*.img);;All Files (*)"))
68 if self.__isBackupMode:
69 self.firmwarePicker.setMode(
70 E5PathPickerModes.SaveFileEnsureExtensionMode)
71 self.modeComboBox.setEnabled(False)
72 self.setWindowTitle(self.tr("Backup Firmware"))
73 else:
74 self.firmwarePicker.setMode(E5PathPickerModes.OpenFileMode)
75 self.modeComboBox.addItems(self.FlashModes)
76 self.setWindowTitle(self.tr("Restore Firmware"))
77
78 msh = self.minimumSizeHint()
79 self.resize(max(self.width(), msh.width()), msh.height())
80
81 def __updateOkButton(self):
82 """
83 Private method to update the state of the OK button.
84 """
85 firmwareFile = self.firmwarePicker.text()
86 enable = (bool(self.espComboBox.currentText()) and
87 bool(firmwareFile))
88 if self.__isBackupMode:
89 enable &= bool(self.sizeComboBox.currentText())
90 else:
91 enable &= os.path.exists(firmwareFile)
92 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable)
93
94 @pyqtSlot(str)
95 def on_espComboBox_currentTextChanged(self, chip):
96 """
97 Private slot to handle the selection of a chip type.
98
99 @param chip selected chip type
100 @type str
101 """
102 selectedSize = self.sizeComboBox.currentText()
103 self.sizeComboBox.clear()
104 if chip and chip in self.FlashSizes:
105 self.sizeComboBox.addItem("")
106 for text, data in self.FlashSizes[chip]:
107 self.sizeComboBox.addItem(text, data)
108
109 self.sizeComboBox.setCurrentText(selectedSize)
110
111 self.__updateOkButton()
112
113 @pyqtSlot(str)
114 def on_firmwarePicker_textChanged(self, firmware):
115 """
116 Private slot handling a change of the firmware path.
117
118 @param firmware path to the firmware
119 @type str
120 """
121 self.__updateOkButton()
122
123 def getData(self):
124 """
125 Public method to get the entered data.
126
127 @return tuple containing the selected chip type, the firmware size,
128 the flash mode and the path of the firmware file
129 @rtype tuple of (str, str, str, str)
130 """
131 return (
132 self.espComboBox.currentText().lower(),
133 self.sizeComboBox.currentData(),
134 self.modeComboBox.currentText(),
135 self.firmwarePicker.text(),
136 )

eric ide

mercurial