Qt.py and safety
Hi community,
Today we’ve made a significant leap forwards for Qt.py and implemented a
guarantee where if your program runs with Qt.py and any binding, such as
PySide2, it will run in an identical fashion on any binding.
This means that it will throw an error if you use any feature of any
particular binding that isn’t available on another binding.
What’s changed?
This is possible with the current iteration of Qt.py.
1: from Qt import QtGui, QtCore2: 3: class Widget(QtGui.QWidget):4:
my_signal = QtCore.pyqtSignal(str)
- On the third line, we run into an immediate problem; QWidget is only
available via QtGui in PyQt4 and PySide(1).
- On the 4th line, we refer to a signal as pyqtSignal which would work
well on both PyQt4 and PyQt5, but fail in PySide and PySide2.
- Worst yet, these problems would not make themselves known until you
run it on each of the 4 bindings and make sure, first hand that it works as
you’d expect.
With this new change, Qt.py limits the available members of each submodule
into a subset of members that exist across all bindings. The result is
finding out about these problems faster and being able to guarantee that if
it runs on one binding, it works on all.
1: from Qt import QtGui2: 3: class Widget(QtGui.QWidget):4: pass5:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'QWidget'
It’s a breaking change
As it is a breaking change, this bumps Qt.py from a 0.x.x release into a
1.x.x. This means some of your already-written software with Qt.py may need
some tweaking. On the up-side, the software that would behave badly now,
are those that would have already behaved badly in any of the 4 bindings.
So this is your chance to smoke some of that out.
We are confident in this change and direction, but are still in discussion
about whether now is the right time. One of the bindings, namely PySide2,
is so far behind the other bindings that it the weakest link by far, and
critical submodules - such as QtOpenGL - is still missing.
These are the modules supported by Qt.py with this change.
__all__ = [
"QtGui",
"QtCore",
"QtWidgets",
"QtNetwork",
"QtXml",
"QtHelp",
"QtCompat"
]
The second concern regards which version of this weakest link to match. As
PySide2 matures, more feature will be added and Qt.py could start to grow.
But Maya 2017 and others are currently fixed at version 2.0.0. Growing
Qt.py beyond what Maya 2017 is capable of would limit its usefulness.
For this I figure it wouldn’t be too cumbersome to implement compatibility
profiles; where the end-user specifies which version of, say, the VFX
Platform to provide support for.
$ # For example
$ export QT_BASELINE=CY2018
$ python -c "from Qt import QtOpenGL"
Bridging the bindings
For the time being, and where you need functionality exclusive to any
particular binding, such as sip in PyQt, there is still the __binding__
member that allows conditional inclusion.
if "PySide" in __binding__:
do_pyside_stuff()
This would allow you to explicitly mark the parts of your codebase that
depend on any particular binding, and to enable a bridge to your code today
and your code sometime in the future when the required functionality is
officially part of Qt.py.
Guinea pigs unite!
For now, we’d appreciate your feedback on this major change and for you to
test it out for yourself. The release is still considered “alpha” and is
available directly via GitHub for download or install.
$ pip install git+git://github.com/mottosso/Qt.py
- Source <https://github.com/mottosso/Qt.py/blob/master/Qt.py>
- Pull request <https://github.com/mottosso/Qt.py/pull/173>
- Issue <https://github.com/mottosso/Qt.py/issues/152>
Thanks to Matthew Levine for the initial feature request
<https://github.com/mottosso/Qt.py/issues/152> and Fredrik Averpil for the
unwavering support. :)
Best,
Marcus
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODFjo%2BzMcM0OzmnDxJ2BeTNZ%2BjNHPQVKtJoEv-w7PT%3D%2BQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.