from PySide2 import QtWidgets, QtCore, QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as omui
from shiboken2 import wrapInstance
class CustomDockableUI(object):
objName = 'customDockableWindow'
windowTitle = 'Custom Tool'
def __init__(self):
self.window = None
self.deleteIfExists()
self.createUI()
def deleteIfExists(self):
if cmds.workspaceControl(self.objName, q=True, exists=True):
cmds.deleteUI(self.objName, control=True)
def createUI(self):
mainWindowPtr = omui.MQtUtil.mainWindow()
mainWindow = wrapInstance(long(mainWindowPtr), QtWidgets.QWidget)
self.window = QtWidgets.QDockWidget(self.windowTitle, parent=mainWindow)
self.window.setObjectName(self.objName)
self.window.setAllowedAreas(QtCore.Qt.AllDockWidgetAreas)
widget = QtWidgets.QWidget()
self.window.setWidget(widget)
layout = QtWidgets.QVBoxLayout(widget)
# Header Image Placeholder
header = QtWidgets.QLabel()
pixmap = QtGui.QPixmap(160, 90) # Placeholder size for 16:9 image
pixmap.fill(QtGui.QColor('grey'))
header.setPixmap(pixmap)
layout.addWidget(header)
# Buttons
buttonLayout = QtWidgets.QHBoxLayout()
tagObjectBtn = QtWidgets.QPushButton("Tag Object")
tagAllBtn = QtWidgets.QPushButton("Tag All")
buttonLayout.addWidget(tagObjectBtn)
buttonLayout.addWidget(tagAllBtn)
layout.addLayout(buttonLayout)
itagButtonLayout = QtWidgets.QHBoxLayout()
itagObjectBtn = QtWidgets.QPushButton("I Tag Object")
untagAllBtn = QtWidgets.QPushButton("Untag All")
itagButtonLayout.addWidget(itagObjectBtn)
itagButtonLayout.addWidget(untagAllBtn)
layout.addLayout(itagButtonLayout)
createStructureBtn = QtWidgets.QPushButton("Create Structure")
layout.addWidget(createStructureBtn)
# Selection Status Box
self.selectionStatus = QtWidgets.QLabel()
self.selectionStatus.setAlignment(QtCore.Qt.AlignCenter)
self.updateSelectionStatus()
layout.addWidget(self.selectionStatus)
cmds.workspaceControl(self.objName, e=True, wp="preferred", mw=400, mh=300)
cmds.workspaceControl(self.objName, e=True, dockToMainWindow=('right', False))
# Connect signals
cmds.scriptJob(event=["SelectionChanged", self.updateSelectionStatus], parent=self.objName)
def updateSelectionStatus(self):
selected = cmds.ls(selection=True)
if selected:
self.selectionStatus.setText(selected[0])
self.selectionStatus.setStyleSheet("background-color: dull green;")
else:
self.selectionStatus.setText("No object selected")
self.selectionStatus.setStyleSheet("background-color: dull red;")
def show(self):
self.window.show()
def main():
global customUI
customUI = CustomDockableUI()
customUI.show()
if __name__ == "__main__":
main()