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

Handling PyQt4.QtCore.QDate.toPyDate vs PySide2.QtCore.QDate.toPython #281

Open
RachelKLowe opened this issue Mar 21, 2018 · 1 comment
Open
Labels

Comments

@RachelKLowe
Copy link

Hello, we are using Qt.py to help with our transition from PyQt4 to PySide2 and I've run into some problems with QDate objects. I have a dialog that needs to be able to function in PyQt4 in one environment, and in PySide2 inside of Maya 2018. It is using a QDateEdit, QDateEdit.date() returns a QDate, but in PyQt4 we need to call QDateEdit.date().toPyDate() to get a datetime object back and in PySide2 we need to call QDateEdit.date().toPython().

I tried handling this in QtSiteConfig.py with the following update_compatibility_members method:

def update_compatibility_members(members):
    """This function is called by Qt.py to modify the modules it exposes.

    Arguments:
    members (dict): The members considered by Qt.py
    """
    members['PyQt4']["QtCore.QDate"] = {
        "toPython": "QtCore.QDate.toPyDate",
    }
    members['PyQt4']["QtCore.QDateTime"] = {
        "toPython": "QtCore.QDate.toPyDate",
    }

The code is executing, print statements inside of the method are visible, but when my bindings are PyQt4 QDate objects still do not have a toPython method on them.

Any help to get this working site wide would be greatly appreciated. For now we are just using hasattr to check for toPython on the QDate, and doing QDate.toPython = QDate.toPyDate if it isn't find, but it would be nice to fix it centrally. Thanks!

Kenny

@mottosso
Copy link
Owner

Thanks @kennethlowe, seems like a simple misaligned member in PySide2.

What I'd suggest is done is to unify them like this.

from Qt import QtCompat
QtCompat.QDate.toPyDate()

Such that this new QDate would represent a compatibility wrapper around the Qt 4 and Qt 5 versions. We can't (shouldn't) add it to the original QDate as it would mean (1) monkey patching and (2) leaving the old one behind and nearby, running the risk of either intermixing them in code or using the wrong one.

Have a look at adding this to the _compatibility_members dictionary, and see whether it produces the results you're looking for. Then a PR would trigger the automatic tests and hopefully solve the issue, then I'd be able to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants