diff -r 901caff48307 -r 48dbfea4ac06 src/eric7/MicroPython/CircuitPythonDevices.py --- a/src/eric7/MicroPython/CircuitPythonDevices.py Mon Feb 06 11:00:29 2023 +0100 +++ b/src/eric7/MicroPython/CircuitPythonDevices.py Mon Feb 06 15:02:57 2023 +0100 @@ -10,11 +10,13 @@ import os import shutil -from PyQt6.QtCore import pyqtSlot +from PyQt6.QtCore import QUrl, pyqtSlot +from PyQt6.QtNetwork import QNetworkRequest from PyQt6.QtWidgets import QMenu -from eric7 import Preferences +from eric7 import Globals, Preferences from eric7.EricWidgets import EricFileDialog, EricMessageBox +from eric7.EricWidgets.EricApplication import ericApp from eric7.SystemUtilities import FileSystemUtilities from .CircuitPythonUpdater.CircuitPythonUpdaterInterface import ( @@ -31,6 +33,7 @@ """ DeviceVolumeName = "CIRCUITPY" + GitHubFirmwareUrl = "https://github.com/adafruit/circuitpython/releases/latest" def __init__(self, microPythonWidget, deviceType, boardName, parent=None): """ @@ -252,6 +255,9 @@ self.__libraryMenu.setTearOffEnabled(True) act = menu.addAction( + self.tr("Show CircuitPython Versions"), self.__showCircuitPythonVersions + ) + act = menu.addAction( self.tr("Flash CircuitPython Firmware"), self.__flashCircuitPython ) act.setEnabled(not connected) @@ -328,6 +334,54 @@ ) @pyqtSlot() + def __showCircuitPythonVersions(self): + """ + Private slot to show the CircuitPython version of a connected device and + the latest available one (from Github). + """ + ui = ericApp().getObject("UserInterface") + request = QNetworkRequest(QUrl(CircuitPythonDevice.GitHubFirmwareUrl)) + reply = ui.networkAccessManager().head(request) + reply.finished.connect(lambda: self.__cpyVersionResponse(reply)) + + def __cpyVersionResponse(self, reply): + """ + Private method handling the response of the latest version request. + + @param reply reference to the reply object + @type QNetworkReply + """ + latestUrl = reply.url().toString() + tag = latestUrl.rsplit("/", 1)[-1] + latestVersion = Globals.versionToTuple(tag) + + cpyVersionStr = self.tr("unknown") + cpyVersion = (0, 0, 0) + if self.supportsLocalFileAccess(): + bootFile = os.path.join(self.getWorkspace(), "boot_out.txt") + if os.path.exists(bootFile): + with open(bootFile, "r") as f: + line = f.readline() + cpyVersionStr = line.split(";")[0].split()[2] + cpyVersion = Globals.versionToTuple(cpyVersionStr) + + msg = self.tr( + "<h4>CircuitPython Version Information</h4>" + "<table>" + "<tr><td>Installed:</td><td>{0}</td></tr>" + "<tr><td>Available:</td><td>{1}</td></tr>" + "</table>" + ).format(cpyVersionStr, tag) + if cpyVersion < latestVersion and self.supportsLocalFileAccess(): + msg += self.tr("<p><b>Update available!</b></p>") + + EricMessageBox.information( + None, + self.tr("CircuitPython Version"), + msg, + ) + + @pyqtSlot() def __installLibraryFiles(self, packageMode=False): """ Private slot to install Python files into the onboard library.