Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Control PySide Version To Work With Latest Maya

49 views
Skip to first unread message

Anas Elkinawy

unread,
Nov 25, 2024, 6:19:14 AM11/25/24
to Python Programming for Autodesk Maya
I am trying to update my scripts that was using PySide2 and make them work in maya 2025 or later 

So I thought it would be better if I change PySide Version as String then import it 
But I got the feeling that its not the neatest way !!

If you have any Ideas to make this better without the need to install any packages that maya doesn't support  

Here's My Code 
# =====================================
import importlib
import maya.OpenMayaUI as Omui
 
maya_version = cmds.about(version=True)

# ====================================================================================
# DEFINE  PYSIDE VERSION
qt_widgets = "PySide2.QtWidgets" if int(maya_version) < 2024 else "PySide6.QtWidgets"
qt_core = "PySide2.QtCore" if int(maya_version) < 2024 else "PySide6.QtCore"
shibokenV = "shiboken2" if int(maya_version) < 2024 else "shiboken6"
# ====================================================================================

# ======================================================
# ATTEMPT TO IMPORT
a = importlib.import_module(qt_widgets)
b = importlib.import_module(qt_core)
c = importlib.import_module(shibokenV)
# ======================================================

# ======================================================
# Getting Maya Main Window
maya_main_window_ptr = Omui.MQtUtil.mainWindow()
V = c.wrapInstance(int(maya_main_window_ptr), a.QWidget)
# ======================================================

# =============
# TEST
x = a.QDialog()
x.show()
# =============



Justin Israel

unread,
Nov 25, 2024, 2:35:08 PM11/25/24
to python_in...@googlegroups.com
Hi,

Marcus wrote the Qt.py helper library just for this purpose. Have a look:

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/python_inside_maya/363c2368-4824-4200-9a54-a5776e06fa29n%40googlegroups.com.

Marcus Ottosson

unread,
Nov 27, 2024, 6:47:27 AM11/27/24
to python_in...@googlegroups.com
Yep, that's it. It's meant to be bundled with your project, so as to not have to install anything.
from .vendor import Qt

But can also be installed via pip install Qt.py

import Qt
And it'll run on Maya 2025 down to 2015 or so.

Anas Elkinawy

unread,
Nov 27, 2024, 8:51:48 PM11/27/24
to Python Programming for Autodesk Maya
thanks a lot 

I'll consider using it 
I was afraid that user will have to install non-maya packages 

but its great that its bundeled with the project itself 

thanks Justin, Marcus ^ ^
Reply all
Reply to author
Forward
0 new messages