10.5. The Python-Fu Submenu

Figur 16.205. The Python-Fu submenu

The Python-Fu submenu

By default this submenu just contains the Python-Fu console.

Python-Fu is a set of Python modules that act as a wrapper to libgimp allowing the writing of plug-ins for GIMP.

10.5.1. Activating the submenu

  • You can access this command from the image menu through FiltersPython-Fu

10.5.2. The Python-Fu Console

The Python-Fu console is a dialog window running a Python shell (a Python interpreter in interactive mode). This console is set up to make use of the internal GIMP library routines of libgimp.

You can use the Python-Fu console to interactively test Python commands.

The console consists of a large scrollable main window for input and output, where you can type Python commands. When you type in a Python command and then press the Enter key, the command is executed by the Python interpreter. The command's output as well as its return value (and its error message, if any) will be displayed in the main window.

Figur 16.206. The Python-Fu Console

The Python-Fu Console

The Python-Fu Console Buttons

Gem

This command lets you save the content of the main window, that is the Python-Fu console input and output (including the >>> prompt).

Ryd

Wenn you click on this button, the content of the main window will be removed. Note that you can't get back the removed content using the Save command.

Gennemse...

When clicked, the procedure browser pops up, with an additional button Apply at the bottom of the window.

When you press this Apply button in the procedure browser, a call to the selected procedure will be pasted into the console window as a Python command:

Applied PDB procedure

Now you just have to replace the parameter names (here: width, height, and type) with actual values, e.g.

image = pdb.gimp_image_new(400, 300, RGB)

Then press Enter to execute the command.

You can (and should!) use the constants you find in the decription of the procedure's parameters, for example RGB-IMAGE or OVERLAY-MODE. But note that you have to replace hyphens (-) with underscores (_): RGB_IMAGE, OVERLAY_MODE.

[Vink] Vink

Python-Fu is not limited to just calling procedures from the PDB (GIMP procedural database). To create a new image object like in the example above, you can also type

              image = gimp.Image(width, height, type)
            

(with actual values for width, height, and type).

Luk

Pressing this button closes the console.