Gimp - 2.4 Guía Del Usuario

Descargar
Página de 653
GNU Image Manipulation Program
150 / 653
11.3.4.4
Naming Conventions
Scheme’s naming conventions seem to prefer lowercase letters with hyphens, which I’ve followed in the naming of the function.
However, I’ve departed from the convention with the parameters. I like more descriptive names for my parameters and variables,
and thus add the "in" prefix to the parameters so I can quickly see that they’re values passed into the script, rather than created
within it. I use the prefix "the" for variables defined within the script.
It’s GIMP convention to name your script functions script-fu-abc, because then when they’re listed in the procedural database,
they’ll all show up under script-fu when you’re listing the functions. This also helps distinguish them from plug-ins.
11.3.4.5
Registering The Function
Now, let’s register the function with GIMP. This is done by calling the function script-fu-register. When GIMP reads
in a script, it will execute this function, which registers the script with the procedural database. You can place this function call
wherever you wish in your script, but I usually place it at the end, after all my other code.
Here’s the listing for registering this function (I will explain all its parameters in a minute):
(script-fu-register
"script-fu-text-box"
;func name
"Text Box"
;menu label
"Creates a simple text box, sized to fit\
around the user’s choice of text,\
font, font size, and color."
;description
"Michael Terry"
;author
"copyright 1997, Michael Terry"
;copyright notice
"October 27, 1997"
;date created
""
;image type that the script works on
SF-STRING
"Text:"
"Text Box"
;a string variable
SF-FONT
"Font:"
"Charter"
;a font variable
SF-ADJUSTMENT
"Font size"
’(50 1 1000 1 10 0 1)
;a spin-button
SF-COLOR
"Color:"
’(0 0 0)
;color variable
)
(script-fu-menu-register "script-fu-text-box" "<Toolbox>/Xtns/Script-Fu/Text")
If you save these functions in a text file with a .scm suffix in your script directory, then choose Xtns → Script-Fu → Refresh
Scripts, this new script will appear as Xtns → Script-Fu → Text → Text Box.
If you invoke this new script, it won’t do anything, of course, but you can view the prompts you created when registering the
script (more information about what we did is covered next).
Finally, if you invoke the Procedure Browser ( Xtns → Procedure Browser), you’ll notice that our script now appears in the
database.
11.3.4.6
Steps For Registering The Script
To register our script with GIMP, we call the function script-fu-register, fill in the seven required parameters and add our script’s
own parameters, along with a description and default value for each parameter.
T
HE
R
EQUIRED
P
ARAMETERS
• The name of the function we defined. This is the function called when our script is invoked (the entry-point into our script).
This is necessary because we may define additional functions within the same file, and GIMP needs to know which of these
functions to call. In our example, we only defined one function, text-box, which we registered.
• The location in the menu where the script will be inserted. The exact location of the script is specified like a path in Unix, with
the root of the path being either toolbox or right-click.
If your script does not operate on an existing image (and thus creates a new image, like our Text Box script will), you’ll want
to insert it in the toolbox menu -- this is the menu in GIMP’s main window (where all the tools are located: the selection tools,
magnifying glass, etc.).