src/eric7/MicroPython/EspFirmwareSelectionDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
22 class EspFirmwareSelectionDialog(QDialog, Ui_EspFirmwareSelectionDialog): 22 class EspFirmwareSelectionDialog(QDialog, Ui_EspFirmwareSelectionDialog):
23 """ 23 """
24 Class implementing a dialog to select the ESP chip type and the firmware to 24 Class implementing a dialog to select the ESP chip type and the firmware to
25 be flashed. 25 be flashed.
26 """ 26 """
27
27 Chips = ( 28 Chips = (
28 ("", ""), 29 ("", ""),
29 ("ESP32", "esp32"), 30 ("ESP32", "esp32"),
30 ("ESP32-C3", "esp32c3"), 31 ("ESP32-C3", "esp32c3"),
31 ("ESP32-S2", "esp32s2"), 32 ("ESP32-S2", "esp32s2"),
32 ("ESP32-S3", "esp32s3"), 33 ("ESP32-S3", "esp32s3"),
33 ("ESP8266", "esp8266"), 34 ("ESP8266", "esp8266"),
34 ) 35 )
35 36
36 FlashModes = ( 37 FlashModes = (
37 ("", ""), 38 ("", ""),
38 ("Quad I/O", "qio"), 39 ("Quad I/O", "qio"),
39 ("Quad Output", "qout"), 40 ("Quad Output", "qout"),
40 ("Dual I/O", "dio"), 41 ("Dual I/O", "dio"),
41 ("Dual Output", "dout"), 42 ("Dual Output", "dout"),
42 ) 43 )
43 44
44 FlashAddresses = { 45 FlashAddresses = {
45 "esp8266": "0x0000", 46 "esp8266": "0x0000",
46 "esp32": "0x1000", 47 "esp32": "0x1000",
47 "esp32c3": "0x0000", 48 "esp32c3": "0x0000",
48 "esp32s2": "0x1000", 49 "esp32s2": "0x1000",
49 "esp32s3": "0x0000", 50 "esp32s3": "0x0000",
50 } 51 }
51 52
52 def __init__(self, addon=False, parent=None): 53 def __init__(self, addon=False, parent=None):
53 """ 54 """
54 Constructor 55 Constructor
55 56
56 @param addon flag indicating an addon firmware 57 @param addon flag indicating an addon firmware
57 @type bool 58 @type bool
58 @param parent reference to the parent widget 59 @param parent reference to the parent widget
59 @type QWidget 60 @type QWidget
60 """ 61 """
61 super().__init__(parent) 62 super().__init__(parent)
62 self.setupUi(self) 63 self.setupUi(self)
63 64
64 self.__addon = addon 65 self.__addon = addon
65 66
66 self.firmwarePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) 67 self.firmwarePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
67 self.firmwarePicker.setFilters( 68 self.firmwarePicker.setFilters(self.tr("Firmware Files (*.bin);;All Files (*)"))
68 self.tr("Firmware Files (*.bin);;All Files (*)")) 69
69
70 for text, chip in self.Chips: 70 for text, chip in self.Chips:
71 self.espComboBox.addItem(text, chip) 71 self.espComboBox.addItem(text, chip)
72 72
73 self.baudRateComboBox.addItems([ 73 self.baudRateComboBox.addItems(
74 "74.880", "115.200", "230.400", "460.800", "921.600", "1.500.000"]) 74 ["74.880", "115.200", "230.400", "460.800", "921.600", "1.500.000"]
75 )
75 self.baudRateComboBox.setCurrentIndex(3) 76 self.baudRateComboBox.setCurrentIndex(3)
76 77
77 for text, mode in self.FlashModes: 78 for text, mode in self.FlashModes:
78 self.modeComboBox.addItem(text, mode) 79 self.modeComboBox.addItem(text, mode)
79 80
80 if addon: 81 if addon:
81 self.__validator = QRegularExpressionValidator( 82 self.__validator = QRegularExpressionValidator(
82 QRegularExpression(r"[0-9a-fA-F]{0,7}") 83 QRegularExpression(r"[0-9a-fA-F]{0,7}")
83 ) 84 )
84 self.addressEdit.setValidator(self.__validator) 85 self.addressEdit.setValidator(self.__validator)
85 else: 86 else:
86 self.addressLabel.hide() 87 self.addressLabel.hide()
87 self.addressEdit.hide() 88 self.addressEdit.hide()
88 89
89 msh = self.minimumSizeHint() 90 msh = self.minimumSizeHint()
90 self.resize(max(self.width(), msh.width()), msh.height()) 91 self.resize(max(self.width(), msh.width()), msh.height())
91 92
92 def __updateOkButton(self): 93 def __updateOkButton(self):
93 """ 94 """
94 Private method to update the state of the OK button. 95 Private method to update the state of the OK button.
95 """ 96 """
96 firmwareFile = self.firmwarePicker.text() 97 firmwareFile = self.firmwarePicker.text()
97 enable = (bool(self.espComboBox.currentText()) and 98 enable = (
98 bool(firmwareFile) and os.path.exists(firmwareFile)) 99 bool(self.espComboBox.currentText())
100 and bool(firmwareFile)
101 and os.path.exists(firmwareFile)
102 )
99 if self.__addon: 103 if self.__addon:
100 enable &= bool(self.addressEdit.text()) 104 enable &= bool(self.addressEdit.text())
101 self.buttonBox.button( 105 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(enable)
102 QDialogButtonBox.StandardButton.Ok).setEnabled(enable) 106
103
104 @pyqtSlot(str) 107 @pyqtSlot(str)
105 def on_espComboBox_currentTextChanged(self, chip): 108 def on_espComboBox_currentTextChanged(self, chip):
106 """ 109 """
107 Private slot to handle the selection of a chip type. 110 Private slot to handle the selection of a chip type.
108 111
109 @param chip selected chip type 112 @param chip selected chip type
110 @type str 113 @type str
111 """ 114 """
112 self.__updateOkButton() 115 self.__updateOkButton()
113 116
114 @pyqtSlot(str) 117 @pyqtSlot(str)
115 def on_firmwarePicker_textChanged(self, firmware): 118 def on_firmwarePicker_textChanged(self, firmware):
116 """ 119 """
117 Private slot handling a change of the firmware path. 120 Private slot handling a change of the firmware path.
118 121
119 @param firmware path to the firmware 122 @param firmware path to the firmware
120 @type str 123 @type str
121 """ 124 """
122 self.__updateOkButton() 125 self.__updateOkButton()
123 126
124 @pyqtSlot(str) 127 @pyqtSlot(str)
125 def on_addressEdit_textChanged(self, address): 128 def on_addressEdit_textChanged(self, address):
126 """ 129 """
127 Private slot handling a change of the address. 130 Private slot handling a change of the address.
128 131
129 @param address entered address 132 @param address entered address
130 @type str 133 @type str
131 """ 134 """
132 self.__updateOkButton() 135 self.__updateOkButton()
133 136
134 def getData(self): 137 def getData(self):
135 """ 138 """
136 Public method to get the entered data. 139 Public method to get the entered data.
137 140
138 @return tuple containing the selected chip type, the path of the 141 @return tuple containing the selected chip type, the path of the
139 firmware file, the baud rate, the flash mode and the flash 142 firmware file, the baud rate, the flash mode and the flash
140 address 143 address
141 @rtype tuple of (str, str, str, str, str) 144 @rtype tuple of (str, str, str, str, str)
142 """ 145 """
143 chip = self.espComboBox.currentData() 146 chip = self.espComboBox.currentData()
144 address = ( 147 address = self.addressEdit.text() if self.__addon else self.FlashAddresses[chip]
145 self.addressEdit.text() 148
146 if self.__addon else
147 self.FlashAddresses[chip])
148
149 return ( 149 return (
150 chip, 150 chip,
151 self.firmwarePicker.text(), 151 self.firmwarePicker.text(),
152 self.baudRateComboBox.currentText().replace(".", ""), 152 self.baudRateComboBox.currentText().replace(".", ""),
153 self.modeComboBox.currentData(), 153 self.modeComboBox.currentData(),

eric ide

mercurial