eric6/MicroPython/EspFirmwareSelectionDialog.py

branch
micropython
changeset 7108
4f6133a01c6a
child 7115
fe89c98430b6
equal deleted inserted replaced
7103:aea236dc8002 7108:4f6133a01c6a
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 firmware to
8 be flashed.
9 """
10
11 from __future__ import unicode_literals
12
13 import os
14
15 from PyQt5.QtCore import pyqtSlot, QRegularExpression
16 from PyQt5.QtGui import QRegularExpressionValidator
17 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
18
19 from E5Gui.E5PathPicker import E5PathPickerModes
20
21 from .Ui_EspFirmwareSelectionDialog import Ui_EspFirmwareSelectionDialog
22
23
24 class EspFirmwareSelectionDialog(QDialog, Ui_EspFirmwareSelectionDialog):
25 """
26 Class implementing a dialog to select the ESP chip type and the firmware to
27 be flashed.
28 """
29 def __init__(self, addon=False, parent=None):
30 """
31 Constructor
32
33 @param addon flag indicating an addon firmware
34 @type bool
35 @param parent reference to the parent widget
36 @type QWidget
37 """
38 super(EspFirmwareSelectionDialog, self).__init__(parent)
39 self.setupUi(self)
40
41 self.__addon = addon
42
43 self.firmwarePicker.setMode(E5PathPickerModes.OpenFileMode)
44 self.firmwarePicker.setFilters(
45 self.tr("Firmware Files (*.bin);;All Files (*)"))
46
47 self.espComboBox.addItems(["", "ESP32", "ESP8266"])
48
49 if addon:
50 self.__validator = QRegularExpressionValidator(
51 QRegularExpression(r"[0-9a-fA-F]{0,4}")
52 )
53 self.addressEdit.setValidator(self.__validator)
54 else:
55 self.addressLabel.hide()
56 self.addressEdit.hide()
57
58 msh = self.minimumSizeHint()
59 self.resize(max(self.width(), msh.width()), msh.height())
60
61 def __updateOkButton(self):
62 """
63 Private method to update the state of the OK button.
64 """
65 firmwareFile = self.firmwarePicker.text()
66 enable = (bool(self.espComboBox.currentText()) and
67 bool(firmwareFile) and os.path.exists(firmwareFile))
68 if self.__addon:
69 enable &= bool(self.addressEdit.text())
70 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable)
71
72 @pyqtSlot(str)
73 def on_espComboBox_currentTextChanged(self, chip):
74 """
75 Private slot to handle the selection of a chip type.
76
77 @param chip selected chip type
78 @type str
79 """
80 self.__updateOkButton()
81
82 @pyqtSlot(str)
83 def on_firmwarePicker_textChanged(self, firmware):
84 """
85 Private slot handling a change of the firmware path.
86
87 @param firmware path to the firmware
88 @type str
89 """
90 self.__updateOkButton()
91
92 def getData(self):
93 """
94 Public method to get the entered data.
95
96 @return tuple containing the selected chip type, the path of the
97 firmware file and the flash address
98 @rtype tuple of (str, str, str)
99 """
100 if self.__addon:
101 address = self.addressEdit.text()
102 else:
103 address = ""
104
105 return (
106 self.espComboBox.currentText().lower(),
107 self.firmwarePicker.text(),
108 address,
109 )

eric ide

mercurial