Guest User

Untitled

a guest
Jan 16th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. """Basic QT window exercise"""
  2. import maya.cmds as cmds
  3. import maya.OpenMayaUI as omUi
  4. from PyQt4 import QtCore, QtGui
  5. import sip
  6.  
  7.  
  8. def get_maya_window():
  9. """
  10. Get the maya main window as a QMainWindow instance
  11. """
  12. ptr = omUi.MQtUtil.mainWindow()
  13. return sip.wrapinstance(long(ptr), QtCore.QObject)
  14.  
  15.  
  16. def main():
  17. """
  18. Show the dialog
  19. """
  20. dialog = BasicDialog()
  21. dialog.show()
  22.  
  23.  
  24. class BasicDialog(QtGui.QDialog):
  25. """ Main Dialog
  26. A basic demo of a Maya PyQt Window.
  27. """
  28. def __init__(self, parent=get_maya_window()):
  29. """
  30. Initialize the window.
  31. """
  32. super(BasicDialog, self).__init__(parent)
  33.  
  34. self.setWindowTitle('Maya PyQt Basic Dialog Demo')
  35.  
  36. self.shape_type_cb = QtGui.QComboBox(parent=self)
  37. self.shape_type_cb.addItems(['Sphere', 'Cube', 'Cylinder'])
  38.  
  39. self.name_le = QtGui.QLineEdit('newShape', parent=self)
  40. self.make_button = QtGui.QPushButton("Make Shape", parent=self)
  41. self.desc_label = QtGui.QLabel("This is a description", parent=self)
  42.  
  43. # Add connections so that things happen when the user makes changes to
  44. # the different widgets
  45. self.connect(self.shape_type_cb,
  46. QtCore.SIGNAL("currentIndexChanged(int)"),
  47. self.update_description)
  48.  
  49. # Set up a signal to call the updateDescription method whenever the text
  50. # in the nameLE is changed.
  51. self.connect(self.name_le, QtCore.SIGNAL("textChanged(const QString&)"),
  52. self.update_description)
  53.  
  54. # Set up a signal to call the makeShape method whenever the makeButton
  55. # is clicked.
  56. self.connect(self.make_button, QtCore.SIGNAL("clicked()"),
  57. self.make_shape)
  58.  
  59. self.layout = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom, self)
  60. self.layout.addLayout(action_layout)
  61. self.layout.addWidget(self.desc_label)
  62.  
  63. self.update_description()
  64.  
  65. def update_description(self):
  66. """
  67. Update the descriptive label. This method gets called when either the
  68. shapeTypeCB or nameLE get modified by the user.
  69. """
  70. description = 'Make a %s named "%s"' % \
  71. (self.shape_type_cb.currentText(), self.name_le.text())
  72. self.desc_label.setText(description)
  73.  
  74. def make_shape(self):
  75. """
  76. Make the shape. This gets called when the user clicks on the
  77. "Make Shape" makeButton.
  78. """
  79. # Get the current text from shapeTypeCB
  80. obj_type = self.shape_type_cb.currentText()
  81.  
  82. # Figure out which poly command to use
  83. if obj_type == 'Sphere':
  84. cmd = cmds.polySphere
  85. elif obj_type == 'Cube':
  86. cmd = cmds.polyCube
  87. else:
  88. cmd = cmds.polyCylinder
  89.  
  90. cmd(name=str(self.name_le.text()))
Add Comment
Please, Sign In to add comment