eric6/MicroPython/MicroPythonWidget.py

changeset 8082
2242a6a1d786
parent 8079
331e717c458e
child 8096
5425a9072300
equal deleted inserted replaced
8081:e0087e542717 8082:2242a6a1d786
176 17: QBrush(QColor(255, 255, 255)), 176 17: QBrush(QColor(255, 255, 255)),
177 }, 177 },
178 } 178 }
179 179
180 180
181 # TODO: extract UF2 flashing support into a general MPy functionality with own
182 # vid/pid list
181 class MicroPythonWidget(QWidget, Ui_MicroPythonWidget): 183 class MicroPythonWidget(QWidget, Ui_MicroPythonWidget):
182 """ 184 """
183 Class implementing the MicroPython REPL widget. 185 Class implementing the MicroPython REPL widget.
184 186
185 @signal dataReceived(data) emitted to send data received via the serial 187 @signal dataReceived(data) emitted to send data received via the serial
189 ZoomMax = 20 191 ZoomMax = 20
190 192
191 DeviceTypeRole = Qt.UserRole 193 DeviceTypeRole = Qt.UserRole
192 DeviceBoardRole = Qt.UserRole + 1 194 DeviceBoardRole = Qt.UserRole + 1
193 DevicePortRole = Qt.UserRole + 2 195 DevicePortRole = Qt.UserRole + 2
196 DeviceVidRole = Qt.UserRole + 3
197 DevicePidRole = Qt.UserRole + 4
194 198
195 dataReceived = pyqtSignal(bytes) 199 dataReceived = pyqtSignal(bytes)
196 200
197 def __init__(self, parent=None): 201 def __init__(self, parent=None):
198 """ 202 """
302 devices, unknownDevices = MicroPythonDevices.getFoundDevices() 306 devices, unknownDevices = MicroPythonDevices.getFoundDevices()
303 if devices: 307 if devices:
304 self.deviceInfoLabel.setText( 308 self.deviceInfoLabel.setText(
305 self.tr("%n supported device(s) detected.", "", len(devices))) 309 self.tr("%n supported device(s) detected.", "", len(devices)))
306 310
307 for index, (boardType, boardName, description, portName) in ( 311 for index, (boardType, boardName, description, portName,
308 enumerate(sorted(devices), 1) 312 vid, pid) in enumerate(sorted(devices), 1):
309 ):
310 self.deviceTypeComboBox.addItem( 313 self.deviceTypeComboBox.addItem(
311 self.tr("{0} - {1} ({2})", 314 self.tr("{0} - {1} ({2})",
312 "board name, description, port name") 315 "board name, description, port name")
313 .format(boardName, description, portName) 316 .format(boardName, description, portName)
314 ) 317 )
316 index, boardType, self.DeviceTypeRole) 319 index, boardType, self.DeviceTypeRole)
317 self.deviceTypeComboBox.setItemData( 320 self.deviceTypeComboBox.setItemData(
318 index, boardName, self.DeviceBoardRole) 321 index, boardName, self.DeviceBoardRole)
319 self.deviceTypeComboBox.setItemData( 322 self.deviceTypeComboBox.setItemData(
320 index, portName, self.DevicePortRole) 323 index, portName, self.DevicePortRole)
324 self.deviceTypeComboBox.setItemData(
325 index, vid, self.DeviceVidRole)
326 self.deviceTypeComboBox.setItemData(
327 index, pid, self.DevicePidRole)
321 328
322 else: 329 else:
323 self.deviceInfoLabel.setText( 330 self.deviceInfoLabel.setText(
324 self.tr("No supported devices detected.")) 331 self.tr("No supported devices detected."))
325 332
433 deviceType = self.deviceTypeComboBox.itemData( 440 deviceType = self.deviceTypeComboBox.itemData(
434 index, self.DeviceTypeRole) 441 index, self.DeviceTypeRole)
435 self.deviceIconLabel.setPixmap(MicroPythonDevices.getDeviceIcon( 442 self.deviceIconLabel.setPixmap(MicroPythonDevices.getDeviceIcon(
436 deviceType, False)) 443 deviceType, False))
437 444
438 self.__device = MicroPythonDevices.getDevice(deviceType, self) 445 vid = self.deviceTypeComboBox.itemData(
446 index, self.DeviceVidRole)
447 pid = self.deviceTypeComboBox.itemData(
448 index, self.DevicePidRole)
449
450 self.__device = MicroPythonDevices.getDevice(deviceType, self,
451 vid, pid)
439 self.__device.setButtons() 452 self.__device.setButtons()
440 453
441 self.connectButton.setEnabled(bool(deviceType)) 454 self.connectButton.setEnabled(bool(deviceType))
442 455
443 @pyqtSlot() 456 @pyqtSlot()

eric ide

mercurial