eric6/MicroPython/MicrobitDevices.py

changeset 8062
8dc5acb30a8b
parent 8051
b78279548993
child 8067
a467ab075be0
diff -r 979562f350bf -r 8dc5acb30a8b eric6/MicroPython/MicrobitDevices.py
--- a/eric6/MicroPython/MicrobitDevices.py	Wed Feb 03 19:14:35 2021 +0100
+++ b/eric6/MicroPython/MicrobitDevices.py	Wed Feb 03 19:15:58 2021 +0100
@@ -42,6 +42,8 @@
         super(MicrobitDevice, self).__init__(microPythonWidget, parent)
         
         self.__deviceType = deviceType
+        
+        self.__workspace = self.__findWorkspace()
     
     def setButtons(self):
         """
@@ -132,17 +134,34 @@
         @return workspace directory used for saving files
         @rtype str
         """
+        if self.__workspace:
+            # return cached entry
+            return self.__workspace
+        else:
+            self.__workspace = self.__findWorkspace()
+            return self.__workspace
+    
+    def __findWorkspace(self):
+        """
+        Public method to find the workspace directory.
+        
+        @return workspace directory used for saving files
+        @rtype str
+        """
         # Attempts to find the path on the filesystem that represents the
         # plugged in MICROBIT or MINI board.
         if self.__deviceType == "bbc_microbit":
             # BBC micro:bit
-            deviceDirectory = Utilities.findVolume("MICROBIT")
+            deviceDirectories = Utilities.findVolume("MICROBIT", all=True)
         else:
             # Calliope mini
-            deviceDirectory = Utilities.findVolume("MINI")
+            deviceDirectories = Utilities.findVolume("MINI", all=True)
         
-        if deviceDirectory:
-            return deviceDirectory
+        if deviceDirectories:
+            if len(deviceDirectories) == 1:
+                return deviceDirectories[0]
+            else:
+                return self.selectDeviceDirectory(deviceDirectories)
         else:
             # return the default workspace and give the user a warning
             E5MessageBox.warning(
@@ -207,20 +226,22 @@
         # Attempts to find the path on the file system that represents the
         # plugged in micro:bit board. To flash the DAPLink firmware, it must be
         # in maintenance mode, for MicroPython in standard mode.
-        # The Calliope mini board must be in standard mode.
         if self.__deviceType == "bbc_microbit":
             # BBC micro:bit
             if firmware:
-                deviceDirectory = Utilities.findVolume("MAINTENANCE")
+                deviceDirectories = Utilities.findVolume("MAINTENANCE",
+                                                         all=True)
             else:
-                deviceDirectory = Utilities.findVolume("MICROBIT")
+                deviceDirectories = Utilities.findVolume("MICROBIT",
+                                                         all=True)
         else:
             # Calliope mini
             if firmware:
-                deviceDirectory = Utilities.findVolume("MAINTENANCE")
+                deviceDirectories = Utilities.findVolume("MAINTENANCE",
+                                                         all=True)
             else:
-                deviceDirectory = Utilities.findVolume("MINI")
-        if not deviceDirectory:
+                deviceDirectories = Utilities.findVolume("MINI", all=True)
+        if len(deviceDirectories) == 0:
             if self.__deviceType == "bbc_microbit":
                 # BBC micro:bit is not ready or not mounted
                 if firmware:
@@ -284,7 +305,7 @@
                             '</p>'
                         )
                     )
-        else:
+        elif len(deviceDirectories) == 1:
             downloadsPath = QStandardPaths.standardLocations(
                 QStandardPaths.DownloadLocation)[0]
             firmware = E5FileDialog.getOpenFileName(
@@ -294,7 +315,14 @@
                 self.tr("MicroPython/Firmware Files (*.hex *.bin);;"
                         "All Files (*)"))
             if firmware and os.path.exists(firmware):
-                shutil.copy2(firmware, deviceDirectory)
+                shutil.copy2(firmware, deviceDirectories[0])
+        else:
+            E5MessageBox.warning(
+                self,
+                self.tr("Flash MicroPython/Firmware"),
+                self.tr("There are multiple devices in ready for flashing."
+                        " Please make sure, that only one device is prepared.")
+            )
     
     @pyqtSlot()
     def __saveMain(self):

eric ide

mercurial