src/eric7/MicroPython/Devices/CircuitPythonUpdater/ShowBundlesDialog.py

Sun, 16 Mar 2025 12:53:12 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 16 Mar 2025 12:53:12 +0100
branch
eric7
changeset 11170
6d6199d668fb
parent 11090
f5f5f5803935
permissions
-rw-r--r--

Added the Adafruit Feather nRF52840 to the list of known NRF52 boards and changed the list of known CircuitPython boards to be more explicit with respect to Adafruit boards (i.e. VID 0x239A).

# -*- coding: utf-8 -*-

# Copyright (c) 2023 - 2025 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog showing the available bundles and their modules.
"""

import circup

from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QDialog, QTreeWidgetItem

from .Ui_ShowBundlesDialog import Ui_ShowBundlesDialog


class ShowBundlesDialog(QDialog, Ui_ShowBundlesDialog):
    """
    Class implementing a dialog showing the available bundles and their modules.
    """

    def __init__(self, withModules, parent=None):
        """
        Constructor

        @param withModules flag indicating to list the modules and their version
        @type bool
        @param parent reference to the parent widget (defaults to None)
        @type QWidget (optional)
        """
        super().__init__(parent)
        self.setupUi(self)

        self.header.setText(
            self.tr("Available Bundles and Modules")
            if withModules
            else self.tr("Available Bundles")
        )
        self.bundlesWidget.setColumnCount(2)

        localBundles = circup.get_bundles_local_dict().values()
        bundles = circup.get_bundles_list()
        availableModules = circup.get_bundle_versions(bundles)

        for bundle in bundles:
            topItm = QTreeWidgetItem(
                self.bundlesWidget, [bundle.key, bundle.current_tag]
            )
            topItm.setExpanded(True)
            if bundle.key in localBundles:
                font = topItm.font(0)
                font.setUnderline(True)
                topItm.setFont(0, font)
            itm = QTreeWidgetItem(topItm, [bundle.url])
            itm.setFirstColumnSpanned(True)

            if withModules:
                modulesHeader = QTreeWidgetItem(topItm, [self.tr("Modules")])
                modulesHeader.setExpanded(True)
                for name, mod in sorted(availableModules.items()):
                    if mod["bundle"] == bundle:
                        QTreeWidgetItem(
                            modulesHeader,
                            [name, mod.get("__version__", self.tr("unknown"))],
                        )

        self.bundlesWidget.resizeColumnToContents(0)
        self.bundlesWidget.resizeColumnToContents(1)
        self.bundlesWidget.sortItems(0, Qt.SortOrder.AscendingOrder)

eric ide

mercurial