eric6/MicroPython/MicrobitDevices.py

changeset 8038
73ec029d4107
parent 8032
76375aa6bc04
child 8051
b78279548993
diff -r cf0e5b8cd23a -r 73ec029d4107 eric6/MicroPython/MicrobitDevices.py
--- a/eric6/MicroPython/MicrobitDevices.py	Sun Jan 31 17:47:01 2021 +0100
+++ b/eric6/MicroPython/MicrobitDevices.py	Sun Jan 31 17:47:55 2021 +0100
@@ -12,7 +12,7 @@
 import shutil
 
 from PyQt5.QtCore import pyqtSlot, QStandardPaths
-from PyQt5.QtWidgets import QInputDialog, QLineEdit
+from PyQt5.QtWidgets import QInputDialog, QLineEdit, QDialog
 
 from .MicroPythonDevices import MicroPythonDevice
 from .MicroPythonWidget import HAS_QTCHART
@@ -377,16 +377,48 @@
             # Calliope mini
             return Preferences.getMicroPython("CalliopeDocuUrl")
     
-    def getFirmwareUrl(self):
+    def getFirmwareUrl(self, fwtype="mpy"):
         """
         Public method to get the device firmware download URL.
         
+        @param fwtype type of firmware to download
+            (valid values are "mpy" and "dap"; defaults to "mpy")
+        @type str (optional)
         @return firmware download URL of the device
         @rtype str
         """
         if self.__deviceType == "bbc_microbit":
-            # BBC micro:bit
-            return Preferences.getMicroPython("MicrobitFirmwareUrl")
+            # BBC micro:bit V1
+            if fwtype == "mpy":
+                return Preferences.getMicroPython("MicrobitMicroPythonUrl")
+            elif fwtype == "dap":
+                return Preferences.getMicroPython("MicrobitFirmwareUrl")
+            else:
+                return ""
         else:
             # Calliope mini
             return Preferences.getMicroPython("CalliopeFirmwareUrl")
+    
+    def downloadFirmware(self):
+        """
+        Public method to download the device firmware.
+        """
+        fwtype = ""
+        if self.__deviceType == "bbc_microbit":
+            # BBC micro:bit
+            from E5Gui.E5ComboSelectionDialog import E5ComboSelectionDialog
+            dlg = E5ComboSelectionDialog(
+                [(self.tr("MicroPython"), "mpy"), (self.tr("DAPLink"), "dap")],
+                title=self.tr("Firmware Type"),
+                message=self.tr("Select the firmware type to download from"
+                                " the list below:")
+            )
+            if dlg.exec() == QDialog.Accepted:
+                fwtype = dlg.getSelection()[1]
+            else:
+                # user cancelled
+                return
+        
+        url = self.getFirmwareUrl(fwtype)
+        if url:
+            e5App().getObject("UserInterface").launchHelpViewer(url)

eric ide

mercurial