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

uic.compileUi for PySide2 #190

Closed
Winand opened this issue May 30, 2019 · 2 comments · Fixed by #202
Closed

uic.compileUi for PySide2 #190

Winand opened this issue May 30, 2019 · 2 comments · Fixed by #202

Comments

@Winand
Copy link

Winand commented May 30, 2019

I think compileUi can be added smoothly to uic module for PySide2 backend. pyside2uic is a part of PySide2 distribution and pyside2uic.compileUi has almost the same interface as PyQt's analogue.

Now I use monkey-patching in my project:

from qtpy import uic, API
if API.startswith('pyside'):
    import pyside2uic
    uic.compileUi = pyside2uic.compileUi
@j9ac9k
Copy link

j9ac9k commented Jun 13, 2020

With PySide2 5.14.2.2 pytside2-uic was brought back, we had to re-incorporate it in pyqtgraph, you can see the diff too re-enable that in our abstraction layer here:

https://github.com/pyqtgraph/pyqtgraph/pull/1211/files#diff-ef920af841b22fdd54535d097f2b8b24

@dalthviz
Copy link
Member

Closing since the compileUi import was added with PR #202 See v1.11.0 qtpy.uic:

qtpy/qtpy/uic.py

Lines 85 to 88 in 6b12fba

elif PYSIDE2:
from PySide2.QtCore import QMetaObject
from PySide2.QtUiTools import QUiLoader
from pyside2uic import compileUi

Current state (v2.0.1):

qtpy/qtpy/uic.py

Lines 84 to 102 in 936e0c9

elif PYSIDE2:
from PySide2.QtCore import QMetaObject
from PySide2.QtUiTools import QUiLoader
try:
from pyside2uic import compileUi
# Patch UIParser as xml.etree.Elementree.Element.getiterator
# was deprecated since Python 3.2 and removed in Python 3.9
# https://docs.python.org/3.9/whatsnew/3.9.html#removed
from pyside2uic.uiparser import UIParser
from xml.etree.ElementTree import Element
class ElemPatched(Element):
def getiterator(self, *args, **kwargs):
return self.iter(*args, **kwargs)
def readResources(self, elem):
return self._readResources(ElemPatched(elem))
UIParser._readResources = UIParser.readResources
UIParser.readResources = readResources
except ImportError:
pass

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

Successfully merging a pull request may close this issue.

4 participants