Thu, 04 Feb 2021 14:38:01 +0100
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
# -*- coding: utf-8 -*- # Copyright (c) 2019 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing a dialog to enter the firmware flashing data. """ import os from PyQt5.QtCore import pyqtSlot from PyQt5.QtWidgets import QDialog, QDialogButtonBox from E5Gui.E5PathPicker import E5PathPickerModes from E5Gui import E5MessageBox from .Ui_CircuitPythonFirmwareSelectionDialog import ( Ui_CircuitPythonFirmwareSelectionDialog ) import Utilities import UI.PixmapCache class CircuitPythonFirmwareSelectionDialog( QDialog, Ui_CircuitPythonFirmwareSelectionDialog): """ Class implementing a dialog to enter the firmware flashing data. """ def __init__(self, parent=None): """ Constructor @param parent reference to the parent widget @type QWidget """ super(CircuitPythonFirmwareSelectionDialog, self).__init__(parent) self.setupUi(self) self.retestButton.setIcon(UI.PixmapCache.getIcon("rescan")) self.firmwarePicker.setMode(E5PathPickerModes.OpenFileMode) self.firmwarePicker.setFilters( self.tr("CircuitPython Firmware Files (*.uf2);;" "All Files (*)")) self.bootPicker.setMode(E5PathPickerModes.DirectoryShowFilesMode) self.__manualMarker = "<manual>" boards = ( ("", ""), # indicator for no selection # Adafruit boards ("--- Adafruit ---", ""), ("BadgeLC", "BADGELCBOOT"), ("CLUE nRF52840 Express", "CLUEBOOT"), ("Circuit Playground Bluefruit", "CPLAYBTBOOT"), ("Circuit Playground Express", "CPLAYBOOT"), ("Feather Arcade D51", "ARCADE-D5"), ("Feather Bluefruit Sense", "FTHR840BOOT"), ("Feather M0 Adalogger", "FEATHERBOOT"), ("Feather M0 Basic", "FEATHERBOOT"), ("Feather M0 Express", "FEATHERBOOT"), ("Feather M0 RFM69", "FEATHERBOOT"), ("Feather M0 RFM9x", "FEATHERBOOT"), ("Feather M4 Express", "FEATHERBOOT"), ("Feather nRF52840 Express", "FTHR840BOOT"), ("Gemma M0", "GEMMABOOT"), ("Grand Central M4 Express", "GCM4BOOT"), ("Hallowing M0", "HALLOWBOOT"), ("Hallowing M4 Express", "HALLOM4BOOT"), ("Itsy Arcade D51", "ARCADE-D5"), ("ItsyBitsy M0 Express", "ITSYBOOT"), ("ItsyBitsy M4 Express", "ITSYM4BOOT"), ("ItsyBitsy nRF52840 Express", " ITSY840BOOT"), ("Metro M0 Express", "METROBOOT"), ("Metro M4 Express", "METROM4BOOT"), ("Metro M4 Express AirLift", "METROM4BOOT"), ("NeoTrelis M4 Express", "TRELM4BOOT"), ("PyBadge", "BADGEBOOT"), ("PyGamer", "PYGAMERBOOT"), ("PyPortal", "PORTALBOOT"), ("PyPortal M4 Express", "PORTALBOOT"), ("PyPortal Pynt", "PORTALBOOT"), ("PyPortal Titano", "PORTALBOOT"), ("PyRuler", "TRINKETBOOT"), ("QT Py M0", "QTPY_BOOT"), ("Radiofruit M0", "RADIOBOOT"), ("Trellis M4 Express", "TRELM4BOOT"), ("Trinket M0", "TRINKETBOOT"), ("crickit", "CRICKITBOOT"), ("pIRKey M0", "PIRKEYBOOT"), # SparkFun boards ("--- SparkFun ---", ""), ("Qwiic Micro", "QwiicMicro"), ("SAMD21 Dev Breakout", "SPARKFUN"), ("SAMD21 Mini Breakout", "SPARKFUN"), ("SAMD51 Thing Plus", "51THINGBOOT"), ("RedBoard Turbo", "TURBOBOOT"), ("Pro nRF52840 Mini", "NRF52BOOT"), # Seed boards ("--- Seeed Studio ---", ""), ("Grove Zero", "Grove Zero"), ("Seeduino XIAO", "Arduino"), # other boards we know about (self.tr("--- Others ---"), ""), ("Arduino MKR1300", "MKR1300"), ("Arduino MKRZero", "MKRZEROBOOT"), ("Eitech Robotics", "ROBOTICS"), ("Generic Corp. SAMD21 Board", "SAMD21"), ("Generic Corp. SAME54 Board", "SAME54"), ("Mini SAM M0", "MINISAMBOOT"), ("Mini SAM M4", "MINISAMBOOT"), ("Robo HAT MM1", "ROBOM0BOOT"), ("Robo HAT MM1 M4", "ROBOM4BOOT"), (self.tr("Manual Select"), self.__manualMarker), ) for boardName, bootVolume in boards: self.boardComboBox.addItem(boardName, bootVolume) msh = self.minimumSizeHint() self.resize(max(self.width(), msh.width()), msh.height()) def __updateOkButton(self): """ Private method to update the state of the OK button and the retest button. """ firmwareFile = self.firmwarePicker.text() self.retestButton.setEnabled(bool(firmwareFile) and os.path.exists(firmwareFile)) if not bool(firmwareFile) or not os.path.exists(firmwareFile): enable = False else: volumeName = self.boardComboBox.currentData() if volumeName and volumeName != self.__manualMarker: # check if the user selected a board and the board is in # bootloader mode deviceDirectories = Utilities.findVolume(volumeName, findAll=True) if len(deviceDirectories) > 1: enable = False E5MessageBox.warning( self, self.tr("Select Path to Device"), self.tr("There are multiple devices in 'bootloader'" " mode and mounted. Please make sure, that" " only one device is prepared for flashing.") ) elif len(deviceDirectories) == 1: self.bootPicker.setText(deviceDirectories[0]) enable = True else: enable = False E5MessageBox.warning( self, self.tr("Select Path to Device"), self.tr("""<p>The device volume <b>{0}</b> could not""" """ be found. Is the device in 'bootloader'""" """ mode and mounted?</p> <p>Alternatively""" """ select the "Manual Select" entry and""" """ enter the path to the device below.</p>""") .format(volumeName) ) elif volumeName == self.__manualMarker: # select the device path manually deviceDirectory = self.bootPicker.text() enable = (bool(deviceDirectory) and os.path.exists(deviceDirectory)) else: # illegal entry enable = False self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable) @pyqtSlot(str) def on_firmwarePicker_textChanged(self, firmware): """ Private slot handling a change of the firmware path. @param firmware path to the firmware @type str """ self.__updateOkButton() @pyqtSlot(int) def on_boardComboBox_currentIndexChanged(self, index): """ Private slot to handle the selection of a board type. @param index index of the selected board type @type int """ if self.boardComboBox.itemData(index) == self.__manualMarker: self.bootPicker.clear() self.bootPicker.setEnabled(True) else: self.bootPicker.setEnabled(False) self.__updateOkButton() @pyqtSlot() def on_retestButton_clicked(self): """ Private slot to research for the selected volume. """ self.__updateOkButton() @pyqtSlot(str) def on_bootPicker_textChanged(self, devicePath): """ Private slot handling a change of the device path. @param devicePath path to the device @type str """ self.__updateOkButton() def getData(self): """ Public method to obtain the entered data. @return tuple containing the path to the CircuitPython firmware file and the path to the device @rtype tuple of (str, str) """ return self.firmwarePicker.text(), self.bootPicker.text()