← Back to team overview

kicad-developers team mailing list archive

Scripting hooks

 

This post is partly inspired by "Auto-generated backup files: are they
useful?" but I have been thinking about this for a longer time.

KiCad could benefit from a scripting hook system. There could be
pre-hooks and post-hooks for certain actions. Let's take this backup
file discussion as an example. One system of backups or file history
may not make everyone happy. What if KiCad had hooks for Save etc.? It
would call, let's say pcbnew_save_pre() and pcbnew_save_post() python
functions which could do anything they want to do with the project. In
this case it could create backup files. The script writer would decide
how it would be done.

It could even use a third-party git or svn python library or external
program and make a commit every time the user Saves the document.

Let's take another example which was problematic in the past. I don't
remember the details, but I think an attempt to enhance the window
titles was abandoned because it was somehow problematic. What if there
was pcbnew_mainwindow_printwindowtitle_pre(arg1, arg2...) hook which
would return a string from the python function? It would take possible
parts of the window title as arguments.  The python function could
form the title as it likes.

Third example: pcbnew_plot_gerber_post() could rename and zip the
plotted gerber files. See
https://gitlab.com/kicad/code/kicad/-/issues/2076.

Fourth example: https://gitlab.com/kicad/code/kicad/-/issues/2339.
This is obviously something which is impossible to make to satisfy all
use cases, but create_new_project_post() hook could create any folders
the user wants.

It's easy to see that only imagination is the limit, and this would
take some needless responsibilities and decisions from the developers
and would give freedom to the users. There could and often should be
some reasonable default behavior, but the user could decide if it's
enough. If the proper infrastructure (asset installer and repository)
will be made, the users could share what they have.

Eeli Kaikkonen


Follow ups