|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to show the licenses of an environment. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import Qt |
|
11 from PyQt6.QtWidgets import QDialog, QTreeWidgetItem |
|
12 |
|
13 from .Ui_PipLicensesDialog import Ui_PipLicensesDialog |
|
14 |
|
15 |
|
16 class PipLicensesDialog(QDialog, Ui_PipLicensesDialog): |
|
17 """ |
|
18 Class documentation goes here. |
|
19 """ |
|
20 LicensesPackageColumn = 0 |
|
21 LicensesVersionColumn = 1 |
|
22 LicensesLicenseColumn = 2 |
|
23 |
|
24 SummaryCountColumn = 0 |
|
25 SummaryLicenseColumn = 1 |
|
26 |
|
27 def __init__(self, pip, environment, parent=None): |
|
28 """ |
|
29 Constructor |
|
30 |
|
31 @param pip reference to the pip interface object |
|
32 @type Pip |
|
33 @param envName name of the environment to show the licenses for |
|
34 @type str |
|
35 @param parent reference to the parent widget (defaults to None) |
|
36 @type QWidget (optional) |
|
37 """ |
|
38 super().__init__(parent) |
|
39 self.setupUi(self) |
|
40 |
|
41 self.__pip = pip |
|
42 |
|
43 if environment: |
|
44 self.environmentLabel.setText("<b>{0}</b>".format( |
|
45 self.tr("Licenses of {0}").format(environment) |
|
46 )) |
|
47 |
|
48 # step 1: show the licenses per package |
|
49 self.licensesList.setUpdatesEnabled(True) |
|
50 licenses = self.__pip.getLicenses(environment) |
|
51 for license in licenses: |
|
52 QTreeWidgetItem(self.licensesList, [ |
|
53 license["Name"], |
|
54 license["Version"], |
|
55 license["License"].replace("; ", "\n"), |
|
56 ]) |
|
57 |
|
58 self.licensesList.sortItems( |
|
59 PipLicensesDialog.LicensesPackageColumn, |
|
60 Qt.SortOrder.AscendingOrder) |
|
61 for col in range(self.licensesList.columnCount()): |
|
62 self.licensesList.resizeColumnToContents(col) |
|
63 self.licensesList.setUpdatesEnabled(True) |
|
64 |
|
65 # step 2: show the licenses summary |
|
66 self.summaryList.setUpdatesEnabled(True) |
|
67 licenses = self.__pip.getLicensesSummary(environment) |
|
68 for license in licenses: |
|
69 QTreeWidgetItem(self.summaryList, [ |
|
70 "{0:4d}".format(license["Count"]), |
|
71 license["License"].replace("; ", "\n"), |
|
72 ]) |
|
73 |
|
74 self.summaryList.sortItems( |
|
75 PipLicensesDialog.SummaryLicenseColumn, |
|
76 Qt.SortOrder.AscendingOrder) |
|
77 for col in range(self.summaryList.columnCount()): |
|
78 self.summaryList.resizeColumnToContents(col) |
|
79 self.summaryList.setUpdatesEnabled(True) |
|
80 |
|
81 else: |
|
82 # That should never happen; play it safe. |
|
83 self.environmentLabel.setText(self.tr("No environment specified.")) |