diff options
Diffstat (limited to 'sources/pyside2/PySide2/support/signature/mapping.py')
-rw-r--r-- | sources/pyside2/PySide2/support/signature/mapping.py | 159 |
1 files changed, 47 insertions, 112 deletions
diff --git a/sources/pyside2/PySide2/support/signature/mapping.py b/sources/pyside2/PySide2/support/signature/mapping.py index dd3df0988..1a769484d 100644 --- a/sources/pyside2/PySide2/support/signature/mapping.py +++ b/sources/pyside2/PySide2/support/signature/mapping.py @@ -1,6 +1,6 @@ ############################################################################# ## -## Copyright (C) 2017 The Qt Company Ltd. +## Copyright (C) 2018 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of Qt for Python. @@ -46,114 +46,28 @@ This module has the mapping from the pyside C-modules view of signatures to the Python representation. The PySide modules are not loaded in advance, but only after they appear -in sys.modules. This minimises the loading overhead. -In principle, we need to re-load the module, when the imports change. -But it is much easier to do it on demand, when we get an exception. -See _resolve_value() in singature.py +in sys.modules. This minimizes the loading overhead. """ -import sys -import struct import PySide2 -try: - from . import typing -except ImportError: - import typing - -ellipsis = "..." -Char = typing.Union[str, int] # how do I model the limitation to 1 char? -StringList = typing.List[str] -IntList = typing.List[int] -Variant = typing.Any -ModelIndexList = typing.List[int] -QImageCleanupFunction = typing.Callable -FloatMatrix = typing.List[typing.List[float]] -# Pair could be more specific, but we loose the info in the generator. -Pair = typing.Tuple[typing.Any, typing.Any] -MultiMap = typing.DefaultDict[str, typing.List[str]] -Text = typing.Text - -# ulong_max is only 32 bit on windows. -ulong_max = 2*sys.maxsize+1 if len(struct.pack("L", 1)) != 4 else 0xffffffff -ushort_max = 0xffff - -GL_COLOR_BUFFER_BIT = 0x00004000 -GL_NEAREST = 0x2600 - -WId = int -# from 5.9 -GL_TEXTURE_2D = 0x0DE1 -GL_RGBA = 0x1908 - -class _NotCalled(str): - """ - Wrap some text with semantics - - This class is wrapped around text in order to avoid calling it. - There are three reasons for this: - - - some instances cannot be created since they are abstract, - - some can only be created after qApp was created, - - some have an ugly __repr__ with angle brackets in it. - - By using derived classes, good looking instances can be created - which can be used to generate source code or .pyi files. When the - real object is needed, the wrapper can simply be called. - """ - def __repr__(self): - suppress = "PySide2.support.signature.typing." - text = self[len(suppress):] if self.startswith(suppress) else self - return "{}({})".format(type(self).__name__, text) - - def __call__(self): - from .mapping import __dict__ as namespace - text = self if self.endswith(")") else self + "()" - return eval(text, namespace) - -# Some types are abstract. They just show their name. -class Virtual(_NotCalled): - pass - -# Other types I simply could not find. -class Missing(_NotCalled): - pass +from signature_loader.sbk_mapping import * -class Invalid(_NotCalled): - pass +Sbk_Reloader = Reloader -# Helper types -class Default(_NotCalled): - pass - -class Instance(_NotCalled): - pass - - -class Reloader(object): - def __init__(self): - self.sys_module_count = 0 - self.uninitialized = PySide2.__all__[:] +class Reloader(Sbk_Reloader): + _uninitialized = Sbk_Reloader._uninitialized + PySide2.__all__ + _prefixes = Sbk_Reloader._prefixes + ["PySide2."] def update(self): - if self.sys_module_count == len(sys.modules): - return - self.sys_module_count = len(sys.modules) - g = globals() - for mod_name in self.uninitialized[:]: - if "PySide2." + mod_name in sys.modules: - self.uninitialized.remove(mod_name) - proc_name = "init_" + mod_name - if proc_name in g: - g.update(g[proc_name]()) - + Sbk_Reloader.update(self, globals()) update_mapping = Reloader().update -type_map = {} + def init_QtCore(): import PySide2.QtCore - from PySide2.QtCore import Qt, QUrl, QDir, QGenericArgument + from PySide2.QtCore import Qt, QUrl, QDir from PySide2.QtCore import QRect, QSize, QPoint, QLocale, QByteArray from PySide2.QtCore import QMarginsF # 5.9 try: @@ -201,9 +115,8 @@ def init_QtCore(): "ULONG_MAX": ulong_max, "quintptr": int, "PyCallable": typing.Callable, - "...": ellipsis, # no idea how this should be translated... maybe so? "PyTypeObject": type, - "PySequence": typing.Sequence, + "PySequence": typing.Iterable, # important for numpy "qptrdiff": int, "true": True, "Qt.HANDLE": int, # be more explicit with some consts? @@ -242,7 +155,7 @@ def init_QtCore(): "QDir.SortFlags(QDir.Name | QDir.IgnoreCase)"), "PyBytes": bytes, "PyByteArray": bytearray, - "PyUnicode": Text, + "PyUnicode": typing.Text, "signed long": int, "PySide2.QtCore.int": int, "PySide2.QtCore.char": StringList, # A 'char **' is a list of strings. @@ -259,13 +172,13 @@ def init_QtCore(): "float[][]": FloatMatrix, # 5.9 "PySide2.QtCore.unsigned int": int, # 5.9 Ubuntu "PySide2.QtCore.long long": int, # 5.9, MSVC 15 - "QGenericArgument(nullptr)": QGenericArgument(None), # 5.10 + "QGenericArgument(nullptr)": ellipsis, # 5.10 "QModelIndex()": Invalid("PySide2.QtCore.QModelIndex"), # repr is btw. very wrong, fix it?! - "QGenericArgument((0))": None, # 5.6, RHEL 6.6. Is that ok? - "QGenericArgument()": None, - "QGenericArgument(0)": None, - "QGenericArgument(NULL)": None, # 5.6, MSVC - "QGenericArgument(Q_NULLPTR)": None, + "QGenericArgument((0))": ellipsis, # 5.6, RHEL 6.6. Is that ok? + "QGenericArgument()": ellipsis, + "QGenericArgument(0)": ellipsis, + "QGenericArgument(NULL)": ellipsis, # 5.6, MSVC + "QGenericArgument(Q_NULLPTR)": ellipsis, "zero(PySide2.QtCore.QObject)": None, "zero(PySide2.QtCore.QThread)": None, "zero(quintptr)": 0, @@ -289,6 +202,9 @@ def init_QtCore(): "zero(PySide2.QtCore.QEvent.Type)": None, "CheckIndexOption.NoOption": Instance( "PySide2.QtCore.QAbstractItemModel.CheckIndexOptions.NoOption"), # 5.11 + "QVariantMap": dict, + "PySide2.QtCore.QCborStreamReader.StringResult": typing.AnyStr, + "PySide2.QtCore.double": float, }) try: type_map.update({ @@ -299,9 +215,10 @@ def init_QtCore(): pass return locals() + def init_QtGui(): import PySide2.QtGui - from PySide2.QtGui import QPageLayout, QPageSize # 5.9 + from PySide2.QtGui import QPageLayout, QPageSize # 5.12 macOS type_map.update({ "QVector< QTextLayout.FormatRange >()": [], # do we need more structure? "USHRT_MAX": ushort_max, @@ -313,7 +230,7 @@ def init_QtGui(): "GL_COLOR_BUFFER_BIT": GL_COLOR_BUFFER_BIT, "GL_NEAREST": GL_NEAREST, "WId": WId, - "PySide2.QtGui.QPlatformSurface": Virtual("PySide2.QtGui.QPlatformSurface"), # hmm... + "PySide2.QtGui.QPlatformSurface": int, # a handle "QList< QTouchEvent.TouchPoint >()": [], # XXX improve? "QPixmap()": Default("PySide2.QtGui.QPixmap"), # can't create without qApp "PySide2.QtCore.uint8_t": int, # macOS 5.9 @@ -325,9 +242,11 @@ def init_QtGui(): "zero(PySide2.QtGui.QTextLayout.FormatRange)": None, "zero(PySide2.QtGui.QTouchDevice)": None, "zero(PySide2.QtGui.QScreen)": None, + "PySide2.QtGui.QGenericMatrix": Missing("PySide2.QtGui.QGenericMatrix"), }) return locals() + def init_QtWidgets(): import PySide2.QtWidgets from PySide2.QtWidgets import QWidget, QMessageBox, QStyleOption, QStyleHintReturn, QStyleOptionComplex @@ -364,6 +283,7 @@ def init_QtWidgets(): }) return locals() + def init_QtSql(): import PySide2.QtSql from PySide2.QtSql import QSqlDatabase @@ -373,6 +293,7 @@ def init_QtSql(): }) return locals() + def init_QtNetwork(): import PySide2.QtNetwork type_map.update({ @@ -383,6 +304,7 @@ def init_QtNetwork(): }) return locals() + def init_QtXmlPatterns(): import PySide2.QtXmlPatterns from PySide2.QtXmlPatterns import QXmlName @@ -392,16 +314,16 @@ def init_QtXmlPatterns(): }) return locals() -def init_QtMultimedia(): - import PySide2.QtMultimedia + +def init_QtMultimediaWidgets(): import PySide2.QtMultimediaWidgets type_map.update({ - "QVariantMap": dict, "QGraphicsVideoItem": PySide2.QtMultimediaWidgets.QGraphicsVideoItem, "QVideoWidget": PySide2.QtMultimediaWidgets.QVideoWidget, }) return locals() + def init_QtOpenGL(): import PySide2.QtOpenGL type_map.update({ @@ -418,6 +340,7 @@ def init_QtOpenGL(): }) return locals() + def init_QtQml(): import PySide2.QtQml type_map.update({ @@ -430,6 +353,7 @@ def init_QtQml(): }) return locals() + def init_QtQuick(): import PySide2.QtQuick type_map.update({ @@ -441,6 +365,7 @@ def init_QtQuick(): }) return locals() + def init_QtScript(): import PySide2.QtScript type_map.update({ @@ -448,6 +373,7 @@ def init_QtScript(): }) return locals() + def init_QtTest(): import PySide2.QtTest type_map.update({ @@ -459,7 +385,6 @@ def init_QtTest(): def init_QtWebEngineWidgets(): import PySide2.QtWebEngineWidgets type_map.update({ - "PySide2.QtTest.QTouchEventSequence": PySide2.QtTest.QTest.QTouchEventSequence, "zero(PySide2.QtWebEngineWidgets.QWebEnginePage.FindFlags)": 0, }) return locals() @@ -472,6 +397,16 @@ def init_QtWinExtras(): }) return locals() -# Here was testbinding, actually the source of all evil. +# from 5.12, macOS +def init_QtDataVisualization(): + from PySide2.QtDataVisualization import QtDataVisualization + QtDataVisualization.QBarDataRow = typing.List[QtDataVisualization.QBarDataItem] + QtDataVisualization.QBarDataArray = typing.List[QtDataVisualization.QBarDataRow] + QtDataVisualization.QSurfaceDataRow = typing.List[QtDataVisualization.QSurfaceDataItem] + QtDataVisualization.QSurfaceDataArray = typing.List[QtDataVisualization.QSurfaceDataRow] + type_map.update({ + "100.0f": 100.0, + }) + return locals() # end of file |