src/eric7/MicroPython/Devices/CircuitPythonDevices.py

branch
eric7
changeset 9944
011ae0edbcff
parent 9929
4a81ccaa7c7f
child 9972
68ac01294544
--- a/src/eric7/MicroPython/Devices/CircuitPythonDevices.py	Wed Mar 29 11:32:06 2023 +0200
+++ b/src/eric7/MicroPython/Devices/CircuitPythonDevices.py	Wed Mar 29 14:15:55 2023 +0200
@@ -15,13 +15,13 @@
 
 from PyQt6.QtCore import QUrl, pyqtSlot
 from PyQt6.QtNetwork import QNetworkReply, QNetworkRequest
-from PyQt6.QtWidgets import QMenu
+from PyQt6.QtWidgets import QInputDialog, QMenu
 
 from eric7 import Globals, Preferences
 from eric7.EricGui.EricOverrideCursor import EricOverrideCursor, EricOverridenCursor
 from eric7.EricWidgets import EricFileDialog, EricMessageBox
 from eric7.EricWidgets.EricApplication import ericApp
-from eric7.SystemUtilities import FileSystemUtilities
+from eric7.SystemUtilities import FileSystemUtilities, OSUtilities
 
 from ..EthernetDialogs import WiznetUtilities
 from ..MicroPythonWidget import HAS_QTCHART
@@ -76,6 +76,7 @@
         self.__boardName = boardName
         self.__vidpid = (vid, pid)
 
+        self.__workspaceSelected = False
         self.__workspace = self.__findWorkspace() if hasWorkspace else None
 
         self.__updater = CircuitPythonUpdaterInterface(self)
@@ -243,10 +244,17 @@
         if self.__workspace and not os.path.exists(self.__workspace):
             self.__workspace = ""  # reset
 
-        if self.__workspace and self.DeviceVolumeName not in self.__workspace:
+        if (
+            self.__workspace
+            and self.DeviceVolumeName not in self.__workspace
+            and not self.__workspaceSelected
+        ):
             self.__workspace = ""  # reset
 
-        return self.DeviceVolumeName in self.getWorkspace(silent=True)
+        return (
+            self.__workspaceSelected
+            or self.DeviceVolumeName in self.getWorkspace(silent=True)
+        )
 
     def __findDeviceDirectories(self, directories):
         """
@@ -328,6 +336,16 @@
             self.__workspace = self.__findWorkspace(silent=silent)
             return self.__workspace
 
+    def setWorkspace(self, workspacePath):
+        """
+        Public method to set the device workspace directory.
+
+        @param workspacePath directory to be used for saving files
+        @type str
+        """
+        self.__workspace = workspacePath
+        self.__workspaceSelected = True
+
     def __createCPyMenu(self):
         """
         Private method to create the CircuitPython submenu.
@@ -343,6 +361,10 @@
             self.tr("Show CircuitPython Versions"), self.showCircuitPythonVersions
         )
         self.__cpyMenu.addSeparator()
+        self.__cpyMenu.addAction(
+            self.tr("Select Device Volume"), self.__selectDeviceVolume
+        )
+        self.__cpyMenu.addSeparator()
         self.__bootloaderAct = self.__cpyMenu.addAction(
             self.tr("Activate Bootloader"), self.__activateBootloader
         )
@@ -691,6 +713,29 @@
             ),
         ]
 
+    @pyqtSlot()
+    def __selectDeviceVolume(self):
+        """
+        Private slot to select the mounted device volume, if it could not be found
+        automatically.
+        """
+        userMounts = FileSystemUtilities.getUserMounts()
+        msg = (
+            self.tr("Select the drive letter of the device:")
+            if OSUtilities.isWindowsPlatform()
+            else self.tr("Select the path of the mounted device:")
+        )
+        selectedMount, ok = QInputDialog.getItem(
+            None,
+            self.tr("Select Device Volume"),
+            msg,
+            userMounts,
+            0, False,
+        )
+        if ok and selectedMount:
+            self.__workspace = selectedMount
+            self.__workspaceSelected = self.DeviceVolumeName not in self.__workspace
+
     ##################################################################
     ## Methods below implement WiFi related methods
     ##################################################################

eric ide

mercurial