Hello PySide2

  1. import sys
  2. from PySide2.QtWidgets import QApplication, QLabel
  3. app = QApplication(sys.argv)
  4. #label = QLabel("Hello World!")
  5. label = QLabel("<font color=red size=40>Hello World!</font>")
  6. label.show()
  7. app.exec_()

Hello PySide2 in Maya

  1. try:
  2. from PySide2.QtCore import *
  3. from PySide2.QtGui import *
  4. from PySide2.QtWidgets import *
  5. from PySide2 import __version__
  6. from shiboken2 import wrapInstance
  7. except ImportError:
  8. from PySide.QtCore import *
  9. from PySide.QtGui import *
  10. from PySide import __version__
  11. from shiboken import wrapInstance
  12. from maya import OpenMayaUI as omui
  13. import maya.cmds as cmds
  14. import maya.mel as mel
  15. def maya_main_window():
  16. maya_window_ptr = omui.MQtUtil.mainWindow()
  17. return wrapInstance(long(mayaMainWindowPtr), QWidget)
  18. class XgitsMayaToolbox(MayaQWidgetDockableMixin,QDialog):
  19. def __init__(self, parent=maya_main_window()):
  20. super(XgitsMayaToolbox,self).__init__(parent)
  21. self.setWindowTitle("Liudian")
  22. self.setWindowFlags(Qt.Window)
  23. self.setAttribute(Qt.WA_DeleteOnClose)
  24. self.create_layout()
  25. self.create_connections()
  26. def create_layout(self):
  27. self.uv_btn = QPushButton('UV')
  28. self.shader_btn = QPushButton('Shader')
  29. self.outliner_btn = QPushButton('Outliner')
  30. main_layout = QVBoxLayout()
  31. main_layout.addWidget(self.uv_btn)
  32. main_layout.addWidget(self.shader_btn)
  33. main_layout.addWidget(self.outliner_btn)
  34. main_layout.setSpacing(6)
  35. main_layout.setContentsMargins(3,3,3,3)
  36. main_layout.addStretch()
  37. self.setLayout(main_layout)
  38. def create_connections(self):
  39. self.uv_btn.clicked.connect(XgitsMayaToolbox.show_TextureViewWindow)
  40. self.shader_btn.clicked.connect(XgitsMayaToolbox.show_HypershadeWindow)
  41. self.outliner_btn.clicked.connect(XgitsMayaToolbox.show_OutlinerWindow)
  42. @classmethod
  43. def show_TextureViewWindow(cls):
  44. mel.eval("TextureViewWindow")
  45. @classmethod
  46. def show_HypershadeWindow(cls):
  47. mel.eval("HypershadeWindow")
  48. @classmethod
  49. def show_OutlinerWindow(cls):
  50. mel.eval("OutlinerWindow")
  51. if __name__ == "__main__":
  52. try:
  53. ui.close()
  54. except:
  55. pass
  56. ui = XgitsMayaToolbox()
  57. ui.show(dockable=1)

pyside dock

  1. try:
  2. from PySide2.QtCore import *
  3. from PySide2.QtGui import *
  4. from PySide2.QtWidgets import *
  5. from PySide2 import __version__
  6. from shiboken2 import wrapInstance
  7. except ImportError:
  8. from PySide.QtCore import *
  9. from PySide.QtGui import *
  10. from PySide import __version__
  11. from shiboken import wrapInstance
  12. from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
  13. from maya import OpenMayaUI as omui
  14. import maya.cmds as cmds
  15. import maya.mel as mel
  16. def maya_main_window():
  17. maya_window_ptr = omui.MQtUtil.mainWindow()
  18. return wrapInstance(long(maya_window_ptr), QWidget)
  19. class XgitsMayaToolbox(MayaQWidgetDockableMixin,QDialog):
  20. def __init__(self, parent=maya_main_window()):
  21. super(XgitsMayaToolbox,self).__init__(parent)
  22. self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
  23. self.setObjectName("LiudianTest")
  24. self.setWindowTitle("Liudian")
  25. self.setWindowFlags(Qt.Window)
  26. self.setAttribute(Qt.WA_DeleteOnClose)
  27. self.create_layout()
  28. self.create_connections()
  29. def create_layout(self):
  30. self.uv_btn = QPushButton('UV')
  31. self.shader_btn = QPushButton('Shader')
  32. self.outliner_btn = QPushButton('Outliner')
  33. main_layout = QVBoxLayout()
  34. main_layout.setContentsMargins(3,3,3,3)
  35. main_layout.setSpacing(6)
  36. main_layout.addWidget(self.uv_btn)
  37. main_layout.addWidget(self.shader_btn)
  38. main_layout.addWidget(self.outliner_btn)
  39. main_layout.addStretch()
  40. self.setLayout(main_layout)
  41. def create_connections(self):
  42. self.uv_btn.clicked.connect(XgitsMayaToolbox.show_TextureViewWindow)
  43. self.shader_btn.clicked.connect(XgitsMayaToolbox.show_HypershadeWindow)
  44. self.outliner_btn.clicked.connect(XgitsMayaToolbox.show_OutlinerWindow)
  45. @classmethod
  46. def show_TextureViewWindow(cls):
  47. mel.eval("TextureViewWindow")
  48. @classmethod
  49. def show_HypershadeWindow(cls):
  50. mel.eval("HypershadeWindow")
  51. @classmethod
  52. def show_OutlinerWindow(cls):
  53. mel.eval("OutlinerWindow")
  54. if __name__ == "__main__":
  55. try:
  56. ui.close()
  57. except:
  58. pass
  59. if cmds.window(uiName, q=True, exists=True):
  60. print "Deleting ", uiName
  61. cmds.deleteUI(uiName)
  62. if cmds.dockControl( uiName, q=True, ex=True):
  63. print "Deleting ", uiName
  64. cmds.deleteUI( uiName )
  65. cmds.deleteUI( uiName+'WorkspaceControl' )
  66. ui = XgitsMayaToolbox()
  67. ui.show(dockable=1)
  68. uiName = ui.objectName()
  69. cmds.dockControl(uiName,w=500,h=600,
  70. fixedHeight=1,
  71. fixedWidth=1,
  72. moveable=1,
  73. area="left",
  74. content=uiName,
  75. label="Liudian")
文档更新时间: 2018-06-18 06:29   作者:刘电