diff -r a00cd6b55728 -r 31a7decd3393 eric7/PipInterface/PipLicensesDialog.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/eric7/PipInterface/PipLicensesDialog.py Sun Mar 27 19:56:41 2022 +0200 @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing a dialog to show the licenses of an environment. +""" + +from PyQt6.QtCore import Qt +from PyQt6.QtWidgets import QDialog, QTreeWidgetItem + +from .Ui_PipLicensesDialog import Ui_PipLicensesDialog + + +class PipLicensesDialog(QDialog, Ui_PipLicensesDialog): + """ + Class documentation goes here. + """ + LicensesPackageColumn = 0 + LicensesVersionColumn = 1 + LicensesLicenseColumn = 2 + + SummaryCountColumn = 0 + SummaryLicenseColumn = 1 + + def __init__(self, pip, environment, parent=None): + """ + Constructor + + @param pip reference to the pip interface object + @type Pip + @param envName name of the environment to show the licenses for + @type str + @param parent reference to the parent widget (defaults to None) + @type QWidget (optional) + """ + super().__init__(parent) + self.setupUi(self) + + self.__pip = pip + + if environment: + self.environmentLabel.setText("<b>{0}</b>".format( + self.tr("Licenses of {0}").format(environment) + )) + + # step 1: show the licenses per package + self.licensesList.setUpdatesEnabled(True) + licenses = self.__pip.getLicenses(environment) + for license in licenses: + QTreeWidgetItem(self.licensesList, [ + license["Name"], + license["Version"], + license["License"].replace("; ", "\n"), + ]) + + self.licensesList.sortItems( + PipLicensesDialog.LicensesPackageColumn, + Qt.SortOrder.AscendingOrder) + for col in range(self.licensesList.columnCount()): + self.licensesList.resizeColumnToContents(col) + self.licensesList.setUpdatesEnabled(True) + + # step 2: show the licenses summary + self.summaryList.setUpdatesEnabled(True) + licenses = self.__pip.getLicensesSummary(environment) + for license in licenses: + QTreeWidgetItem(self.summaryList, [ + "{0:4d}".format(license["Count"]), + license["License"].replace("; ", "\n"), + ]) + + self.summaryList.sortItems( + PipLicensesDialog.SummaryLicenseColumn, + Qt.SortOrder.AscendingOrder) + for col in range(self.summaryList.columnCount()): + self.summaryList.resizeColumnToContents(col) + self.summaryList.setUpdatesEnabled(True) + + else: + # That should never happen; play it safe. + self.environmentLabel.setText(self.tr("No environment specified."))