eric6/MicroPython/CircuitPythonDevices.py

branch
micropython
changeset 7116
233b6e62ca2b
parent 7100
c4d9c28ebcd8
child 7122
8e67ef7975de
--- a/eric6/MicroPython/CircuitPythonDevices.py	Fri Aug 02 19:52:11 2019 +0200
+++ b/eric6/MicroPython/CircuitPythonDevices.py	Fri Aug 02 19:53:00 2019 +0200
@@ -9,6 +9,11 @@
 
 from __future__ import unicode_literals
 
+import shutil
+
+from PyQt5.QtCore import pyqtSlot
+from PyQt5.QtWidgets import QDialog
+
 from E5Gui import E5MessageBox
 
 from .MicroPythonDevices import MicroPythonDevice
@@ -37,9 +42,6 @@
         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)
         
@@ -97,7 +99,6 @@
         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.
@@ -124,7 +125,7 @@
         else:
             # return the default workspace and give the user a warning
             E5MessageBox.warning(
-                self.microPythonWidget,
+                self.microPython,
                 self.tr("Workspace Directory"),
                 self.tr("Python files for CircuitPython devices are stored on"
                         " the device. Therefore, to edit these files you need"
@@ -132,3 +133,37 @@
                         " device, the standard directory will be used."))
             
             return super(CircuitPythonDevice, self).getWorkspace()
+    
+    def addDeviceMenuEntries(self, menu):
+        """
+        Public method to add device specific entries to the given menu.
+        
+        @param menu reference to the context menu
+        @type QMenu
+        """
+        connected = self.microPython.isConnected()
+        
+        act = menu.addAction(self.tr("Flash CircuitPython Firmware"),
+                             self.__flashCircuitPython)
+        act.setEnabled(not connected)
+    
+    @pyqtSlot()
+    def __flashCircuitPython(self):
+        """
+        Private slot to flash a CircuitPython firmware to the device.
+        """
+        ok = E5MessageBox.information(
+            self.microPython,
+            self.tr("Flash CircuitPython Firmware"),
+            self.tr("Please reset the device to bootloader mode and confirm"
+                    " when ready."),
+            E5MessageBox.StandardButtons(
+                E5MessageBox.Abort |
+                E5MessageBox.Ok))
+        if ok:
+            from .CircuitPythonFirmwareSelectionDialog import (
+                CircuitPythonFirmwareSelectionDialog)
+            dlg = CircuitPythonFirmwareSelectionDialog()
+            if dlg.exec_() == QDialog.Accepted:
+                cpyPath, devicePath = dlg.getData()
+                shutil.copy2(cpyPath, devicePath)

eric ide

mercurial