src/eric7/CondaInterface/Conda.py

branch
eric7
changeset 11233
295366a93bbf
parent 11230
8a15b05eeee3
--- a/src/eric7/CondaInterface/Conda.py	Wed Apr 23 18:13:44 2025 +0200
+++ b/src/eric7/CondaInterface/Conda.py	Thu Apr 24 12:58:23 2025 +0200
@@ -11,7 +11,7 @@
 import json
 import os
 
-from PyQt6.QtCore import QCoreApplication, QObject, QProcess, pyqtSignal
+from PyQt6.QtCore import QCoreApplication, QObject, QProcess, pyqtSignal, pyqtSlot
 from PyQt6.QtWidgets import QDialog
 
 from eric7 import Preferences
@@ -51,17 +51,31 @@
         super().__init__(parent)
 
         self.__ui = parent
+        with contextlib.suppress(AttributeError):
+            self.__ui.preferencesChanged.connect(self.__preferencesChanged)
 
+        self.__preferencesChanged()
+
+    @pyqtSlot()
+    def __preferencesChanged(self):
+        """
+        Private slot handling a change of configuration.
+        """
         envManager = ericApp().getObject("VirtualEnvManager")
-        envManager.registerType(
-            VirtualenvType(
-                name=Conda.EnvironmentType,
-                visual_name=self.tr("Anaconda"),
-                createFunc=self.createCondaVirtualEnvironment,
-                deleteFunc=self.deleteCondaVirtualEnvironment,
-                defaultExecPathFunc=self.condaDefaultExecPath,
-            )
-        )
+        if isCondaAvailable():
+            with contextlib.suppress(KeyError):
+                # conda was possibly registered already
+                envManager.registerType(
+                    VirtualenvType(
+                        name=Conda.EnvironmentType,
+                        visual_name=self.tr("Anaconda"),
+                        createFunc=self.createCondaVirtualEnvironment,
+                        deleteFunc=self.deleteCondaVirtualEnvironment,
+                        defaultExecPathFunc=self.condaDefaultExecPath,
+                    )
+                )
+        else:
+            envManager.unregisterType(name=Conda.EnvironmentType)
 
     #######################################################################
     ## environment related methods below

eric ide

mercurial