eric7/PipInterface/PipLicensesDialog.py

branch
eric7
changeset 9103
8ac26b4c4316
parent 9014
cdf68c00881d
child 9108
19a57544f32c
--- a/eric7/PipInterface/PipLicensesDialog.py	Tue May 24 14:56:10 2022 +0200
+++ b/eric7/PipInterface/PipLicensesDialog.py	Tue May 24 15:34:31 2022 +0200
@@ -53,6 +53,8 @@
         self.__pip = pip
         self.__environment = environment
         
+        self.__allFilter = self.tr("<All>")
+        
         self.__saveCSVButton = self.buttonBox.addButton(
             self.tr("Save as CSV..."), QDialogButtonBox.ButtonRole.ActionRole)
         self.__saveCSVButton.clicked.connect(self.__saveAsCSV)
@@ -74,6 +76,9 @@
             # That should never happen; play it safe.
             self.environmentLabel.setText(self.tr("No environment specified."))
         
+        self.licenseFilterComboBox.currentTextChanged.connect(
+            self.__filterPackagesByLicense)
+        
         self.__refreshLicenses()
         
     @pyqtSlot()
@@ -84,6 +89,9 @@
         with EricOverrideCursor():
             self.licensesList.clear()
             self.summaryList.clear()
+            self.licenseFilterComboBox.clear()
+            
+            licensesForFilter = set()
             
             # step 1: show the licenses per package
             self.licensesList.setUpdatesEnabled(False)
@@ -118,6 +126,7 @@
                     "{0:4d}".format(lic["Count"]),
                     lic["License"].replace("; ", "\n"),
                 ])
+                licensesForFilter |= set(lic["License"].split("; "))
             
             self.summaryList.sortItems(
                 PipLicensesDialog.SummaryLicenseColumn,
@@ -125,10 +134,30 @@
             for col in range(self.summaryList.columnCount()):
                 self.summaryList.resizeColumnToContents(col)
             self.summaryList.setUpdatesEnabled(True)
+            
+            self.licenseFilterComboBox.addItems(
+                [self.__allFilter] + sorted(licensesForFilter))
         
         enable = bool(self.licensesList.topLevelItemCount())
         self.__saveCSVButton.setEnabled(enable)
     
+    @pyqtSlot(str)
+    def __filterPackagesByLicense(self, license):
+        """
+        Private slot to filter the list of packages by license.
+        
+        @param license license name
+        @type str
+        """
+        for row in range(self.licensesList.topLevelItemCount()):
+            itm = self.licensesList.topLevelItem(row)
+            if license == self.__allFilter:
+                itm.setHidden(False)
+            else:
+                itm.setHidden(license not in itm.text(
+                    PipLicensesDialog.LicensesLicenseColumn
+                ))
+    
     @pyqtSlot()
     def __saveAsCSV(self):
         """

eric ide

mercurial