snip–><–snip

Archive for January, 2012

PySide in maya 2010.

by on Jan.01, 2012, under Uncategorized

The last time i tired this it broke and it broke good, but this time when i installed pyside, i made sure it was the 64bit version from:

http://developer.qt.nokia.com/wiki/PySide_Binaries_Windows

maya 2010 uses python 2.6, so make sure you have that installed and then install pyside on that.

Getting pyside to lauch in maya was as easy as:

**EDIT: Forgot to check to the instance..
Checking for the instance gets rid of this error:
# Error: RuntimeError: A QApplication instance already exists. #

<br />
import sys<br />
sys.path.append('C:/Python26/Lib/site-packages/')# this is where python and pyside exist.<br />
#from PySide import QtCore, QtGui<br />
from PySide.QtCore import *<br />
from PySide.QtGui import *<br />
# Create a Qt applicatio<br />
app = QApplication.instance()<br />
if app == None:<br />
    app = QApplication(sys.argv)<br />
# Create a Label and show it<br />
label = QLabel("Hello World")<br />
label.show()<br />
# Enter Qt application main loop<br />
app.exec_()<br />
sys.exit()<br />

That loads hello world.

Next up, so you can load the .ui file in a python app with out having to compile the file.
Nathan Horne wrote a nice wrapper:
PySide_loadUiType.py

So then you can do this:

<br />
&amp;amp;amp;lt;pre&amp;amp;amp;gt;from PySide import QtCore, QtGui<br />
from PySide_loadUiType import loadUiType<br />
form_class,base_class = loadUiType('C:/temp/sgToolCreator02.ui')<br />
class AssetTaskCreator(form_class, base_class):<br />
    def __init__(self, parent=None):<br />
        super(AssetTaskCreator, self).__init__(parent)<br />
        self.setupUi(self)<br />
        #i have a button in the ui, i can now assign it a function that exist out side the ui:<br />
        # in the qt designer, i have called my button: createButton<br />
        # so if i want to assign something, i do it like this:<br />
        self.createButton.clicked.connect(self.onCreateButton)<br />

Then the rest of the ui goes below this point.
So if i make any changes to the layout of the ui, as long as i dont change the names of the ui elements that i have already assigned functions.
everything will work fine.

2 Comments more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!