Files
Nexus/2023/scripts/animation_tools/dwpicker/pyside.py
2025-11-24 21:05:22 +08:00

50 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
PySide Compatibility Module
自动检测并导入合适的 Qt 绑定PySide2 或 PySide6
支持 Maya 2017-2026+ 所有版本
"""
try:
ModuleNotFoundError
except NameError:
# Python 2 backward compatibility
class ModuleNotFoundError(ImportError):
pass
from maya import cmds
# 尝试导入 PySide6Maya 2025+
try:
maya_version = int(cmds.about(majorVersion=True))
if maya_version >= 2025:
print(f"DwPicker: Detected Maya {maya_version}, using PySide6")
from PySide6 import QtCore, QtGui, QtWidgets
from PySide6 import __version__
import shiboken6 as shiboken2
# PySide6 兼容性映射
QtWidgets.QShortcut = QtGui.QShortcut
QtWidgets.QAction = QtGui.QAction
QtGui.QMouseEvent.pos = lambda x: x.position().toPoint()
QtGui.QMouseEvent.globalPos = QtGui.QMouseEvent.globalPosition
QtGui.QWheelEvent.pos = QtGui.QWheelEvent.position
QtCore.Qt.BackgroundColorRole = QtCore.Qt.BackgroundRole
else:
# Maya 2017-2024 使用 PySide2
raise TypeError("Maya version < 2025, will use PySide2")
except (ModuleNotFoundError, TypeError, ImportError) as e:
# 降级到 PySide2Maya 2017-2024
try:
maya_version = int(cmds.about(majorVersion=True))
print(f"DwPicker: Detected Maya {maya_version}, using PySide2")
except:
print("DwPicker: Using PySide2")
from PySide2 import QtCore, QtGui, QtWidgets
import shiboken2