I'm trying to create a simple QT app using PySide and Python that I want it to run as a 3dsMax script, a Modo script and a stand-alone app if needed. So, I've saved the following files in my D:\PyTest. It's just a QLabel for this test.
When I run it (TestWidget.py) as a stand-alone it works fine. When I start it (ModoStart.py) from Modo it starts correctly but if I try to click anywhere in Modo it crashes the whole window. In 3dsMax I get the following error: Traceback (most recent call last): File "D:/PyTest\TestWidget.py", line 13, in SystemExit: -1
Any ideas how I can make it work?
Thanks,
Nick
TestWidget.py
import sys
from PySide import QtGui
def open_widget(app, parent_handle=None):
w = QtGui.QLabel()
w.setText("My Widget")
w.show()
if parent_handle is not None:
w.setParent(parent_handle)
sys.exit(app.exec_())
if __name__ == '__main__':
open_widget(QtGui.QApplication(sys.argv))
MaxStart.py
import sys
FileDir = 'D:/PyTest'
if FileDir not in sys.path:
sys.path.append(FileDir)
#Rest imports
from PySide import QtGui
import MaxPlus
import TestWidget
reload(TestWidget)
app = QtGui.QApplication.instance()
parent_handle = QtGui.QWidget(MaxPlus.GetQMaxWindow())
TestWidget.open_widget(app, parent_handle)
ModoStart.py
import sys
FileDir = 'D:/PyTest'
if FileDir not in sys.path:
sys.path.append(FileDir)
#Rest imports
from PySide import QtGui
import TestWidget
reload(TestWidget)
app = QtGui.QApplication.instance()
TestWidget.open_widget(app)
UPDATE:
I also tried to have one file for all three options (3dsMax/Modo/Stand-alone). It seems that it works fine for 3dsMax and Stand-Alone, but in Modo, if I click outside the Widget or if I try to close it, Modo instantly crashes.
import sys
import traceback
from PySide import QtGui
handle = None
appMode = None
try:
import MaxPlus
appMode = '3dsMax'
handle = MaxPlus.GetQMaxWindow()
except:
try:
import lx
appMode = 'Modo'
except:
appMode = 'StandAlone'
app = QtGui.QApplication.instance()
if not app:
app = QtGui.QApplication([])
def main():
w = QtGui.QLabel(handle)
w.setText("My Widget")
w.resize(250, 100)
w.setWindowTitle('PySide Qt Window')
w.show()
try:
sys.exit(app.exec_())
except Exception, err:
traceback.print_exc()
pass
main()
Ok, with a little help from The Foundry I have a working version. They gave me this very useful link http://sdk.luxology.com/wiki/CustomView
3dsMax.py
Modo.py
StandAlone.py
ToolboxUI.py