Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """Basic QT window exercise"""
- import maya.cmds as cmds
- import maya.OpenMayaUI as omUi
- from PyQt4 import QtCore, QtGui
- import sip
- def get_maya_window():
- """
- Get the maya main window as a QMainWindow instance
- """
- ptr = omUi.MQtUtil.mainWindow()
- return sip.wrapinstance(long(ptr), QtCore.QObject)
- def main():
- """
- Show the dialog
- """
- dialog = BasicDialog()
- dialog.show()
- class BasicDialog(QtGui.QDialog):
- """ Main Dialog
- A basic demo of a Maya PyQt Window.
- """
- def __init__(self, parent=get_maya_window()):
- """
- Initialize the window.
- """
- super(BasicDialog, self).__init__(parent)
- self.setWindowTitle('Maya PyQt Basic Dialog Demo')
- self.shape_type_cb = QtGui.QComboBox(parent=self)
- self.shape_type_cb.addItems(['Sphere', 'Cube', 'Cylinder'])
- self.name_le = QtGui.QLineEdit('newShape', parent=self)
- self.make_button = QtGui.QPushButton("Make Shape", parent=self)
- self.desc_label = QtGui.QLabel("This is a description", parent=self)
- # Add connections so that things happen when the user makes changes to
- # the different widgets
- self.connect(self.shape_type_cb,
- QtCore.SIGNAL("currentIndexChanged(int)"),
- self.update_description)
- # Set up a signal to call the updateDescription method whenever the text
- # in the nameLE is changed.
- self.connect(self.name_le, QtCore.SIGNAL("textChanged(const QString&)"),
- self.update_description)
- # Set up a signal to call the makeShape method whenever the makeButton
- # is clicked.
- self.connect(self.make_button, QtCore.SIGNAL("clicked()"),
- self.make_shape)
- self.layout = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom, self)
- self.layout.addLayout(action_layout)
- self.layout.addWidget(self.desc_label)
- self.update_description()
- def update_description(self):
- """
- Update the descriptive label. This method gets called when either the
- shapeTypeCB or nameLE get modified by the user.
- """
- description = 'Make a %s named "%s"' % \
- (self.shape_type_cb.currentText(), self.name_le.text())
- self.desc_label.setText(description)
- def make_shape(self):
- """
- Make the shape. This gets called when the user clicks on the
- "Make Shape" makeButton.
- """
- # Get the current text from shapeTypeCB
- obj_type = self.shape_type_cb.currentText()
- # Figure out which poly command to use
- if obj_type == 'Sphere':
- cmd = cmds.polySphere
- elif obj_type == 'Cube':
- cmd = cmds.polyCube
- else:
- cmd = cmds.polyCylinder
- cmd(name=str(self.name_le.text()))
Add Comment
Please, Sign In to add comment