MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.

Mon, 01 Feb 2021 20:01:18 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 01 Feb 2021 20:01:18 +0100
changeset 8051
b78279548993
parent 8050
2090a7b8a326
child 8052
22d519ab13df

MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.

eric6/MicroPython/MicroPythonDevices.py file | annotate | diff | comparison | revisions
eric6/MicroPython/MicroPythonWidget.py file | annotate | diff | comparison | revisions
eric6/MicroPython/MicrobitDevices.py file | annotate | diff | comparison | revisions
eric6/Preferences/ConfigurationPages/MicroPythonPage.py file | annotate | diff | comparison | revisions
eric6/Preferences/ConfigurationPages/MicroPythonPage.ui file | annotate | diff | comparison | revisions
eric6/Preferences/__init__.py file | annotate | diff | comparison | revisions
--- a/eric6/MicroPython/MicroPythonDevices.py	Mon Feb 01 16:09:29 2021 +0100
+++ b/eric6/MicroPython/MicroPythonDevices.py	Mon Feb 01 20:01:18 2021 +0100
@@ -452,3 +452,13 @@
         url = self.getFirmwareUrl()
         if url:
             e5App().getObject("UserInterface").launchHelpViewer(url)
+    
+    def getDownloadMenuEntries(self):
+        """
+        Public method to retrieve the entries for the downloads menu.
+        
+        @return list of tuples with menu text and URL to be opened for each
+            entry
+        @rtype list of tuple of (str, str)
+        """
+        return []
--- a/eric6/MicroPython/MicroPythonWidget.py	Mon Feb 01 16:09:29 2021 +0100
+++ b/eric6/MicroPython/MicroPythonWidget.py	Mon Feb 01 20:01:18 2021 +0100
@@ -10,6 +10,7 @@
 import re
 import time
 import os
+import functools
 
 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QPoint, QEvent
 from PyQt5.QtGui import QColor, QKeySequence, QTextCursor, QBrush
@@ -1163,6 +1164,21 @@
         Private slot to populate the Super Menu before showing it.
         """
         self.__superMenu.clear()
+        
+        # prepare the download menu
+        if self.__device:
+            menuEntries = self.__device.getDownloadMenuEntries()
+            if menuEntries:
+                downloadMenu = QMenu(self.tr("Downloads"), self.__superMenu)
+                for text, url in menuEntries:
+                    downloadMenu.addAction(
+                        text,
+                        functools.partial(self.__downloadFromUrl, url)
+                    )
+            else:
+                downloadMenu = None
+        
+        # populate the super menu
         if self.__device:
             hasTime = self.__device.hasTimeCommands()
         else:
@@ -1202,9 +1218,14 @@
         if self.__device:
             self.__device.addDeviceMenuEntries(self.__superMenu)
             self.__superMenu.addSeparator()
-            act = self.__superMenu.addAction(
-                self.tr("Download Firmware"), self.__downloadFirmware)
-            act.setEnabled(self.__device.hasFirmwareUrl())
+            if downloadMenu is None:
+                # generic download action
+                act = self.__superMenu.addAction(
+                    self.tr("Download Firmware"), self.__downloadFirmware)
+                act.setEnabled(self.__device.hasFirmwareUrl())
+            else:
+                # download sub-menu
+                self.__superMenu.addMenu(downloadMenu)
             self.__superMenu.addSeparator()
             act = self.__superMenu.addAction(
                 self.tr("Show Documentation"), self.__showDocumentation)
@@ -1544,6 +1565,20 @@
         
         self.__device.downloadFirmware()
     
+    def __downloadFromUrl(self, url):
+        """
+        Private method to open a web browser for the given URL.
+        
+        @param url URL to be opened
+        @type str
+        """
+        if self.__device is None:
+            # abort silently
+            return
+        
+        if url:
+            e5App().getObject("UserInterface").launchHelpViewer(url)
+    
     @pyqtSlot()
     def __manageIgnored(self):
         """
--- 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"))
+            ]
--- a/eric6/Preferences/ConfigurationPages/MicroPythonPage.py	Mon Feb 01 16:09:29 2021 +0100
+++ b/eric6/Preferences/ConfigurationPages/MicroPythonPage.py	Mon Feb 01 20:01:18 2021 +0100
@@ -118,7 +118,9 @@
         
         # Calliope mini URLs
         self.calliopeFirmwareUrlLineEdit.setText(
-            Preferences.getMicroPython("CalliopeFirmwareUrl"))
+            Preferences.getMicroPython("CalliopeDAPLinkUrl"))
+        self.calliopeMicroPythonUrlLineEdit.setText(
+            Preferences.getMicroPython("CalliopeMicroPythonUrl"))
         self.calliopeDocuUrlLineEdit.setText(
             Preferences.getMicroPython("CalliopeDocuUrl"))
     
@@ -188,9 +190,12 @@
         
         # Calliope mini URLs
         Preferences.setMicroPython(
-            "CalliopeFirmwareUrl",
+            "CalliopeDAPLinkUrl",
             self.calliopeFirmwareUrlLineEdit.text())
         Preferences.setMicroPython(
+            "CalliopeMicroPythonUrl",
+            self.calliopeMicroPythonUrlLineEdit.text())
+        Preferences.setMicroPython(
             "CalliopeDocuUrl",
             self.calliopeDocuUrlLineEdit.text())
 
--- a/eric6/Preferences/ConfigurationPages/MicroPythonPage.ui	Mon Feb 01 16:09:29 2021 +0100
+++ b/eric6/Preferences/ConfigurationPages/MicroPythonPage.ui	Mon Feb 01 20:01:18 2021 +0100
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>476</width>
-    <height>984</height>
+    <height>1001</height>
    </rect>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
@@ -357,7 +357,7 @@
      <property name="title">
       <string>Calliope mini:</string>
      </property>
-     <layout class="QGridLayout" name="gridLayout_8">
+     <layout class="QGridLayout" name="gridLayout_4">
       <item row="0" column="0">
        <widget class="QLabel" name="label_21">
         <property name="text">
@@ -373,13 +373,27 @@
        </widget>
       </item>
       <item row="1" column="0">
+       <widget class="QLabel" name="label_5">
+        <property name="text">
+         <string>MicroPython:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="E5ClearableLineEdit" name="calliopeMicroPythonUrlLineEdit">
+        <property name="toolTip">
+         <string>Enter the URL for the Calliope mini MicroPython Firmware</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="0">
        <widget class="QLabel" name="label_20">
         <property name="text">
          <string>Documentation:</string>
         </property>
        </widget>
       </item>
-      <item row="1" column="1">
+      <item row="2" column="1">
        <widget class="E5ClearableLineEdit" name="calliopeDocuUrlLineEdit">
         <property name="toolTip">
          <string>Enter the URL for the Calliope mini MicroPython documentation</string>
@@ -433,6 +447,7 @@
   <tabstop>microbitMicroPythonUrlLineEdit</tabstop>
   <tabstop>microbitDocuUrlLineEdit</tabstop>
   <tabstop>calliopeFirmwareUrlLineEdit</tabstop>
+  <tabstop>calliopeMicroPythonUrlLineEdit</tabstop>
   <tabstop>calliopeDocuUrlLineEdit</tabstop>
  </tabstops>
  <resources/>
--- a/eric6/Preferences/__init__.py	Mon Feb 01 16:09:29 2021 +0100
+++ b/eric6/Preferences/__init__.py	Mon Feb 01 20:01:18 2021 +0100
@@ -1465,17 +1465,20 @@
             "https://circuitpython.readthedocs.io/en/latest/",
         "CircuitPythonFirmwareUrl":
             "https://circuitpython.org/downloads/",
+        # TODO: add entry for Adafruit library
         # BBC micro:bit URLs
         "MicrobitDocuUrl":
             "https://microbit-micropython.readthedocs.io/en/latest/",
         "MicrobitFirmwareUrl":
             "https://microbit.org/guide/firmware/",
         "MicrobitMicroPythonUrl":
-            "https://github.com/bbcmicrobit/micropython/releases",
+            "https://github.com/bbcmicrobit/micropython/releases/",
         # calliope mini URLS
         "CalliopeDocuUrl":
             "https://github.com/calliope-mini/calliope-mini-micropython/",
-        "CalliopeFirmwareUrl":
+        "CalliopeDAPLinkUrl":
+            "https://github.com/calliope-mini/production-test/releases/",
+        "CalliopeMicroPythonUrl":
             "https://github.com/calliope-mini/calliope-mini-micropython/",
     }
     if Globals.isWindowsPlatform():

eric ide

mercurial