Changing callbacks at startup


#1

Hi !

I was wondering if it’s possible to modify the different callbacks in init.py.
I need to change 2 things :

  1. the “beforeProjectSave” in the project settings (is there a “afterProjectSave” callback BTW ?)
  2. the “afterFrameRender” in all write nodes.

Is it possible ?
Thanks !


#2

In init.py, set the afterNodeCreatedCallback on all nodes that are a write node:

def beforeProjectSave(filename, app, autoSave):
    print 'saving %s' % filename

def afterFrameRenderCallback(frame, thisNode, app):
    print 'blablabla'


def afterNodeCreatedCallback(thisNode, app, userEdited):
    
    if thisNode.isWriterNode():
        thisNode.afterFrameRender.setValue('afterFrameRenderCallback')

def projectInitCallback(app):
    app.afterNodeCreated.set('afterNodeCreatedCallback')
    app.beforeProjectSave.set('beforeProjectSave')

#Set the After Project Created/Loaded callbacks
NatronEngine.natron.setOnProjectCreatedCallback("projectInitCallback")
NatronEngine.natron.setOnProjectLoadedCallback("projectInitCallback")

No afterSaveCallback.

See http://natron.readthedocs.io/en/master/devel/callbacks.html for more info


#3

Hi @MrKepzie
Thanks for your answer !
The callback functions are now in the different node attributes but when i save (or render), i cannot see the prints in the terminal.
Is it normal ?


#4

Check the script editor, not the terminal.


#5

Ok !
Thanks again ! :slight_smile:


#6

Hi,
The beforeSaveProject callback seems to be working while I can figure out why the afterFrameRender does not.
print ‘blabla’ is not executed. I’ve tried with file creation instead of print too without success.
Am I missing something ?