eric6/MicroPython/AddEditDevicesDialog.py

Sat, 06 Feb 2021 19:17:25 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 06 Feb 2021 19:17:25 +0100
changeset 8080
218ca8019eb8
child 8110
c5af1d1d2a78
permissions
-rw-r--r--

Added the files forgotten in the last commit.

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

eric ide

mercurial