eric6/MicroPython/UnknownDevicesDialog.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 8099
522946e53835
child 8143
2c730d5fd177
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

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 manage the list of unknown devices.
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
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 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
11 from PyQt5.QtGui import QDesktopServices
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from PyQt5.QtWidgets import QDialog, QListWidgetItem
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from E5Gui import E5MessageBox
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from .Ui_UnknownDevicesDialog import Ui_UnknownDevicesDialog
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 import Preferences
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 UnknownDevicesDialog(QDialog, Ui_UnknownDevicesDialog):
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 manage the list of unknown devices.
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 DeviceDataRole = Qt.UserRole
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 ModifiedRole = Qt.UserRole + 1
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 def __init__(self, parent=None):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 Constructor
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @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
34 @type QWidget (optional)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 super(UnknownDevicesDialog, self).__init__(parent)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 self.setupUi(self)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 self.__loadDevices()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 def __loadDevices(self):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 Private method to load the list of unknown devices.
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.deviceList.clear()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 devices = Preferences.getMicroPython("ManualDevices")
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 for device in devices:
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 itm = QListWidgetItem(
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.tr("{0} (0x{1:04x}/0x{2:04x})", "description, VID, PID")
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 .format(device["description"], device["vid"], device["pid"]),
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.deviceList)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 itm.setData(self.DeviceDataRole, device)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 itm.setData(self.ModifiedRole, False)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.__initialDeviceCount = self.deviceList.count()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.__checkButtons()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 def __isDirty(self):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 Private method to check, if the dialog contains unsaved data.
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 @return flag indicating the presence of unsaved data
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 @rtype bool
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 dirty = False
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 for row in range(self.deviceList.count()):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 dirty |= self.deviceList.item(row).data(self.ModifiedRole)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 dirty |= self.deviceList.count() != self.__initialDeviceCount
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 return dirty
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 def __editItem(self, item):
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 Private method to edit the given item.
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 @param item reference to the item to be edited
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 @type QListWidgetItem
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 if item is None:
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 # play it safe
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 return
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 from .AddEditDevicesDialog import AddEditDevicesDialog
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 dlg = AddEditDevicesDialog(deviceData=item.data(self.DeviceDataRole))
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 if dlg.exec() == QDialog.Accepted:
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 deviceDict = dlg.getDeviceDict()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 item.setData(self.DeviceDataRole, deviceDict)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 item.setData(self.ModifiedRole, True)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 item.setText(self.tr("{0} (*)", "list entry is modified")
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 .format(item.text()))
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 def __saveDeviceData(self):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 Private method to save the device data.
8099
522946e53835 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8080
diff changeset
97
522946e53835 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8080
diff changeset
98 @return flag indicating a successful save
522946e53835 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8080
diff changeset
99 @rtype bool
8080
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 devices = []
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 for row in range(self.deviceList.count()):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 devices.append(self.deviceList.item(row).data(
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 self.DeviceDataRole))
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 Preferences.setMicroPython("ManualDevices", devices)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 return True
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 @pyqtSlot()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 def __checkButtons(self):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 Private slot to set the enabled state of the buttons.
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 selectedItemsCount = len(self.deviceList.selectedItems())
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 self.editButton.setEnabled(selectedItemsCount == 1)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 self.deleteButton.setEnabled(selectedItemsCount >= 1)
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 @pyqtSlot(QListWidgetItem)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 def on_deviceList_itemActivated(self, item):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 Private slot to edit the data of the activated item.
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 @param item reference to the activated item
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 @type QListWidgetItem
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 self.__editItem(item)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 @pyqtSlot()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 def on_deviceList_itemSelectionChanged(self):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 Private slot to handle a change of selected items.
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 self.__checkButtons()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 @pyqtSlot()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 def on_editButton_clicked(self):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 Private slot to edit the selected item.
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 itm = self.deviceList.selectedItems()[0]
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 self.__editItem(itm)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 @pyqtSlot()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 def on_deleteButton_clicked(self):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 Private slot to delete the selected entries.
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 unsaved = False
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 for itm in self.deviceList.selectedItems():
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 unsaved |= itm.data(self.ModifiedRole)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 if unsaved:
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 ok = E5MessageBox.yesNo(
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 self,
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 self.tr("Delete Unknown Devices"),
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 self.tr("The selected entries contain some with modified"
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 " data. Shall they really be deleted?"))
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 if not ok:
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 return
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 for itm in self.deviceList.selectedItems():
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 self.deviceList.takeItem(self.deviceList.row(itm))
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 del itm
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 @pyqtSlot()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 def on_deleteAllButton_clicked(self):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 Private slot to delete all devices.
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 if self.__isDirty():
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 ok = E5MessageBox.yesNo(
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 self,
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 self.tr("Delete Unknown Devices"),
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 self.tr("The list contains some devices with modified"
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 " data. Shall they really be deleted?"))
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 if not ok:
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 return
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 self.deviceList.clear()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 @pyqtSlot()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 def on_restoreButton_clicked(self):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 Private slot to restore the list of unknown devices.
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 if self.__isDirty():
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 ok = E5MessageBox.yesNo(
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 self,
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 self.tr("Restore Unknown Devices"),
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 self.tr("Restoring the list of unknown devices will overwrite"
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 " all changes made. Do you really want to restore the"
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 " list?"))
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 if not ok:
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 return
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 self.__loadDevices()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 @pyqtSlot()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 def on_reportButton_clicked(self):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 Private slot to report the data of all boards to the eric-bugs email
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 address.
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 if self.deviceList.count() > 0:
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 bodyList = [
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 "These are my MicroPython devices not yet known by eric."
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 " Please add them.",
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 "",
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 ]
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 for row in range(self.deviceList.count()):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 deviceDict = self.deviceList.item(row).data(
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 self.DeviceDataRole)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 bodyList += [
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 "Board #{0}:".format(row),
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 " VID: {0}".format(deviceDict["vid"]),
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 " PID: {0}".format(deviceDict["pid"]),
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 " Description: {0}".format(deviceDict["description"]),
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 " Device Type: {0}".format(deviceDict["type"]),
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 " Data Volume: {0}".format(deviceDict["data_volume"]),
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 " Flash Volume: {0}".format(deviceDict["flash_volume"]),
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 ""
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 ]
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 urlQuery = QUrlQuery()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 urlQuery.addQueryItem("subject", "Unsupported MicroPython Devices")
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 urlQuery.addQueryItem("body", "\r\n".join(bodyList))
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 url = QUrl("mailto:{0}".format(BugAddress))
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 url.setQuery(urlQuery)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 QDesktopServices.openUrl(url)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 @pyqtSlot()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 def on_buttonBox_accepted(self):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 Private slot to handle the OK button press.
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 This action saves the edited list to the preferences store.
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 self.__saveDeviceData()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 self.accept()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 @pyqtSlot()
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 def on_buttonBox_rejected(self):
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 Private slot handling the cancellation of the dialog.
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 """
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 if self.__isDirty():
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 ok = E5MessageBox.okToClearData(
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 self,
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 self.tr("Unsaved Data"),
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 self.tr("""The list of devices contains some with modified"""
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 """ data."""),
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 self.__saveDeviceData)
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 if not ok:
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 return
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258
218ca8019eb8 Added the files forgotten in the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 self.reject()

eric ide

mercurial