src/eric7/MicroPython/AddEditDevicesDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
22 class AddEditDevicesDialog(QDialog, Ui_AddEditDevicesDialog): 22 class AddEditDevicesDialog(QDialog, Ui_AddEditDevicesDialog):
23 """ 23 """
24 Class implementing a dialog to add or edit data of unknown MicroPython 24 Class implementing a dialog to add or edit data of unknown MicroPython
25 devices. 25 devices.
26 """ 26 """
27 def __init__(self, vid=0, pid=0, description=0, deviceData=None, 27
28 parent=None): 28 def __init__(self, vid=0, pid=0, description=0, deviceData=None, parent=None):
29 """ 29 """
30 Constructor 30 Constructor
31 31
32 Note: Either vid and pid and description or deviceData dictionary 32 Note: Either vid and pid and description or deviceData dictionary
33 must be given. 33 must be given.
34 34
35 @param vid vendor ID of the device (defaults to 0) 35 @param vid vendor ID of the device (defaults to 0)
36 @type int (optional) 36 @type int (optional)
37 @param pid product ID of the device (defaults to 0) 37 @param pid product ID of the device (defaults to 0)
38 @type int (optional) 38 @type int (optional)
39 @param description description for the device (defaults to "") 39 @param description description for the device (defaults to "")
43 @param parent reference to the parent widget (defaults to None) 43 @param parent reference to the parent widget (defaults to None)
44 @type QWidget (optional) 44 @type QWidget (optional)
45 """ 45 """
46 super().__init__(parent) 46 super().__init__(parent)
47 self.setupUi(self) 47 self.setupUi(self)
48 48
49 # populate the device type combo box 49 # populate the device type combo box
50 self.deviceTypeComboBox.addItem("", "") 50 self.deviceTypeComboBox.addItem("", "")
51 for board, desc in sorted(getSupportedDevices(), key=lambda x: x[1]): 51 for board, desc in sorted(getSupportedDevices(), key=lambda x: x[1]):
52 self.deviceTypeComboBox.addItem(desc, board) 52 self.deviceTypeComboBox.addItem(desc, board)
53 53
54 if deviceData is not None: 54 if deviceData is not None:
55 self.vidEdit.setText("0x{0:04x}".format(deviceData["vid"])) 55 self.vidEdit.setText("0x{0:04x}".format(deviceData["vid"]))
56 self.pidEdit.setText("0x{0:04x}".format(deviceData["pid"])) 56 self.pidEdit.setText("0x{0:04x}".format(deviceData["pid"]))
57 self.descriptionEdit.setText(deviceData["description"]) 57 self.descriptionEdit.setText(deviceData["description"])
58 self.deviceTypeComboBox.setCurrentIndex( 58 self.deviceTypeComboBox.setCurrentIndex(
59 self.deviceTypeComboBox.findData(deviceData["type"])) 59 self.deviceTypeComboBox.findData(deviceData["type"])
60 )
60 self.dataVolumeEdit.setText(deviceData["data_volume"]) 61 self.dataVolumeEdit.setText(deviceData["data_volume"])
61 self.flashVolumeEdit.setText(deviceData["flash_volume"]) 62 self.flashVolumeEdit.setText(deviceData["flash_volume"])
62 else: 63 else:
63 self.vidEdit.setText("0x{0:04x}".format(vid)) 64 self.vidEdit.setText("0x{0:04x}".format(vid))
64 self.pidEdit.setText("0x{0:04x}".format(pid)) 65 self.pidEdit.setText("0x{0:04x}".format(pid))
65 self.descriptionEdit.setText(description) 66 self.descriptionEdit.setText(description)
66 self.deviceTypeComboBox.setCurrentText("") 67 self.deviceTypeComboBox.setCurrentText("")
67 self.dataVolumeEdit.setText("") 68 self.dataVolumeEdit.setText("")
68 self.flashVolumeEdit.setText("") 69 self.flashVolumeEdit.setText("")
69 70
70 self.deviceTypeComboBox.setFocus(Qt.FocusReason.OtherFocusReason) 71 self.deviceTypeComboBox.setFocus(Qt.FocusReason.OtherFocusReason)
71 72
72 msh = self.minimumSizeHint() 73 msh = self.minimumSizeHint()
73 self.resize(max(self.width(), msh.width()), msh.height()) 74 self.resize(max(self.width(), msh.width()), msh.height())
74 75
75 @pyqtSlot(int) 76 @pyqtSlot(int)
76 def on_deviceTypeComboBox_currentIndexChanged(self, index): 77 def on_deviceTypeComboBox_currentIndexChanged(self, index):
77 """ 78 """
78 Private slot to handle the selection of a device type. 79 Private slot to handle the selection of a device type.
79 80
80 @param index index of the current item 81 @param index index of the current item
81 @type int 82 @type int
82 """ 83 """
83 board = self.deviceTypeComboBox.currentData() 84 board = self.deviceTypeComboBox.currentData()
84 self.buttonBox.button( 85 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(
85 QDialogButtonBox.StandardButton.Ok).setEnabled(bool(board)) 86 bool(board)
87 )
86 self.reportButton.setEnabled(bool(board)) 88 self.reportButton.setEnabled(bool(board))
87 89
88 @pyqtSlot() 90 @pyqtSlot()
89 def on_reportButton_clicked(self): 91 def on_reportButton_clicked(self):
90 """ 92 """
91 Private slot to report the entered data to the eric-bugs email address. 93 Private slot to report the entered data to the eric-bugs email address.
92 """ 94 """
93 body = "\r\n".join([ 95 body = "\r\n".join(
94 "This is an unknown MicroPython device. Please add it.", 96 [
95 "", 97 "This is an unknown MicroPython device. Please add it.",
96 "VID: {0}".format(self.vidEdit.text()), 98 "",
97 "PID: {0}".format(self.pidEdit.text()), 99 "VID: {0}".format(self.vidEdit.text()),
98 "Description: {0}".format(self.descriptionEdit.text()), 100 "PID: {0}".format(self.pidEdit.text()),
99 "Device Type: {0}".format(self.deviceTypeComboBox.currentData()), 101 "Description: {0}".format(self.descriptionEdit.text()),
100 "Data Volume: {0}".format(self.dataVolumeEdit.text().strip()), 102 "Device Type: {0}".format(self.deviceTypeComboBox.currentData()),
101 "Flash Volume: {0}".format(self.flashVolumeEdit.text().strip()), 103 "Data Volume: {0}".format(self.dataVolumeEdit.text().strip()),
102 ]) 104 "Flash Volume: {0}".format(self.flashVolumeEdit.text().strip()),
103 105 ]
106 )
107
104 urlQuery = QUrlQuery() 108 urlQuery = QUrlQuery()
105 urlQuery.addQueryItem("subject", "Unsupported MicroPython Device") 109 urlQuery.addQueryItem("subject", "Unsupported MicroPython Device")
106 urlQuery.addQueryItem("body", body) 110 urlQuery.addQueryItem("body", body)
107 111
108 url = QUrl("mailto:{0}".format(BugAddress)) 112 url = QUrl("mailto:{0}".format(BugAddress))
109 url.setQuery(urlQuery) 113 url.setQuery(urlQuery)
110 114
111 QDesktopServices.openUrl(url) 115 QDesktopServices.openUrl(url)
112 116
113 def getDeviceDict(self): 117 def getDeviceDict(self):
114 """ 118 """
115 Public method to get the entered data as a dictionary. 119 Public method to get the entered data as a dictionary.
116 120
117 @return dictionary containing the entered data 121 @return dictionary containing the entered data
118 @rtype dict 122 @rtype dict
119 """ 123 """
120 return { 124 return {
121 "vid": int(self.vidEdit.text(), 16), 125 "vid": int(self.vidEdit.text(), 16),

eric ide

mercurial