CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.

Wed, 17 Oct 2018 19:53:13 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 17 Oct 2018 19:53:13 +0200
changeset 6547
77c817301ca1
parent 6546
30829a28e969
child 6548
21f8260753b5

CreateDialogCodeDialog: third attempt on getting this working with projects using a virtual environment different from the one used to run eric.

Project/CreateDialogCodeDialog.py file | annotate | diff | comparison | revisions
Project/UicLoadUi.py file | annotate | diff | comparison | revisions
Utilities/GetSysPath.py file | annotate | diff | comparison | revisions
eric6.e4p file | annotate | diff | comparison | revisions
--- a/Project/CreateDialogCodeDialog.py	Sun Oct 14 18:24:49 2018 +0200
+++ b/Project/CreateDialogCodeDialog.py	Wed Oct 17 19:53:13 2018 +0200
@@ -8,13 +8,17 @@
 """
 
 from __future__ import unicode_literals
+try:
+    str = unicode       # __IGNORE_EXCEPTION__
+except NameError:
+    pass
 
 import os
-import sys
+import json
 import xml.etree.ElementTree
 
 from PyQt5.QtCore import QMetaObject, QByteArray, QRegExp, Qt, pyqtSlot, \
-    QMetaMethod, QSortFilterProxyModel
+    QMetaMethod, QSortFilterProxyModel, QProcess
 from PyQt5.QtGui import QStandardItemModel, QBrush, QStandardItem
 from PyQt5.QtWidgets import QWidget, QDialog, QDialogButtonBox, QAction
 from PyQt5 import uic
@@ -30,8 +34,6 @@
 
 from Globals import qVersionTuple
 
-import Utilities
-
 
 pyqtSignatureRole = Qt.UserRole + 1
 pythonSignatureRole = Qt.UserRole + 2
@@ -145,70 +147,130 @@
         """
         return self.__initError
         
-    def __loadUi(self, formFile, package=""):
+    def __objectNameExternal(self):
         """
-        Private method to load a form file and instantiate the defined form.
+        Private method to get the object name of a form via an external
+        interpreter.
         
-        @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
+        @return object name
+        @rtype str
         """
-        oldSysPath = []
         interpreter = self.project.getDebugProperty("INTERPRETER")
-        if interpreter:
-            oldSysPath = sys.path[:]
-            sys.path = oldSysPath + Utilities.getSysPath(interpreter)
+        objectName = ""
+        
+        loadUi = os.path.join(os.path.dirname(__file__), "UicLoadUi.py")
+        args = [
+            loadUi,
+            "object_name",
+            self.formFile,
+            self.project.getProjectPath(),
+        ]
         
-        dlg = uic.loadUi(formFile, package=package)
+        proc = QProcess()
+        proc.start(interpreter, args)
+        finished = proc.waitForFinished(30000)
+        if finished:
+            text = proc.readAllStandardOutput()
+            if proc.exitCode() == 0:
+                objectName = str(text, "utf-8", "replace").strip()
+            else:
+                errorText = str(text, "utf-8", "replace")
+                E5MessageBox.critical(
+                    self,
+                    self.tr("uic error"),
+                    self.tr(
+                        """<p>There was an error loading the form <b>{0}</b>"""
+                        """.</p><p>{1}</p>""").format(
+                        self.formFile, errorText))
         
-        if oldSysPath:
-            sys.path = oldSysPath
-        
-        return dlg
+        return objectName
     
     def __objectName(self):
         """
-        Private method to get the object name of the dialog.
+        Private method to get the object name of a form.
         
-        @return object name (string)
+        @return object name
+        @rtype str
+        """
+        if self.project.getDebugProperty("INTERPRETER"):
+            return self.__objectNameExternal()
+        else:
+            try:
+                dlg = uic.loadUi(
+                    self.formFile, package=self.project.getProjectPath())
+                return dlg.objectName()
+            except (AttributeError, ImportError,
+                    xml.etree.ElementTree.ParseError) as err:
+                E5MessageBox.critical(
+                    self,
+                    self.tr("uic error"),
+                    self.tr(
+                        """<p>There was an error loading the form <b>{0}</b>"""
+                        """.</p><p>{1}</p>""").format(self.formFile, str(err)))
+                return ""
+    
+    def __classNameExternal(self):
+        """
+        Private method to get the class name of a form via an external
+        interpreter.
+        
+        @return class name
+        @rtype str
         """
-        try:
-            dlg = self.__loadUi(
-                self.formFile, package=self.project.getProjectPath())
-            return dlg.objectName()
-        except (AttributeError, ImportError,
-                xml.etree.ElementTree.ParseError) as err:
-            E5MessageBox.critical(
-                self,
-                self.tr("uic error"),
-                self.tr(
-                    """<p>There was an error loading the form <b>{0}</b>"""
-                    """.</p><p>{1}</p>""").format(self.formFile, str(err)))
-            return ""
+        interpreter = self.project.getDebugProperty("INTERPRETER")
+        className = ""
+        
+        loadUi = os.path.join(os.path.dirname(__file__), "UicLoadUi.py")
+        args = [
+            loadUi,
+            "class_name",
+            self.formFile,
+            self.project.getProjectPath(),
+        ]
         
+        proc = QProcess()
+        proc.start(interpreter, args)
+        finished = proc.waitForFinished(30000)
+        if finished:
+            text = proc.readAllStandardOutput()
+            if proc.exitCode() == 0:
+                className = str(text, "utf-8", "replace").strip()
+            else:
+                errorText = str(text, "utf-8", "replace")
+                E5MessageBox.critical(
+                    self,
+                    self.tr("uic error"),
+                    self.tr(
+                        """<p>There was an error loading the form <b>{0}</b>"""
+                        """.</p><p>{1}</p>""").format(
+                        self.formFile, errorText))
+        
+        return className
+    
     def __className(self):
         """
-        Private method to get the class name of the dialog.
+        Private method to get the class name of a form.
         
-        @return class name (sting)
+        @return class name
+        @rtype str
         """
-        try:
-            dlg = self.__loadUi(
-                self.formFile, package=self.project.getProjectPath())
-            return dlg.metaObject().className()
-        except (AttributeError, ImportError,
-                xml.etree.ElementTree.ParseError) as err:
-            E5MessageBox.critical(
-                self,
-                self.tr("uic error"),
-                self.tr(
-                    """<p>There was an error loading the form <b>{0}</b>"""
-                    """.</p><p>{1}</p>""").format(self.formFile, str(err)))
-            return ""
-        
+        if self.project.getDebugProperty("INTERPRETER"):
+            return self.__objectNameExternal()
+        else:
+            try:
+                dlg = uic.loadUi(
+                    self.formFile, package=self.project.getProjectPath())
+                return dlg.metaObject().className()
+            except (AttributeError, ImportError,
+                    xml.etree.ElementTree.ParseError) as err:
+                E5MessageBox.critical(
+                    self,
+                    self.tr("uic error"),
+                    self.tr(
+                        """<p>There was an error loading the form <b>{0}</b>"""
+                        """.</p><p>{1}</p>""").format(self.formFile, str(err)))
+                return ""
+    
     def __signatures(self):
         """
         Private slot to get the signatures.
@@ -243,148 +305,239 @@
         """
         mapped = bytes(type_).decode()
         
+        # I. always check for *
+        mapped = mapped.replace("*", "")
+        
         if self.project.getProjectLanguage() != "Python2" or \
            self.project.getProjectType in ("PySide", "PySide2"):
             # 1. check for const
             mapped = mapped.replace("const ", "")
             
-            # 2. check for *
-            mapped = mapped.replace("*", "")
-            
-            # 3. replace QString and QStringList
+            # 2. replace QString and QStringList
             mapped = mapped.replace("QStringList", "list")\
                            .replace("QString", "str")
             
-            # 4. replace double by float
+            # 3. replace double by float
             mapped = mapped.replace("double", "float")
         
         return mapped
+    
+    def __updateSlotsModelExternal(self):
+        """
+        Private slot to update the slots tree display getting the data via an
+        external interpreter.
+        """
+        interpreter = self.project.getDebugProperty("INTERPRETER")
+        objectsList = []
         
+        loadUi = os.path.join(os.path.dirname(__file__), "UicLoadUi.py")
+        args = [
+            loadUi,
+            "signatures",
+            self.formFile,
+            self.project.getProjectPath(),
+        ]
+        
+        proc = QProcess()
+        proc.start(interpreter, args)
+        finished = proc.waitForFinished(30000)
+        if not finished:
+            return
+        
+        text = proc.readAllStandardOutput()
+        if proc.exitCode() != 0:
+            errorText = str(text, "utf-8", "replace")
+            E5MessageBox.critical(
+                self,
+                self.tr("uic error"),
+                self.tr(
+                    """<p>There was an error loading the form <b>{0}</b>"""
+                    """.</p><p>{1}</p>""").format(
+                    self.formFile, errorText))
+        else:
+            objectsListStr = str(text, "utf-8", "replace").strip()
+            objectsList = json.loads(objectsListStr)
+            
+            signatureList = self.__signatures()
+            
+            for objectDict in objectsList:
+                itm = QStandardItem("{0} ({1})".format(
+                    objectDict["name"],
+                    objectDict["class_name"]))
+                self.slotsModel.appendRow(itm)
+                for methodDict in objectDict["methods"]:
+                    itm2 = QStandardItem(methodDict["signature"])
+                    itm.appendRow(itm2)
+                    
+                    if self.__module is not None:
+                        if methodDict["methods"][0] in signatureList or \
+                           methodDict["methods"][1] in signatureList:
+                            itm2.setFlags(
+                                Qt.ItemFlags(Qt.ItemIsEnabled))
+                            itm2.setCheckState(Qt.Checked)
+                            itm2.setForeground(QBrush(Qt.blue))
+                            continue
+            
+                    itm2.setData(methodDict["pyqt_signature"],
+                                 pyqtSignatureRole)
+                    itm2.setData(methodDict["python_signature"],
+                                 pythonSignatureRole)
+                    itm2.setData(methodDict["return_type"],
+                                 returnTypeRole)
+                    itm2.setData(methodDict["parameter_types"],
+                                 parameterTypesListRole)
+                    itm2.setData(methodDict["parameter_names"],
+                                 parameterNamesListRole)
+                    
+                    itm2.setFlags(Qt.ItemFlags(
+                        Qt.ItemIsUserCheckable |
+                        Qt.ItemIsEnabled |
+                        Qt.ItemIsSelectable)
+                    )
+                    itm2.setCheckState(Qt.Unchecked)
+            
+            self.slotsView.sortByColumn(0, Qt.AscendingOrder)
+    
     def __updateSlotsModel(self):
         """
         Private slot to update the slots tree display.
         """
         self.filterEdit.clear()
         
-        try:
-            dlg = self.__loadUi(
-                self.formFile, package=self.project.getProjectPath())
-            objects = dlg.findChildren(QWidget) + dlg.findChildren(QAction)
-            
-            signatureList = self.__signatures()
-            
-            self.slotsModel.clear()
-            self.slotsModel.setHorizontalHeaderLabels([""])
-            for obj in objects:
-                name = obj.objectName()
-                if not name or name.startswith("qt_"):
-                    # ignore un-named or internal objects
-                    continue
+        if self.project.getDebugProperty("INTERPRETER"):
+            self.__updateSlotsModelExternal()
+        else:
+            try:
+                dlg = uic.loadUi(
+                    self.formFile, package=self.project.getProjectPath())
+                objects = dlg.findChildren(QWidget) + dlg.findChildren(QAction)
+                
+                signatureList = self.__signatures()
                 
-                metaObject = obj.metaObject()
-                className = metaObject.className()
-                itm = QStandardItem("{0} ({1})".format(name, className))
-                self.slotsModel.appendRow(itm)
-                for index in range(metaObject.methodCount()):
-                    metaMethod = metaObject.method(index)
-                    if metaMethod.methodType() == QMetaMethod.Signal:
-                        if qVersionTuple() >= (5, 0, 0):
-                            itm2 = QStandardItem("on_{0}_{1}".format(
-                                name,
-                                bytes(metaMethod.methodSignature()).decode()))
-                        else:
-                            itm2 = QStandardItem("on_{0}_{1}".format(
-                                name, metaMethod.signature()))
-                        itm.appendRow(itm2)
-                        if self.__module is not None:
+                self.slotsModel.clear()
+                self.slotsModel.setHorizontalHeaderLabels([""])
+                for obj in objects:
+                    name = obj.objectName()
+                    if not name or name.startswith("qt_"):
+                        # ignore un-named or internal objects
+                        continue
+                    
+                    metaObject = obj.metaObject()
+                    className = metaObject.className()
+                    itm = QStandardItem("{0} ({1})".format(name, className))
+                    self.slotsModel.appendRow(itm)
+                    for index in range(metaObject.methodCount()):
+                        metaMethod = metaObject.method(index)
+                        if metaMethod.methodType() == QMetaMethod.Signal:
                             if qVersionTuple() >= (5, 0, 0):
-                                method = "on_{0}_{1}".format(
+                                itm2 = QStandardItem("on_{0}_{1}".format(
                                     name,
                                     bytes(metaMethod.methodSignature())
-                                    .decode().split("(")[0])
+                                    .decode()
+                                ))
                             else:
-                                method = "on_{0}_{1}".format(
-                                    name, metaMethod.signature().split("(")[0])
-                            method2 = "{0}({1})".format(
-                                method, ", ".join(
-                                    [self.__mapType(t)
-                                     for t in metaMethod.parameterTypes()]))
-                            
-                            if method2 in signatureList or \
-                                    method in signatureList:
-                                itm2.setFlags(Qt.ItemFlags(Qt.ItemIsEnabled))
-                                itm2.setCheckState(Qt.Checked)
-                                itm2.setForeground(QBrush(Qt.blue))
-                                continue
-                        
-                        returnType = self.__mapType(
-                            metaMethod.typeName().encode())
-                        if returnType == 'void':
-                            returnType = ""
-                        parameterTypesList = [
-                            self.__mapType(t)
-                            for t in metaMethod.parameterTypes()]
-                        pyqtSignature = ", ".join(parameterTypesList)
-                        
-                        parameterNames = metaMethod.parameterNames()
-                        if parameterNames:
-                            for index in range(len(parameterNames)):
-                                if not parameterNames[index]:
-                                    parameterNames[index] = \
-                                        QByteArray("p{0:d}".format(index)
-                                                   .encode("utf-8"))
-                        parameterNamesList = [bytes(n).decode()
-                                              for n in parameterNames]
-                        methNamesSig = ", ".join(parameterNamesList)
-                        
-                        if methNamesSig:
-                            if qVersionTuple() >= (5, 0, 0):
-                                pythonSignature = \
-                                    "on_{0}_{1}(self, {2})".format(
+                                itm2 = QStandardItem("on_{0}_{1}".format(
+                                    name, metaMethod.signature()
+                                ))
+                            itm.appendRow(itm2)
+                            if self.__module is not None:
+                                if qVersionTuple() >= (5, 0, 0):
+                                    method = "on_{0}_{1}".format(
                                         name,
                                         bytes(metaMethod.methodSignature())
-                                        .decode().split("(")[0],
-                                        methNamesSig)
-                            else:
-                                pythonSignature = \
-                                    "on_{0}_{1}(self, {2})".format(
+                                        .decode().split("(")[0])
+                                else:
+                                    method = "on_{0}_{1}".format(
                                         name,
-                                        metaMethod.signature().split("(")[0],
-                                        methNamesSig)
-                        else:
-                            if qVersionTuple() >= (5, 0, 0):
-                                pythonSignature = "on_{0}_{1}(self)".format(
-                                    name,
-                                    bytes(metaMethod.methodSignature())
-                                    .decode().split("(")[0])
+                                        metaMethod.signature().split("(")[0])
+                                method2 = "{0}({1})".format(
+                                    method,
+                                    ", ".join([
+                                        self.__mapType(t)
+                                        for t in metaMethod.parameterTypes()
+                                    ])
+                                )
+                                
+                                if method2 in signatureList or \
+                                        method in signatureList:
+                                    itm2.setFlags(
+                                        Qt.ItemFlags(Qt.ItemIsEnabled))
+                                    itm2.setCheckState(Qt.Checked)
+                                    itm2.setForeground(QBrush(Qt.blue))
+                                    continue
+                            
+                            returnType = self.__mapType(
+                                metaMethod.typeName().encode())
+                            if returnType == 'void':
+                                returnType = ""
+                            parameterTypesList = [
+                                self.__mapType(t)
+                                for t in metaMethod.parameterTypes()]
+                            pyqtSignature = ", ".join(parameterTypesList)
+                            
+                            parameterNames = metaMethod.parameterNames()
+                            if parameterNames:
+                                for index in range(len(parameterNames)):
+                                    if not parameterNames[index]:
+                                        parameterNames[index] = \
+                                            QByteArray("p{0:d}".format(index)
+                                                       .encode("utf-8"))
+                            parameterNamesList = [bytes(n).decode()
+                                                  for n in parameterNames]
+                            methNamesSig = ", ".join(parameterNamesList)
+                            
+                            if methNamesSig:
+                                if qVersionTuple() >= (5, 0, 0):
+                                    pythonSignature = \
+                                        "on_{0}_{1}(self, {2})".format(
+                                            name,
+                                            bytes(metaMethod.methodSignature())
+                                            .decode().split("(")[0],
+                                            methNamesSig)
+                                else:
+                                    pythonSignature = \
+                                        "on_{0}_{1}(self, {2})".format(
+                                            name,
+                                            metaMethod.signature()
+                                            .split("(")[0],
+                                            methNamesSig)
                             else:
-                                pythonSignature = "on_{0}_{1}(self)".format(
-                                    name,
-                                    metaMethod.signature().split("(")[0])
-                        itm2.setData(pyqtSignature, pyqtSignatureRole)
-                        itm2.setData(pythonSignature, pythonSignatureRole)
-                        itm2.setData(returnType, returnTypeRole)
-                        itm2.setData(parameterTypesList,
-                                     parameterTypesListRole)
-                        itm2.setData(parameterNamesList,
-                                     parameterNamesListRole)
-                        
-                        itm2.setFlags(Qt.ItemFlags(
-                            Qt.ItemIsUserCheckable |
-                            Qt.ItemIsEnabled |
-                            Qt.ItemIsSelectable)
-                        )
-                        itm2.setCheckState(Qt.Unchecked)
-            
-            self.slotsView.sortByColumn(0, Qt.AscendingOrder)
-        except (AttributeError, ImportError,
-                xml.etree.ElementTree.ParseError) as err:
-            E5MessageBox.critical(
-                self,
-                self.tr("uic error"),
-                self.tr(
-                    """<p>There was an error loading the form <b>{0}</b>"""
-                    """.</p><p>{1}</p>""").format(self.formFile, str(err)))
+                                if qVersionTuple() >= (5, 0, 0):
+                                    pythonSignature = "on_{0}_{1}(self)"\
+                                        .format(
+                                            name,
+                                            bytes(metaMethod.methodSignature())
+                                            .decode().split("(")[0])
+                                else:
+                                    pythonSignature = "on_{0}_{1}(self)"\
+                                        .format(
+                                            name,
+                                            metaMethod.signature().split(
+                                                "(")[0])
+                            itm2.setData(pyqtSignature, pyqtSignatureRole)
+                            itm2.setData(pythonSignature, pythonSignatureRole)
+                            itm2.setData(returnType, returnTypeRole)
+                            itm2.setData(parameterTypesList,
+                                         parameterTypesListRole)
+                            itm2.setData(parameterNamesList,
+                                         parameterNamesListRole)
+                            
+                            itm2.setFlags(Qt.ItemFlags(
+                                Qt.ItemIsUserCheckable |
+                                Qt.ItemIsEnabled |
+                                Qt.ItemIsSelectable)
+                            )
+                            itm2.setCheckState(Qt.Unchecked)
+                
+                self.slotsView.sortByColumn(0, Qt.AscendingOrder)
+            except (AttributeError, ImportError,
+                    xml.etree.ElementTree.ParseError) as err:
+                E5MessageBox.critical(
+                    self,
+                    self.tr("uic error"),
+                    self.tr(
+                        """<p>There was an error loading the form <b>{0}</b>"""
+                        """.</p><p>{1}</p>""").format(self.formFile, str(err)))
         
     def __generateCode(self):
         """
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Project/UicLoadUi.py	Wed Oct 17 19:53:13 2018 +0200
@@ -0,0 +1,251 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2011 - 2018 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module to get sys.path of an external interpreter.
+"""
+
+from __future__ import print_function
+try:
+    bytes = unicode     # __IGNORE_EXCEPTION__
+except NameError:
+    pass
+
+import sys
+import json
+import xml.etree.ElementTree
+
+try:
+    from PyQt5.QtCore import qVersion, QMetaMethod, QByteArray
+    from PyQt5.QtWidgets import QAction, QWidget, QApplication
+    from PyQt5 import uic
+    
+    pyqtType = 5
+except ImportError:
+    try:
+        # try a potential PyQt4 installation
+        from PyQt4.QtCore import qVersion, QMetaMethod, QByteArray
+        from PyQt4.QtGui import QAction, QWidget, QApplication
+        from PyQt4 import uic
+        
+        pyqtType = 4
+    except ImportError:
+        print("Neither PyQt5 nor PyQt4 found.")
+        sys.exit(1)
+
+
+def objectName(formFile, projectPath):
+    """
+    Function to get the object name of a form.
+    
+    @param formFile file name of the form
+    @type str
+    @param projectPath directory name of the project
+    @type str
+    """
+    app = QApplication([])      # __IGNORE_WARNING__
+    try:
+        dlg = uic.loadUi(formFile, package=projectPath)
+        print(dlg.objectName())
+        sys.exit(0)
+    except (AttributeError, ImportError,
+            xml.etree.ElementTree.ParseError) as err:
+        print(str(err))
+        sys.exit(1)
+
+
+def className(formFile, projectPath):
+    """
+    Function to get the class name of a form.
+    
+    @param formFile file name of the form
+    @type str
+    @param projectPath directory name of the project
+    @type str
+    """
+    app = QApplication([])      # __IGNORE_WARNING__
+    try:
+        dlg = uic.loadUi(formFile, package=projectPath)
+        print(dlg.metaObject().className())
+        sys.exit(0)
+    except (AttributeError, ImportError,
+            xml.etree.ElementTree.ParseError) as err:
+        print(str(err))
+        sys.exit(1)
+
+
+def __mapType(type_):
+    """
+    Private function to map a type as reported by Qt's meta object to the
+    correct Python type.
+    
+    @param type_ type as reported by Qt
+    @type QByteArray or bytes
+    @return mapped Python type
+    @rtype str
+    """
+    mapped = bytes(type_).decode()
+    
+    # I. always check for *
+    mapped = mapped.replace("*", "")
+    
+    if pyqtType != 4:
+        # 1. check for const
+        mapped = mapped.replace("const ", "")
+        
+        # 2. replace QString and QStringList
+        mapped = mapped.replace("QStringList", "list")\
+                       .replace("QString", "str")
+        
+        # 3. replace double by float
+        mapped = mapped.replace("double", "float")
+    
+    return mapped
+
+
+def signatures(formFile, projectPath):
+    """
+    Function to get the signatures of form elements.
+    
+    @param formFile file name of the form
+    @type str
+    @param projectPath directory name of the project
+    @type str
+    """
+    objectsList = []
+    
+    app = QApplication([])      # __IGNORE_WARNING__
+    try:
+        dlg = uic.loadUi(formFile, package=projectPath)
+        objects = dlg.findChildren(QWidget) + dlg.findChildren(QAction)
+        for obj in objects:
+            name = obj.objectName()
+            if not name or name.startswith("qt_"):
+                # ignore un-named or internal objects
+                continue
+            
+            metaObject = obj.metaObject()
+            objectDict = {
+                "name": name,
+                "class_name": metaObject.className(),
+                "methods": [],
+            }
+            
+            for index in range(metaObject.methodCount()):
+                metaMethod = metaObject.method(index)
+                if metaMethod.methodType() == QMetaMethod.Signal:
+                    signatureDict = {
+                        "methods": []
+                    }
+                    if qVersion().startswith("5."):
+                        signatureDict["signature"] = "on_{0}_{1}".format(
+                            name,
+                            bytes(metaMethod.methodSignature()).decode()
+                        )
+                    else:
+                        signatureDict["signature"] = "on_{0}_{1}".format(
+                            name,
+                            metaMethod.signature()
+                        )
+                    
+                    if qVersion().startswith("5."):
+                        signatureDict["methods"].append("on_{0}_{1}".format(
+                            name,
+                            bytes(metaMethod.methodSignature())
+                            .decode().split("(")[0]
+                        ))
+                    else:
+                        signatureDict["methods"].append("on_{0}_{1}".format(
+                            name,
+                            metaMethod.signature().split("(")[0]
+                        ))
+                    signatureDict["methods"].append("{0}({1})".format(
+                        signatureDict["methods"][-1],
+                        ", ".join([
+                            __mapType(t)
+                            for t in metaMethod.parameterTypes()
+                        ])
+                    ))
+                    
+                    returnType = __mapType(
+                        metaMethod.typeName().encode())
+                    if returnType == 'void':
+                        returnType = ""
+                    signatureDict["return_type"] = returnType
+                    parameterTypesList = [
+                        __mapType(t)
+                        for t in metaMethod.parameterTypes()
+                    ]
+                    signatureDict["parameter_types"] = parameterTypesList
+                    pyqtSignature = ", ".join(parameterTypesList)
+                    signatureDict["pyqt_signature"] = pyqtSignature
+                    
+                    parameterNames = metaMethod.parameterNames()
+                    if parameterNames:
+                        for index in range(len(parameterNames)):
+                            if not parameterNames[index]:
+                                parameterNames[index] = \
+                                    QByteArray("p{0:d}".format(index)
+                                               .encode("utf-8"))
+                    parameterNamesList = [bytes(n).decode()
+                                          for n in parameterNames]
+                    signatureDict["parameter_names"] = parameterNamesList
+                    methNamesSig = ", ".join(parameterNamesList)
+                    
+                    if methNamesSig:
+                        if qVersion().startswith("5."):
+                            pythonSignature = \
+                                "on_{0}_{1}(self, {2})".format(
+                                    name,
+                                    bytes(metaMethod.methodSignature())
+                                    .decode().split("(")[0],
+                                    methNamesSig)
+                        else:
+                            pythonSignature = \
+                                "on_{0}_{1}(self, {2})".format(
+                                    name,
+                                    metaMethod.signature().split("(")[0],
+                                    methNamesSig)
+                    else:
+                        if qVersion().startswith("5."):
+                            pythonSignature = "on_{0}_{1}(self)".format(
+                                name,
+                                bytes(metaMethod.methodSignature())
+                                .decode().split("(")[0])
+                        else:
+                            pythonSignature = "on_{0}_{1}(self)".format(
+                                name,
+                                metaMethod.signature().split("(")[0])
+                    signatureDict["python_signature"] = pythonSignature
+                    
+                    objectDict["methods"].append(signatureDict)
+            
+            objectsList.append(objectDict)
+        
+        print(json.dumps(objectsList))
+        sys.exit(0)
+    except (AttributeError, ImportError,
+            xml.etree.ElementTree.ParseError) as err:
+        print(str(err))
+        sys.exit(1)
+
+
+if __name__ == "__main__":
+    if len(sys.argv) != 4:
+        print("Wrong number of arguments.")
+        sys.exit(1)
+    
+    if sys.argv[1] == "object_name":
+        objectName(sys.argv[2], sys.argv[3])
+    elif sys.argv[1] == "class_name":
+        className(sys.argv[2], sys.argv[3])
+    elif sys.argv[1] == "signatures":
+        signatures(sys.argv[2], sys.argv[3])
+    else:
+        print("Unknow operation given.")
+        sys.exit(1)
+    
+#
+# eflag: noqa = M701, M801
--- a/Utilities/GetSysPath.py	Sun Oct 14 18:24:49 2018 +0200
+++ b/Utilities/GetSysPath.py	Wed Oct 17 19:53:13 2018 +0200
@@ -4,7 +4,7 @@
 #
 
 """
-Module to check for the presence of PySide/PySide2 by importing it.
+Module to get sys.path of an external interpreter.
 """
 
 from __future__ import print_function
--- a/eric6.e4p	Sun Oct 14 18:24:49 2018 +0200
+++ b/eric6.e4p	Wed Oct 17 19:53:13 2018 +0200
@@ -941,6 +941,7 @@
     <Source>Project/QuickFindFileDialog.py</Source>
     <Source>Project/SpellingPropertiesDialog.py</Source>
     <Source>Project/TranslationPropertiesDialog.py</Source>
+    <Source>Project/UicLoadUi.py</Source>
     <Source>Project/UserPropertiesDialog.py</Source>
     <Source>Project/__init__.py</Source>
     <Source>PyUnit/UnittestDialog.py</Source>

eric ide

mercurial