Added code to search for a Python2 interpreter in some known places. If none is found, the user can configure it on the Debugger, Python config page.

Sat, 02 Jul 2011 18:16:01 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 02 Jul 2011 18:16:01 +0200
changeset 1162
ab292b7f4f8a
parent 1161
ddab52aa1a6b
child 1163
0155e7aa345d

Added code to search for a Python2 interpreter in some known places. If none is found, the user can configure it on the Debugger, Python config page.

Globals/__init__.py file | annotate | diff | comparison | revisions
Preferences/__init__.py file | annotate | diff | comparison | revisions
--- a/Globals/__init__.py	Sat Jul 02 15:47:49 2011 +0200
+++ b/Globals/__init__.py	Sat Jul 02 18:16:01 2011 +0200
@@ -8,6 +8,7 @@
 """
 
 import sys
+import os
 
 # names of the various settings objects
 settingsNameOrganization = "Eric5"
@@ -46,3 +47,44 @@
     @return flag indicating Linux platform (boolean)
     """
     return sys.platform.startswith("linux")
+
+
+################################################################################
+## functions for searching a Python2 interpreter
+################################################################################
+
+
+def findPython2Interpreters():
+    """
+    Module function for searching a Python2 interpreter.
+    
+    @return list of interpreters found (list of strings)
+    """
+    winPathList = ["C:\\Python25", "C:\\Python26", "C:\\Python27", "C:\\Python28"]
+    posixPathList = ["/usr/bin", "/usr/local/bin"]
+    posixVersionsList = ["2.5", "2.6", "2.7", "2.8"]
+    
+    interpreters = []
+    if isWindowsPlatform():
+        # search the interpreters on Windows platforms
+        for path in winPathList:
+            exeList = [
+                "python.exe",
+                "python{0}.{1}.exe".format(path[-2], path[-1]),
+            ]
+            for exe in exeList:
+                interpreter = os.path.join(path, exe)
+                if os.path.isfile(interpreter):
+                    interpreters.append(interpreter)
+##    elif isMacPlatform():
+##        # don't know how to do this due to lack of a Mac
+##        pass
+    else:
+        # search interpreters on Posix platforms
+        for path in posixPathList:
+            for version in posixVersionsList:
+                interpreter = os.path.join(path, "python{0}".format(version))
+                if os.path.isfile(interpreter):
+                    interpreters.append(interpreter)
+    
+    return interpreters
--- a/Preferences/__init__.py	Sat Jul 02 15:47:49 2011 +0200
+++ b/Preferences/__init__.py	Sat Jul 02 18:16:01 2011 +0200
@@ -22,7 +22,7 @@
 
 from PyQt4.QtCore import QDir, QPoint, QLocale, QSettings, QFileInfo, QCoreApplication, \
     QByteArray, QSize, QUrl, Qt
-from PyQt4.QtGui import QColor, QFont
+from PyQt4.QtGui import QColor, QFont, QInputDialog
 from PyQt4.QtNetwork import QNetworkRequest
 from PyQt4.QtWebKit import QWebSettings
 from PyQt4.Qsci import QsciScintilla
@@ -32,7 +32,7 @@
 import QScintilla.Lexers
 
 from Globals import settingsNameOrganization, settingsNameGlobal, settingsNameRecent, \
-    isWindowsPlatform, isLinuxPlatform
+    isWindowsPlatform, isLinuxPlatform, findPython2Interpreters
 
 from Project.ProjectBrowserFlags import SourcesBrowserFlag, FormsBrowserFlag, \
     ResourcesBrowserFlag, TranslationsBrowserFlag, InterfacesBrowserFlag, \
@@ -1050,6 +1050,28 @@
     elif key in ["AllowedHosts"]:
         return toList(
             prefClass.settings.value("Debugger/" + key, prefClass.debuggerDefaults[key]))
+    elif key == "PythonInterpreter":
+        interpreter = \
+            prefClass.settings.value("Debugger/" + key, prefClass.debuggerDefaults[key])
+        if not interpreter:
+            interpreters = findPython2Interpreters()
+            if interpreters:
+                if len(interpreters) == 1:
+                    interpreter = interpreters[0]
+                else:
+                    selection, ok = QInputDialog.getItem(
+                        None,
+                        QCoreApplication.translate("Preferences",
+                            "Select Python2 Interpreter"),
+                        QCoreApplication.translate("Preferences",
+                            "Select the Python2 interpreter to be used:"),
+                        interpreters,
+                        0, False)
+                    if ok and selection != "":
+                        interpreter = selection
+                if interpreter:
+                    setDebugger("PythonInterpreter", interpreter)
+        return interpreter
     else:
         return \
             prefClass.settings.value("Debugger/" + key, prefClass.debuggerDefaults[key])

eric ide

mercurial