$ show mottosso/Qt.py
Qt.py is a single-file Python compatibility shim that provides a unified API across PySide6, PyQt6, PySide2, and PyQt5 Qt bindings. It exports a curated set of common member classes and functions, ensuring that code written with `from Qt import ...` works identically on any supported binding. The library handles disparities in module structure (e.g., QAction location), different signal/slot syntax, and missing utilities like `loadUi` by implementing its own `QUiLoader`-based fallback. It also includes a command-line tool for converting PySide2-compiled .ui files, and supports per-import configuration via environment variables and `QtSiteConfig.py`. While primarily a library, it has CLI entry points and extensive test infrastructure.
The LLM identified 2 files worth highlighting for reuse:
The `_loadUi` function and the internal `_UiLoader` class implement a full replacement for PyQt's `uic.loadUi` that works with PySide bindings. It handles custom widget registration, base instance embedding, and signal/slot connections. This is a non-trivial pattern demonstrating how to bridge incompatible UI loading APIs across bindings. The code is isolated and could be extracted for use in any project needing PySide UI loading.
The `_wrapinstance` function and its companion `_getcpppointer` and `_isvalid` provide a robust mechanism for wrapping C++ Qt object pointers into Python objects, auto-detecting the most specific class via metaclass introspection. This decouples code from the underlying binding's wrapper (shiboken vs sip) and can be reused in any scenario requiring direct memory manipulation of Qt objects, such as embedding external widgets or interacting with low-level Qt APIs.