NickHugi / PyKotor

A Python library that can read and modify most file formats used by the game Knights of the Old Republic and its sequel.
GNU Lesser General Public License v3.0
11 stars 3 forks source link

Qt abstraction layer #89

Closed th3w1zard1 closed 4 months ago

th3w1zard1 commented 5 months ago

The toolset is hardcoded to work with PyQt5. However with the qtpy library, which unifies most of the syntax, most of the other qt versions can be loaded as simply as this:


    os.environ["QT_API"] = os.environ.get("QT_API", "pyside2")  # supports pyqt5, pyqt6, pyside2, pyside6

    # Import the appropriate resources module based on the Qt bindings being used
    import qtpy

    if qtpy.API_NAME == "PySide2":
        from toolset.rcc.resources_rc_pyside2 import qCleanupResources, qInitResources
    elif qtpy.API_NAME == "PySide6":
        from toolset.rcc.resources_rc_pyside6 import qCleanupResources, qInitResources
    elif qtpy.API_NAME == "PyQt5":
        from toolset.rcc.resources_rc_pyqt5 import qCleanupResources, qInitResources
    elif qtpy.API_NAME == "PyQt6":
        from toolset.rcc.resources_rc_pyqt6 import qCleanupResources, qInitResources
    else:
        raise ImportError(f"Unsupported Qt bindings: {qtpy.API_NAME}")
    print(f"Using qt bindings '{qtpy.API_NAME}'")

from qtpy.QtWidgets import QApplication
app = QApplication(sys.argv)

As can be seen the 'QT_API' environment variable tells qtpy what qt version to use.

While we may not be planning to swap to another Qt version, this pr is still important as it allows further upgrades to be possible down the road, as qt5 is an ancient version.

PyQt5 isn't compatible with PyPy but PySide6 is.

This pr also updates the convertui.py script.

Caveats: