-1

I use Maya 2016 + PyQt4.8

I create a simple window. It's worked. But i want dialog to be dockable.

import sip
import maya.OpenMayaUI as mui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import uic
import maya.cmds as cmds

#----------------------------------------------------------------------
def getMayaWindow():
    ptr = mui.MQtUtil.mainWindow()
    return sip.wrapinstance(long(ptr), QObject)

#----------------------------------------------------------------------
class SetTreeOnSplines(QDialog):
    def __init__(self, parent=getMayaWindow()):
        super(SetTreeOnSplines, self).__init__(parent)
        uic.loadUi('X:/tools/Maya/windows/2016/python/setTree.ui', self)

#----------------------------------------------------------------------
# window
def setTree():
    formCollect = SetTreeOnSplines()
    formCollect.show()

#----------------------------------------------------------------------
# MAIN
setTree()

How to modify script using PyQt to the dialog was dockable?

Massimo
  • 836
  • 3
  • 17
  • 38

1 Answers1

2
import sip
import maya.OpenMayaUI as mui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import uic
import maya.cmds as cmds

windowTitle  = "Set_Tree_On_Splines"
windowObject = "SetTreeOnSplinesWinObject"

#----------------------------------------------------------------------
def getMayaWindow():
    ptr = mui.MQtUtil.mainWindow()
    return sip.wrapinstance(long(ptr), QObject)

#----------------------------------------------------------------------
class SetTreeOnSplines(QDialog):
    def __init__(self, parent=getMayaWindow()):
        super(SetTreeOnSplines, self).__init__(parent)
        uic.loadUi('X:/tools/Maya/windows/2016/python/setTree.ui', self)
        self.setWindowTitle(windowTitle)
        self.setObjectName(windowObject)

#----------------------------------------------------------------------
# window
def setTree():
    if cmds.window(windowObject, q=True, exists=True):
        print "Deleting ", windowObject
        cmds.deleteUI(windowObject)
    if cmds.dockControl( 'MayaWindow|'+windowTitle, q=True, ex=True):
        print "Deleting ", 'MayaWindow|'+windowTitle
        cmds.deleteUI( 'MayaWindow|'+windowTitle )
    formCollect = SetTreeOnSplines()
    cmds.dockControl( windowTitle, label=windowTitle.replace("_"," "), area='right', content=windowObject, allowedArea=['right', 'left'] )
    #formCollect.show()

#----------------------------------------------------------------------
# MAIN
setTree()

I added two variables (windowTitle and windowObject), they are used to set the window title and the window object name once the UI is loaded. I also added a check to see if the window and the dockable area already exist in order to delete them.

DrHaze
  • 1,318
  • 10
  • 22