eric6/MicroPython/CircuitPythonDevices.py

branch
micropython
changeset 7092
7414b3b012b1
parent 7084
3eddfc540614
child 7100
c4d9c28ebcd8
diff -r 84d2a73b448a -r 7414b3b012b1 eric6/MicroPython/CircuitPythonDevices.py
--- a/eric6/MicroPython/CircuitPythonDevices.py	Sat Jul 27 19:22:21 2019 +0200
+++ b/eric6/MicroPython/CircuitPythonDevices.py	Sat Jul 27 19:22:58 2019 +0200
@@ -44,7 +44,11 @@
         Public method to enable the supported action buttons.
         """
         super(CircuitPythonDevice, self).setButtons()
-        self.microPython.setActionButtons(repl=True, chart=HAS_QTCHART)
+        self.microPython.setActionButtons(run=True, repl=True, chart=HAS_QTCHART)
+        
+        workspace = self.getWorkspace()
+        if workspace.endswith("CIRCUITPY"):
+            self.microPython.setActionButtons(open=True, save=True)
     
     def forceInterrupt(self):
         """
@@ -94,6 +98,26 @@
         """
         self.__plotterActive = on
     
+    def canRunScript(self):
+        """
+        Public method to determine, if a script can be executed.
+        
+        @return tuple containing a flag indicating it is safe to start a
+            Plotter and a reason why it cannot.
+        @rtype tuple of (bool, str)
+        """
+        return True, ""
+    
+    def runScript(self, script):
+        """
+        Public method to run the given Python script.
+        
+        @param script script to be executed
+        @type str
+        """
+        pythonScript = script.split("\n")
+        self.sendCommands(pythonScript)
+    
     def getWorkspace(self):
         """
         Public method to get the workspace directory.
@@ -131,23 +155,23 @@
             #
             oldMode = ctypes.windll.kernel32.SetErrorMode(1)
             try:
-                for disk in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
-                    path = '{0}:\\'.format(disk)
+                for disk in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
+                    path = "{0}:\\".format(disk)
                     if (os.path.exists(path) and
-                            getVolumeName(path) == 'CIRCUITPY'):
+                            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']:
+            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')
+                        if volume.endswith(b"CIRCUITPY"):
+                            deviceDirectory = volume.decode("utf-8")
                             break
                     if deviceDirectory:
                         break

eric ide

mercurial