src/eric7/MicroPython/Devices/CircuitPythonDevices.py

branch
eric7
changeset 9944
011ae0edbcff
parent 9929
4a81ccaa7c7f
child 9972
68ac01294544
equal deleted inserted replaced
9943:02a40e8bd135 9944:011ae0edbcff
13 import os 13 import os
14 import shutil 14 import shutil
15 15
16 from PyQt6.QtCore import QUrl, pyqtSlot 16 from PyQt6.QtCore import QUrl, pyqtSlot
17 from PyQt6.QtNetwork import QNetworkReply, QNetworkRequest 17 from PyQt6.QtNetwork import QNetworkReply, QNetworkRequest
18 from PyQt6.QtWidgets import QMenu 18 from PyQt6.QtWidgets import QInputDialog, QMenu
19 19
20 from eric7 import Globals, Preferences 20 from eric7 import Globals, Preferences
21 from eric7.EricGui.EricOverrideCursor import EricOverrideCursor, EricOverridenCursor 21 from eric7.EricGui.EricOverrideCursor import EricOverrideCursor, EricOverridenCursor
22 from eric7.EricWidgets import EricFileDialog, EricMessageBox 22 from eric7.EricWidgets import EricFileDialog, EricMessageBox
23 from eric7.EricWidgets.EricApplication import ericApp 23 from eric7.EricWidgets.EricApplication import ericApp
24 from eric7.SystemUtilities import FileSystemUtilities 24 from eric7.SystemUtilities import FileSystemUtilities, OSUtilities
25 25
26 from ..EthernetDialogs import WiznetUtilities 26 from ..EthernetDialogs import WiznetUtilities
27 from ..MicroPythonWidget import HAS_QTCHART 27 from ..MicroPythonWidget import HAS_QTCHART
28 from . import FirmwareGithubUrls 28 from . import FirmwareGithubUrls
29 from .CircuitPythonUpdater.CircuitPythonUpdaterInterface import ( 29 from .CircuitPythonUpdater.CircuitPythonUpdaterInterface import (
74 self._submitMode = "paste" # use 'paste' mode to avoid loosing state 74 self._submitMode = "paste" # use 'paste' mode to avoid loosing state
75 75
76 self.__boardName = boardName 76 self.__boardName = boardName
77 self.__vidpid = (vid, pid) 77 self.__vidpid = (vid, pid)
78 78
79 self.__workspaceSelected = False
79 self.__workspace = self.__findWorkspace() if hasWorkspace else None 80 self.__workspace = self.__findWorkspace() if hasWorkspace else None
80 81
81 self.__updater = CircuitPythonUpdaterInterface(self) 82 self.__updater = CircuitPythonUpdaterInterface(self)
82 83
83 self.__createCPyMenu() 84 self.__createCPyMenu()
241 @rtype bool 242 @rtype bool
242 """ 243 """
243 if self.__workspace and not os.path.exists(self.__workspace): 244 if self.__workspace and not os.path.exists(self.__workspace):
244 self.__workspace = "" # reset 245 self.__workspace = "" # reset
245 246
246 if self.__workspace and self.DeviceVolumeName not in self.__workspace: 247 if (
248 self.__workspace
249 and self.DeviceVolumeName not in self.__workspace
250 and not self.__workspaceSelected
251 ):
247 self.__workspace = "" # reset 252 self.__workspace = "" # reset
248 253
249 return self.DeviceVolumeName in self.getWorkspace(silent=True) 254 return (
255 self.__workspaceSelected
256 or self.DeviceVolumeName in self.getWorkspace(silent=True)
257 )
250 258
251 def __findDeviceDirectories(self, directories): 259 def __findDeviceDirectories(self, directories):
252 """ 260 """
253 Private method to find the device directories associated with the 261 Private method to find the device directories associated with the
254 current board name. 262 current board name.
326 return self.__workspace 334 return self.__workspace
327 else: 335 else:
328 self.__workspace = self.__findWorkspace(silent=silent) 336 self.__workspace = self.__findWorkspace(silent=silent)
329 return self.__workspace 337 return self.__workspace
330 338
339 def setWorkspace(self, workspacePath):
340 """
341 Public method to set the device workspace directory.
342
343 @param workspacePath directory to be used for saving files
344 @type str
345 """
346 self.__workspace = workspacePath
347 self.__workspaceSelected = True
348
331 def __createCPyMenu(self): 349 def __createCPyMenu(self):
332 """ 350 """
333 Private method to create the CircuitPython submenu. 351 Private method to create the CircuitPython submenu.
334 """ 352 """
335 self.__libraryMenu = QMenu(self.tr("Library Management")) 353 self.__libraryMenu = QMenu(self.tr("Library Management"))
339 self.__flashMenu = self.__createFlashMenus() 357 self.__flashMenu = self.__createFlashMenus()
340 358
341 self.__cpyMenu = QMenu(self.tr("CircuitPython Functions")) 359 self.__cpyMenu = QMenu(self.tr("CircuitPython Functions"))
342 self.__cpyMenu.addAction( 360 self.__cpyMenu.addAction(
343 self.tr("Show CircuitPython Versions"), self.showCircuitPythonVersions 361 self.tr("Show CircuitPython Versions"), self.showCircuitPythonVersions
362 )
363 self.__cpyMenu.addSeparator()
364 self.__cpyMenu.addAction(
365 self.tr("Select Device Volume"), self.__selectDeviceVolume
344 ) 366 )
345 self.__cpyMenu.addSeparator() 367 self.__cpyMenu.addSeparator()
346 self.__bootloaderAct = self.__cpyMenu.addAction( 368 self.__bootloaderAct = self.__cpyMenu.addAction(
347 self.tr("Activate Bootloader"), self.__activateBootloader 369 self.tr("Activate Bootloader"), self.__activateBootloader
348 ) 370 )
688 ( 710 (
689 self.tr("CircuitPython Libraries"), 711 self.tr("CircuitPython Libraries"),
690 Preferences.getMicroPython("CircuitPythonLibrariesUrl"), 712 Preferences.getMicroPython("CircuitPythonLibrariesUrl"),
691 ), 713 ),
692 ] 714 ]
715
716 @pyqtSlot()
717 def __selectDeviceVolume(self):
718 """
719 Private slot to select the mounted device volume, if it could not be found
720 automatically.
721 """
722 userMounts = FileSystemUtilities.getUserMounts()
723 msg = (
724 self.tr("Select the drive letter of the device:")
725 if OSUtilities.isWindowsPlatform()
726 else self.tr("Select the path of the mounted device:")
727 )
728 selectedMount, ok = QInputDialog.getItem(
729 None,
730 self.tr("Select Device Volume"),
731 msg,
732 userMounts,
733 0, False,
734 )
735 if ok and selectedMount:
736 self.__workspace = selectedMount
737 self.__workspaceSelected = self.DeviceVolumeName not in self.__workspace
693 738
694 ################################################################## 739 ##################################################################
695 ## Methods below implement WiFi related methods 740 ## Methods below implement WiFi related methods
696 ################################################################## 741 ##################################################################
697 742

eric ide

mercurial