eric6/MicroPython/MicroPythonWidget.py

changeset 8096
5425a9072300
parent 8082
2242a6a1d786
child 8099
522946e53835
diff -r d8caff84ffcf -r 5425a9072300 eric6/MicroPython/MicroPythonWidget.py
--- a/eric6/MicroPython/MicroPythonWidget.py	Thu Feb 11 11:59:32 2021 +0100
+++ b/eric6/MicroPython/MicroPythonWidget.py	Fri Feb 12 16:15:18 2021 +0100
@@ -28,6 +28,7 @@
 from .Ui_MicroPythonWidget import Ui_MicroPythonWidget
 
 from . import MicroPythonDevices
+from . import UF2FlashDialog
 try:
     from .MicroPythonGraphWidget import MicroPythonGraphWidget
     HAS_QTCHART = True
@@ -178,8 +179,6 @@
 }
 
 
-# TODO: extract UF2 flashing support into a general MPy functionality with own
-#       vid/pid list
 class MicroPythonWidget(QWidget, Ui_MicroPythonWidget):
     """
     Class implementing the MicroPython REPL widget.
@@ -347,7 +346,10 @@
                 tuple(d)
                 for d in Preferences.getMicroPython("IgnoredUnknownDevices")
             }
-            newUnknownDevices = set(unknownDevices) - ignoredUnknown
+            uf2Devices = {(*x[2], x[1]) for x in UF2FlashDialog.getFoundDevices()}
+            newUnknownDevices = (
+                set(unknownDevices) - ignoredUnknown - uf2Devices
+            )
             if newUnknownDevices:
                 button = E5MessageBox.information(
                     self,
@@ -1282,7 +1284,11 @@
             act = self.__superMenu.addAction(
                 self.tr("Show Documentation"), self.__showDocumentation)
             act.setEnabled(self.__device.hasDocumentationUrl())
-        self.__superMenu.addSeparator()
+            self.__superMenu.addSeparator()
+        if not self.__device.hasFlashMenuEntry():
+            self.__superMenu.addAction(self.tr("Flash UF2 Device"),
+                                       self.__flashUF2)
+            self.__superMenu.addSeparator()
         self.__superMenu.addAction(self.tr("Manage Unknown Devices"),
                                    self.__manageUnknownDevices)
         self.__superMenu.addAction(self.tr("Ignored Serial Devices"),
@@ -1706,3 +1712,12 @@
             
             # rescan the ports
             self.__populateDeviceTypeComboBox()
+    
+    @pyqtSlot()
+    def __flashUF2(self):
+        """
+        Private slot to flash MicroPython/CircuitPython to a device
+        support the UF2 bootloader.
+        """
+        dlg = UF2FlashDialog.UF2FlashDialog()
+        dlg.exec()

eric ide

mercurial