src/eric7/PipInterface/PipPackagesWidget.py

branch
eric7
changeset 10206
d6921563be6c
parent 10133
39d1353996b9
child 10207
df02f650f574
--- a/src/eric7/PipInterface/PipPackagesWidget.py	Mon Sep 11 17:58:47 2023 +0200
+++ b/src/eric7/PipInterface/PipPackagesWidget.py	Tue Sep 12 16:59:22 2023 +0200
@@ -1316,7 +1316,7 @@
             self.tr("Check Vulnerabilities"), self.__checkVulnerability
         )
         # updateVulnerabilityDbAct
-        self.__pipMenu.addAction(
+        self.__updateVulnerabilitiesAct = self.__pipMenu.addAction(
             self.tr("Update Vulnerability Database"), self.__updateVulnerabilityDbCache
         )
         self.__pipMenu.addSeparator()
@@ -1364,7 +1364,12 @@
         self.__editVirtualenvConfigAct.setEnabled(enable)
 
         self.__checkVulnerabilityAct.setEnabled(
-            enable & self.vulnerabilityCheckBox.isEnabled()
+            enable
+            and self.vulnerabilityCheckBox.isEnabled()
+            and Preferences.getPip("VulnerabilityCheckEnabled")
+        )
+        self.__updateVulnerabilitiesAct.setEnabled(
+            enable and Preferences.getPip("VulnerabilityCheckEnabled")
         )
 
         self.__cyclonedxAct.setEnabled(enable)
@@ -1589,6 +1594,7 @@
             if dlg.result() == QDialog.DialogCode.Accepted:
                 dlg.setPreferences()
                 Preferences.syncPreferences()
+                self.preferencesChanged()
 
     @pyqtSlot()
     def __showCacheInfo(self):
@@ -1631,6 +1637,20 @@
     ##################################################################
 
     @pyqtSlot(bool)
+    def setVulnerabilityEnabled(self, enable):
+        """
+        Public slot to set the enabled state of the vulnerability checks.
+
+        @param enable vulnerability checks enabled state
+        @type bool
+        """
+        self.vulnerabilityCheckBox.setChecked(enable)
+        self.vulnerabilityCheckBox.setEnabled(enable)
+        self.packagesList.setColumnHidden(
+            PipPackagesWidget.VulnerabilityColumn, not enable
+        )
+
+    @pyqtSlot(bool)
     def on_vulnerabilityCheckBox_clicked(self, checked):
         """
         Private slot handling a change of the automatic vulnerability checks.
@@ -1717,11 +1737,7 @@
             VulnerabilityCheckError.FullDbUnavailable,
             VulnerabilityCheckError.SummaryDbUnavailable,
         ):
-            self.vulnerabilityCheckBox.setChecked(False)
-            self.vulnerabilityCheckBox.setEnabled(False)
-            self.packagesList.setColumnHidden(
-                PipPackagesWidget.VulnerabilityColumn, True
-            )
+            self.setVulnerabilityEnabled(False)
 
     @pyqtSlot()
     def __updateVulnerabilityDbCache(self):
@@ -2102,3 +2118,22 @@
         if venvName == self.__pip.getProjectEnvironmentString():
             venvName = "<project>"
         CycloneDXInterface.createCycloneDXFile(venvName)
+
+    ##################################################################
+    ## Interface to preferences
+    ##################################################################
+
+    @pyqtSlot()
+    def preferencesChanged(self):
+        """
+        Public slot to handle a change of preferences.
+        """
+        enable = self.setVulnerabilityEnabled(
+            Preferences.getPip("VulnerabilityCheckEnabled")
+        )
+        if enable != self.vulnerabilityCheckBox.isEnabled():
+            # only if status changes because it is an expensive operation
+            if self.vulnerabilityCheckBox.isChecked():
+                self.__updateVulnerabilityData(clearFirst=True)
+            else:
+                self.__clearVulnerabilityInfo()

eric ide

mercurial