I have used a simple panel to to this--the idea was to emulate maya's single
line message box.. Below is the code I am using. The nuke interface does not
make it very easy to make it compact in the UI although you can hide tabs, etc.
I would like to see something like this integrated into nuke.
#----------------
import nuke
import nukescripts
# mystery nuke module
import pyui
#: Unique panel ID
ID = "ikaLoggerPanel"
LABEL = "Ika Messages"
class DockPanelBase(pyui.Dialog):
"""
A simplified version of nukescripts.PythonPanel without the callbacks
"""
def __init__(self, title, id):
pyui.Dialog.__init__( self, title, id )
self._node = nuke.PanelNode()
self._widget = None
self._openTabGroups = 0
def addKnob( self, knob ):
if type(knob) == nuke.BeginTabGroup_Knob:
self.__openTabGroups += 1
elif type(knob) == nuke.EndTabGroup_Knob:
self.__openTabGroups -= 1
elif type(knob) == nuke.Tab_Knob and self.__openTabGroups <= 0:
self.addKnob( nuke.BeginTabGroup_Knob() )
self._node.addKnob( knob )
knob.setFlag( nuke.NO_UNDO | nuke.NO_ANIMATION )
def create( self ):
while self._openTabGroups > 0:
self.addKnob(nuke.EndTabGroup_Knob())
if self._widget == None:
self._widget = self._node.createWidget( self )
self.add( self._widget, 0, 0, 1, 3 )
def hide( self ):
super(PythonPanel, self).hide()
def addToPane( self, pane = None ):
self.create()
if pane != None:
pane.add( self )
elif nuke.thisPane() != None:
nuke.thisPane().add( self )
return self
class LoggerPanel(DockPanelBase):
"""
A panel meant to be used with logging to provide feedback inside nuke
"""
def __init__(self):
if nuke.IkaLoggerPanel:
raise Exception('LoggerPanel should be a singleton; Use getPanel() instead')
super(LoggerPanel, self).__init__(LABEL, ID)
self.outputKnob = nuke.String_Knob('output')
# self.outputKnob.setEnabled(False)
self.addKnob(self.outputKnob)
self.outputKnob.setLabel('Output')
self.outputKnob.setTooltip('Python output')
def updateOutput(self, msg, level=None):
if level in ['WARNING', 'ERROR']:
msg = '%s: %s' % (level, msg)
self.outputKnob.setValue(msg)
#: Monkeypatch global singleton instance
# If we do not hang onto it here, nuke does some strange things and creates
multiple instances
if nuke.GUI and not nuke.IkaLoggerPanel and nuke.NUKE_VERSION_MAJOR > 5:
nuke.IkaLoggerPanel = LoggerPanel()
def getPanel():
"""
Use this to ensure we deal with the correct singleton instance
"""
return nuke.IkaLoggerPanel
def addToPane():
"""
Function used in panel registration in init.py:
nukescripts.registerPanel(ui.logger_panel.ID, ui.logger_panel.addToPane)
"""
panel = getPanel()
if not panel:
raise Exception('Logger Panel not found')
return panel.addToPane()
----- Original Message -----
From: "Jordan O" <[email protected]>
To: "Nuke Python discussion" <[email protected]>
Sent: Saturday, November 2, 2013 7:20:39 PM
Subject: Re: [Nuke-python] Nuke Logging Handler
Hi Jesse,
So if I understand you right, you're looking for an alternative for presenting
logger messages besides popups? And the script editor / nuke console isn't
sufficient as it's hidden? I can't think of any other way to alert the comper
(as Nuke has no status bar). You could have a python callback something in the
node graph, such as have a backdrop with logs on it as a label, or something
visual like that..
cheers,
Jordan
On Fri, Nov 1, 2013 at 8:00 AM, Jesse Kretschmer < [email protected] > wrote:
Heyo,
I've worked with Nuke for a while and I've realized the logging within nuke is
a bit nuanced. At my facility I implemented a global logger that most of our
tools use, including Nuke. In Maya, I swap the stream handler with the
maya.utils.MayaGuiLogHandler(). I have not come across a similar handler for
Nuke, so I wrote a simple custom logging handler.
class NukeLogHandler(logging.Handler):
def emit(self, record):
if record.levelno >= logging.CRITICAL:
nuke.critical(record.getMessage())
elif record.levelno >= logging.ERROR:
nuke.error(record.getMessage())
elif record.levelno >= logging.WARNING:
nuke.warning(record.getMessage())
else:
nuke.debug(record.getMessage())
nuke.tprint("%s: %s" % (record.levelname,record.getMessage()))
First I noticed that there is no nuke.info level to map to the standard logging
levels. I'd like to present errors and warnings to the user in a nice way. Maya
has a common method of bubbling these messages up that's not intrusive, but
nuke only seems to have nuke.critical() and nuke.message(). Popups are so
intrusive, that I'd like to find another way to handle certain message. The
command console prints information for these messages, but that's often hidden
beneath the main nuke window.
Can anyone offer any suggestions to make this better?
Cheers,
Jesse
_______________________________________________
Nuke-python mailing list
[email protected] , http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python