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.setWindowTitle("Liudian")
  23. self.setObjectName("Liudian")
  24. self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
  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.workspaceControl("LiudianWorkspaceControl",q=1,ex=1):
  60. cmds.deleteUI("LiudianWorkspaceControl")
  61. ui = XgitsMayaToolbox()
  62. ui.show(dockable=1, floating=False, area='left', setAllowedAreas='left',width=200,height=300)
  63. cmds.workspaceControl(ui.objectName()+'WorkspaceControl', e=True, ttc=["Spliter", -1], wp="preferred", mw=420)
  64. ui.raise_()
文档更新时间: 2018-06-18 06:29   作者:刘电