Hi, I’m writing a thing in maya and have run in to trouble. Really don’t know what I did, I was going to adress something else when this happened, the last thing I did was add a button to the layout.
I have been messing around with this for a long time now and as far as I can tell, the uiScript flag doesn’t like arguments passed in the method call…? what happens is, it never sets the restore flag to True so that bit never hits. resulting in it spawning multiple windows in maya. I’m also trying to figure out where the cmds.deleteUI try clause should go, not entrirely sure where I had it before this happened. If anyone could offer any insight I would be most grateful, cheers /S
in the script below, I have replaced an instance of my ui with just a button, it makes no difference on the behaviour.
from PySide2 import QtWidgets, QtCore from maya.app.general.mayaMixin import MayaQWidgetDockableMixin import maya.OpenMayaUI as mui import maya.cmds as cmds import weakref if not 'customMixinWindow' in globals(): customMixinWindow = None class DockableWidget(MayaQWidgetDockableMixin, QtWidgets.QWidget): instances = list() CONTROL_NAME = 'customMixinWindow' def __init__(self, parent=None): super(DockableWidget, self).__init__(parent=parent) DockableWidget.delete_instances() self.__class__.instances.append(weakref.proxy(self)) self.main_layout = QtWidgets.QVBoxLayout() self.button = QtWidgets.QPushButton() self.main_layout.addWidget(self.button) self.setLayout(self.main_layout) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) @staticmethod def delete_instances(): print "deleting" for ins in DockableWidget.instances: try: ins.setParent(None) ins.deleteLater() except: pass DockableWidget.instances.remove(ins) del ins def DockableWidgetUIScript(restore=False): global customMixinWindow if restore == True: restoredControl = mui.MQtUtil.getCurrentParent() customMixinWindow = DockableWidget() if customMixinWindow is None: #customMixinWindow = DockableWidget() customMixinWindow.setObjectName('customMayaMixinWindow') if restore == True: mixinPtr = mui.MQtUtil.findControl(customMixinWindow.objectName()) mui.MQtUtil.addWidgetToMayaLayout(long(mixinPtr), long(restoredControl)) else: try: cmds.workspaceControl('customMayaMixinWindowWorkspaceControl', e=True, close=True) cmds.deleteUI('customMayaMixinWindowWorkspaceControl') except: pass customMixinWindow.show(dockable=True, restore=True, height=400, width=400, uiScript='import dockWin; dockWin.DockableWidgetUIScript(restore=True)') def main(): ui = DockableWidgetUIScript() return ui if __name__ == 'dockWin': main()