--- a/src/eric7/MicroPython/CircuitPythonDevices.py Sun Feb 12 15:14:28 2023 +0100 +++ b/src/eric7/MicroPython/CircuitPythonDevices.py Sun Feb 12 18:11:20 2023 +0100 @@ -10,7 +10,7 @@ import os import shutil -from PyQt6.QtCore import QUrl, pyqtSlot +from PyQt6.QtCore import QProcess, QUrl, pyqtSlot from PyQt6.QtNetwork import QNetworkRequest from PyQt6.QtWidgets import QMenu @@ -54,10 +54,6 @@ self.__updater = CircuitPythonUpdaterInterface(self) - self.__nonUF2devices = { - "teensy": self.__flashTeensy, - } - self.__createCPyMenu() def setButtons(self): @@ -256,13 +252,29 @@ self.tr("Show CircuitPython Versions"), self.__showCircuitPythonVersions ) self.__cpyMenu.addSeparator() - self.__flashCpyAct = self.__cpyMenu.addAction( - self.tr("Flash CircuitPython Firmware"), self.__flashCircuitPython - ) + + lBoardName = self.microPython.getCurrentBoard().lower() + if "teensy" in lBoardName: + # Teensy 4.0 and 4.1 don't support UF2 flashing + self.__cpyMenu.addAction( + self.tr("CircuitPython Flash Instructions"), + self.__showTeensyFlashInstructions, + ) + self.__flashCpyAct = self.__cpyMenu.addAction( + self.tr("Flash CircuitPython Firmware"), self.__startTeensyLoader + ) + self.__flashCpyAct.setToolTip( + self.tr( + "Start the 'Teensy Loader' application to flash the Teensy device." + ) + ) + else: + self.__flashCpyAct = self.__cpyMenu.addAction( + self.tr("Flash CircuitPython Firmware"), self.__flashCircuitPython + ) self.__cpyMenu.addSeparator() self.__cpyMenu.addMenu(self.__libraryMenu) - def addDeviceMenuEntries(self, menu): """ Public method to add device specific entries to the given menu. @@ -313,23 +325,16 @@ @pyqtSlot() def __flashCircuitPython(self): """ - Private slot to flash a CircuitPython firmware to the device. + Private slot to flash a CircuitPython firmware to a device supporting UF2. """ from .UF2FlashDialog import UF2FlashDialog - lBoardName = self.microPython.getCurrentBoard().lower() - if lBoardName: - for name in self.__nonUF2devices: - if name in lBoardName: - self.__nonUF2devices[name]() - break - else: - dlg = UF2FlashDialog(boardType="circuitpython") - dlg.exec() + dlg = UF2FlashDialog(boardType="circuitpython") + dlg.exec() - def __flashTeensy(self): + def __showTeensyFlashInstructions(self): """ - Private method to show a message box because Teens does not support + Private method to show a message box because Teensy does not support the UF2 bootloader yet. """ EricMessageBox.information( @@ -345,6 +350,24 @@ ).format("https://www.pjrc.com/teensy/loader.html"), ) + def __startTeensyLoader(self): + """ + Private method to start the 'Teensy Loader' application. + + Note: The application must be accessible via the application search path. + """ + ok, _ = QProcess.startDetached("teensy") + if not ok: + EricMessageBox.warning( + self.microPython, + self.tr("Start 'Teensy Loader'"), + self.tr( + """<p>The 'Teensy Loader' application <b>teensy</b> could not""" + """ be started. Ensure it is in the application search path or""" + """ start it manually.</p>""" + ), + ) + @pyqtSlot() def __showCircuitPythonVersions(self): """