Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在“曲线图编辑器”(Graph Editor)窗口中设置新的、用户创建的按钮的父级?_Python_Window_Maya_Mel - Fatal编程技术网

Python 如何在“曲线图编辑器”(Graph Editor)窗口中设置新的、用户创建的按钮的父级?

Python 如何在“曲线图编辑器”(Graph Editor)窗口中设置新的、用户创建的按钮的父级?,python,window,maya,mel,Python,Window,Maya,Mel,我想向Maya Graph editor添加一些新按钮——特别是在通道列表顶部,所有属性都在窗口左侧。但是,我不想在Graph Editor本身的Maya启动脚本上乱搞。是否有一种方法可以使用单独的脚本在每个新的Graph Editor窗口中“创建”我想要的新按钮 理想情况下,这可以是所有Python。为此,您可能必须使用PySide/PyQt。找到图形编辑器的指针并找到元素的布局方式 以下是有关更改maya菜单样式表的示例: from maya.OpenMayaUI import MQtUti

我想向Maya Graph editor添加一些新按钮——特别是在通道列表顶部,所有属性都在窗口左侧。但是,我不想在Graph Editor本身的Maya启动脚本上乱搞。是否有一种方法可以使用单独的脚本在每个新的Graph Editor窗口中“创建”我想要的新按钮


理想情况下,这可以是所有Python。

为此,您可能必须使用PySide/PyQt。找到图形编辑器的指针并找到元素的布局方式

以下是有关更改maya菜单样式表的示例:

from maya.OpenMayaUI import MQtUtil as omui
import sip
from PyQt4 import QtGui

def changeMayaMenuColors(fontStyle='italic', fontWeight='bold', fontColor='cyan'):
    # Get the widget
    widgetStr = mel.eval( 'string $tempString = $gMainCreateMenu' )
    ptr = omui.findControl( widgetStr )
    widget = sip.wrapinstance(long(ptr), QtGui.QWidget)
    widget.setStyleSheet('font-style:%s;'%fontStyle +'font-weight:%s;'%fontWeight + 'color:%s;'%fontColor)
下面是一些关于channelBox的实验:

from PySide import QtGui, QtCore
from shiboken import wrapInstance
from maya.OpenMayaUI import MQtUtil


channelbox = wrapInstance(long(MQtUtil.findControl('mainChannelBox')), QtGui.QWidget)
channelbox_children = channelbox.children()

first_widget = channelbox_children[0] # EDIT
first_widget.hide()
#first_widget.show()
#---------------------------------------------------------------------------------------------------------------
mySubWdget = first_widget.children()

new_button = QtGui.QPushButton()
new_layout = QtGui.QVBoxLayout()
first_widget.setLayout(new_layout)
new_layout.addWidget(new_button)

def print_hodor():
    print 'HODOR'

new_button.clicked.connect(print_hodor)
您可以使用所有maya小部件进行这一系列实验(找到指针,然后使用wrapInstance获取QT指针,然后遍历子对象以找到您可能需要的布局)


希望它能有所帮助,您可能需要使用PySide/PyQt。找到图形编辑器的指针并找到元素的布局方式

以下是有关更改maya菜单样式表的示例:

from maya.OpenMayaUI import MQtUtil as omui
import sip
from PyQt4 import QtGui

def changeMayaMenuColors(fontStyle='italic', fontWeight='bold', fontColor='cyan'):
    # Get the widget
    widgetStr = mel.eval( 'string $tempString = $gMainCreateMenu' )
    ptr = omui.findControl( widgetStr )
    widget = sip.wrapinstance(long(ptr), QtGui.QWidget)
    widget.setStyleSheet('font-style:%s;'%fontStyle +'font-weight:%s;'%fontWeight + 'color:%s;'%fontColor)
下面是一些关于channelBox的实验:

from PySide import QtGui, QtCore
from shiboken import wrapInstance
from maya.OpenMayaUI import MQtUtil


channelbox = wrapInstance(long(MQtUtil.findControl('mainChannelBox')), QtGui.QWidget)
channelbox_children = channelbox.children()

first_widget = channelbox_children[0] # EDIT
first_widget.hide()
#first_widget.show()
#---------------------------------------------------------------------------------------------------------------
mySubWdget = first_widget.children()

new_button = QtGui.QPushButton()
new_layout = QtGui.QVBoxLayout()
first_widget.setLayout(new_layout)
new_layout.addWidget(new_button)

def print_hodor():
    print 'HODOR'

new_button.clicked.connect(print_hodor)
您可以使用所有maya小部件进行这一系列实验(找到指针,然后使用wrapInstance获取QT指针,然后遍历子对象以找到您可能需要的布局)


希望它能帮助TL;博士

if cmds.window("GE_ui_window", exists=True): #If the window exists
    cmds.deleteUI("GE_ui_window") #Delete it
cmds.window("GE_ui_window", title="My custom Graph Editor") #Create your custom win

cmds.frameLayout("GE_ui_frameLayout", p="GE_ui_window", lv=False, bv=False ) 

if cmds.scriptedPanel("GE_ui_scriptedPanel", exists=True): #If the scriptel panel already exists
    cmds.deleteUI("GE_ui_scriptedPanel") #Delete it
cmds.scriptedPanel("GE_ui_scriptedPanel", unParent=True, type="graphEditor")
cmds.scriptedPanel( "GE_ui_scriptedPanel", e=True, parent="GE_ui_window|GE_ui_frameLayout") #parent the scripted panel to your frame layout

cmds.showWindow("GE_ui_window")

channelLayout = cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", query=True, ca=True)[0] #Get the channel box's layout
filterLayout = cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", query=True, ca=True)[1] #Get the filter's layout

myRowLayout=cmds.rowLayout(numberOfColumns=3, p="GE_ui_scriptedPanelOutlineEdForm") #Create a row layout 
cmds.button(label="Café", h=100, p=myRowLayout) #Add some buttons
cmds.button(label="Clope", p=myRowLayout)
cmds.button(label="Caca", p=myRowLayout)

#This will reorder the content of the left formLayout
cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", edit=True, af=[ \
            (channelLayout, "bottom", 0), \
            (channelLayout, "right", 0),  \
            (filterLayout, "top", 0),  \
            (myRowLayout, "left", 0),  \
            (myRowLayout, "right", 0)],  \
            ac=[(myRowLayout, "top", 0, filterLayout), \
            (channelLayout, "top", 0, myRowLayout)])

在编辑Maya的UI时,有两件事非常有用

首先是脚本编辑器中的
History->Echo all commands
复选框。这样可以打印出大量垃圾,其中包含有用的信息

第二件事是
whatIs
命令()

此命令接受一个字符串类型参数并返回一个字符串 指示参数是否为内置的“命令”,即“Mel” 过程、脚本或变量。如果是变量,则类型为 并给出了该变量的计算公式。如果参数是Mel过程或 脚本文件,包含脚本或过程的文件的路径 包含在返回值中

此组合将允许您跟踪图形编辑器的创建方式和创建位置。现在让我们开始吧

1:打开图形编辑器
窗口->动画编辑器->图形编辑器

GraphEditor;
tearOffPanel "Graph Editor" "graphEditor" true;
// Result: graphEditor1Window // 
channelLayout = cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", query=True, ca=True)[0] #Get the channel box's layout
filterLayout = cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", query=True, ca=True)[1] #Get the filter's layout

myRowLayout=cmds.rowLayout(numberOfColumns=3, p="GE_ui_scriptedPanelOutlineEdForm") #Create a row layout 
cmds.button(label="Café", h=100, p=myRowLayout) #Add some buttons
cmds.button(label="Clope", p=myRowLayout)
cmds.button(label="Caca", p=myRowLayout)

#This will reorder the content of the left formLayout
cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", edit=True, af=[ \
            (channelLayout, "bottom", 0), \
            (channelLayout, "right", 0),  \
            (filterLayout, "top", 0),  \
            (myRowLayout, "left", 0),  \
            (myRowLayout, "right", 0)],  \
            ac=[(myRowLayout, "top", 0, filterLayout), \
            (channelLayout, "top", 0, myRowLayout)])
图形编辑器
是一个运行时命令,它执行
tearofpanel“Graph Editor”“graphEditor”true调用时。这就是它出现在脚本编辑器中的原因

2:运行
whatIs“tearofpanel”(mel)

在这个文件中进行一点调查,就可以推断出可以使用
scriptedPanel
命令创建一个全新的图形编辑器

3:创建自己的图形面板

// Result: Mel procedure found in: C:/Program Files/Autodesk/Maya2014/scripts/startup/tearOffPanel.mel // 
演示如何创建脚本化面板并将其包含在窗口中。 现在,您可以使用以下方法创建自定义图形编辑器:

if cmds.window("GE_ui_window", exists=True):
    cmds.deleteUI("GE_ui_window")
cmds.window("GE_ui_window", title="My custom Graph Editor")

cmds.frameLayout("GE_ui_frameLayout", p="GE_ui_window", lv=False, bv=False )

if cmds.scriptedPanel("GE_ui_scriptedPanel", exists=True):
    cmds.deleteUI("GE_ui_scriptedPanel")
cmds.scriptedPanel("GE_ui_scriptedPanel", unParent=True, type="graphEditor", label='Sample')
cmds.scriptedPanel( "GE_ui_scriptedPanel", e=True, parent="GE_ui_window|GE_ui_frameLayout")

cmds.showWindow("GE_ui_window")
4:尝试了解图形编辑器是如何构建的

此脚本将打印出图形编辑器的小部件层次结构(首先创建自定义图形编辑器):

此外,您还可以签入
C:\Program Files\Autodesk\Maya2014\scripts\others\graphieditorpanel.mel
@939:global proc addgraphieditor(string$whichPanel)

现在,您可以意识到许多小部件没有任何名称,只有Maya提供的默认名称。因此,我们不能添加小部件并使用完整路径作为它们的父级,因为每次创建新的图形编辑器时,该路径都会更改

我们将尝试依赖的项目是
GE\u ui\u scriptedPanelOutlineEdForm
,它是一个
formLayout
,包含另一个
formLayout
paneLayout

|___|___GE_ui_scriptedPanelOutlineEdForm 
|___|___|___paneLayout123 #layout containing the two channel boxes
|___|___|___|___GE_ui_scriptedPanelOutlineEd
|___|___|___|___GE_ui_scriptedPanelOutlineEdSlave
|___|___|___formLayout276 #Layout containing the "filter part"
|___|___|___|___textField63 #It's text
|___|___|___|___iconTextButton102
5:创建按钮并对
GE\u ui\u scriptedPanelOutlineEdForm

GraphEditor;
tearOffPanel "Graph Editor" "graphEditor" true;
// Result: graphEditor1Window // 
channelLayout = cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", query=True, ca=True)[0] #Get the channel box's layout
filterLayout = cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", query=True, ca=True)[1] #Get the filter's layout

myRowLayout=cmds.rowLayout(numberOfColumns=3, p="GE_ui_scriptedPanelOutlineEdForm") #Create a row layout 
cmds.button(label="Café", h=100, p=myRowLayout) #Add some buttons
cmds.button(label="Clope", p=myRowLayout)
cmds.button(label="Caca", p=myRowLayout)

#This will reorder the content of the left formLayout
cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", edit=True, af=[ \
            (channelLayout, "bottom", 0), \
            (channelLayout, "right", 0),  \
            (filterLayout, "top", 0),  \
            (myRowLayout, "left", 0),  \
            (myRowLayout, "right", 0)],  \
            ac=[(myRowLayout, "top", 0, filterLayout), \
            (channelLayout, "top", 0, myRowLayout)])

TL;博士

if cmds.window("GE_ui_window", exists=True): #If the window exists
    cmds.deleteUI("GE_ui_window") #Delete it
cmds.window("GE_ui_window", title="My custom Graph Editor") #Create your custom win

cmds.frameLayout("GE_ui_frameLayout", p="GE_ui_window", lv=False, bv=False ) 

if cmds.scriptedPanel("GE_ui_scriptedPanel", exists=True): #If the scriptel panel already exists
    cmds.deleteUI("GE_ui_scriptedPanel") #Delete it
cmds.scriptedPanel("GE_ui_scriptedPanel", unParent=True, type="graphEditor")
cmds.scriptedPanel( "GE_ui_scriptedPanel", e=True, parent="GE_ui_window|GE_ui_frameLayout") #parent the scripted panel to your frame layout

cmds.showWindow("GE_ui_window")

channelLayout = cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", query=True, ca=True)[0] #Get the channel box's layout
filterLayout = cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", query=True, ca=True)[1] #Get the filter's layout

myRowLayout=cmds.rowLayout(numberOfColumns=3, p="GE_ui_scriptedPanelOutlineEdForm") #Create a row layout 
cmds.button(label="Café", h=100, p=myRowLayout) #Add some buttons
cmds.button(label="Clope", p=myRowLayout)
cmds.button(label="Caca", p=myRowLayout)

#This will reorder the content of the left formLayout
cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", edit=True, af=[ \
            (channelLayout, "bottom", 0), \
            (channelLayout, "right", 0),  \
            (filterLayout, "top", 0),  \
            (myRowLayout, "left", 0),  \
            (myRowLayout, "right", 0)],  \
            ac=[(myRowLayout, "top", 0, filterLayout), \
            (channelLayout, "top", 0, myRowLayout)])

在编辑Maya的UI时,有两件事非常有用

首先是脚本编辑器中的
History->Echo all commands
复选框。这样可以打印出大量垃圾,其中包含有用的信息

第二件事是
whatIs
命令()

此命令接受一个字符串类型参数并返回一个字符串 指示参数是否为内置的“命令”,即“Mel” 过程、脚本或变量。如果是变量,则类型为 并给出了该变量的计算公式。如果参数是Mel过程或 脚本文件,包含脚本或过程的文件的路径 包含在返回值中

此组合将允许您跟踪图形编辑器的创建方式和创建位置。现在让我们开始吧

1:打开图形编辑器
窗口->动画编辑器->图形编辑器

GraphEditor;
tearOffPanel "Graph Editor" "graphEditor" true;
// Result: graphEditor1Window // 
channelLayout = cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", query=True, ca=True)[0] #Get the channel box's layout
filterLayout = cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", query=True, ca=True)[1] #Get the filter's layout

myRowLayout=cmds.rowLayout(numberOfColumns=3, p="GE_ui_scriptedPanelOutlineEdForm") #Create a row layout 
cmds.button(label="Café", h=100, p=myRowLayout) #Add some buttons
cmds.button(label="Clope", p=myRowLayout)
cmds.button(label="Caca", p=myRowLayout)

#This will reorder the content of the left formLayout
cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", edit=True, af=[ \
            (channelLayout, "bottom", 0), \
            (channelLayout, "right", 0),  \
            (filterLayout, "top", 0),  \
            (myRowLayout, "left", 0),  \
            (myRowLayout, "right", 0)],  \
            ac=[(myRowLayout, "top", 0, filterLayout), \
            (channelLayout, "top", 0, myRowLayout)])
图形编辑器
是一个运行时命令,它执行
tearofpanel“Graph Editor”“graphEditor”true调用时。这就是它出现在脚本编辑器中的原因

2:运行
whatIs“tearofpanel”(mel)

在这个文件中进行一点调查,就可以推断出可以使用
scriptedPanel
命令创建一个全新的图形编辑器

3:创建自己的图形面板

// Result: Mel procedure found in: C:/Program Files/Autodesk/Maya2014/scripts/startup/tearOffPanel.mel // 
演示如何创建脚本化面板并将其包含在窗口中。 现在,您可以使用以下方法创建自定义图形编辑器:

if cmds.window("GE_ui_window", exists=True):
    cmds.deleteUI("GE_ui_window")
cmds.window("GE_ui_window", title="My custom Graph Editor")

cmds.frameLayout("GE_ui_frameLayout", p="GE_ui_window", lv=False, bv=False )

if cmds.scriptedPanel("GE_ui_scriptedPanel", exists=True):
    cmds.deleteUI("GE_ui_scriptedPanel")
cmds.scriptedPanel("GE_ui_scriptedPanel", unParent=True, type="graphEditor", label='Sample')
cmds.scriptedPanel( "GE_ui_scriptedPanel", e=True, parent="GE_ui_window|GE_ui_frameLayout")

cmds.showWindow("GE_ui_window")
4:尝试了解图形编辑器是如何构建的

此脚本将打印出图形编辑器的小部件层次结构(首先创建自定义图形编辑器):

此外,您还可以签入
C:\Program Files\Autodesk\Maya2014\scripts\others\graphieditorpanel.mel
@939:global proc addgraphieditor(string$whichPanel)

现在,您可以意识到许多小部件没有任何名称,只有Maya提供的默认名称。因此,我们不能添加widget和paren