src/eric7/MicroPython/AddEditDevicesDialog.py

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

eric ide

mercurial