[gimp-perl] Document how to make gimp-perl extension. Bug 728068



commit 65d7c11125c1e7b3112a1d1649ab8161c9a765b7
Author: Ed J <m8r-35s8eo mailinator com>
Date:   Sat Apr 12 00:14:14 2014 +0100

    Document how to make gimp-perl extension. Bug 728068

 Gimp.pm                    |  123 ++++++++++++++++++++++++++++----------------
 Gimp/Fu.pm                 |   90 +++++++++++++++++++-------------
 Gimp/Lib.xs                |   10 ++++
 Gimp/Util.pm               |   11 ----
 MANIFEST                   |    5 +-
 Net/Net.pm                 |   24 ++++-----
 UI/UI.pm                   |   32 +++++------
 examples/dialogtest        |   41 +++------------
 examples/example-extension |   51 ++++++++++++++++++
 examples/glowing_steel     |   20 +++-----
 10 files changed, 234 insertions(+), 173 deletions(-)
---
diff --git a/Gimp.pm b/Gimp.pm
index a9ec9b2..2172ecd 100644
--- a/Gimp.pm
+++ b/Gimp.pm
@@ -6,7 +6,7 @@ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD %EXPORT_TAGS @EXPORT_FAIL
             @PREFIXES @GUI_FUNCTIONS
             $function $basename $spawn_opts
             $in_quit $in_run $in_net $in_init $in_query $no_SIG
-            $help $verbose $host $in_top);
+            $host $in_top);
 use subs qw(init end lock unlock);
 
 BEGIN {
@@ -38,24 +38,26 @@ my @_default = (@_procs, ':consts');
 my @POLLUTE_CLASSES;
 my $net_init;
 
-# we really abuse the import facility..
 sub import($;@) {
    my $pkg = shift;
-   warn "$$-$pkg->import(@_)" if $verbose;
+   warn "$$-$pkg->import(@_)" if $Gimp::verbose;
    my $up = caller;
    my @export;
 
    # make sure we can call GIMP functions - start net conn if required
    map { $net_init = $1 if /net_init=(\S+)/; } @_;
-   if ($interface_type eq "net") {
+   if ($interface_type eq "net" and not &Gimp::Net::initialized) {
       map { *{"Gimp::$_"} = \&{"Gimp::Constant::$_"} }
         qw(RUN_INTERACTIVE RUN_NONINTERACTIVE);
       Gimp::Net::gimp_init(grep {defined} $net_init);
    }
-   warn "$$-Loading constants" if $verbose;
-   # now get constants from GIMP
+   # do this here as not guaranteed access to GIMP before
    require Gimp::Constant;
-   import Gimp::Constant;
+   if (not defined &{$Gimp::Constant::EXPORT[-1]}) {
+     warn "$$-Loading constants" if $Gimp::verbose;
+     # now get constants from GIMP
+     import Gimp::Constant;
+   }
 
    @_= _default unless @_;
 
@@ -150,8 +152,8 @@ $in_query=0 unless defined $in_query;
 $in_top=$in_quit=$in_run=$in_net=$in_init=0;
 ($function)=$0=~/([^\/\\]+)$/;
 
-$verbose=0 unless defined $verbose;
-# $verbose=1;
+$Gimp::verbose=0 unless defined $Gimp::verbose;
+# $Gimp::verbose=1;
 
 $interface_type = "net";
 if (@ARGV) {
@@ -162,7 +164,7 @@ if (@ARGV) {
       while(@ARGV) {
          $_=shift(@ARGV);
          if (/^-h$|^--?help$|^-\?$/) {
-            $help=1;
+            $Gimp::help=1;
             print __<<EOF;
 Usage: $0 [gimp-args..] [interface-args..] [script-args..]
            gimp-arguments are
@@ -173,7 +175,7 @@ Usage: $0 [gimp-args..] [interface-args..] [script-args..]
                                       (for more info, see Gimp::Net(3))
 EOF
          } elsif (/^-v$|^--verbose$/) {
-            $verbose++;
+            $Gimp::verbose++;
          } elsif (/^--host$|^--tcp$/) {
             $host=shift(@ARGV);
          } else {
@@ -217,7 +219,7 @@ sub logger {
    $args{function} = ""                   unless defined $args{function};
    $args{fatal}    = 1                    unless defined $args{fatal};
    push(@log,[$basename,@args{'function','message','fatal'}]);
-   print STDERR format_msg($log[-1]),"\n" if !($in_query || $in_init || $in_quit) || $verbose;
+   print STDERR format_msg($log[-1]),"\n" if !($in_query || $in_init || $in_quit) || $Gimp::verbose;
    _initialized_callback if initialized();
 }
 
@@ -413,7 +415,7 @@ _pseudoclass qw(Image               ), @image_prefixes;
 _pseudoclass qw(Drawable       ), @drawable_prefixes;
 _pseudoclass qw(Selection      gimp_selection_);
 _pseudoclass qw(Vectors                gimp_vectors_);
-_pseudoclass qw(Channel                gimp_channel_ gimp_selection_), @drawable_prefixes;
+_pseudoclass qw(Channel                gimp_channel_), @drawable_prefixes;
 _pseudoclass qw(Display                gimp_display_ gimp_);
 _pseudoclass qw(Plugin         ), @plugin_prefixes;
 _pseudoclass qw(Gradient       gimp_gradient_);
@@ -438,7 +440,6 @@ _pseudoclass qw(Context         gimp_context_);
 _pseudoclass qw(Brushes                gimp_brush_ gimp_brushes_);
 _pseudoclass qw(Brush          gimp_brush_);
 _pseudoclass qw(Edit           gimp_edit_);
-_pseudoclass qw(Gradients      gimp_gradients_);
 _pseudoclass qw(Patterns       gimp_patterns_);
 _pseudoclass qw(Pattern                gimp_pattern_);
 
@@ -468,15 +469,6 @@ sub compare($$)            { $_[0]->[0] eq $_[1]->[0] and
 sub new($$$$)          { shift; [ _] }
 }
 
-{
-package Gimp::run_mode;
-
-# I guess I now use almost every perl feature available ;)
-
-use overload fallback => 1,
-             '0+'     => sub { ${$_[0]} };
-}
-
 =head1 NAME
 
 Gimp - a Perl extension for writing Gimp Extensions/Plug-ins/Load &
@@ -576,9 +568,10 @@ Access to GIMP's Procedural Database (pdb) for manipulation of
 most objects.
 
 =item *
-Use either a plain pdb (scheme-like) interface or an object-oriented
-syntax, i.e. C<gimp_image_new(600,300,RGB)> is the same as C<new
-Gimp::Image(600,300,RGB)>
+Use either a plain pdb (scheme-like but with perl OO
+class method) interface or a fully object-oriented syntax,
+i.e. C<Gimp-E<gt>image_new(600,300,RGB)> is the same as C<new
+Gimp::Image(600,300,RGB)>.
 
 =item *
 Networked plug-ins look/behave the same as those running from within gimp.
@@ -617,11 +610,11 @@ arguments.
 =head2 From outside GIMP
 
 The script will use C<Gimp> as above, and use Gimp functions as it
-wishes. Behind the scenes, GIMP has running a perl plugin (as described
-above) that is constantly running, and waits for connections from
-perl scripts. Your script, when it uses GIMP procedures (and Gimp-Perl
-functions), will actually be communicating with the perl server running
-under GIMP.
+wishes. If you are using GIMP interactively, you need to run the Perl
+server (under "Filters/Perl" to allow your script to connect. Otherwise,
+the script will start its own GIMP, in "batch mode".  Either way,
+your script, when it uses GIMP procedures (and Gimp-Perl functions),
+will actually be communicating with the perl server running under GIMP.
 
 The architecture may be visualised like this:
 
@@ -668,7 +661,7 @@ done automatically.
 
 Do any activities that must be performed at Gimp startup, when the
 procedure is queried.  Should typically have at least one call to
-gimp_install_procedure.
+Gimp->install_procedure.
 
 =item Gimp::on_net
 
@@ -677,7 +670,7 @@ running it standalone).
 
 =item Gimp::on_lib
 
-Run only when called interactively from within Gimp.
+Run only when called from within Gimp.
 
 =item Gimp::on_run
 
@@ -685,6 +678,47 @@ Run when anything calls it (network or lib).
 
 =back
 
+=head1 OUTLINE OF A GIMP EXTENSION
+
+A GIMP extension is a special type of plugin. Once started, it stays
+running all the time. Typically during its run-initialisation (not on
+query) it will install temporary procedures.
+
+If it has no parameters, then rather than being run when called, either
+from a menu or a scripting interface, it is run at GIMP startup.
+
+A working, albeit trivial, example is provided in
+examples/example-extension. A summarised example:
+
+  use Gimp;
+  Gimp::register_callback extension_gp_test => sub {
+    # do some relevant initialisation here
+    Gimp->install_temp_proc(
+      "perl_fu_temp_demo", "help", "blurb", "id", "id", "2014-04-11",
+      "<Toolbox>/Xtns/Perl/Test/Temp Proc demo", undef,
+      &Gimp::TEMPORARY,
+      [ [ &Gimp::PDB_INT32, 'run_mode', 'Run-mode', 0 ], ],
+      [],
+    );
+    Gimp->extension_ack;
+    while (1) {
+      Gimp->extension_process(0);
+    }
+  };
+  Gimp::register_callback perl_fu_temp_demo => sub {
+    my ($run_mode) = @_;
+    # here could bring up UI if $run_mode == RUN_INTERACTIVE
+  };
+  Gimp::on_query {
+     Gimp->install_procedure(
+       "extension_gp_test", "help", "blurb", "id", "id", "2014-04-11",
+       undef, undef,
+       &Gimp::EXTENSION,
+       [], [],
+     );
+  };
+  exit Gimp::main;
+
 =head1 CALLING GIMP FUNCTIONS
 
 There are two different flavours of gimp-functions. Functions from the
@@ -703,13 +737,13 @@ normal perl (this requires the use of the C<:auto> import tag - see
 the import C<:auto> note for non-OO limitation; see below for another
 possibility!):
 
- gimp_palette_set_foreground([20,5,7]);
- gimp_palette_set_background("cornsilk");
+ Gimp->palette_set_foreground([20,5,7]);
+ Gimp->palette_set_background("cornsilk");
 
 If you don't use the C<:auto> import tag, you can call all Gimp functions
 using OO-Syntax:
 
- Gimp->gimp_palette_set_foreground([20,5,7]);
+ Gimp->palette_set_foreground([20,5,7]);
  Gimp->palette_set_background("cornsilk");
  Gimp::Palette->set_foreground('#1230f0');
 
@@ -776,7 +810,7 @@ database is similar, but not identical to the X11 default rgb.txt)
 =item Gimp::initialized()
 
 this function returns true whenever it is safe to call gimp functions. This is
-usually only the case after gimp_main or gimp_init have been called.
+usually only the case after gimp_main has been called.
 
 =item Gimp::register_callback(gimp_function_name, perl_function)
 
@@ -816,25 +850,25 @@ or C<$object-E<gt>>).
 
 =over 4
 
-=item gimp_install_procedure(name, blurb, help, author, copyright, date, menu_path, image_types, type, 
[params], [return_vals])
+=item Gimp->install_procedure(name, blurb, help, author, copyright, date, menu_path, image_types, type, 
[params], [return_vals])
 
 Mostly same as gimp_install_procedure from the C library. The
 parameters and return values for the functions are specified as an
 array ref containing either integers or array-refs with three elements,
 [PARAM_TYPE, \"NAME\", \"DESCRIPTION\"].
 
-=item gimp_progress_init(message,[])
+=item Gimp::Progress->init(message,[])
 
 Initializes a progress bar. In networked modules this is a no-op.
 
-=item gimp_progress_update(percentage)
+=item Gimp::Progress->update(percentage)
 
 Updates the progress bar. No-op in networked modules.
 
 =item gimp_tile_*, gimp_pixel_rgn_*, gimp_drawable_get
 
 With these functions you can access the raw pixel data of drawables. They
-are documented in L<Gimp::Pixel>, to keep this manual page short.
+are documented in L<Gimp::PixelRgn>, to keep this manual page short.
 
 =item gimp_call_procedure(procname, arguments...)
 
@@ -861,7 +895,7 @@ integers>, rather than blessed objects.
 
 Returns an array (x,y,w,h) containing the upper left corner and the
 size of currently selected parts of the drawable, just as needed by
-PixelRgn->new and similar functions.
+Gimp::PixelRgn->new and similar functions.
 
 =item server_eval(string)
 
@@ -1024,9 +1058,8 @@ Ed J (with oversight and guidance from Kevin Cozens) (2.3+)
 
 =head1 SEE ALSO
 
-perl(1), gimp(1), L<Gimp::OO>, L<Gimp::Data>, L<Gimp::Pixel>,
-L<Gimp::Util>, L<Gimp::UI>, L<Gimp::Net>,
-L<Gimp::Config>, and L<Gimp::Lib>.
+perl(1), gimp(1), L<Gimp::OO>, L<Gimp::Data>, L<Gimp::PixelRgn>,
+L<Gimp::Util>, L<Gimp::UI>, L<Gimp::Config>, L<Gimp::Net>, and L<Gimp::Lib>.
 
 =cut
 
diff --git a/Gimp/Fu.pm b/Gimp/Fu.pm
index a476370..b3f0e32 100644
--- a/Gimp/Fu.pm
+++ b/Gimp/Fu.pm
@@ -1,15 +1,17 @@
 package Gimp::Fu;
 
-use Gimp ('croak', '__');
 use Gimp::Data;
 use File::Basename;
 use strict;
-use Carp qw(croak);
+use Carp qw(croak carp);
 use vars qw($run_mode @EXPORT);
 
 @EXPORT = qw($run_mode);
 # EXPORT_OK = qw($run_mode save_image);
 
+# manual import
+sub __ ($) { goto &Gimp::__ }
+
 use constant {
   PF_INT8 => Gimp::PDB_INT8,
   PF_INT16 => Gimp::PDB_INT16,
@@ -91,16 +93,16 @@ a starting point for your experiments)
 sub Gimp::RUN_FULLINTERACTIVE (){ Gimp::RUN_INTERACTIVE+100 }; # you don't want to know
 
 my %pf_type2string = (
-         &PF_INT8      => 'small integer',
-         &PF_INT16     => 'medium integer',
-         &PF_INT32     => 'integer',
-         &PF_FLOAT     => 'value',
+         &PF_INT8      => 'integer (0-255)',
+         &PF_INT16     => 'integer (0-32767)',
+         &PF_INT32     => 'integer (0-4294967295)',
+         &PF_FLOAT     => 'number',
          &PF_STRING    => 'string',
          &PF_BRUSH     => 'string',
          &PF_GRADIENT  => 'string',
          &PF_PATTERN   => 'string',
          &PF_COLOR     => 'colour',
-         &PF_FONT      => 'XLFD',
+         &PF_FONT      => 'font',
          &PF_TOGGLE    => 'boolean',
          &PF_SLIDER    => 'integer',
          &PF_SPINNER   => 'integer',
@@ -139,17 +141,17 @@ sub import {
 }
 
 # Some Standard Arguments
-my @image_params = ([&Gimp::PDB_IMAGE          , "image",      "The image to work on"],
-                    [&Gimp::PDB_DRAWABLE       , "drawable",   "The drawable to work on"]);
+my @image_params = ([&Gimp::PDB_IMAGE, "image", "The image to work on"],
+                    [&Gimp::PDB_DRAWABLE, "drawable", "The drawable to work on"]);
 
-my @load_params  = ([&Gimp::PDB_STRING , "filename",   "The name of the file"],
-                    [&Gimp::PDB_STRING , "raw_filename","The name of the file"]);
+my @load_params  = ([&Gimp::PDB_STRING, "filename", "The name of the file"],
+                    [&Gimp::PDB_STRING, "raw_filename", "The name of the file"]);
 
 my @save_params  = (@image_params, @load_params);
 
-my @load_retvals = ([&Gimp::PDB_IMAGE          , "image",      "Output image"]);
+my @load_retvals = ([&Gimp::PDB_IMAGE, "image", "Output image"]);
 
-my $image_retval = [&Gimp::PDB_IMAGE           , "image",      "The resulting image"];
+my $image_retval = [&Gimp::PDB_IMAGE, "image", "The resulting image"];
 
 # expand all the pod directives in string (currently they are only removed)
 sub expand_podsections() {
@@ -175,24 +177,12 @@ sub expand_podsections() {
 my $old_trace;
 
 sub interact {
-   eval { require Gtk2 };
-
-   if ($@) {
-      my @res = map {
-         die __"the gtk perl module is required to run\nthis plug-in in interactive mode\n" unless defined 
$_->[3];
-         $_->[3];
-      } @{ $_[3] };
-      Gimp::logger(message => __"the gtk perl module is required to open a dialog\nwindow, running with 
default values",
-                   fatal => 1, function => $_[0]);
-      return (1,@res);
-   }
-
    require Gimp::UI;
    goto &Gimp::UI::interact;
 }
 
 sub this_script {
-   return $scripts[0] unless $#scripts;
+   return $scripts[0] if @scripts == 1;
    # well, not-so-easy-day today
    require File::Basename;
    my $exe = File::Basename::basename($0);
@@ -256,7 +246,8 @@ Gimp::on_net {
    no strict 'refs';
    my $this = this_script;
    my(%map,@args);
-   my($interact)=1;
+   my $interact = 1;
+   $outputfile = undef;
 
    my($perl_sub,$function,$blurb,$help,$author,$copyright,$date,
       $menupath,$imagetypes,$params,$results,$code,$type)= $this;
@@ -506,8 +497,20 @@ a C<PF_COLOR>.
 
 =item the return values
 
-This is just like the parameter array except that it describes the return
-values. Specify the type and variable name only. This argument is optional.
+This is just like the parameter array except that it describes the
+return values. Specify the type and variable name only. This argument is
+optional. If you wish your plugin to return an image, you must specify
+that, e.g.:
+
+  use Gimp;
+  use Gimp::Fu;
+  register
+     'function_name', "help", "blurb", "author", "copyright", "2014-04-11",
+     "<Image>/Filters/Render/Do Something...",
+     "*",
+     [ [PF_INT32, "input", "Input value", 1] ],
+     [ [PF_IMAGE, "output image", "Output image", 1] ],
+     sub { Gimp::Image->new($_[0], $_[0], RGB) };
 
 =item the code
 
@@ -515,10 +518,17 @@ This is either an anonymous sub declaration (C<sub { your code here; }>, or a
 coderef, which is called when the script is run. Arguments (including the
 image and drawable for <Image> plug-ins) are supplied automatically.
 
-It is good practise to return an image, if the script creates one, or
-C<undef>, since the return value is interpreted by Gimp::Fu (like displaying
-the image or writing it to disk). If your script creates multiple pictures,
-return an array.
+You must make sure your plugin returns the correct types of value, or none:
+
+ sub {
+   # no return parameters were specified
+   ();
+ };
+
+If you want to display images, you must have your script do that
+(and call C<Gimp-E<gt>displays_flush> at the end). C<Gimp::Fu> plugins
+will thereby be good GIMP "citizens", able to fit in with plugins/filters
+written in other languages.
 
 =back
 
@@ -545,12 +555,12 @@ A gimp image.
 
 =item PF_DRAWABLE
 
-A gimp drawable (image, channel or layer).
+A gimp drawable (channel or layer).
 
 =item PF_TOGGLE, PF_BOOL
 
-A boolean value (anything Perl would accept as true or false). The description
-will be used for the toggle-button label!
+A boolean value (anything Perl would accept as true or false). The
+description will be used for the toggle-button label.
 
 =item PF_SLIDER
 
@@ -924,7 +934,13 @@ sub print_switches {
    for(@{$this->[9]}) {
       my $type=$pf_type2string{$_->[0]};
       my $key=mangle_key($_->[1]);
-      printf "           -%-25s %s%s\n","$key $type",$_->[2],defined $_->[3] ? " [$_->[3]]" : "";
+      my $default_text = defined $_->[3]
+         ? " [".(ref $_->[3] eq 'ARRAY' ? "[ {$_->[3]}]" : $_->[3])."]"
+         : "";
+      printf "           -%-25s %s%s\n",
+       "$key $type",
+       $_->[2],
+       $default_text;
    }
 }
 
diff --git a/Gimp/Lib.xs b/Gimp/Lib.xs
index c2dfd33..10232c1 100644
--- a/Gimp/Lib.xs
+++ b/Gimp/Lib.xs
@@ -1721,6 +1721,16 @@ gimp_lib_quit()
        gimp_quit ();
 
 void
+gimp_extension_process(timeout)
+  guint timeout
+
+void
+gimp_extension_enable()
+
+void
+gimp_extension_ack()
+
+void
 gimp_set_data(id, data)
        SV *    id
        SV *    data;
diff --git a/Gimp/Util.pm b/Gimp/Util.pm
index 1b27149..05c2cd1 100644
--- a/Gimp/Util.pm
+++ b/Gimp/Util.pm
@@ -228,17 +228,6 @@ sub layer_add_layer_as_mask {
 # all functions below are by Marc Lehmann
 =pod
 
-=item C<gimp_text_wh $text,$fontname>
-
-returns the width and height of the "$text" of the given font (XLFD format)
-
-=cut
-sub gimp_text_wh {
-   (Gimp->text_get_extents_fontname($_[0],xlfd_size $_[1],$_[1]))[0,1];
-}
-
-=pod
-
 =item C<gimp_image_layertype $alpha>
 
 returns the corresponding layer type for an image, alpha controls wether the layer type
diff --git a/MANIFEST b/MANIFEST
index 3cdc3a7..d8ef09b 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -22,7 +22,7 @@ Gimp/Lib.pm
 Gimp/Lib.xs
 Gimp/Makefile.PL
 Gimp/OO.pod
-Gimp/Pixel.pod
+Gimp/PixelRgn.pod
 Gimp/Pod.pm
 Gimp/Util.pm
 Gimp.pm
@@ -50,6 +50,7 @@ examples/dialogtest
 examples/ditherize
 examples/dots
 examples/dust
+examples/example-extension
 examples/example-fu
 examples/example-net
 examples/example-oo
@@ -140,10 +141,10 @@ po/zh_CN.po
 po/zh_TW.po
 pxgettext
 t/import.t
-t/perlplugin.t
 t/loadlib.t
 t/load.t
 t/pdl.t
+t/perlplugin.t
 t/run.t
 t/supplied.t
 typemap
diff --git a/Net/Net.pm b/Net/Net.pm
index e6af57c..af44034 100644
--- a/Net/Net.pm
+++ b/Net/Net.pm
@@ -31,12 +31,13 @@ use strict 'vars';
 use vars qw($VERSION $trace_res);
 use subs qw(gimp_call_procedure);
 use base qw(DynaLoader);
-
 use IO::Socket;
-
 use Carp 'croak';
 use Fcntl qw(F_SETFD);
 
+$VERSION = 2.3001;
+bootstrap Gimp::Net $VERSION;
+
 use constant {
   PS_FLAG_QUIET => 1 << 0, # do not output messages
   PS_FLAG_BATCH => 1 << 1, # started via Gimp::Net, extra = filehandle
@@ -45,10 +46,6 @@ use constant {
 my $PROTOCOL_VERSION = 4; # protocol version
 my ($server_fh, $gimp_pid, $trace_level, $auth);
 
-require DynaLoader;
-$VERSION = 2.3001;
-bootstrap Gimp::Net $VERSION;
-
 my $DEFAULT_TCP_PORT  = 10009;
 my $DEFAULT_UNIX_DIR  = "/tmp/gimp-perl-serv-uid-$>/";
 my $DEFAULT_UNIX_SOCK = "gimp-perl-serv";
@@ -155,21 +152,20 @@ sub start_server {
       open STDOUT,">/dev/null";
       #open STDERR,">&1";
    }
-   my @args;
    my $flags = PS_FLAG_BATCH | ($Gimp::verbose ? 0 : PS_FLAG_QUIET);
    my $args = join ' ',
      &Gimp::RUN_NONINTERACTIVE,
      $flags,
      fileno($gimp_fh),
      int($Gimp::verbose);
-   warn __"$$-plug-in-perl-server args='$args'" if $Gimp::verbose;
-   push(@args,"--no-data") if $opt=~s/(^|:)no-?data//;
-   push(@args,"-i") unless $opt=~s/(^|:)gui//;
-   push(@args,"--verbose") if $Gimp::verbose;
+   my @args;
+   push @args,"--no-data" if $opt=~s/(^|:)no-?data//;
+   push @args,"-i" unless $opt=~s/(^|:)gui//;
+   push @args,"--verbose" if $Gimp::verbose;
+   warn __"$$-plug-in-perl-server args='$args' \ args(@args)" if $Gimp::verbose;
    { # block to suppress warning
    exec $Gimp::Config{GIMP},
        "--no-splash",
-       #"never",
        "--console-messages",
        @args,
        "--batch-interpreter",
@@ -184,6 +180,7 @@ sub start_server {
 
 sub try_connect {
    local $_=$_[0];
+   warn "$$-".__PACKAGE__."::try_connect(@_)" if $Gimp::verbose;
    my $fh;
    $auth = s/^(.*)\@// ? $1 : "";      # get authorization
    if ($_ eq "") {
@@ -552,7 +549,8 @@ done automatically while installing the Gimp extension. If you have a
 menu entry C<<Xtns>/Perl-Server> then it is probably installed.
 
 The Perl-Server can either be started from the C<<Xtns>> menu in Gimp,
-or automatically when a perl script can't find a running Perl-Server.
+or automatically when a perl script can't find a running Perl-Server,
+in which case it will start up its own copy of GIMP.
 
 When started from within GIMP, the Perl-Server will create a unix
 domain socket to which local clients can connect. If an authorization
diff --git a/UI/UI.pm b/UI/UI.pm
index 1d8294f..c574902 100644
--- a/UI/UI.pm
+++ b/UI/UI.pm
@@ -2,6 +2,7 @@ package Gimp::UI;
 
 use Gimp ('__');
 use Gimp::Fu;
+use Gtk2;
 use base 'DynaLoader';
 
 no warnings "all";
@@ -18,7 +19,7 @@ Gimp::UI - interface to libgimpui, and more!
 
 The libgimpwidgets api has improved considerably in 1.4 (mostly due to
 it being based on gobjects), but the resulting widgets still are not
-full-featured gobjects, so a lot of manual workaround is neccessary. Most
+full-featured gobjects, so a lot of manual workaround is necessary. Most
 of the API has been converted.
 
 =over 4
@@ -38,25 +39,18 @@ of the API has been converted.
 
 # <sjburges gimp org> removed the camel logo from scripts
 
-$VERSION = 2.3001;
-
-if (eval { require Gtk2; import Gtk2 (); 1 }) {
-   local $/;
-
-   require XSLoader;
-   XSLoader::load Gimp::UI $VERSION;
-
-   eval <DATA>;
-   die $@ if $@;
-   close DATA;
+BEGIN {
+   $VERSION = 2.3001;
+   eval {
+      require XSLoader;
+      XSLoader::load Gimp::UI $VERSION;
+   } or do {
+      require DynaLoader;
+      @ISA = qw(DynaLoader);
+      bootstrap Gimp::UI $VERSION;
+   };
 }
 
-1;
-
-# All Gtk-dependent functions are put below
-__DATA__
-#line 58 "..../Gimp/UI.pm"
-
 # shows the properties of a glib object
 #d# just to debug
 sub info {
@@ -896,3 +890,5 @@ Marc Lehmann <pcg goof com>, Seth Burgess <sjburges gimp org>
 perl(1), L<Gimp>.
 
 =cut
+
+1;
diff --git a/examples/dialogtest b/examples/dialogtest
index e0d6b22..9356cd9 100755
--- a/examples/dialogtest
+++ b/examples/dialogtest
@@ -1,48 +1,21 @@
 #!/usr/local/bin/perl -w
 
 use strict;
+#BEGIN { $Gimp::verbose = 1; }
 use Gimp qw(:auto __ N_);
 use Gimp::Fu;
-#BEGIN { $Gimp::verbose = 1; }
 #Gimp::set_trace(TRACE_ALL);
 
-sub boilerplate_params {
-  my ($testing, $menuloc) = @_;
-  (
-    ("exercise gimp-perl filter testing $testing") x 2,
-    ("boilerplate id") x 2,
-    "20140310",
-    N_$menuloc,
-    "*",
-  );
-}
-
-if (0) {
-&register(
-  "test_dialogs2",
-  boilerplate_params(
-    'menu entries',
-    '<Image>/Filters/Perl/Dialog Test',
-  ),
-  [
-    [ PF_COLOR, "colour", "Image colour", [255, 127, 0], ],
-    [ PF_FONT, "font", "Font", 'Arial', ],
-    [ PF_INT, "size", "Size", 100],
-  ],
-  sub { }
-);
-}
-
 &register(
-  "test_dialogs",
-  boilerplate_params(
-    'dialogs',
-    '<Toolbox>/Xtns/Perl/Test/Dialog',
-  ),
+  "test_dialogs", 'help', 'blurb', 'id', 'id', '20140411',
+  N_ '<Toolbox>/Xtns/Perl/Test/Dialog', undef,
   [
     [ PF_COLOR, "colour", "Image colour", [255, 127, 0], ],
     [ PF_FONT, "font", "Font", 'Arial', ],
-    [ PF_INT, "size", "Size", 100],
+    [ PF_INT8, "int8", "Int8", 100],
+    [ PF_INT16, "int16", "Int16", 100],
+    [ PF_INT32, "int32", "Int32", 100],
+    [ PF_FLOAT, "float", "FLOAT", 100],
   ],
   sub { }
 );
diff --git a/examples/example-extension b/examples/example-extension
new file mode 100755
index 0000000..dbd3433
--- /dev/null
+++ b/examples/example-extension
@@ -0,0 +1,51 @@
+#!/usr/local/bin/perl -w
+
+BEGIN { $Gimp::verbose = 1; }
+use Gimp;
+Gimp::set_trace(TRACE_ALL);
+
+my $OTHER_EVENTLOOP = 0;
+
+Gimp::register_callback extension_gp_test => sub {
+  # do some relevant initialisation here
+  Gimp->install_temp_proc(
+    "perl_fu_temp_demo", "Demo Gimp-Perl temp proc",
+    "Demo a Gimp-Perl extension's temp proc",
+    "Ed J", "Ed J", "2014-04-11",
+    "<Toolbox>/Xtns/Perl/Test/Temp Proc demo", undef,
+    &Gimp::TEMPORARY,
+    [
+      # must take this parameter first, can take others
+      [ &Gimp::PDB_INT32, 'run_mode', 'Run-mode', 0 ],
+    ],
+    [],
+  );
+  Gimp->extension_ack;
+  if ($OTHER_EVENTLOOP) {
+    Gimp->extension_enable;
+    # enter e.g. Gtk event loop
+  } else {
+    while (1) {
+      Gimp->extension_process(0);
+    }
+  }
+};
+
+Gimp::register_callback perl_fu_temp_demo => sub {
+  my ($run_mode) = @_;
+  # here could bring up UI if $run_mode == RUN_INTERACTIVE
+};
+
+Gimp::on_query {
+   Gimp->install_procedure(
+      "extension_gp_test", "Demo Gimp-Perl extension",
+      "Demo a Gimp-Perl extension",
+      "Ed J", "Ed J", "2014-04-11",
+      undef, undef,
+      &Gimp::EXTENSION,
+      [],
+      [],
+   );
+};
+
+exit Gimp::main;
diff --git a/examples/glowing_steel b/examples/glowing_steel
index 75af086..ffbd91d 100755
--- a/examples/glowing_steel
+++ b/examples/glowing_steel
@@ -1,8 +1,5 @@
 #!/usr/bin/perl
 
-eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
-    if 0; # not running under some shell
-
 # A plug-in for GIMP for producing logos and other such nifty things
 # which appear to be made of steel and floating over a glowing cloud.
 # This plug-in also includes several filters and such for performing the
@@ -45,9 +42,6 @@ sub perl_fu_glowing_steel {
 
   # Gimp::set_trace(TRACE_ALL);
 
-  ($size, $units) = xlfd_size($font) if $size < 1;
-  die("glowing_steel: No font size given or inferable") if $size < 1;
-
   gimp_context_push();
 
   my $image = gimp_image_new(100, 100, RGB);
@@ -272,7 +266,7 @@ sub perl_fu_highlight_edges {
 register
   "highlight_edges",
   "Frame an alpha layer with black and white edges",
-  "Use this pluggin to highlight the edges of an alpha layer and make ".
+  "Highlight the edges of an alpha layer and make ".
        "it appear to have height. Not quite the same as a beveled edge, ".
        "this is a somewhat more subtle technique.",
   "Aaron Sherman", "Aaron Sherman (c)", "1999-06-14",
@@ -286,7 +280,7 @@ register
 register
   "brushed_metal",
   "Create a brushed metal surface effect",
-  "Use this pluggin to make a surface (selected area) look like ".
+  "Make a surface (selected area) look like ".
        "brushed metal (kind of like steel).",
   "Aaron Sherman", "Aaron Sherman (c)", "1999-06-14",
   N_"<Image>/Filters/Render/Pattern/Brushed Metal...",
@@ -302,7 +296,7 @@ register
 register
   "add_glow",
   "Add a glow behind an alpha layer",
-  "Use this pluggin to add a glowing layer behind an existing layer. This ".
+  "Add a glowing layer behind an existing layer. This ".
        "is very different from drop shadows, as the glow will extend out ".
        "in the given radius from all edges of the layer.",
   "Aaron Sherman", "Aaron Sherman (c)", "1999-06-14",
@@ -317,7 +311,7 @@ register
 register
   "glowing_steel",
   "Render metal surface over glowing background",
-  "Use this pluggin to create the effect of a metalic surface over ".
+  "Create the effect of a metallic surface over ".
        "a glowing surface. This effect was inspired by a poster for the ".
        "film \"Lost In Space\".",
   "Aaron Sherman", "Aaron Sherman (c)", "1999-06-14",
@@ -327,7 +321,7 @@ register
   [
    [PF_STRING, "string", "string", "GET LOST"],
    # The font in the poster was like "cobalt extended"
-   [PF_FONT, "font", "Font", "Bitstream Charter Bold 72"],
+   [PF_FONT, "font", "Font", "Bitstream Charter Bold"],
    [PF_SPINNER, "size", "Size", 100, [0, 3000, 1]],
    [PF_COLOR, "glow_color", "Color", [1.0, 0.8157, 0]],
    [PF_COLOR, "background", "Color", [0x00, 0x00, 0x00]],
@@ -344,7 +338,7 @@ __END__
 
 =head1 NAME
 
-glowing_steel - A logo plugin for the Gimp
+glowing_steel - A logo plugin for GIMP
 
 =head1 SYNOPSIS
 
@@ -360,7 +354,7 @@ style that combines the I<Brushed Metal> effect with the I<Highlight Edges>
 and I<Add Glow> effects. The text is surfaced with brushed metal, and
 highlighted, and the glow is added in the background.
 
-This plug-in also includes the effects listed above as separete tools
+This plug-in also includes the effects listed above as separate tools
 which may be used independant of creating a logo. These tools are:
 
 =over 5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]