Hi,
I am using the dockableWorkspaceWidget.py from maya’s devkit as a base for dockable window I am creating. I am having an issue though that if I leave the window open and close maya, then re launch maya, the window is still open (I would rather not have it automatically open), and the window is completely blank (widgets are all missing). Trying to relaunch the window will just cause errors.
Does anyone know how to make sure this UI is deleted upon closing maya, and so it does not re open when maya is re launched.
for reference
# Copyright 2017 Autodesk, Inc. All rights reserved.
#
# Use of this software is subject to the terms of the Autodesk license
# agreement provided at the time of installation or download, or which
# otherwise accompanies this software in either electronic or hard copy form.
import maya.cmds as cmds
from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
from maya import OpenMayaUI as omui
from PySide2 import QtWidgets, QtCore, QtGui
if not 'customMixinWindow' in globals():
customMixinWindow = None
''' MayaQWidgetDockableMixin is not a workspace control in itself, it is added
as a child to a created workspace control. See help(MayaQWidgetDockableMixin)
for more details. The following class is a simple widget with a layout and a push button.
'''
class DockableWidget(MayaQWidgetDockableMixin, QtWidgets.QDialog):
def __init__(self, parent=None):
super(DockableWidget, self).__init__(parent=parent)
self.button1 = QtWidgets.QPushButton()
self.button1.setText('PushMe')
self.setSizeGripEnabled(False)
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.button1)
self.setLayout(layout)
self.setWindowTitle('Custom Maya Mixin Workspace Control')
''' A workspace control is created by calling show() on the DockableWidget class.
This control is only created once if the retain property is set to true, which
is the default. The uiScript argument passed to the show() method will be
invoked every time this control is opened/restored. It is recommended to add
the proper import statement in the uiScript argument.
For example, in renderSetup.py file the UIScript for renderSetupWindow is
"uiScript='import maya.app.renderSetup.views.renderSetup as renderSetup\nrenderSetup.createUI(restore=True)'"
The following method needs to be invoked in order to create the workspace control for the example above.
If the control is being restored, then Maya will call the method by passing restore=True
'''
def DockableWidgetUIScript(restore=False):
print restore
global customMixinWindow
''' When the control is restoring, the workspace control has already been created and
all that needs to be done is restoring its UI.
'''
if restore == True:
# Grab the created workspace control with the following.
restoredControl = omui.MQtUtil.getCurrentParent()
print restoredControl
if not customMixinWindow:
# Create a custom mixin widget for the first time
customMixinWindow = DockableWidget()
customMixinWindow.setObjectName('customMayaMixinWindow')
if restore == True:
# Add custom mixin widget to the workspace control
mixinPtr = omui.MQtUtil.findControl(customMixinWindow.objectName())
omui.MQtUtil.addWidgetToMayaLayout(long(mixinPtr), long(restoredControl))
else:
# Create a workspace control for the mixin widget by passing all the needed parameters. See workspaceControl command documentation for all available flags.
customMixinWindow.show(dockable=True, area='right', floating=False, height=900, width=400, uiScript='DockableWidgetUIScript(restore=True)')
cmds.workspaceControl('customMayaMixinWindowWorkspaceControl', e=True, ttc=["AttributeEditor", -1], wp="preferred", mw=200)
return customMixinWindow
''' Using the workspaceControl Maya command to query/edit flags about the created
workspace control can be achieved this way:
maya.cmds.workspaceControl('customMayaMixinWindowWorkspaceControl', q=True, visible=True)
maya.cmds.workspaceControl('customMayaMixinWindowWorkspaceControl', e=True, visible=False)
Note that Maya automatically appends the "WorkspaceControl" string to the
workspace control child object name. In this example it is the child widget name (customMayaMixinWindow)
'''
def start_test_ui():
ui = DockableWidgetUIScript()
return ui