8000 Add PyQt6 support by MHendricks · Pull Request #431 · mottosso/Qt.py · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add PyQt6 support #431

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

Merged
merged 6 commits into from
Apr 21, 2025
Merged

Add PyQt6 support #431

merged 6 commits into from
Apr 21, 2025

Conversation

MHendricks
Copy link
Collaborator

Add the binding information for PyQt6 support.

PyQt6 seems to have removed a lot of backwards compatible support that PySide6 has not. This introduces a few issues that should be figured out before this is merged. I will add additional notes calling out the specifics.

@MHendricks
Copy link
Collaborator Author

I wanted to ask how to solve the two failing PyQt6 tests. It looks like PyQt6 is capturing the FileNotFoundError error that is getting raised and these tests are looking for and wrapping it in a generic PyQt6.uic.exceptions.UIFileException that only inherits from Exception not from FileNotFoundError. This breaks the test, but also makes it so if a Qt.py user wanted to handle mis 8000 sing file exceptions they now have to account for if you are using PyQt6.

Do we accept this limitation and I just update the tests so they pass, or should I look into extracting the original exception and raise it in the _loadUi function?

The exception raised by the test:

ERROR: tests.test_load_ui_invalidpath
Tests to see if loadUi successfully fails on invalid paths
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/.local/lib/python3.10/site-packages/PyQt6/uic/ui_file.py", line 35, in __init__
    document = ElementTree.parse(ui_file)
  File "/usr/lib/python3.10/xml/etree/ElementTree.py", line 1222, in parse
    tree.parse(source, parser)
  File "/usr/lib/python3.10/xml/etree/ElementTree.py", line 569, in parse
    source = open(source, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'made/up/path'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/runner/work/Qt.py/Qt.py/tests.py", line 622, in test_load_ui_invalidpath
    assert_raises(IOError, QtCompat.loadUi, 'made/up/path')
  File "/usr/lib/python3.10/unittest/case.py", line 738, in assertRaises
    return context.handle('assertRaises', args, kwargs)
  File "/usr/lib/python3.10/unittest/case.py", line 201, in handle
    callable_obj(*args, **kwargs)
  File "/home/runner/work/Qt.py/Qt.py/Qt.py", line 798, in _loadUi
    return Qt._uic.loadUi(uifile, baseinstance)
  File "/home/runner/.local/lib/python3.10/site-packages/PyQt6/uic/load_ui.py", line 86, in loadUi
    return DynamicUILoader(package).loadUi(uifile, baseinstance)
  File "/home/runner/.local/lib/python3.10/site-packages/PyQt6/uic/Loader/loader.py", line 62, in loadUi
    return self.parse(filename)
  File "/home/runner/.local/lib/python3.10/site-packages/PyQt6/uic/uiparser.py", line 995, in parse
    ui_file = UIFile(filename)
  File "/home/runner/.local/lib/python3.10/site-packages/PyQt6/uic/ui_file.py", line 37, in __init__
    self._raise_exception("invalid Qt Designer file", detail=str(e))
  File "/home/runner/.local/lib/python3.10/site-packages/PyQt6/uic/ui_file.py", line 92, in _raise_exception
    raise UIFileException(self._ui_file, message, detail=detail)
PyQt6.uic.exceptions.UIFileException: made/up/path: invalid Qt Designer file: [Errno 2] No such file or directory: 'made/up/path'

@mottosso
Copy link
Owner
mottosso commented Apr 2, 2025

Great initiative. I'm in the start of a house-move at the moment and will be slow to reply, but I would like invite others to join in on the conversation too so if you are reading this, do chime in.

- Don't mutate the current test suite binding when testing None. This was causing
the tests after it runs to use the wrong binding.
- Restore the original working directory to prevent file lock issues when testing on windows.
- run_tests.py now includes the failing bindings in the summary exception for ease of debugging.
- QtCompat.QFont.fromString adds support for Qt6 font strings in Qt4/5.
- QtCompat.enumValue interface for converting Qt enums to int values.
@MHendricks
Copy link
Collaborator Author

I wanted to ask how to solve the two failing PyQt6 tests. It looks like PyQt6 is capturing the FileNotFoundError error that is getting raised and these tests are looking for and wrapping it in a generic PyQt6.uic.exceptions.UIFileException that only inherits from Exception not from FileNotFoundError. This breaks the test, but also makes it so if a Qt.py user wanted to handle missing file exceptions they now have to account for if you are using PyQt6.

Do we accept this limitation and I just update the tests so they pass, or should I look into extracting the original exception and raise it in the _loadUi function?

I chose the latter. For known exceptions we are testing for IOError and xml.etree.ElementTree.ParseError it will raise the generic exception(error.__context__). Otherwise it will raise the original PyQt6 specific errors, but for now I'm guessing it's unlikely that devs will be handling those errors in code.

This removes the UIFileException exception if the cause exception is not
PyQt6 specific. This should make it easier to handle exceptions consistently
between bindings.
Tests for Qt_convert_enum.py are written but require at least python 3.7 to run successfully.
These tests will be enabled once the underlying testing suite is updated to current requirements.
@MHendricks MHendricks marked this pull request as ready for review April 18, 2025 01:58
@MHendricks
Copy link
Collaborator Author

I think this is ready to release I'll try to do that on Monday.

@MHendricks MHendricks self-assigned this Apr 18, 2025
@mottosso
Copy link
Owner

Good luck and great work. :) I'll be here if things go south.

@MHendricks MHendricks merged commit 1b7b13a into mottosso:master Apr 21, 2025
10 checks passed
@MHendricks MHendricks deleted the mikeh/pyqt6 branch April 21, 2025 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0