eric6/MicroPython/CircuitPythonDevices.py

Tue, 30 Jul 2019 19:29:15 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 30 Jul 2019 19:29:15 +0200
branch
micropython
changeset 7100
c4d9c28ebcd8
parent 7092
7414b3b012b1
child 7116
233b6e62ca2b
permissions
-rw-r--r--

Devices.py files: removed some methods no longer needed after the recent improvements.

# -*- coding: utf-8 -*-

# Copyright (c) 2019 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing the device interface class for CircuitPython boards.
"""

from __future__ import unicode_literals

from E5Gui import E5MessageBox

from .MicroPythonDevices import MicroPythonDevice
from .MicroPythonReplWidget import HAS_QTCHART

import Utilities


class CircuitPythonDevice(MicroPythonDevice):
    """
    Class implementing the device for CircuitPython boards.
    """
    def __init__(self, microPythonWidget, parent=None):
        """
        Constructor
        
        @param microPythonWidget reference to the main MicroPython widget
        @type MicroPythonReplWidget
        @param parent reference to the parent object
        @type QObject
        """
        super(CircuitPythonDevice, self).__init__(microPythonWidget, parent)
    
    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)
        # 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"):
            self.microPython.setActionButtons(open=True, save=True)
    
    def forceInterrupt(self):
        """
        Public method to determine the need for an interrupt when opening the
        serial connection.
        
        @return flag indicating an interrupt is needed
        @rtype bool
        """
        return False
    
    def canStartRepl(self):
        """
        Public method to determine, if a REPL can be started.
        
        @return tuple containing a flag indicating it is safe to start a REPL
            and a reason why it cannot.
        @rtype tuple of (bool, str)
        """
        return True, ""
    
    def canStartPlotter(self):
        """
        Public method to determine, if a Plotter can be started.
        
        @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 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)
    
    # 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.
        
        @return workspace directory used for saving files
        @rtype str
        """
        # Attempts to find the path on the filesystem that represents the
        # plugged in CIRCUITPY board.
        deviceDirectory = Utilities.findVolume("CIRCUITPY")
        
        if deviceDirectory:
            return deviceDirectory
        else:
            # return the default workspace and give the user a warning
            E5MessageBox.warning(
                self.microPythonWidget,
                self.tr("Workspace Directory"),
                self.tr("Python files for CircuitPython devices are stored on"
                        " the device. Therefore, to edit these files you need"
                        " to have the device plugged in. Until you plug in a"
                        " device, the standard directory will be used."))
            
            return super(CircuitPythonDevice, self).getWorkspace()

eric ide

mercurial