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

PySide2 and Python3.9: xml.etree.ElementTree.Element' object has no attribute 'getchildren #238

Closed
AndrewAmmerlaan opened this issue May 29, 2021 · 0 comments · Fixed by #224
Labels
Milestone

Comments

@AndrewAmmerlaan
Copy link
Contributor

With QT_API="pyside2", QtPy-1.9.0 and python3.9, I get the following test failure:

=============================================================================================== FAILURES ================================================================================================
_______________________________________________________________________________________ test_load_ui_custom_auto ________________________________________________________________________________________

tmpdir = local('/var/tmp/portage/dev-python/QtPy-1.9.0-r4/temp/pytest-of-portage/pytest-5/test_load_ui_custom_auto0')

@pytest.mark.skipif((PYSIDE2 and os.environ.get('CI', None) is not None),
reason="It segfaults in our CIs with PYSIDE2")
def test_load_ui_custom_auto(tmpdir):
"""
Test that we can load a .ui file with custom widgets without having to
explicitly specify a dictionary of custom widgets, even in the case of
PySide.
"""

app = get_qapp()

with enabled_qcombobox_subclass(tmpdir):
from qcombobox_subclass import _QComboBoxSubclass
>           ui = loadUi(os.path.join(os.path.dirname(__file__), 'test_custom.ui'))

_QComboBoxSubclass = <class 'qcombobox_subclass._QComboBoxSubclass'>
app        = <PySide2.QtWidgets.QApplication(0x559c6cc2d810) at 0x7f2e425790c0>
tmpdir     = local('/var/tmp/portage/dev-python/QtPy-1.9.0-r4/temp/pytest-of-portage/pytest-5/test_load_ui_custom_auto0')

qtpy/tests/test_uic.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
qtpy/uic.py:219: in loadUi
customWidgets = _get_custom_widgets(uifile)
baseinstance = None
uifile     = '/var/tmp/portage/dev-python/QtPy-1.9.0-r4/work/QtPy-1.9.0/qtpy/tests/test_custom.ui'
workingDirectory = None
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

ui_file = '/var/tmp/portage/dev-python/QtPy-1.9.0-r4/work/QtPy-1.9.0/qtpy/tests/test_custom.ui'

def _get_custom_widgets(ui_file):
"""
This function is used to parse a ui file and look for the <customwidgets>
section, then automatically load all the custom widget classes.
"""

import sys
import importlib
from xml.etree.ElementTree import ElementTree

# Parse the UI file
etree = ElementTree()
ui = etree.parse(ui_file)

# Get the customwidgets section
custom_widgets = ui.find('customwidgets')

if custom_widgets is None:
return {}

custom_widget_classes = {}

>       for custom_widget in custom_widgets.getchildren():
E       AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getchildren'

ElementTree = <class 'xml.etree.ElementTree.ElementTree'>
custom_widget_classes = {}
custom_widgets = <Element 'customwidgets' at 0x7f2de8996220>
etree      = <xml.etree.ElementTree.ElementTree object at 0x7f2e425603d0>
importlib  = <module 'importlib' from '/usr/lib/python3.9/importlib/__init__.py'>
sys        = <module 'sys' (built-in)>
ui         = <Element 'ui' at 0x7f2de898cae0>
ui_file    = '/var/tmp/portage/dev-python/QtPy-1.9.0-r4/work/QtPy-1.9.0/qtpy/tests/test_custom.ui'

qtpy/uic.py:184: AttributeError

Please let me know if you require any additional information.

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