NAME
Gimp::Extension - Easy framework for Gimp-Perl extensions
SYNOPSIS
use Gimp;
use Gimp::Fu; # necessary for variable insertion and param constants
use Gimp::Extension;
podregister {
# your code
};
exit main;
__END__
=head1 NAME
function_name - Short description of the function
=head1 SYNOPSIS
<Image>/Filters/Menu/Location...
=head1 DESCRIPTION
Longer description of the function...
DESCRIPTION
This module provides all the infrastructure you need to write Gimp-Perl extensions.
Your main interface for using Gimp::Extension
is the podregister
function. This works in exactly the same way as "PODREGISTER" in Gimp::Fu, including declaring/receiving your variables for you.
Before control is passed to your function, these procedures are called:
Gimp::gtk_init; # sets up Gtk2, ready for event loop
Gimp->extension_ack; # GIMP hangs till this is called
Gimp->extension_enable; # adds an event handler in Glib mainloop for
# GIMP messages
Your function will then either proceed as if it were a plugin, or call the Glib/Gtk2 mainloop:
Gtk2->main;
Values returned by your function will still be returned to a caller, as with a plugin.
One benefit of being an extension vs a plugin is that you can keep running, installing temporary procedures which are called by the user. When they are called, the perl function you have registered will be called, possibly accessing your persistent data or at least benefiting from the fact that you have already started up.
Another benefit is that you can respond to events outside of GIMP, such as network connections (this is how the Perl-Server is implemented).
Additionally, if no parameters are specified, then the extension will be started as soon as GIMP starts up. Make sure you specify menupath <None>, so no parameters will be added for you.
If you need to clean up on exit, just register a callback with Gimp::on_quit
. This is how Perl-Server
removes its Unix-domain socket on exit.
FUNCTIONS AVAILABLE TO EXTENSIONS
These are all exported by default.
podregister
As discussed above.
add_listener
This is a convenience wrapper around Glib::IO->add_watch
. It takes parameters:
- $listen_socket
-
This will be an IO::Socket subclass object, a listener socket. When it becomes readable, its
accept
method will be called. - \&handler
-
This mandatory parameter is a function that is installed as the new connection's Glib handler. Its parameters are:
$fd, $condition, $fh
- in Glib terms, the file handle will be registered as the "data" parameter. When it returns false, the socket will be closed. - \&on_accept
-
This optional parameter will, if defined, be a function that is called one time with the new socket as a parameter, possibly logging and/or sending an initial message down that socket.
podregister_temp
podregister_temp perl_fu_procname => sub {
...
};
=head1 TEMPORARY PROCEDURES
=head2 procname - blurb
Longer help text.
=head3 SYNOPSIS
<Image>/File/Label...
=head3 PARAMETERS
# params...
Registers a temporary procedure, reading from the POD the SYNOPSIS, PARAMETERS, RETURN VALUES, IMAGE TYPES, etc, as for Gimp::Fu. As you can see above, the temporary procedure's relevant information is in similarly-named sections, but at level 2 or 3, not 1, within the suitably-named level 2 section. Unlike podregister
, it will not interpolate variables for you.
register_temp
This is a convenience wrapper around Gimp->install_temp_proc
, supplying a number of parameters from information in the extension's POD. The registration will only happen when the extension's on_run
callback is called. It takes parameters:
- $proc_name
-
The name of the new PDB procedure.
- $blurb
- $help
- $imagetypes
- $params
- $retvals
-
All as per "Gimp->install_procedure" in Gimp.
- \&callback
AUTHOR
Ed J