Skip to content
Advertisement

The Foundry Nuke – Display an animated value on a QLabel

I am currently trying to display a value in a QLabel (QLineEdit would work too) based on a NUKE (or Maya) timeline.

I am using Nuke to run the code and I would like to display the value based on the current frame to display something like this:

The current frame is 1001. If I change to frame 1002, I would like the QLabel to change accordingly.

Is there a way to do that ?

import PySide.QtGui as QtGui
import PySide.QtCore as QtCore

def test():
    class framePanel(QtGui.QWidget):
       super(framePanel, self).__init__(self):
           layout = QtGui.QVBoxLayout(self)
           self.label = QtGui.QLabel('This is frame 1001')
           layout.addWidget(self.label)

    framePanel = framePanel()
    framePanel.show()

test()

Thanks.

Advertisement

Answer

I’ve written the following code for Mac version of The Foundry Nuke 11.2v4, so there’s a PySide2 module instead of PySide that is for previous versions of Nuke. Also, there are some differences touching QtWidgets vs QtGui. For getting a current frame you have to use nuke.frame().

Here is the example with QLabel:

import nuke
from PySide2 import QtGui, QtCore
from PySide2 import QtWidgets

def theTest():  
    class framePanel(QtWidgets.QWidget):
        label = QtWidgets.QLabel("The current frame is: %s" % nuke.frame())
        label.show()
theTest()

enter image description here

And here is an example of QMessageBox with dynamically changing value:

import nuke
import os.path
from PySide2 import QtGui, QtCore
from PySide2 import QtWidgets

def signalEmitter():
    qApplication = QtWidgets.QApplication.activeWindow()
    qApplication.emit(QtCore.SIGNAL('wasChanged()'))

nuke.addKnobChanged(signalEmitter, nodeClass='Viewer')
qmBox = QtWidgets.QMessageBox(None)
qmBox.setText('The current frame is: %s' % nuke.frame())
qmBox.connect(QtCore.SIGNAL("wasChanged()"), lambda: qmBox.setText('The current frame is: %s' % nuke.frame()))
qmBox.setModal(False)
qmBox.show()

The QMessageBox is not modal.

enter image description here

Press on this picture to play a GIF animation!

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement