Created
April 17, 2013 12:33
-
-
Save petfactory/5403877 to your computer and use it in GitHub Desktop.
Testing out PySide in Maya 2014. Creating a simple Tab layout with some buttons. Not sure if this is the "proper" way to do it. Copied some stuff from a Nuke PySide test I did a while back. Seems to work though. Feedback are of course welcome.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PySide import QtCore, QtGui | |
from shiboken import wrapInstance | |
import maya.OpenMayaUI as apiUI | |
import sys | |
def getMayaWindow(): | |
""" | |
Get the main Maya window as a QtGui.QMainWindow instance | |
@return: QtGui.QMainWindow instance of the top level Maya windows | |
""" | |
ptr = apiUI.MQtUtil.mainWindow() | |
if ptr is not None: | |
return wrapInstance(long(ptr), QtGui.QMainWindow) | |
class HelloWorld(QtGui.QDialog): | |
def __init__(self, parent=getMayaWindow()): | |
super(HelloWorld, self).__init__(parent) | |
self.initUI() | |
def initUI(self): | |
# layout | |
self.setLayout(QtGui.QVBoxLayout()) | |
# add tabs | |
self.tab_widget = QtGui.QTabWidget() | |
self.layout().addWidget(self.tab_widget) | |
self.tab_widget.addTab(MyButtons(), "One") | |
self.tab_widget.addTab(MyButtons(), "Two") | |
self.tab_widget.addTab(MyButtons(), "Three") | |
self.show() | |
class MyButtons(QtGui.QWidget): | |
def __init__(self, parent=None): | |
super(MyButtons, self).__init__(parent) | |
# layout | |
self.setLayout(QtGui.QVBoxLayout()) | |
# buttons | |
for name in ['One', 'Two', 'Three']: | |
btn =QtGui.QPushButton(name) | |
self.layout().addWidget(btn) | |
btn.clicked.connect(self.buttonClicked) | |
def buttonClicked(self): | |
sender = self.sender() | |
sys.stdout.write(sender.text() + ' was pressed\n') | |
ex = HelloWorld() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment