如何在Nuke中通过Python框架创建自定义面板?

时间:2017-04-05 07:18:26

标签: python pyqt pyqt4 nuke

你能告诉我如何在NUKE中创建没有间距的自定义面板(即无框窗口)吗?

目前它看起来像这样:

enter image description here

但我需要它看起来像这样:

enter image description here

2 个答案:

答案 0 :(得分:4)

这种情况正在发生,因为该面板有几个嵌套的小部件,每个小部件都添加了自己的边距,因此您需要遍历每个小部件和setContentsMargins。

"""
Get rid of the margins surrounding custom Panels
"""

import nuke
import PySide.QtCore as QtCore
import PySide.QtGui as QtGui
from nukescripts import panels

def set_widget_margins_to_zero(widget_object):

    if widget_object:
        target_widgets = set()
        target_widgets.add(widget_object.parentWidget().parentWidget())
        target_widgets.add(widget_object.parentWidget().parentWidget().parentWidget().parentWidget())

        for widget_layout in target_widgets:
            try:
                widget_layout.layout().setContentsMargins(0, 0, 0, 0)
            except:
                pass

class Example_Window(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        layout = QtGui.QVBoxLayout()
        label = QtGui.QLabel('Margins be-gone!')
        label.setStyleSheet('QLabel{background: #eeffcc}')

        layout.setContentsMargins(0,0,0,0)
        layout.addWidget(label)
        self.setLayout(layout)

        expandingPolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                                            QtGui.QSizePolicy.Expanding)
        label.setSizePolicy(expandingPolicy)
        self.setSizePolicy(expandingPolicy)

    def event(self, event):
        if event.type() == QtCore.QEvent.Type.Show:

            try:
                set_widget_margins_to_zero(self)
            except:
                pass

        return QtGui.QWidget.event(self, event)

panels.registerWidgetAsPanel('Example_Window', 'Example Widget',
                             'mwbp.Example_Widget')

给予应有的信用,我不久前在这里找到了解决方案:https://gist.github.com/maty974/4739917并发布了一个集成的示例小部件。

答案 1 :(得分:0)

制作我通过Python认识的面板的唯一方法就是这样(但它是框架):

class myCustomPanel( nukescripts.PythonPanel ):

    def __init__( self ):

        nukescripts.PythonPanel.__init__( self, 'myCustomPanel' )
        self.update = nuke.PyScript_Knob( 'update', 'Update Info' )
        self.info = nuke.Multiline_Eval_String_Knob( 'info', 'Info' )
        self.info.setEnabled( True )
        self.addKnob( self.update )
        self.addKnob( self.info )

def addInfoPanel():

    global iPanel
    iPanel = myCustomPanel()
    return iPanel.addToPane()

paneMenu = nuke.menu( 'Pane' )
paneMenu.addCommand( 'myCustomPanel', addInfoPanel )

enter image description here