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), |