Last active
December 5, 2022 17:07
-
-
Save sporty/56be027134acf30ccd9c0397b3216600 to your computer and use it in GitHub Desktop.
workspace control sample
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
#!/usr/bin/env python | |
# coding=utf-8 | |
from __future__ import absolute_import, division, print_function | |
from maya.app.general.mayaMixin import MayaQWidgetBaseMixin, MayaQWidgetDockableMixin | |
import maya.OpenMayaUI as omui | |
from PySide2 import QtWidgets | |
class MyTool(QtWidgets.QWidget): | |
TITLE = u"MyTool" | |
def __init__(self, parent=None): | |
super(MyTool, self).__init__(parent) | |
self.setObjectName(self.TITLE) | |
self.setWindowTitle(self.TITLE) | |
QtWidgets.QPushButton(u"Hello World", self) | |
class DialogWidget(MayaQWidgetBaseMixin, MyTool): | |
pass | |
class DockableWidget(MayaQWidgetDockableMixin, MyTool): | |
pass | |
custom_mixin_widget = None | |
def ui_script(restore=False): | |
global custom_mixin_widget | |
if not custom_mixin_widget: | |
custom_mixin_widget = DockableWidget() | |
if restore: | |
restored_control = omui.MQtUtil.getCurrentParent() | |
mixin_ptr = omui.MQtUtil.findControl(custom_mixin_widget.objectName()) | |
omui.MQtUtil.addWidgetToMayaLayout(long(mixin_ptr), long(restored_control)) | |
else: | |
workspace_control_name = custom_mixin_widget.objectName() + u"WorkspaceControl" | |
if cmds.workspaceControl(workspace_control_name, exists=True): | |
pm.deleteUI(workspace_control_name) | |
_ui_script = u"import {0}; {0}.ui_script(restore=True)".format(__name__) | |
custom_mixin_widget.show(dockable=True, uiScript=_ui_script) | |
return custom_mixin_widget | |
def main(): | |
win = DialogWidget() | |
win.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment