VirtualenvManager: changed code to allow environments without environment directory denoting a global environment.

Tue, 12 Jun 2018 18:59:45 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 12 Jun 2018 18:59:45 +0200
changeset 6341
a00e63f6d766
parent 6340
0eb6c62ceb8e
child 6342
c79ecba9cde7

VirtualenvManager: changed code to allow environments without environment directory denoting a global environment.

VirtualEnv/VirtualenvAddEditDialog.py file | annotate | diff | comparison | revisions
VirtualEnv/VirtualenvAddEditDialog.ui file | annotate | diff | comparison | revisions
VirtualEnv/VirtualenvManager.py file | annotate | diff | comparison | revisions
--- a/VirtualEnv/VirtualenvAddEditDialog.py	Sun Jun 10 17:21:43 2018 +0200
+++ b/VirtualEnv/VirtualenvAddEditDialog.py	Tue Jun 12 18:59:45 2018 +0200
@@ -63,6 +63,8 @@
         self.nameEdit.setText(venvName)
         self.targetDirectoryPicker.setText(venvDirectory)
         self.pythonExecPicker.setText(venvInterpreter)
+        self.globalCheckBox.setChecked(self.__editMode and
+                                       not bool(venvDirectory))
         
         self.__updateOk()
     
@@ -81,11 +83,16 @@
                 bool(self.nameEdit.text()) and
                 self.__manager.isUnique(self.nameEdit.text())
             )
-            
+        
+        if not self.globalCheckBox.isChecked():
+            enable = (
+                enable and
+                bool(self.targetDirectoryPicker.text()) and
+                os.path.exists(self.targetDirectoryPicker.text())
+            )
+        
         enable = (
             enable and
-            bool(self.targetDirectoryPicker.text()) and
-            os.path.exists(self.targetDirectoryPicker.text()) and
             bool(self.pythonExecPicker.text()) and
             os.access(self.pythonExecPicker.text(), os.X_OK)
         )
@@ -128,6 +135,18 @@
         """
         self.__updateOk()
     
+    @pyqtSlot(bool)
+    def on_globalCheckBox_toggled(self, checked):
+        """
+        Private slot handling a change of the global check box state.
+        
+        @param checked state of the check box
+        @type bool
+        """
+        self.targetDirectoryPicker.setEnabled(not checked)
+        
+        self.__updateOk()
+    
     def getData(self):
         """
         Public method to retrieve the entered data.
@@ -136,8 +155,15 @@
             interpreter of the virtual environment
         @rtype tuple of (str, str, str)
         """
-        return (
-            self.nameEdit.text(),
-            self.targetDirectoryPicker.text(),
-            self.pythonExecPicker.text(),
-        )
+        if self.globalCheckBox.isChecked():
+            return (
+                self.nameEdit.text(),
+                "",
+                self.pythonExecPicker.text(),
+            )
+        else:
+            return (
+                self.nameEdit.text(),
+                self.targetDirectoryPicker.text(),
+                self.pythonExecPicker.text(),
+            )
--- a/VirtualEnv/VirtualenvAddEditDialog.ui	Sun Jun 10 17:21:43 2018 +0200
+++ b/VirtualEnv/VirtualenvAddEditDialog.ui	Tue Jun 12 18:59:45 2018 +0200
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>700</width>
-    <height>124</height>
+    <height>154</height>
    </rect>
   </property>
   <property name="sizeGripEnabled">
@@ -75,6 +75,16 @@
     </widget>
    </item>
    <item row="3" column="0" colspan="2">
+    <widget class="QCheckBox" name="globalCheckBox">
+     <property name="toolTip">
+      <string>Select to denote a global environment (i.e. no virtual environment directory to be given)</string>
+     </property>
+     <property name="text">
+      <string>Global Environment</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="0" colspan="2">
     <widget class="QDialogButtonBox" name="buttonBox">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
--- a/VirtualEnv/VirtualenvManager.py	Sun Jun 10 17:21:43 2018 +0200
+++ b/VirtualEnv/VirtualenvManager.py	Tue Jun 12 18:59:45 2018 +0200
@@ -205,11 +205,13 @@
                 venvMessages
             )
             if dlg.exec_() == QDialog.Accepted:
-                if venvName in self.__virtualEnvironments and \
-                        bool(self.__virtualEnvironments[venvName]):
-                    shutil.rmtree(self.__virtualEnvironments[venvName], True)
-                    del self.__virtualEnvironments[venvName]
-                    del self.__virtualEnvironmentInterpreters[venvName]
+                for venvName in venvNames:
+                    if venvName in self.__virtualEnvironments and \
+                            bool(self.__virtualEnvironments[venvName]):
+                        shutil.rmtree(self.__virtualEnvironments[venvName],
+                                      True)
+                        del self.__virtualEnvironments[venvName]
+                        del self.__virtualEnvironmentInterpreters[venvName]
                 
                 self.__updateSettings()
                 
@@ -218,15 +220,14 @@
     
     def removeVirtualEnvs(self, venvNames):
         """
-        Public method to delete virtuals environment from the list.
+        Public method to delete virtual environment from the list.
         
         @param venvNames list of logical names for the virtual environments
         @type list of str
         """
         venvMessages = []
         for venvName in venvNames:
-            if venvName in self.__virtualEnvironments and \
-                    bool(self.__virtualEnvironments[venvName]):
+            if venvName in self.__virtualEnvironments:
                 venvMessages.append(self.tr("{0} - {1}").format(
                     venvName, self.__virtualEnvironments[venvName]))
         if venvMessages:
@@ -240,10 +241,10 @@
                 venvMessages
             )
             if dlg.exec_() == QDialog.Accepted:
-                if venvName in self.__virtualEnvironments and \
-                        bool(self.__virtualEnvironments[venvName]):
-                    del self.__virtualEnvironments[venvName]
-                    del self.__virtualEnvironmentInterpreters[venvName]
+                for venvName in venvNames:
+                    if venvName in self.__virtualEnvironments:
+                        del self.__virtualEnvironments[venvName]
+                        del self.__virtualEnvironmentInterpreters[venvName]
                 
                 self.__updateSettings()
                 
@@ -313,6 +314,20 @@
         else:
             return ""
     
+    def getVirtualenvDirectory(self, venvName):
+        """
+        Public method to get the directory of a virtual environment.
+        
+        @param venvName logical name for the virtual environment
+        @type str
+        @return directory path
+        @rtype str
+        """
+        if venvName in self.__virtualEnvironments:
+            return self.__virtualEnvironments[venvName]
+        else:
+            return ""
+    
     def getVirtualenvNames(self):
         """
         Public method to get a list of defined virtual environments.

eric ide

mercurial