1. # support any maya version >= 2014 since pyside is built-in from 2014
  2. try:
  3. from PySide2.QtCore import *
  4. from PySide2.QtGui import *
  5. from PySide2.QtWidgets import *
  6. from PySide2 import __version__
  7. from shiboken2 import wrapInstance
  8. except ImportError:
  9. from PySide.QtCore import *
  10. from PySide.QtGui import *
  11. from PySide import __version__
  12. from shiboken import wrapInstance
  13. try:
  14. from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
  15. except ImportError:
  16. from ldmaya.mayaMixin2015 import MayaQWidgetDockableMixin # if it's 2014
  17. from maya import OpenMayaUI as omui
  18. from ldmaya import ldmaya as ld
  19. from ldmaya import ldpyside2 as ldps2
  20. import maya.cmds as cmds
  21. import maya.mel as mel
  22. def maya_main_window():
  23. maya_window_ptr = omui.MQtUtil.mainWindow()
  24. return wrapInstance(long(maya_window_ptr), QWidget)
  25. class LDMayaToolbox_ui(MayaQWidgetDockableMixin,QDialog):
  26. def __init__(self, parent=maya_main_window()):
  27. super(LDMayaToolbox_ui,self).__init__(parent)
  28. self.setWindowTitle("LD Maya Toolbox")
  29. self.setObjectName("LDMayaToolbox")
  30. self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
  31. self.setWindowFlags(Qt.Window)
  32. self.setAttribute(Qt.WA_DeleteOnClose)
  33. self.create_layout()
  34. self.create_connections()
  35. def create_layout(self):
  36. self.uv_btn = QPushButton('UV')
  37. self.shader_btn = QPushButton('Shader')
  38. self.outliner_btn = QPushButton('Outliner')
  39. self.uv_btn.setFont(font_standard)
  40. main_layout = QHBoxLayout()
  41. main_layout.setContentsMargins(3,3,3,3)
  42. main_layout.setSpacing(6)
  43. main_layout.addWidget(self.uv_btn)
  44. main_layout.addWidget(self.shader_btn)
  45. main_layout.addWidget(self.outliner_btn)
  46. main_layout.addStretch()
  47. self.setLayout(main_layout)
  48. def create_connections(self):
  49. self.uv_btn.clicked.connect(LDMayaToolbox_ui.show_TextureViewWindow)
  50. self.shader_btn.clicked.connect(LDMayaToolbox_ui.show_HypershadeWindow)
  51. self.outliner_btn.clicked.connect(LDMayaToolbox_ui.show_OutlinerWindow)
  52. @classmethod
  53. def show_TextureViewWindow(cls):
  54. ld.toggle("hyperShade")
  55. @classmethod
  56. def show_HypershadeWindow(cls):
  57. mel.eval("HypershadeWindow")
  58. @classmethod
  59. def show_OutlinerWindow(cls):
  60. mel.eval("OutlinerWindow")
  61. if __name__ == "__main__":
  62. try:
  63. ui.close()
  64. except:
  65. pass
  66. #workspaceControl compatibility
  67. try:
  68. if cmds.workspaceControl('LDMayaToolboxWorkspaceControl',q=1,ex=1):
  69. cmds.deleteUI('LDMayaToolboxWorkspaceControl')
  70. except:
  71. pass
  72. ui = LDMayaToolbox_ui()
  73. ui.show(dockable=1, floating=False, area='left', setAllowedAreas='left',width=200,height=20)
  74. ui.uv_btn.setFont(font_standard)
  75. #workspaceControl compatibility
  76. try:
  77. cmds.workspaceControl('LDMayaToolboxWorkspaceControl', e=True, dtc=["Outliner","right"], wp="preferred", mw=1, w=200)
  78. except:
  79. pass
  80. ui.raise_()
文档更新时间: 2018-06-19 01:24   作者:刘电