--- a/eric6/MicroPython/CircuitPythonDevices.py Tue Jul 30 19:26:56 2019 +0200 +++ b/eric6/MicroPython/CircuitPythonDevices.py Tue Jul 30 19:29:15 2019 +0200 @@ -9,16 +9,12 @@ from __future__ import unicode_literals -import os -import ctypes -from subprocess import check_output - from E5Gui import E5MessageBox from .MicroPythonDevices import MicroPythonDevice from .MicroPythonReplWidget import HAS_QTCHART -import Globals +import Utilities class CircuitPythonDevice(MicroPythonDevice): @@ -35,16 +31,17 @@ @type QObject """ super(CircuitPythonDevice, self).__init__(microPythonWidget, parent) - - self.__replActive = False - self.__plotterActive = False def setButtons(self): """ Public method to enable the supported action buttons. """ super(CircuitPythonDevice, self).setButtons() - self.microPython.setActionButtons(run=True, repl=True, chart=HAS_QTCHART) +## self.microPython.setActionButtons( +## run=True, repl=True, chart=HAS_QTCHART) + # TODO: check, if this really works + self.microPython.setActionButtons( + run=True, repl=True, files=True, chart=HAS_QTCHART) workspace = self.getWorkspace() if workspace.endswith("CIRCUITPY"): @@ -70,15 +67,6 @@ """ return True, "" - def setRepl(self, on): - """ - Public method to set the REPL status and dependent status. - - @param on flag indicating the active status - @type bool - """ - self.__replActive = on - def canStartPlotter(self): """ Public method to determine, if a Plotter can be started. @@ -89,15 +77,6 @@ """ return True, "" - def setPlotter(self, on): - """ - Public method to set the Plotter status and dependent status. - - @param on flag indicating the active status - @type bool - """ - self.__plotterActive = on - def canRunScript(self): """ Public method to determine, if a script can be executed. @@ -118,6 +97,17 @@ pythonScript = script.split("\n") self.sendCommands(pythonScript) + # TODO: check, if this really works + def canStartFileManager(self): + """ + Public method to determine, if a File Manager can be started. + + @return tuple containing a flag indicating it is safe to start a + File Manager and a reason why it cannot. + @rtype tuple of (bool, str) + """ + return True, "" + def getWorkspace(self): """ Public method to get the workspace directory. @@ -125,58 +115,9 @@ @return workspace directory used for saving files @rtype str """ - deviceDirectory = None - # Attempts to find the path on the filesystem that represents the # plugged in CIRCUITPY board. - if Globals.isWindowsPlatform(): - # we are on a Windows platform - def getVolumeName(diskName): - """ - Local function to determine the volume of a disk or device. - - Each disk or external device connected to windows has an - attribute called "volume name". This function returns the - volume name for the given disk/device. - - Code from http://stackoverflow.com/a/12056414 - """ - volumeNameBuffer = ctypes.create_unicode_buffer(1024) - ctypes.windll.kernel32.GetVolumeInformationW( - ctypes.c_wchar_p(diskName), volumeNameBuffer, - ctypes.sizeof(volumeNameBuffer), None, None, None, None, 0) - return volumeNameBuffer.value - - # - # In certain circumstances, volumes are allocated to USB - # storage devices which cause a Windows popup to raise if their - # volume contains no media. Wrapping the check in SetErrorMode - # with SEM_FAILCRITICALERRORS (1) prevents this popup. - # - oldMode = ctypes.windll.kernel32.SetErrorMode(1) - try: - for disk in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": - path = "{0}:\\".format(disk) - if (os.path.exists(path) and - getVolumeName(path) == "CIRCUITPY"): - deviceDirectory = path - break - finally: - ctypes.windll.kernel32.SetErrorMode(oldMode) - else: - # we are on a Linux or macOS platform - for mountCommand in ["mount", "/sbin/mount", "/usr/sbin/mount"]: - try: - mountOutput = check_output(mountCommand).splitlines() - mountedVolumes = [x.split()[2] for x in mountOutput] - for volume in mountedVolumes: - if volume.endswith(b"CIRCUITPY"): - deviceDirectory = volume.decode("utf-8") - break - if deviceDirectory: - break - except FileNotFoundError: - pass + deviceDirectory = Utilities.findVolume("CIRCUITPY") if deviceDirectory: return deviceDirectory