liaokong
liaokong

Reputation: 165

How to create custom panel without framing via Python in Nuke?

Could you tell me how to create custom panel in NUKE having no spacing (i.e. frameless window)?

At the moment it looks like this:

enter image description here

But I need it to look like this:

enter image description here

Upvotes: 2

Views: 2242

Answers (2)

MattWBP
MattWBP

Reputation: 392

This is happening because the panel has several nested widgets each adding their own margin, so you'll need to iterate through the parent widgets and setContentsMargins on each.

"""
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')

to give credit where it's due, I found the solution a while ago here : https://gist.github.com/maty974/4739917 and have posted an integrated example widget.

Upvotes: 4

Andy Jazz
Andy Jazz

Reputation: 58563

The only way to make a panel that I know via Python is this (but it's with frame):

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

Upvotes: 0

Related Questions