Nice!
Fredrik suggested this:
def setupUi(uifile, base_instance=None):
"""Load a Qt Designer .ui file and returns an instance of the user
interface
Args:
uifile (str): Absolute path to .ui file
base_instance (QWidget): The widget into which UI widgets are loaded
Returns:
QWidget: the base instance
"""
ui = QtCompat.load_ui(uifile) # Qt.py mapped function
if not base_instance:
return ui
else:
for member in dir(ui):
if not member.startswith('__') and \
member is not 'staticMetaObject':
setattr(base_instance, member, getattr(ui, member))
return ui
and then use it like:
class MyWidget(QtWidgets.QtWidget):
def __init__(self, parent=wgQtUtil.getMayaWindow()):
super(MyWidget, self).__init__(parent)
setupUi(MyWidgetUI, self)
which seems neat and gets around the compile stuff but sadly widgets loaded
that way don't let me add them into another layout.
On Tue, Feb 7, 2017 at 1:25 PM, Slavomir Kaslev <[email protected]>
wrote:
> On Sat, Feb 4, 2017 at 8:26 AM, jonn <[email protected]> wrote:
>
>>
>> form_class, base_class = uic.loadUiType(ui_file)
>> how to do it
>>
>
> Here's what we use:
>
> from cStringIO import StringIO
> import xml.etree.ElementTree as xml
> import Qt
> from Qt import QtCore, QtWidgets
>
> def load_ui_type(ui_file):
> parsed = xml.parse(ui_file)
> widget_class = parsed.find('widget').get('class')
> form_class = parsed.find('class').text
> if Qt.__binding__ == 'PySide2':
> from pyside2uic import compileUi
> elif Qt.__binding__ == 'PyQt5':
> from PyQt5.uic import compileUi
> elif Qt.__binding__ == 'PySide':
> from pysideuic import compileUi
> elif Qt.__binding__ == 'PyQt4':
> from PyQt4.uic import compileUi
> else:
> assert False, 'Qt binding %s is unknown' % Qt.__binding__
>
> with open(ui_file, 'r') as f:
> frame = {}
> o = StringIO()
> compileUi(f, o, indent=0)
> pyc = compile(o.getvalue(), '<string>', 'exec')
> exec pyc in frame
> form_class = frame['Ui_%s' % form_class]
> base_class = eval('QtWidgets.%s' % widget_class)
> return form_class, base_class
>
> Maybe something along those lines will make it in Qt.py?
>
>
>>
>>
>> 在 2017年1月25日星期三 UTC+8下午10:28:25,Marcus Ottosson写道:
>>
>>> 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/ms
>> gid/python_inside_maya/43d2447f-159b-4e48-b9e7-c8e5eb2ed251%
>> 40googlegroups.com
>> <https://groups.google.com/d/msgid/python_inside_maya/43d2447f-159b-4e48-b9e7-c8e5eb2ed251%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Slavomir Kaslev
>
> --
> 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/CAE0o1NveARPR83UD_xgKL6Mfc20PKBC4WLxpK6ThK%
> 2BQVr1rAmA%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAE0o1NveARPR83UD_xgKL6Mfc20PKBC4WLxpK6ThK%2BQVr1rAmA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
Sebastian Schoellhammer
www.sebscorner.org
--
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/CAMLepcZ2Ltzfu_yrsa87c2xJFDzbp-kMJi0yi8H7OVefKVM2HQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.