Last active
July 16, 2022 15:06
-
-
Save leixingyu/8fb523cfd38b47c9cb1476b5c41eafd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from shiboken2 import wrapInstance | |
from builtins import int | |
import maya.cmds as cmds | |
from maya.app.general.mayaMixin import MayaQWidgetDockableMixin | |
WORKSPACE_CTRL_NAME = 'CustomWidgetWorkspaceControl' | |
WIDGET_OBJECT_NAME = 'CustomWidget' | |
class DockableUI(MayaQWidgetDockableMixin, QtWidgets.QMainWindow): | |
def __init__(self, parent=None): | |
super(DockableUI, self).__init__(parent) | |
_loadUi(UI_PATH, self) | |
def deleteInstances(): | |
for ctrlName in [WIDGET_OBJECT_NAME, WORKSPACE_CTRL_NAME]: | |
ctrl = OpenMayaUI.MQtUtil.findControl(ctrlName) | |
if ctrl: | |
widget = wrapInstance(int(ctrl), QtWidgets.QWidget) | |
widget.close() | |
try: | |
cmds.deleteUI(WORKSPACE_CTRL_NAME) | |
except: | |
pass | |
def show(): | |
deleteInstances() | |
global _DOCKWIDGET | |
_DOCKWIDGET = DockableUI() | |
_DOCKWIDGET.setObjectName(WIDGET_OBJECT_NAME) | |
_DOCKWIDGET.show(dockable=True, dup=False) | |
# this auto docks the widget | |
cmds.workspaceControl(WORKSPACE_CTRL_NAME, e=True, dockToMainWindow=["right", 1], wp="preferred", retain=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment