eric7/PipInterface/PipLicensesDialog.py

branch
eric7
changeset 9003
6bc210cd5726
parent 9002
31a7decd3393
child 9014
cdf68c00881d
equal deleted inserted replaced
9002:31a7decd3393 9003:6bc210cd5726
5 5
6 """ 6 """
7 Module implementing a dialog to show the licenses of an environment. 7 Module implementing a dialog to show the licenses of an environment.
8 """ 8 """
9 9
10 from PyQt6.QtCore import Qt 10 from PyQt6.QtCore import pyqtSlot, Qt
11 from PyQt6.QtWidgets import QDialog, QTreeWidgetItem 11 from PyQt6.QtWidgets import QDialog, QTreeWidgetItem
12
13 from EricGui.EricOverrideCursor import EricOverrideCursor
12 14
13 from .Ui_PipLicensesDialog import Ui_PipLicensesDialog 15 from .Ui_PipLicensesDialog import Ui_PipLicensesDialog
14 16
15 17
16 class PipLicensesDialog(QDialog, Ui_PipLicensesDialog): 18 class PipLicensesDialog(QDialog, Ui_PipLicensesDialog):
17 """ 19 """
18 Class documentation goes here. 20 Class implementing a dialog to show the licenses of an environment.
19 """ 21 """
20 LicensesPackageColumn = 0 22 LicensesPackageColumn = 0
21 LicensesVersionColumn = 1 23 LicensesVersionColumn = 1
22 LicensesLicenseColumn = 2 24 LicensesLicenseColumn = 2
23 25
24 SummaryCountColumn = 0 26 SummaryCountColumn = 0
25 SummaryLicenseColumn = 1 27 SummaryLicenseColumn = 1
26 28
27 def __init__(self, pip, environment, parent=None): 29 def __init__(self, pip, environment, localPackages=True, usersite=False,
30 parent=None):
28 """ 31 """
29 Constructor 32 Constructor
30 33
31 @param pip reference to the pip interface object 34 @param pip reference to the pip interface object
32 @type Pip 35 @type Pip
33 @param envName name of the environment to show the licenses for 36 @param environment name of the environment to show the licenses for
34 @type str 37 @type str
38 @param localPackages flag indicating to show the licenses for local
39 packages only
40 @type bool
41 @param usersite flag indicating to show the licenses for packages
42 installed in user-site directory only
43 @type bool
35 @param parent reference to the parent widget (defaults to None) 44 @param parent reference to the parent widget (defaults to None)
36 @type QWidget (optional) 45 @type QWidget (optional)
37 """ 46 """
38 super().__init__(parent) 47 super().__init__(parent)
39 self.setupUi(self) 48 self.setupUi(self)
40 49
41 self.__pip = pip 50 self.__pip = pip
51 self.__environment = environment
52
53 self.localCheckBox.setChecked(localPackages)
54 self.userCheckBox.setChecked(usersite)
55
56 self.localCheckBox.toggled.connect(self.__refreshLicenses)
57 self.userCheckBox.toggled.connect(self.__refreshLicenses)
42 58
43 if environment: 59 if environment:
44 self.environmentLabel.setText("<b>{0}</b>".format( 60 self.environmentLabel.setText("<b>{0}</b>".format(
45 self.tr("Licenses of {0}").format(environment) 61 self.tr('Licenses of "{0}"').format(environment)
46 )) 62 ))
63 else:
64 # That should never happen; play it safe.
65 self.environmentLabel.setText(self.tr("No environment specified."))
66
67 self.__refreshLicenses()
68
69 @pyqtSlot()
70 def __refreshLicenses(self):
71 """
72 Private slot to refresh the license lists.
73 """
74 with EricOverrideCursor():
75 self.licensesList.clear()
76 self.summaryList.clear()
47 77
48 # step 1: show the licenses per package 78 # step 1: show the licenses per package
49 self.licensesList.setUpdatesEnabled(True) 79 self.licensesList.setUpdatesEnabled(False)
50 licenses = self.__pip.getLicenses(environment) 80 licenses = self.__pip.getLicenses(
51 for license in licenses: 81 self.__environment,
82 localPackages=self.localCheckBox.isChecked(),
83 usersite=self.userCheckBox.isChecked(),
84 )
85 for lic in licenses:
52 QTreeWidgetItem(self.licensesList, [ 86 QTreeWidgetItem(self.licensesList, [
53 license["Name"], 87 lic["Name"],
54 license["Version"], 88 lic["Version"],
55 license["License"].replace("; ", "\n"), 89 lic["License"].replace("; ", "\n"),
56 ]) 90 ])
57 91
58 self.licensesList.sortItems( 92 self.licensesList.sortItems(
59 PipLicensesDialog.LicensesPackageColumn, 93 PipLicensesDialog.LicensesPackageColumn,
60 Qt.SortOrder.AscendingOrder) 94 Qt.SortOrder.AscendingOrder)
61 for col in range(self.licensesList.columnCount()): 95 for col in range(self.licensesList.columnCount()):
62 self.licensesList.resizeColumnToContents(col) 96 self.licensesList.resizeColumnToContents(col)
63 self.licensesList.setUpdatesEnabled(True) 97 self.licensesList.setUpdatesEnabled(True)
64 98
65 # step 2: show the licenses summary 99 # step 2: show the licenses summary
66 self.summaryList.setUpdatesEnabled(True) 100 self.summaryList.setUpdatesEnabled(False)
67 licenses = self.__pip.getLicensesSummary(environment) 101 licenses = self.__pip.getLicensesSummary(
68 for license in licenses: 102 self.__environment,
103 localPackages=self.localCheckBox.isChecked(),
104 usersite=self.userCheckBox.isChecked(),
105 )
106 for lic in licenses:
69 QTreeWidgetItem(self.summaryList, [ 107 QTreeWidgetItem(self.summaryList, [
70 "{0:4d}".format(license["Count"]), 108 "{0:4d}".format(lic["Count"]),
71 license["License"].replace("; ", "\n"), 109 lic["License"].replace("; ", "\n"),
72 ]) 110 ])
73 111
74 self.summaryList.sortItems( 112 self.summaryList.sortItems(
75 PipLicensesDialog.SummaryLicenseColumn, 113 PipLicensesDialog.SummaryLicenseColumn,
76 Qt.SortOrder.AscendingOrder) 114 Qt.SortOrder.AscendingOrder)
77 for col in range(self.summaryList.columnCount()): 115 for col in range(self.summaryList.columnCount()):
78 self.summaryList.resizeColumnToContents(col) 116 self.summaryList.resizeColumnToContents(col)
79 self.summaryList.setUpdatesEnabled(True) 117 self.summaryList.setUpdatesEnabled(True)
80
81 else:
82 # That should never happen; play it safe.
83 self.environmentLabel.setText(self.tr("No environment specified."))

eric ide

mercurial