How Krita Executes Scripts

In this blog post you learn a bit about how Krita loads and executes your scripts.

How does Krita Execute Scripts

When starting up Krita runs through each of its enabled scripts and executes it. Taking the skeleton script in my earlier post as an example the class MyExtension is defined and then execution falls into this code:

# And add the extension to Krita's list of extensions:
app=Krita.instance()
extension=MyExtension(parent=app) #instantiate your class
app.addExtension(extension) 

That is, the code gets a reference to the Krita application, instantiates the MyExtension class and then adds that extension to the Krita application. You could put any code you like here and Krita will execute it on startup.

Ordinarily, scripts will define either a Krita Extension or a Krita Docker – you haven’t met dockers yet. You’ll need to wait for a later post!  In each case, the script will create an instance of the object before passing it to Krita to register it. This means that the __init__ methods of all of those classes will be executed.

After running all of the scripts Krita then goes back over all of the extensions that were registered with Krita in the previous step and runs each extension’s setup method.

Finally, Krita goes over each of the dockers you have registered in the first step. To register a docker you don’t instantiate it directly, rather you create a factory that will create the docker and pass the factory to Krita. Krita starts the docker factories after running the setup methods for any extensions you have.  That means that your dockers are instantiated later and, at that time, their constructor methods __init__ are run.

Leave a comment