Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add QMatrix to QtGui members #330

Merged
merged 5 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions Qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,22 @@
]
}

""" Missing members

This mapping describes members that have been deprecated
in one or more bindings and have been left out of the
_common_members mapping.
justinfx marked this conversation as resolved.
Show resolved Hide resolved

The member can provide an extra details string to be
included in exceptions and warnings.
"""

_missing_members = {
"QtGui": {
"QMatrix": "Deprecated in PyQt5",
},
}


def _qInstallMessageHandler(handler):
"""Install a message handler that works in all bindings
Expand Down Expand Up @@ -1734,6 +1750,36 @@ def _cli(args):
sys.stdout.write("Successfully converted \"%s\"\n" % args.convert)


class MissingMember(object):
"""
A placeholder type for a missing Qt object not
included in Qt.py

Args:
name (str): The name of the missing type
details (str): An optional custom error message
"""
ERR_TMPL = ("{} is not a common object across PySide2 "
"and the other Qt bindings. It is not included "
"as a common member in the Qt.py layer")

def __init__(self, name, details=''):
self.__name = name
self.__err = self.ERR_TMPL.format(name)

if details:
self.__err = "{}: {}".format(self.__err, details)

def __repr__(self):
return "<{}: {}>".format(self.__class__.__name__, self.__name)

def __getattr__(self, name):
raise NotImplementedError(self.__err)

def __call__(self, *a, **kw):
raise NotImplementedError(self.__err)


def _install():
# Default order (customise order and content via QT_PREFERRED_BINDING)
default_order = ("PySide2", "PyQt5", "PySide", "PyQt4")
Expand Down Expand Up @@ -1801,6 +1847,22 @@ def _install():

setattr(our_submodule, member, their_member)

# Install missing member placeholders
for name, members in _missing_members.items():
our_submodule = getattr(Qt, name)

for member in members:

# If the submodule already has this member installed,
# either by the common members, or the site config,
# then skip installing this one over it.
if hasattr(our_submodule, member):
continue

placeholder = MissingMember("{}.{}".format(name, member),
details=members[member])
setattr(our_submodule, member, placeholder)

# Enable direct import of QtCompat
sys.modules['Qt.QtCompat'] = Qt.QtCompat

Expand Down
23 changes: 23 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,29 @@ def test_membership():
)


def test_missing():
"""Missing members of Qt.py have been defined with placeholders"""
import Qt

missing_members = Qt._missing_members.copy()

missing = list()
for module, members in missing_members.items():

mod = getattr(Qt, module)
missing.extend(
member for member in members
if not hasattr(mod, member) or
not isinstance(getattr(mod, member), Qt.MissingMember)
)

binding = Qt.__binding__
assert not missing, (
"Some members did not exist in {binding} as "
"a Qt.MissingMember type\n{missing}".format(**locals())
)


if sys.version_info <= (3, 4):
# PySide is not available for Python > 3.4
# Shiboken(1) doesn't support Python 3.5
Expand Down