Maya-PyQt 一些必须的代码

import maya.OpenMayaUI as mui
import sip
def GetMayaLayout(layoutString):
'''
Will return the correct QT object for a given UI string.
:param layoutString: `str`
:returns: `QWidget`
>>> GetMayaLayout('MayaWindow|MainAttributeEditorLayout')
'''
ptr = mui.MQtUtil.findLayout(layoutString)
if ptr:
return sip.wrapinstance(long(ptr), QtCore.QObject)

def GetWindow(windowName):
'''
Will get a child floating QWidget of the Maya Main Window
:param windowName: `str` eg "AssetBrowserForm"
:returns: `QWidget`
'''
ptr = mui.MQtUtil.findWindow(windowName)
if ptr:
return sip.wrapinstance(long(ptr), QtCore.QObject)

def GetFullName(QObject):
'''
Get the fullName of a QObject
'''
pointer = sip.unwrapinstance(QObject)
if type(pointer) == long:
windowString = mui.MQtUtil.fullName(pointer)
if windowString:
return windowString
else:
return ""
else:
# Fix for bug in 32bit Maya.... build the long name as we search for the QObject
return GetQtWidget(QObject.objectName(), LongName = True)[-1]


def GetMayaMainWindow():
'''
:returns: `QtWidget` that pertains to the Maya Main Window
'''
ptr = mui.MQtUtil.mainWindow()
if ptr:
return sip.wrapinstance(long(ptr), QtCore.QObject)

def GetQtWidget(QWidgetName, LongName=False):
'''
:param QWidgetName: `str`
:returns: `QtWidget` that pertains to the maya interface
'''
RootName = str(GetMayaMainWindow().objectName())
Name = QWidgetName.split("|")[-1]
for w in QtGui.qApp.topLevelWidgets():
try:
if w.objectName() == Name:
if LongName:
return (w, "|" + "|".join([RootName, QWidgetName]))
else:
return w
except:
pass
try:
for w in QtGui.qApp.topLevelWidgets():
for c in w.children():
if c.objectName() == Name:
if LongName:
return (c, "|" + "|".join([str(w.objectName()),
str(c.objectName())]))
else:
return c
except:
pass
def UIExists(Name, AsBool=True):
'''
Simple wrapper that will search both long and short names of UI's. Good if the window
has become docked.
:param Name: Name of the UI we're looking for. Can be the shortName or fullaName.
:Returns: `QObject` or a `bool` based on AsBool parameter.
'''
QObject = GetQtWidget(Name)
if QObject:
if AsBool:
return bool(QObject)
return QObject
else:
if AsBool:
return False
return None


def Raise(Name):
'''
Based on the long or shortName this will find the QObject and call QObject.raise_()
'''
QObject = GetQtWidget(Name)
if QObject:
QObject.setHidden(False)
QObject.raise_()
return True
else:
return False



转载于:https://www.cnblogs.com/looksoon/archive/2012/03/04/2379364.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值