Started to remove all explicit references to Python interpreters and replace them by references to virtuak environments.

Thu, 14 Jun 2018 19:20:52 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 14 Jun 2018 19:20:52 +0200
changeset 6346
92ed63434dce
parent 6345
b41a239a4949
child 6347
bcca9eba56a1

Started to remove all explicit references to Python interpreters and replace them by references to virtuak environments.

Preferences/ConfigurationDialog.py file | annotate | diff | comparison | revisions
Preferences/ConfigurationPages/DebuggerPython3Page.py file | annotate | diff | comparison | revisions
Preferences/ConfigurationPages/DebuggerPython3Page.ui file | annotate | diff | comparison | revisions
Preferences/ConfigurationPages/DebuggerPythonPage.py file | annotate | diff | comparison | revisions
Preferences/ConfigurationPages/DebuggerPythonPage.ui file | annotate | diff | comparison | revisions
Preferences/__init__.py file | annotate | diff | comparison | revisions
--- a/Preferences/ConfigurationDialog.py	Thu Jun 14 19:19:15 2018 +0200
+++ b/Preferences/ConfigurationDialog.py	Thu Jun 14 19:20:52 2018 +0200
@@ -215,7 +215,7 @@
                 [self.tr("General"), "preferences-debugger.png",
                  "DebuggerGeneralPage", "0debuggerPage", None],
                 "debuggerPythonPage":
-                [self.tr("Python"), "preferences-pyDebugger.png",
+                [self.tr("Python2"), "preferences-pyDebugger.png",
                  "DebuggerPythonPage", "0debuggerPage", None],
                 "debuggerPython3Page":
                 [self.tr("Python3"), "preferences-pyDebugger.png",
--- a/Preferences/ConfigurationPages/DebuggerPython3Page.py	Thu Jun 14 19:19:15 2018 +0200
+++ b/Preferences/ConfigurationPages/DebuggerPython3Page.py	Thu Jun 14 19:20:52 2018 +0200
@@ -9,6 +9,7 @@
 
 from __future__ import unicode_literals
 
+from E5Gui.E5Application import e5App
 from E5Gui.E5PathPicker import E5PathPickerModes
 
 from .ConfigurationPageBase import ConfigurationPageBase
@@ -29,10 +30,13 @@
         self.setupUi(self)
         self.setObjectName("DebuggerPython3Page")
         
-        self.interpreterPicker.setMode(E5PathPickerModes.OpenFileMode)
-        self.interpreterPicker.setToolTip(self.tr(
-            "Press to select the Python3 interpreter via a file selection"
-            " dialog"))
+        try:
+            virtualenvManager = e5App().getObject("VirtualEnvManager")
+        except KeyError:
+            from VirtualEnv.VirtualenvManager import VirtualenvManager
+            virtualenvManager = VirtualenvManager()
+        self.venvComboBox.addItems(
+            [""] + sorted(virtualenvManager.getVirtualenvNames()))
         
         self.debugClientPicker.setMode(E5PathPickerModes.OpenFileMode)
         self.debugClientPicker.setToolTip(self.tr(
@@ -40,8 +44,12 @@
         self.debugClientPicker.setFilters(self.tr("Python Files (*.py *.py3)"))
         
         # set initial values
-        self.interpreterPicker.setText(
-            Preferences.getDebugger("Python3Interpreter"), toNative=False)
+        venvName = Preferences.getDebugger("Python3VirtualEnv")
+        if venvName:
+            index = self.venvComboBox.findText(venvName)
+            if index < 0:
+                index = 0
+            self.venvComboBox.setCurrentIndex(index)
         dct = Preferences.getDebugger("DebugClientType3")
         if dct == "standard":
             self.standardButton.setChecked(True)
@@ -60,9 +68,11 @@
         """
         Public slot to save the Debugger Python configuration.
         """
-        Preferences.setDebugger(
-            "Python3Interpreter",
-            self.interpreterPicker.text(toNative=False))
+        venvName = self.venvComboBox.currentText()
+        if venvName:
+            Preferences.setDebugger(
+                "Python3VirtualEnv",
+                venvName)
         if self.standardButton.isChecked():
             dct = "standard"
         else:
--- a/Preferences/ConfigurationPages/DebuggerPython3Page.ui	Thu Jun 14 19:19:15 2018 +0200
+++ b/Preferences/ConfigurationPages/DebuggerPython3Page.ui	Thu Jun 14 19:20:52 2018 +0200
@@ -7,10 +7,10 @@
     <x>0</x>
     <y>0</y>
     <width>455</width>
-    <height>449</height>
+    <height>500</height>
    </rect>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout_2">
+  <layout class="QVBoxLayout" name="verticalLayout_3">
    <item>
     <widget class="QLabel" name="headerLabel">
      <property name="text">
@@ -32,18 +32,15 @@
     </widget>
    </item>
    <item>
-    <widget class="QGroupBox" name="groupBox">
+    <widget class="QGroupBox" name="groupBox_4">
      <property name="title">
-      <string>Python3 Interpreter for Debug Client</string>
+      <string>Python3 Virtual Environment</string>
      </property>
-     <layout class="QVBoxLayout" name="verticalLayout_3">
+     <layout class="QVBoxLayout" name="verticalLayout_2">
       <item>
-       <widget class="E5PathPicker" name="interpreterPicker" native="true">
-        <property name="focusPolicy">
-         <enum>Qt::StrongFocus</enum>
-        </property>
+       <widget class="QComboBox" name="venvComboBox">
         <property name="toolTip">
-         <string>Enter the path of the Python3 interpreter to be used by the debug client. Leave empty to use the default.</string>
+         <string>Select the virtual environment to be used</string>
         </property>
        </widget>
       </item>
@@ -158,7 +155,7 @@
   </customwidget>
  </customwidgets>
  <tabstops>
-  <tabstop>interpreterPicker</tabstop>
+  <tabstop>venvComboBox</tabstop>
   <tabstop>standardButton</tabstop>
   <tabstop>customButton</tabstop>
   <tabstop>debugClientPicker</tabstop>
--- a/Preferences/ConfigurationPages/DebuggerPythonPage.py	Thu Jun 14 19:19:15 2018 +0200
+++ b/Preferences/ConfigurationPages/DebuggerPythonPage.py	Thu Jun 14 19:20:52 2018 +0200
@@ -9,6 +9,7 @@
 
 from __future__ import unicode_literals
 
+from E5Gui.E5Application import e5App
 from E5Gui.E5PathPicker import E5PathPickerModes
 
 from .ConfigurationPageBase import ConfigurationPageBase
@@ -29,10 +30,13 @@
         self.setupUi(self)
         self.setObjectName("DebuggerPythonPage")
         
-        self.interpreterPicker.setMode(E5PathPickerModes.OpenFileMode)
-        self.interpreterPicker.setToolTip(self.tr(
-            "Press to select the Python interpreter via a file selection"
-            " dialog"))
+        try:
+            virtualenvManager = e5App().getObject("VirtualEnvManager")
+        except KeyError:
+            from VirtualEnv.VirtualenvManager import VirtualenvManager
+            virtualenvManager = VirtualenvManager()
+        self.venvComboBox.addItems(
+            [""] + sorted(virtualenvManager.getVirtualenvNames()))
         
         self.debugClientPicker.setMode(E5PathPickerModes.OpenFileMode)
         self.debugClientPicker.setToolTip(self.tr(
@@ -40,8 +44,12 @@
         self.debugClientPicker.setFilters(self.tr("Python Files (*.py *.py2)"))
         
         # set initial values
-        self.interpreterPicker.setText(
-            Preferences.getDebugger("PythonInterpreter"), toNative=False)
+        venvName = Preferences.getDebugger("Python2VirtualEnv")
+        if venvName:
+            index = self.venvComboBox.findText(venvName)
+            if index < 0:
+                index = 0
+            self.venvComboBox.setCurrentIndex(index)
         dct = Preferences.getDebugger("DebugClientType")
         if dct == "standard":
             self.standardButton.setChecked(True)
@@ -60,9 +68,11 @@
         """
         Public slot to save the Debugger Python configuration.
         """
-        Preferences.setDebugger(
-            "PythonInterpreter",
-            self.interpreterPicker.text(toNative=False))
+        venvName = self.venvComboBox.currentText()
+        if venvName:
+            Preferences.setDebugger(
+                "Python2VirtualEnv",
+                venvName)
         if self.standardButton.isChecked():
             dct = "standard"
         else:
--- a/Preferences/ConfigurationPages/DebuggerPythonPage.ui	Thu Jun 14 19:19:15 2018 +0200
+++ b/Preferences/ConfigurationPages/DebuggerPythonPage.ui	Thu Jun 14 19:20:52 2018 +0200
@@ -7,14 +7,14 @@
     <x>0</x>
     <y>0</y>
     <width>455</width>
-    <height>449</height>
+    <height>500</height>
    </rect>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout_2">
+  <layout class="QVBoxLayout" name="verticalLayout_3">
    <item>
     <widget class="QLabel" name="headerLabel">
      <property name="text">
-      <string>&lt;b&gt;Configure Python Debugger&lt;/b&gt;</string>
+      <string>&lt;b&gt;Configure Python2 Debugger&lt;/b&gt;</string>
      </property>
     </widget>
    </item>
@@ -32,18 +32,15 @@
     </widget>
    </item>
    <item>
-    <widget class="QGroupBox" name="groupBox">
+    <widget class="QGroupBox" name="groupBox_4">
      <property name="title">
-      <string>Python Interpreter for Debug Client</string>
+      <string>Python2 Virtual Environment</string>
      </property>
-     <layout class="QVBoxLayout" name="verticalLayout_3">
+     <layout class="QVBoxLayout" name="verticalLayout_2">
       <item>
-       <widget class="E5PathPicker" name="interpreterPicker" native="true">
-        <property name="focusPolicy">
-         <enum>Qt::StrongFocus</enum>
-        </property>
+       <widget class="QComboBox" name="venvComboBox">
         <property name="toolTip">
-         <string>Enter the path of the Python interpreter to be used by the debug client.</string>
+         <string>Select the virtual environment to be used</string>
         </property>
        </widget>
       </item>
@@ -158,7 +155,7 @@
   </customwidget>
  </customwidgets>
  <tabstops>
-  <tabstop>interpreterPicker</tabstop>
+  <tabstop>venvComboBox</tabstop>
   <tabstop>standardButton</tabstop>
   <tabstop>customButton</tabstop>
   <tabstop>debugClientPicker</tabstop>
--- a/Preferences/__init__.py	Thu Jun 14 19:19:15 2018 +0200
+++ b/Preferences/__init__.py	Thu Jun 14 19:20:52 2018 +0200
@@ -92,6 +92,8 @@
         "SuppressClientExit": False,
         "BreakAlways": False,
         "ShowExceptionInShell": True,
+        "Python2VirtualEnv": "",
+        "Python3VirtualEnv": "",
         "PythonInterpreter": "",
         "Python3Interpreter": "",
         "RubyInterpreter": "",
@@ -1797,34 +1799,27 @@
             prefClass.settings.value(
                 "Debugger/" + key, prefClass.debuggerDefaults[key]))
     elif key in ["PythonInterpreter", "Python3Interpreter"]:
-        interpreter = \
-            prefClass.settings.value(
-                "Debugger/" + key, prefClass.debuggerDefaults[key])
+        # This code is here to ensure backward compatibility.
+        if key == "PythonInterpreter":
+            newKey = "Python2VirtualEnv"
+        else:
+            newKey = "Python3VirtualEnv"
+        venvName = prefClass.settings.value(
+                "Debugger/" + newKey, prefClass.debuggerDefaults[newKey])
+        if venvName:
+            try:
+                from E5Gui.E5Application import e5App
+                virtualenvManager = e5App().getObject("VirtualEnvManager")
+            except KeyError:
+                from VirtualEnv.VirtualenvManager import VirtualenvManager
+                virtualenvManager = VirtualenvManager()
+            interpreter = virtualenvManager.getVirtualenvInterpreter(venvName)
+        else:
+            interpreter = ""
         if not interpreter:
             pyVersion = 2 if key == "PythonInterpreter" else 3
             if sys.version_info[0] == pyVersion:
                 return sys.executable
-
-            interpreters = findPythonInterpreters(pyVersion)
-            if interpreters:
-                if len(interpreters) == 1:
-                    interpreter = interpreters[0]
-                else:
-                    selection, ok = QInputDialog.getItem(
-                        None,
-                        QCoreApplication.translate(
-                            "Preferences",
-                            "Select Python{0} Interpreter").format(pyVersion),
-                        QCoreApplication.translate(
-                            "Preferences",
-                            "Select the Python{0} interpreter to be used:")
-                        .format(pyVersion),
-                        interpreters,
-                        0, False)
-                    if ok and selection != "":
-                        interpreter = selection
-                if interpreter:
-                    setDebugger(key, interpreter)
         return interpreter
     elif key in ["DebugClientType", "DebugClientType3"]:
         debugClientType = prefClass.settings.value(

eric ide

mercurial