CreateDialogCodeDialog: extended the logic to support projects loading custom widgets from outside the eric or project directories (via a virtual environment).

Sat, 13 Oct 2018 14:08:21 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 13 Oct 2018 14:08:21 +0200
changeset 6544
51996454f89f
parent 6543
d9f12defd944
child 6545
f669c4c0d39b

CreateDialogCodeDialog: extended the logic to support projects loading custom widgets from outside the eric or project directories (via a virtual environment).

APIs/Python3/eric6.api file | annotate | diff | comparison | revisions
Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric6.Project.CreateDialogCodeDialog.html file | annotate | diff | comparison | revisions
Documentation/Source/eric6.Utilities.GetSysPath.html file | annotate | diff | comparison | revisions
Documentation/Source/eric6.Utilities.__init__.html file | annotate | diff | comparison | revisions
Documentation/Source/index-eric6.Utilities.html file | annotate | diff | comparison | revisions
Project/CreateDialogCodeDialog.py file | annotate | diff | comparison | revisions
Utilities/GetSysPath.py file | annotate | diff | comparison | revisions
Utilities/__init__.py file | annotate | diff | comparison | revisions
eric6.e4p file | annotate | diff | comparison | revisions
--- a/APIs/Python3/eric6.api	Sun Oct 07 18:18:13 2018 +0200
+++ b/APIs/Python3/eric6.api	Sat Oct 13 14:08:21 2018 +0200
@@ -10319,6 +10319,7 @@
 eric6.Utilities.getPythonVersion?4()
 eric6.Utilities.getQtMacBundle?4(toolname)
 eric6.Utilities.getRealName?4()
+eric6.Utilities.getSysPath?4(interpreter)
 eric6.Utilities.getTestFileName?4(fn)
 eric6.Utilities.getUserName?4()
 eric6.Utilities.getWindowsExecutablePath?4(file)
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Sun Oct 07 18:18:13 2018 +0200
+++ b/Documentation/Help/source.qhp	Sat Oct 13 14:08:21 2018 +0200
@@ -1179,6 +1179,7 @@
             <section title="eric6.Utilities.BackgroundClient" ref="eric6.Utilities.BackgroundClient.html" />
             <section title="eric6.Utilities.BackgroundService" ref="eric6.Utilities.BackgroundService.html" />
             <section title="eric6.Utilities.FtpUtilities" ref="eric6.Utilities.FtpUtilities.html" />
+            <section title="eric6.Utilities.GetSysPath" ref="eric6.Utilities.GetSysPath.html" />
             <section title="eric6.Utilities.MimeTypes" ref="eric6.Utilities.MimeTypes.html" />
             <section title="eric6.Utilities.ModuleParser" ref="eric6.Utilities.ModuleParser.html" />
             <section title="eric6.Utilities.MouseUtilities" ref="eric6.Utilities.MouseUtilities.html" />
@@ -3507,6 +3508,7 @@
       <keyword name="CreateDialogCodeDialog.__className" id="CreateDialogCodeDialog.__className" ref="eric6.Project.CreateDialogCodeDialog.html#CreateDialogCodeDialog.__className" />
       <keyword name="CreateDialogCodeDialog.__generateCode" id="CreateDialogCodeDialog.__generateCode" ref="eric6.Project.CreateDialogCodeDialog.html#CreateDialogCodeDialog.__generateCode" />
       <keyword name="CreateDialogCodeDialog.__generatePythonCode" id="CreateDialogCodeDialog.__generatePythonCode" ref="eric6.Project.CreateDialogCodeDialog.html#CreateDialogCodeDialog.__generatePythonCode" />
+      <keyword name="CreateDialogCodeDialog.__loadUi" id="CreateDialogCodeDialog.__loadUi" ref="eric6.Project.CreateDialogCodeDialog.html#CreateDialogCodeDialog.__loadUi" />
       <keyword name="CreateDialogCodeDialog.__mapType" id="CreateDialogCodeDialog.__mapType" ref="eric6.Project.CreateDialogCodeDialog.html#CreateDialogCodeDialog.__mapType" />
       <keyword name="CreateDialogCodeDialog.__objectName" id="CreateDialogCodeDialog.__objectName" ref="eric6.Project.CreateDialogCodeDialog.html#CreateDialogCodeDialog.__objectName" />
       <keyword name="CreateDialogCodeDialog.__signatures" id="CreateDialogCodeDialog.__signatures" ref="eric6.Project.CreateDialogCodeDialog.html#CreateDialogCodeDialog.__signatures" />
@@ -6488,6 +6490,7 @@
       <keyword name="Function (Constructor)" id="Function (Constructor)" ref="eric6.Utilities.ModuleParser.html#Function.__init__" />
       <keyword name="Function.addDescription" id="Function.addDescription" ref="eric6.Utilities.ModuleParser.html#Function.addDescription" />
       <keyword name="Function.setEndLine" id="Function.setEndLine" ref="eric6.Utilities.ModuleParser.html#Function.setEndLine" />
+      <keyword name="GetSysPath (Module)" id="GetSysPath (Module)" ref="eric6.Utilities.GetSysPath.html" />
       <keyword name="Git" id="Git" ref="eric6.Plugins.VcsPlugins.vcsGit.git.html#Git" />
       <keyword name="Git (Constructor)" id="Git (Constructor)" ref="eric6.Plugins.VcsPlugins.vcsGit.git.html#Git.__init__" />
       <keyword name="Git.__gitGetFileForRevision" id="Git.__gitGetFileForRevision" ref="eric6.Plugins.VcsPlugins.vcsGit.git.html#Git.__gitGetFileForRevision" />
@@ -18952,6 +18955,7 @@
       <keyword name="getSupportedFormats" id="getSupportedFormats" ref="eric6.QScintilla.Exporters.__init__.html#getSupportedFormats" />
       <keyword name="getSupportedLanguages" id="getSupportedLanguages" ref="eric6.QScintilla.Lexers.__init__.html#getSupportedLanguages" />
       <keyword name="getSymlinkIcon" id="getSymlinkIcon" ref="eric6.UI.PixmapCache.html#getSymlinkIcon" />
+      <keyword name="getSysPath" id="getSysPath" ref="eric6.Utilities.__init__.html#getSysPath" />
       <keyword name="getSystem" id="getSystem" ref="eric6.Preferences.__init__.html#getSystem" />
       <keyword name="getTasks" id="getTasks" ref="eric6.Preferences.__init__.html#getTasks" />
       <keyword name="getTemplates" id="getTemplates" ref="eric6.Preferences.__init__.html#getTemplates" />
@@ -20336,6 +20340,7 @@
       <file>eric6.Utilities.ClassBrowsers.pyclbr.html</file>
       <file>eric6.Utilities.ClassBrowsers.rbclbr.html</file>
       <file>eric6.Utilities.FtpUtilities.html</file>
+      <file>eric6.Utilities.GetSysPath.html</file>
       <file>eric6.Utilities.MimeTypes.html</file>
       <file>eric6.Utilities.ModuleParser.html</file>
       <file>eric6.Utilities.MouseUtilities.html</file>
--- a/Documentation/Source/eric6.Project.CreateDialogCodeDialog.html	Sun Oct 07 18:18:13 2018 +0200
+++ b/Documentation/Source/eric6.Project.CreateDialogCodeDialog.html	Sat Oct 13 14:08:21 2018 +0200
@@ -69,6 +69,9 @@
 <td><a href="#CreateDialogCodeDialog.__generatePythonCode">__generatePythonCode</a></td>
 <td>Private slot to generate Python code as requested by the user.</td>
 </tr><tr>
+<td><a href="#CreateDialogCodeDialog.__loadUi">__loadUi</a></td>
+<td>Private method to load a form file and instantiate the defined form.</td>
+</tr><tr>
 <td><a href="#CreateDialogCodeDialog.__mapType">__mapType</a></td>
 <td>Private method to map a type as reported by Qt's meta object to the correct Python type.</td>
 </tr><tr>
@@ -137,7 +140,30 @@
 <b>__generatePythonCode</b>(<i></i>)
 <p>
         Private slot to generate Python code as requested by the user.
-</p><a NAME="CreateDialogCodeDialog.__mapType" ID="CreateDialogCodeDialog.__mapType"></a>
+</p><a NAME="CreateDialogCodeDialog.__loadUi" ID="CreateDialogCodeDialog.__loadUi"></a>
+<h4>CreateDialogCodeDialog.__loadUi</h4>
+<b>__loadUi</b>(<i>formFile, package=""</i>)
+<p>
+        Private method to load a form file and instantiate the defined form.
+</p><dl>
+<dt><i>formFile</i> (str)</dt>
+<dd>
+path of the form file to be loaded
+</dd><dt><i>package</i> (str)</dt>
+<dd>
+base path to be used for relative imports
+</dd>
+</dl><dl>
+<dt>Returns:</dt>
+<dd>
+instantiated form
+</dd>
+</dl><dl>
+<dt>Return Type:</dt>
+<dd>
+QWidget
+</dd>
+</dl><a NAME="CreateDialogCodeDialog.__mapType" ID="CreateDialogCodeDialog.__mapType"></a>
 <h4>CreateDialogCodeDialog.__mapType</h4>
 <b>__mapType</b>(<i>type_</i>)
 <p>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Documentation/Source/eric6.Utilities.GetSysPath.html	Sat Oct 13 14:08:21 2018 +0200
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html><head>
+<title>eric6.Utilities.GetSysPath</title>
+<meta charset="UTF-8">
+<style>
+body {
+    background: #EDECE6;
+    margin: 0em 1em 10em 1em;
+    color: black;
+}
+
+h1 { color: white; background: #85774A; }
+h2 { color: white; background: #85774A; }
+h3 { color: white; background: #9D936E; }
+h4 { color: white; background: #9D936E; }
+    
+a { color: #BA6D36; }
+
+</style>
+</head>
+<body><a NAME="top" ID="top"></a>
+<h1>eric6.Utilities.GetSysPath</h1>
+<p>
+Module to check for the presence of PySide/PySide2 by importing it.
+</p>
+<h3>Global Attributes</h3>
+<table>
+<tr><td>None</td></tr>
+</table>
+<h3>Classes</h3>
+<table>
+<tr><td>None</td></tr>
+</table>
+<h3>Functions</h3>
+<table>
+<tr><td>None</td></tr>
+</table>
+<hr />
+</body></html>
\ No newline at end of file
--- a/Documentation/Source/eric6.Utilities.__init__.html	Sun Oct 07 18:18:13 2018 +0200
+++ b/Documentation/Source/eric6.Utilities.__init__.html	Sat Oct 13 14:08:21 2018 +0200
@@ -148,6 +148,9 @@
 <td><a href="#getRealName">getRealName</a></td>
 <td>Function to get the real name of the user.</td>
 </tr><tr>
+<td><a href="#getSysPath">getSysPath</a></td>
+<td>Module function to get the Python path (sys.path) of a specific interpreter.</td>
+</tr><tr>
 <td><a href="#getTestFileName">getTestFileName</a></td>
 <td>Function to build the filename of a unittest file.</td>
 </tr><tr>
@@ -1115,6 +1118,31 @@
 </dl>
 <div align="right"><a href="#top">Up</a></div>
 <hr /><hr />
+<a NAME="getSysPath" ID="getSysPath"></a>
+<h2>getSysPath</h2>
+<b>getSysPath</b>(<i>interpreter</i>)
+<p>
+    Module function to get the Python path (sys.path) of a specific
+    interpreter.
+</p><dl>
+<dt><i>interpreter</i> (str)</dt>
+<dd>
+Python interpreter executable to get sys.path for
+</dd>
+</dl><dl>
+<dt>Returns:</dt>
+<dd>
+list containing sys.path of the interpreter; an empty list
+        is returned, if the interpreter is the one used to run eric itself
+</dd>
+</dl><dl>
+<dt>Return Type:</dt>
+<dd>
+list of str
+</dd>
+</dl>
+<div align="right"><a href="#top">Up</a></div>
+<hr /><hr />
 <a NAME="getTestFileName" ID="getTestFileName"></a>
 <h2>getTestFileName</h2>
 <b>getTestFileName</b>(<i>fn</i>)
--- a/Documentation/Source/index-eric6.Utilities.html	Sun Oct 07 18:18:13 2018 +0200
+++ b/Documentation/Source/index-eric6.Utilities.html	Sat Oct 13 14:08:21 2018 +0200
@@ -50,6 +50,9 @@
 <td><a href="eric6.Utilities.FtpUtilities.html">FtpUtilities</a></td>
 <td>Module implementing some FTP related utilities.</td>
 </tr><tr>
+<td><a href="eric6.Utilities.GetSysPath.html">GetSysPath</a></td>
+<td>Module to check for the presence of PySide/PySide2 by importing it.</td>
+</tr><tr>
 <td><a href="eric6.Utilities.MimeTypes.html">MimeTypes</a></td>
 <td>Module implementing mimetype dependent functions.</td>
 </tr><tr>
--- a/Project/CreateDialogCodeDialog.py	Sun Oct 07 18:18:13 2018 +0200
+++ b/Project/CreateDialogCodeDialog.py	Sat Oct 13 14:08:21 2018 +0200
@@ -10,6 +10,7 @@
 from __future__ import unicode_literals
 
 import os
+import sys
 import xml.etree.ElementTree
 
 from PyQt5.QtCore import QMetaObject, QByteArray, QRegExp, Qt, pyqtSlot, \
@@ -29,6 +30,8 @@
 
 from Globals import qVersionTuple
 
+import Utilities
+
 
 pyqtSignatureRole = Qt.UserRole + 1
 pythonSignatureRole = Qt.UserRole + 2
@@ -142,6 +145,30 @@
         """
         return self.__initError
         
+    def __loadUi(self, formFile, package=""):
+        """
+        Private method to load a form file and instantiate the defined form.
+        
+        @param formFile path of the form file to be loaded
+        @type str
+        @param package base path to be used for relative imports
+        @type str
+        @return instantiated form
+        @rtype QWidget
+        """
+        oldSysPath = []
+        interpreter = self.project.getDebugProperty("INTERPRETER")
+        if interpreter:
+            oldSysPath = sys.path[:]
+            sys.path = oldSysPath + Utilities.getSysPath(interpreter)
+        
+        dlg = uic.loadUi(formFile, package=package)
+        
+        if oldSysPath:
+            sys.path = oldSysPath
+        
+        return dlg
+    
     def __objectName(self):
         """
         Private method to get the object name of the dialog.
@@ -149,7 +176,7 @@
         @return object name (string)
         """
         try:
-            dlg = uic.loadUi(
+            dlg = self.__loadUi(
                 self.formFile, package=self.project.getProjectPath())
             return dlg.objectName()
         except (AttributeError, ImportError,
@@ -169,7 +196,7 @@
         @return class name (sting)
         """
         try:
-            dlg = uic.loadUi(
+            dlg = self.__loadUi(
                 self.formFile, package=self.project.getProjectPath())
             return dlg.metaObject().className()
         except (AttributeError, ImportError,
@@ -240,7 +267,7 @@
         self.filterEdit.clear()
         
         try:
-            dlg = uic.loadUi(
+            dlg = self.__loadUi(
                 self.formFile, package=self.project.getProjectPath())
             objects = dlg.findChildren(QWidget) + dlg.findChildren(QAction)
             
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utilities/GetSysPath.py	Sat Oct 13 14:08:21 2018 +0200
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2011 - 2018 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module to check for the presence of PySide/PySide2 by importing it.
+"""
+
+from __future__ import print_function
+
+import sys
+import json
+
+if __name__ == "__main__":
+    # print sys.path to stdout
+    print(json.dumps(sys.path))
+    
+    sys.exit(0)
+    
+#
+# eflag: noqa = M701, M801
--- a/Utilities/__init__.py	Sun Oct 07 18:18:13 2018 +0200
+++ b/Utilities/__init__.py	Sat Oct 13 14:08:21 2018 +0200
@@ -1957,6 +1957,42 @@
     else:
         return bool(dataStr)
 
+def getSysPath(interpreter):
+    """
+    Module function to get the Python path (sys.path) of a specific
+    interpreter.
+    
+    @param interpreter Python interpreter executable to get sys.path for
+    @type str
+    @return list containing sys.path of the interpreter; an empty list
+        is returned, if the interpreter is the one used to run eric itself
+    @rtype list of str
+    """
+    import json
+    
+    sysPath = []
+    
+    getSysPath = os.path.join(
+        getConfig('ericDir'), "Utilities", "GetSysPath.py")
+    args = [getSysPath]
+    proc = QProcess()
+    proc.setProcessChannelMode(QProcess.MergedChannels)
+    proc.start(interpreter, args)
+    finished = proc.waitForFinished(30000)
+    if finished:
+        if proc.exitCode() == 0:
+            text = proc.readAllStandardOutput()
+            sysPathResult = str(text, "utf-8", "replace").strip()
+            try:
+                sysPath = json.loads(sysPathResult)
+                if "" in sysPath:
+                    sysPath.remove("")
+            except (TypeError, ValueError):
+                # ignore faulty results and return empty list
+                pass
+    
+    return sysPath
+
 ###############################################################################
 # posix compatibility functions below
 ###############################################################################
--- a/eric6.e4p	Sun Oct 07 18:18:13 2018 +0200
+++ b/eric6.e4p	Sat Oct 13 14:08:21 2018 +0200
@@ -1379,6 +1379,7 @@
     <Source>Utilities/ClassBrowsers/pyclbr.py</Source>
     <Source>Utilities/ClassBrowsers/rbclbr.py</Source>
     <Source>Utilities/FtpUtilities.py</Source>
+    <Source>Utilities/GetSysPath.py</Source>
     <Source>Utilities/MimeTypes.py</Source>
     <Source>Utilities/ModuleParser.py</Source>
     <Source>Utilities/MouseUtilities.py</Source>
@@ -2222,14 +2223,14 @@
   </Resources>
   <Others>
     <Other>.hgignore</Other>
-    <Other>APIs/Python/zope-2.10.7.api</Other>
-    <Other>APIs/Python/zope-2.11.2.api</Other>
-    <Other>APIs/Python/zope-3.3.1.api</Other>
     <Other>APIs/Python3/PyQt4.bas</Other>
     <Other>APIs/Python3/PyQt5.bas</Other>
     <Other>APIs/Python3/QScintilla2.bas</Other>
     <Other>APIs/Python3/eric6.api</Other>
     <Other>APIs/Python3/eric6.bas</Other>
+    <Other>APIs/Python/zope-2.10.7.api</Other>
+    <Other>APIs/Python/zope-2.11.2.api</Other>
+    <Other>APIs/Python/zope-3.3.1.api</Other>
     <Other>APIs/QSS/qss.api</Other>
     <Other>APIs/Ruby/Ruby-1.8.7.api</Other>
     <Other>APIs/Ruby/Ruby-1.8.7.bas</Other>

eric ide

mercurial