Start-up scripts — Natron 2.5.0 documentation

# Start-up scripts

On start-up Natron will run different start-up scripts to let you setup anything like callbacks, menus, etc…

There are 2 different initialization scripts that Natron will look for in the search paths.

> - init.py

>   > This script is always run and should only initialize non-GUI stuff. You may not use it to initialize e.g. new menus or windows. Generally this is a good place to initialize all the callbacks that you may want to use in your projects.

> - initGui.py

>   > This script is only run in GUI mode (that is with the user interface). It should initialize all gui-specific stuff like new menus or windows.

All the scripts with the above name found in the search paths will be run in the order of the search paths.

Warning

This is important that the 2 scripts above are named init.py and initGui.py otherwise they will not be loaded.

Warning

These scripts are run well before any application instance (i.e: project) is created. You should therefore not run any function directly that might rely on the app variable (or app1, etc…). However you’re free to define classes and functions that may rely on these variable being declared, but that will be called only later on, when a project will actually be created.

# Examples

## initGui.py

A complete example of a iniGui.py can be found here .

## init.py

Here is an example of a init.py script, featuring:

- Formats addition to the project

- Modifications of the default values of parameters for nodes

- PyPlug search paths modifications

    #This Source Code Form is subject to the terms of the Mozilla Public
    #License, v. 2.0. If a copy of the MPL was not distributed with this
    #file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    #Created by Alexandre GAUTHIER-FOICHAT on 01/27/2015.

    #To import the variable "natron"
    import NatronEngine

    def addFormats(app):

        app.addFormat ("720p 1280x720 1.0")
        app.addFormat ("2k_185 2048x1108 1.0")

    def afterNodeCreatedCallback(thisNode, app, userEdited):

        #Turn-off the Clamp black for new grade nodes
        if thisNode.getPluginID() == "net.sf.openfx.GradePlugin":
            thisNode.clampBlack.setDefaultValue(False)

        #Set the blur size to (3,3) upon creation
        elif thisNode.getPluginID() == "net.sf.cimg.CImgBlur":
            thisNode.size.setDefaultValue(3,0)
            thisNode.size.setDefaultValue(3,1)

    #This will set the After Node Created callback on the project to tweek default values for parameters
    def setNodeDefaults(app):
        app.afterNodeCreated.set("afterNodeCreatedCallback")

    def setProjectDefaults(app):
        app.getProjectParam('autoPreviews').setValue(False)
        app.getProjectParam('outputFormat').setValue("2k_185")
        app.getProjectParam('frameRate').setValue(24)
        app.getProjectParam('frameRange').setValue(1, 0)
        app.getProjectParam('frameRange').setValue(30, 1)
        app.getProjectParam('lockRange').setValue(True)

    def myCallback(app):
        addFormats(app)
        setNodeDefaults(app)
        setProjectDefaults(app)

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

    #Add this path to the Natron search paths so that our PyPlug can be found.
    #Note that we could also set this from the NATRON_PLUGIN_PATH environment variable
    #or even in the Preferences panel, Plug-ins tab, with the "Pyplugs search path"
    NatronEngine.natron.appendToNatronPath("/Library/Natron/PyPlugs")