eric6/MicroPython/MicrobitDevices.py

changeset 8051
b78279548993
parent 8038
73ec029d4107
child 8062
8dc5acb30a8b
diff -r 2090a7b8a326 -r b78279548993 eric6/MicroPython/MicrobitDevices.py
--- a/eric6/MicroPython/MicrobitDevices.py	Mon Feb 01 16:09:29 2021 +0100
+++ b/eric6/MicroPython/MicrobitDevices.py	Mon Feb 01 20:01:18 2021 +0100
@@ -12,7 +12,7 @@
 import shutil
 
 from PyQt5.QtCore import pyqtSlot, QStandardPaths
-from PyQt5.QtWidgets import QInputDialog, QLineEdit, QDialog
+from PyQt5.QtWidgets import QInputDialog, QLineEdit
 
 from .MicroPythonDevices import MicroPythonDevice
 from .MicroPythonWidget import HAS_QTCHART
@@ -216,7 +216,10 @@
                 deviceDirectory = Utilities.findVolume("MICROBIT")
         else:
             # Calliope mini
-            deviceDirectory = Utilities.findVolume("MINI")
+            if firmware:
+                deviceDirectory = Utilities.findVolume("MAINTENANCE")
+            else:
+                deviceDirectory = Utilities.findVolume("MINI")
         if not deviceDirectory:
             if self.__deviceType == "bbc_microbit":
                 # BBC micro:bit is not ready or not mounted
@@ -253,12 +256,34 @@
                     )
             else:
                 # Calliope mini is not ready or not mounted
-                E5MessageBox.warning(
-                    self.microPython,
-                    self.tr("Flash MicroPython/Firmware"),
-                    self.tr("Could not find an attached {0}.\n\n"
-                            "Please make sure the device is plugged "
-                            "into this computer.").format(self.deviceName()))
+                if firmware:
+                    E5MessageBox.critical(
+                        self.microPython,
+                        self.tr("Flash MicroPython/Firmware"),
+                        self.tr(
+                            '<p>The "Calliope mini" is not ready for flashing'
+                            ' the DAPLink firmware. Follow these'
+                            ' instructions. </p>'
+                            '<ul>'
+                            '<li>unplug USB cable and any batteries</li>'
+                            '<li>keep RESET button pressed an plug USB cable'
+                            ' back in</li>'
+                            '<li>a drive called MAINTENANCE should be'
+                            ' available</li>'
+                            '</ul>'
+                        )
+                    )
+                else:
+                    E5MessageBox.critical(
+                        self.microPython,
+                        self.tr("Flash MicroPython/Firmware"),
+                        self.tr(
+                            '<p>The "Calliope mini" is not ready for flashing'
+                            ' the MicroPython firmware. Please make sure,'
+                            ' that a drive called MINI is available.'
+                            '</p>'
+                        )
+                    )
         else:
             downloadsPath = QStandardPaths.standardLocations(
                 QStandardPaths.DownloadLocation)[0]
@@ -266,7 +291,8 @@
                 self.microPython,
                 self.tr("Flash MicroPython/Firmware"),
                 downloadsPath,
-                self.tr("MicroPython/Firmware Files (*.hex);;All Files (*)"))
+                self.tr("MicroPython/Firmware Files (*.hex *.bin);;"
+                        "All Files (*)"))
             if firmware and os.path.exists(firmware):
                 shutil.copy2(firmware, deviceDirectory)
     
@@ -377,48 +403,25 @@
             # Calliope mini
             return Preferences.getMicroPython("CalliopeDocuUrl")
     
-    def getFirmwareUrl(self, fwtype="mpy"):
+    def getDownloadMenuEntries(self):
         """
-        Public method to get the device firmware download URL.
+        Public method to retrieve the entries for the downloads menu.
         
-        @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
+        @return list of tuples with menu text and URL to be opened for each
+            entry
+        @rtype list of tuple of (str, str)
         """
         if self.__deviceType == "bbc_microbit":
-            # BBC micro:bit V1
-            if fwtype == "mpy":
-                return Preferences.getMicroPython("MicrobitMicroPythonUrl")
-            elif fwtype == "dap":
-                return Preferences.getMicroPython("MicrobitFirmwareUrl")
-            else:
-                return ""
+            return [
+                (self.tr("MicroPython Firmware"),
+                 Preferences.getMicroPython("MicrobitMicroPythonUrl")),
+                (self.tr("DAPLink Firmware"),
+                 Preferences.getMicroPython("MicrobitFirmwareUrl"))
+            ]
         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)
+            return [
+                (self.tr("MicroPython Firmware"),
+                 Preferences.getMicroPython("CalliopeMicroPythonUrl")),
+                (self.tr("DAPLink Firmware"),
+                 Preferences.getMicroPython("CalliopeDAPLinkUrl"))
+            ]

eric ide

mercurial