Skip to content

Instantly share code, notes, and snippets.

@petfactory
Created April 18, 2013 09:37
Show Gist options
  • Save petfactory/5411478 to your computer and use it in GitHub Desktop.
Save petfactory/5411478 to your computer and use it in GitHub Desktop.
PySide Maya experimentation. Testing to load a transparent png.
from maya import cmds
from maya import OpenMayaUI
from PySide import QtCore
from PySide import QtGui
from shiboken import wrapInstance
import os
# testing to load a transparent 24 png from the script dir
usrScriptDir = cmds.internalVar(userScriptDir=True)
img_path = os.path.join(usrScriptDir, "lighthouse_24_alpha.png")
def getMayaWin():
main_win = OpenMayaUI.MQtUtil.mainWindow()
return wrapInstance(long(main_win), QtGui.QWidget)
class testWindow(QtGui.QMainWindow):
def __init__(self, parent = getMayaWin()):
QtGui.QMainWindow.__init__(self, parent)
self.centralwidget = QtGui.QWidget(parent)
self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
self.pixmap = QtGui.QPixmap(img_path)
self.pixLabel = QtGui.QLabel(self)
self.pixLabel.setPixmap(self.pixmap)
self.verticalLayout.addWidget(self.pixLabel)
self.buttonA = QtGui.QPushButton()
self.buttonA.setText('A')
self.verticalLayout.addWidget(self.buttonA)
self.buttonA.clicked.connect(self.clickedA)
self.buttonB = QtGui.QPushButton()
self.buttonB.setText('B')
self.verticalLayout.addWidget(self.buttonB)
self.buttonB.clicked.connect(self.clickedB)
self.buttonC = QtGui.QPushButton()
self.buttonC.setText('C')
self.verticalLayout.addWidget(self.buttonC)
self.buttonC.clicked.connect(self.clickedC)
self.label = QtGui.QLabel()
self.label.setText('Test Label')
self.verticalLayout.addWidget(self.label)
self.setCentralWidget(self.centralwidget)
self.setWindowTitle('Hello World')
self.resize(200, 80)
self.show()
def clickedA(self):
print "A"
def clickedB(self):
print "B"
def clickedC(self):
print "C"
myWin = testWindow()
'''
Testing out various stuff
myWin.hide()
myWin.show()
def toggleVis():
if myWin.isHidden(): myWin.show()
else: myWin.hide()
toggleVis()
for x in dir(myWin):
print(x)
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment