src/eric7/MicroPython/CircuitPythonDevices.py

branch
eric7
changeset 9740
90072e10ae9b
parent 9738
4ae976ee5339
child 9742
48dbfea4ac06
--- a/src/eric7/MicroPython/CircuitPythonDevices.py	Mon Feb 06 10:02:35 2023 +0100
+++ b/src/eric7/MicroPython/CircuitPythonDevices.py	Mon Feb 06 10:09:18 2023 +0100
@@ -17,6 +17,10 @@
 from eric7.EricWidgets import EricFileDialog, EricMessageBox
 from eric7.SystemUtilities import FileSystemUtilities
 
+from .CircuitPythonUpdater.CircuitPythonUpdaterInterface import (
+    CircuitPythonUpdaterInterface,
+    isCircupAvailable,
+)
 from .MicroPythonDevices import MicroPythonDevice
 from .MicroPythonWidget import HAS_QTCHART
 
@@ -46,6 +50,8 @@
         self.__boardName = boardName
         self.__workspace = self.__findWorkspace()
 
+        self.__updater = CircuitPythonUpdaterInterface(self)
+
         self.__nonUF2devices = {
             "teensy": self.__flashTeensy,
         }
@@ -152,22 +158,6 @@
 
         return self.DeviceVolumeName in self.getWorkspace(silent=True)
 
-    def getWorkspace(self, silent=False):
-        """
-        Public method to get the workspace directory.
-
-        @param silent flag indicating silent operations
-        @type bool
-        @return workspace directory used for saving files
-        @rtype str
-        """
-        if self.__workspace:
-            # return cached entry
-            return self.__workspace
-        else:
-            self.__workspace = self.__findWorkspace(silent=silent)
-            return self.__workspace
-
     def __findDeviceDirectories(self, directories):
         """
         Private method to find the device directories associated with the
@@ -232,6 +222,22 @@
 
             return super().getWorkspace()
 
+    def getWorkspace(self, silent=False):
+        """
+        Public method to get the workspace directory.
+
+        @param silent flag indicating silent operations
+        @type bool
+        @return workspace directory used for saving files
+        @rtype str
+        """
+        if self.__workspace:
+            # return cached entry
+            return self.__workspace
+        else:
+            self.__workspace = self.__findWorkspace(silent=silent)
+            return self.__workspace
+
     def addDeviceMenuEntries(self, menu):
         """
         Public method to add device specific entries to the given menu.
@@ -242,15 +248,8 @@
         connected = self.microPython.isConnected()
 
         self.__libraryMenu = QMenu(self.tr("Library Management"))
-        act = self.__libraryMenu.addAction(
-            self.tr("Install Library Files"), self.__installLibraryFiles
-        )
-        act.setEnabled(self.__deviceVolumeMounted())
-        act = self.__libraryMenu.addAction(
-            self.tr("Install Library Package"),
-            lambda: self.__installLibraryFiles(packageMode=True),
-        )
-        act.setEnabled(self.__deviceVolumeMounted())
+        self.__libraryMenu.aboutToShow.connect(self.__aboutToShowLibraryMenu)
+        self.__libraryMenu.setTearOffEnabled(True)
 
         act = menu.addAction(
             self.tr("Flash CircuitPython Firmware"), self.__flashCircuitPython
@@ -259,6 +258,31 @@
         menu.addSeparator()
         menu.addMenu(self.__libraryMenu)
 
+    @pyqtSlot()
+    def __aboutToShowLibraryMenu(self):
+        """
+        Private slot to populate the 'Library Management' menu.
+        """
+        self.__libraryMenu.clear()
+
+        if isCircupAvailable():
+            self.__updater.populateMenu(self.__libraryMenu)
+        else:
+            act = self.__libraryMenu.addAction(
+                self.tr("Install Library Files"), self.__installLibraryFiles
+            )
+            act.setEnabled(self.__deviceVolumeMounted())
+            act = self.__libraryMenu.addAction(
+                self.tr("Install Library Package"),
+                lambda: self.__installLibraryFiles(packageMode=True),
+            )
+            act.setEnabled(self.__deviceVolumeMounted())
+            self.__libraryMenu.addSeparator()
+            self.__libraryMenu.addAction(
+                self.tr("Install 'circup' Package"),
+                self.__updater.installCircup,
+            )
+
     def hasFlashMenuEntry(self):
         """
         Public method to check, if the device has its own flash menu entry.

eric ide

mercurial