Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@MHendricks
Copy link
Collaborator

We make use of optional Qt libraries at Blur Studio, Qsci and QtCore.QJsonDocument. It would be nice to be able to opt-into being able to use those modules. Ideally in a way where we don't have to maintain our own fork of Qt.py. It also means that we don't need to define imports of these modules outside of the Qt object.

To make this happen I made Qt.py attempt to import the python module Qt_site_config. If it can import the module it calls Qt_site_config.update_common_members(_common_members) and updates _common_members with the returned value.

@CLAassistant
Copy link

CLAassistant commented May 25, 2017

CLA assistant check
All committers have signed the CLA.

def test_add_site_members():
import Qt
try:
from Qt import QtGui

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Qt.QtGui' imported but unused

return _common_members

def test_add_site_members():
import Qt

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Qt' imported but unused

]
return _common_members

def test_add_site_members():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

customize available modules for Qt.py without modifying the Qt.py package.
"""

def update_common_members(_common_members):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

Qt.py Outdated
try:
import Qt_site_config
except ImportError:
# If no Qt_site_config module found, no modifications to _common_members

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (80 > 79 characters)

Qt.py Outdated
]
}

def _add_site_members():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

def test_add_site_members():
import Qt
try:
from Qt import QtGui

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Qt.QtGui' imported but unused

return _common_members

def test_add_site_members():
import Qt

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Qt' imported but unused

]
return _common_members

def test_add_site_members():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

customize available modules for Qt.py without modifying the Qt.py package.
"""

def update_common_members(_common_members):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

Qt.py Outdated
try:
import Qt_site_config
except ImportError:
# If no Qt_site_config module found, no modifications to _common_members

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (80 > 79 characters)

Qt.py Outdated
]
}

def _add_site_members():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1


def test_add_site_members():
try:
from Qt import QtGui

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Qt.QtGui' imported but unused

@fredrikaverpil
Copy link
Collaborator

fredrikaverpil commented May 26, 2017

Thanks @MHendricks for this!
Looks like a nice addition to Qt.py to me. I see you've included a test. Well done :)

I'm not too fond of underscores in the module name (Qt_site_config), although according to PEP8, this is fine:

Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged

However, since we are conforming to CamelCase to make Qt.py blend into Qt land. Could you please expand on any reasoning behind this or if you would mind changing it into e.g. QtSiteConfig?

A bit on documentation:

  • Let's add some info on this feature to the main README, preferably under the "Documentation" header, I think.
  • Let's also add this to the list of examples here

But other than these minor things, thanks for this nice contribution!

@mottosso what do you think?

@mottosso
Copy link
Owner

Hi @MHendricks,

There was a change made recently, March this year, to enable optional submodules to become part of Qt.py, without causing trouble for those that did not have the implementation available locally.

I think this would be the preferable method of adding these members and you are welcome to do so. In practice, anything present in _common_members is available via import Qt if the submodule is available locally.

@fredrikaverpil
Copy link
Collaborator

@mottosso so what you're saying is we should just add e.g. Qsci and QtCore.QJsonDocument directly to Qt.py's _common_members itself?

Previously, I think we've only discussed members which we know are included in the more regular type of compilation of Qt. In this case I believe that e.g. Qsci and QtCore.QJsonDocument require custom compilation settings for these members to be available. Am I correct?

This means these members are most likely not available for the "common user"... and I wonder if these should really be added to the _common_members...

@mottosso
Copy link
Owner

In this case I believe that e.g. Qsci and QtCore.QJsonDocument require custom compilation settings for these members to be available. Am I correct?

That's right, this will still work.

There's reasoning behind how and why in the PR and original issue, but in a nutshell, Qt.py should encompass all of PySide2 which should encompass all of Qt in some shape or form. Currently the various distributions of PySide2 vary greatly, with even basic submodules missing, like QtHelp missing from Houdini specifically. This would enable us to grow Qt.py whilst still allowing PySide2 to catch up.

That said, I'm not expecting us to add any submodules that aren't related to PySide2.

@MHendricks
Copy link
Collaborator Author

I also don't like underscores, so I'm happy to rename the module to QtSiteConfig. I can also make the other changes requested.

That said, I'm not expecting us to add any submodules that aren't related to PySide2.

Heh, along those lines I need to make use of QVariant from PyQt so we have access to the type enums PyQt5.QtCore.QVariant.Date for example. At this point we have some bindings that are PyQt specific and we want to use Qt.py to transition to Maya 2017. While we are able to switch to sip api v2 for QVariant we sill need those type enums. I can add code similar to the examples in #185 in the application to support this, but I was planning to use QtSiteConfig to add it that way.

Do you want to proceed with the direction of this pull request, or should I make a new one that just adds the Qsci and QJsonDocument to the existing _common_members?

@mottosso
Copy link
Owner

mottosso commented May 26, 2017

Have you considered using those members via QtCore.QMetaType?

from PyQt4 import QtCore
assert QtCore.QVariant.Date == QtCore.QMetaType.QDate

Do you want to proceed with the direction of this pull request, or should I make a new one that just adds the Qsci and QJsonDocument to the existing _common_members?

I'm not sure yet, on one hand there isn't any harm to existing functionality by introducing this functionality but on the other it may open the floodgates to code not usable by anyone other than the original author if code written with this "extension" in place gets into the wild.

For example, if the developers at your studio are first introduced to Qt.py when extended in this manner are later expecting to write software on their own or to help others write software, then if there is suddenly this "hidden addition" that only the original author knows about it may create more issues than it solves.

I think the ideal scenario was if you could find away to migrate your use of QVariant to QMetaType, and add other PySide2-native submodules you require to Qt.py.

QMetaType currently isn't available in Qt.py nor PySide2, that's in the process of changing and you'd be welcome to add it in which case it would become available to PyQt bindings and to PySide2 once they finish implementing it. Then the question remains whether we should implement backwards compatibility to PySide(1) where it is missing also.

@MHendricks
Copy link
Collaborator Author

I talked with our Qt developer and it looks like we should be able to migrate to QMetaType and away from QVariant.

I went ahead and addressed @fredrikaverpil comments in case we end up merging this pull request.

@fredrikaverpil
Copy link
Collaborator

I went ahead and addressed @fredrikaverpil comments in case we end up merging this pull request.

Thanks @MHendricks :)

@mottosso you decide which route to take here. Either way is fine by me, really. I just reacted to the fact that these particular modules are most often not part of PySide2 and probably never will be in the most popular DCC apps. On the other hand, if you need to use them you might already be aware of this fact.

On a slightly different note, I like the idea of being able to customize Qt.py without actually having to maintain code changes to the Qt.py file itself. The question here is: would it really be useful to be able to customize e.g. the _common_members dictionary?

Perhaps the best way forward would be to just add these members to Qt.py but make inline comments about modules which are not compiled by default?
Or perhaps define a new dictionary called _optional_members which could hold e.g. Qsci. Then we'd merge the _common_members and _optional_members dictionaries into a _members dictionary which would be used in the end. Or perhaps this is just overthinking this problem?

@mottosso
Copy link
Owner

Hi @MHendricks, I had a look at the documentation you've made and gave the implementation a try, I think it's solid.

I made a few tweaks to the API, namely:

  1. update_common_members was renamed to update_members
  2. Argument _common_members was renamed to members
  3. update_members no longer needs to return
  4. No use of global in Qt.py

I've also gone ahead and added QMetaType for your convenience and updated part of the documentation and examples.

Let me know what you think.

@mottosso
Copy link
Owner

mottosso commented May 27, 2017

Was going to add some motivation for the changes but ran out of time; I found some so here goes!

I renamed update_members as it contained an implementation detail of Qt.py, coming from the variable _common_members. Like with exposing any implementation detail, odds are it'll change at some point which would make the name of this function rather nonsensical. update_members is user-facing and logical as it's members of Qt.py being updated.

I removed the return statement, as it didn't seem needed and removing it simplified the method in which the functions needed to be written.

As the function no longer needed to return, it was no longer necessary to assign it in the Qt.py file, which meant we didn't require the use of global.

Finally, I renamed the private function _add_site_members() to _apply_site_config() as it not only added but potentially modified and removed members as well and felt this better reflected its true intention.

@MHendricks
Copy link
Collaborator Author

I wondered if you could just modify the passed in dict. One of the reasons I left it in there is that it made it clear to understand that the function was modifying _common_members by looking at the code. However, I dislike using global if I can avoid it, so I'm happy with the changes. I went ahead and fixed a few broken links from the rename.

Everything looks good to me.

@mottosso mottosso merged commit 52e3c07 into mottosso:master Jun 1, 2017
@fredrikaverpil
Copy link
Collaborator

fredrikaverpil commented Aug 18, 2017

@MHendricks @mottosso Headsup, guys. It seems QtCore.QMetaType was for some reason removed in more recent builds of PySide2:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants