|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2023 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog showing the available bundles and their modules. |
|
8 """ |
|
9 |
|
10 import circup |
|
11 |
|
12 from PyQt6.QtCore import Qt |
|
13 from PyQt6.QtWidgets import QDialog, QTreeWidgetItem |
|
14 |
|
15 from .Ui_ShowBundlesDialog import Ui_ShowBundlesDialog |
|
16 |
|
17 |
|
18 class ShowBundlesDialog(QDialog, Ui_ShowBundlesDialog): |
|
19 """ |
|
20 Class implementing a dialog showing the available bundles and their modules. |
|
21 """ |
|
22 |
|
23 def __init__(self, withModules, parent=None): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param withModules flag indicating to list the modules and their version |
|
28 @type bool |
|
29 @param parent reference to the parent widget (defaults to None) |
|
30 @type QWidget (optional) |
|
31 """ |
|
32 super().__init__(parent) |
|
33 self.setupUi(self) |
|
34 |
|
35 self.header.setText( |
|
36 self.tr("Available Bundles and Modules") |
|
37 if withModules |
|
38 else self.tr("Available Bundles") |
|
39 ) |
|
40 self.bundlesWidget.setColumnCount(2) |
|
41 |
|
42 localBundles = circup.get_bundles_local_dict().values() |
|
43 bundles = circup.get_bundles_list() |
|
44 availableModules = circup.get_bundle_versions(bundles) |
|
45 |
|
46 for bundle in bundles: |
|
47 topItm = QTreeWidgetItem( |
|
48 self.bundlesWidget, [bundle.key, bundle.current_tag] |
|
49 ) |
|
50 topItm.setExpanded(True) |
|
51 if bundle.key in localBundles: |
|
52 font = topItm.font(0) |
|
53 font.setUnderline(True) |
|
54 topItm.setFont(0, font) |
|
55 itm = QTreeWidgetItem(topItm, [bundle.url]) |
|
56 itm.setFirstColumnSpanned(True) |
|
57 |
|
58 if withModules: |
|
59 modulesHeader = QTreeWidgetItem(topItm, [self.tr("Modules")]) |
|
60 modulesHeader.setExpanded(True) |
|
61 for name, mod in sorted(availableModules.items()): |
|
62 if mod["bundle"] == bundle: |
|
63 QTreeWidgetItem( |
|
64 modulesHeader, |
|
65 [name, mod.get("__version__", self.tr("unknown"))], |
|
66 ) |
|
67 |
|
68 self.bundlesWidget.resizeColumnToContents(0) |
|
69 self.bundlesWidget.resizeColumnToContents(1) |
|
70 self.bundlesWidget.sortItems(0, Qt.SortOrder.AscendingOrder) |