diff -r c5bcafe3485c -r 61e5fe703818 src/eric7/MicroPython/MicroPythonWidget.py --- a/src/eric7/MicroPython/MicroPythonWidget.py Tue May 02 12:01:40 2023 +0200 +++ b/src/eric7/MicroPython/MicroPythonWidget.py Tue May 02 18:01:34 2023 +0200 @@ -261,7 +261,8 @@ self.deviceIconLabel.setPixmap(Devices.getDeviceIcon("", False)) - self.checkButton.setIcon(EricPixmapCache.getIcon("question")) + self.repopulateButton.setIcon(EricPixmapCache.getIcon("question")) + self.webreplConfigButton.setIcon(EricPixmapCache.getIcon("edit")) self.runButton.setIcon(EricPixmapCache.getIcon("start")) self.replButton.setIcon(EricPixmapCache.getIcon("terminal")) self.filesButton.setIcon(EricPixmapCache.getIcon("filemanager")) @@ -321,6 +322,9 @@ self.__populateDeviceTypeComboBox() + self.repopulateButton.clicked.connect(self.__populateDeviceTypeComboBox) + self.webreplConfigButton.clicked.connect(self.__configureWebreplUrls) + self.replEdit.installEventFilter(self) # Hack to intercept middle button paste self.__origReplEditMouseReleaseEvent = self.replEdit.mouseReleaseEvent @@ -404,21 +408,34 @@ else: unknownMessage = "" - # add webrepl entries + # add WebREPL entries self.deviceTypeComboBox.insertSeparator(self.deviceTypeComboBox.count()) - # TODO: replace this test data with real code - self.deviceTypeComboBox.addItem("Raspberry Pico W #2") + self.deviceTypeComboBox.addItem(self.tr("WebREPL (manual)")) index = self.deviceTypeComboBox.count() - 1 - self.deviceTypeComboBox.setItemData(index, "rp2040", self.DeviceTypeRole) self.deviceTypeComboBox.setItemData( index, "webrepl", self.DeviceInterfaceTypeRole ) - self.deviceTypeComboBox.setItemData( - index, "ws://repl#3179@192.168.1.52", self.DeviceWebreplUrlRole - ) - ############################# + webreplUrlsDict = Preferences.getMicroPython("WebreplUrls") + for name in sorted(webreplUrlsDict): + self.deviceTypeComboBox.addItem(webreplUrlsDict[name]["description"]) + index = self.deviceTypeComboBox.count() - 1 + self.deviceTypeComboBox.setItemData( + index, webreplUrlsDict[name]["device_type"], self.DeviceTypeRole + ) + self.deviceTypeComboBox.setItemData( + index, "webrepl", self.DeviceInterfaceTypeRole + ) + self.deviceTypeComboBox.setItemData( + index, webreplUrlsDict[name]["url"], self.DeviceWebreplUrlRole + ) + if webreplUrlsDict: + webreplMessage = self.tr( + "\n%n WebREPL connection(s) defined.", "", len(webreplUrlsDict) + ) + else: + webreplMessage = "" - self.deviceInfoLabel.setText(supportedMessage + unknownMessage) + self.deviceInfoLabel.setText(supportedMessage + unknownMessage + webreplMessage) index = self.deviceTypeComboBox.findText( currentDevice, Qt.MatchFlag.MatchExactly @@ -504,6 +521,23 @@ if self.__chartWidget is not None: self.__chartWidget.preferencesChanged() + @pyqtSlot() + def __configureWebreplUrls(self): + """ + Private slot to configure the list of selectable WebREPL URLs. + """ + from .MicroPythonWebreplUrlsConfigDialog import ( + MicroPythonWebreplUrlsConfigDialog + ) + + webreplUrlsDict = Preferences.getMicroPython("WebreplUrls") + dlg = MicroPythonWebreplUrlsConfigDialog(webreplUrlsDict) + if dlg.exec() == QDialog.DialogCode.Accepted: + webreplUrlsDict = dlg.getWebreplDict() + Preferences.setMicroPython("WebreplUrls", webreplUrlsDict) + + self.__populateDeviceTypeComboBox() + def deviceInterface(self): """ Public method to get a reference to the device interface object. @@ -552,7 +586,7 @@ pid = self.deviceTypeComboBox.itemData(index, self.DevicePidRole) serNo = self.deviceTypeComboBox.itemData(index, self.DeviceSerNoRole) - if deviceType or (pid is not None and pid is not None): + if deviceType or (vid is not None and pid is not None): deviceWorkspace = ( self.__device.getWorkspace() if self.__device is not None else None ) @@ -567,13 +601,6 @@ else: self.__device = None - @pyqtSlot() - def on_checkButton_clicked(self): - """ - Private slot to check for connected devices. - """ - self.__populateDeviceTypeComboBox() - def setActionButtons(self, **kwargs): """ Public method to set the enabled state of the various action buttons.