[gimp-perl] Implement register_temp.



commit caf6cd5bec120fbf9ae1d794eec402365b1790cd
Author: Ed J <edj src gnome org>
Date:   Mon May 5 04:40:44 2014 +0100

    Implement register_temp.

 Gimp/Extension.pm                 |   40 +++++++++++--
 MANIFEST                          |    2 +
 examples/example-extension        |  114 ++++++++++++++++++++----------------
 examples/example-extension-no-fu  |   51 ++++++++++++++++
 examples/example-extension-tester |   35 +++++++++++
 5 files changed, 184 insertions(+), 58 deletions(-)
---
diff --git a/Gimp/Extension.pm b/Gimp/Extension.pm
index a43382a..ccb1a19 100644
--- a/Gimp/Extension.pm
+++ b/Gimp/Extension.pm
@@ -23,9 +23,8 @@ FILTER {
 our @EXPORT = qw(podregister main add_listener register_temp);
 
 my @register_params;
-Gimp::on_query {
-   Gimp->install_procedure(@register_params);
-};
+my @temp_procs;
+Gimp::on_query { Gimp->install_procedure(@register_params); };
 
 sub podregister (&) {
    no strict 'refs';
@@ -40,6 +39,20 @@ sub podregister (&) {
    }
    Gimp::register_callback $function => sub {
       warn "$$-Gimp::Extension sub: $function(@_)" if $Gimp::verbose;
+      for my $tp (@temp_procs) {
+        my (
+           $tfunction, $tblurb, $tmenupath, $timagetypes, $thelp,
+           $tparams, $tretvals, $tcallback,
+        ) = @$tp;
+        Gimp::register_callback $tfunction => $tcallback;
+        Gimp->install_temp_proc(
+           $tfunction, $tblurb, $thelp,
+           $author, $copyright, $date,
+           $tmenupath, $timagetypes,
+           &Gimp::TEMPORARY,
+           $tparams, $tretvals,
+        );
+      }
       Gimp::gtk_init;
       Gimp->extension_ack;
       Gimp->extension_enable;
@@ -67,8 +80,8 @@ sub add_listener {
    }, $listen_socket);
 }
 
-sub register_temp ($$$&) {
-   my ($function, $params, $retvals, $callback) = @_;
+sub register_temp ($$$$$$$&) {
+   push @temp_procs, [ @_ ];
 }
 
 1;
@@ -143,6 +156,10 @@ 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.
 
+If you need to clean up on exit, just register a callback with
+C<Gimp::on_quit>. This is how C<Perl-Server> removes its Unix-domain
+socket on exit.
+
 =head1 FUNCTIONS AVAILABLE TO EXTENSIONS
 
 These are all exported by default.
@@ -182,7 +199,8 @@ sending an initial message down that socket.
 
 This is a convenience wrapper around C<Gimp-E<gt>install_temp_proc>,
 supplying a number of parameters from information in the extension's
-POD. It takes parameters:
+POD. The registration will only happen when the extension's C<on_run>
+callback is called. It takes parameters:
 
 =over 4
 
@@ -190,11 +208,19 @@ POD. It takes parameters:
 
 The name of the new PDB procedure.
 
+=item $blurb
+
+=item $help
+
+=item $menupath
+
+=item $imagetypes
+
 =item $params
 
 =item $retvals
 
-Both as per L<Gimp/Gimp-E<gt>install_procedure>.
+All as per L<Gimp/Gimp-E<gt>install_procedure>.
 
 =item \&callback
 
diff --git a/MANIFEST b/MANIFEST
index 01f5b69..78df5ff 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -48,6 +48,8 @@ examples/ditherize
 examples/dots
 examples/dust
 examples/example-extension
+examples/example-extension-tester
+examples/example-extension-no-fu
 examples/example-fu
 examples/example-net
 examples/example-no-fu
diff --git a/examples/example-extension b/examples/example-extension
index dbd3433..3bd4ef8 100755
--- a/examples/example-extension
+++ b/examples/example-extension
@@ -1,51 +1,63 @@
-#!/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;
+#!/usr/bin/perl -w
+
+use strict;
+use Gimp qw(:auto __ N_);
+use Gimp::Extension;
+
+#$Gimp::verbose = 1;
+#Gimp::set_trace(TRACE_ALL);
+my $persist = 6;
+
+register_temp
+  'extension_test_temp',
+  "Demo Gimp-Perl temp proc", "Demo a Gimp-Perl extension's temp proc",
+  undef, '',
+  [
+    # must take this parameter first, can take others
+    [ &Gimp::PDB_INT32, 'run_mode', 'Run-mode', 0 ],
+    [ &Gimp::PDB_INT32, 'number', 'Input number', 0 ],
+  ],
+  [ [ &Gimp::PDB_INT32, 'retval', 'Retval', ], ], sub {
+    my ($run_mode, $num) = @_;
+    # here could bring up UI if $run_mode == RUN_INTERACTIVE
+    $persist += $num;
+    $persist;
+  };
+
+podregister { Gtk2->main; };
+
+exit main;
+__END__
+
+=head1 NAME
+
+extension_test - test Gimp::Extension
+
+=head1 SYNOPSIS
+
+<Image>/Filters/Languages/_Perl/Test _Extension
+
+=head1 DESCRIPTION
+
+Description.
+
+=head1 PARAMETERS
+
+ [&Gimp::PDB_INT32, "run_mode", "Interactive:0=yes,1=no"],
+ [&Gimp::PDB_INT32, "num", "internal flags (must be 0)"],
+
+=head1 RETURN VALUES
+
+ [&Gimp::PDB_INT32, "retnum", "Number returned"],
+
+=head1 AUTHOR
+
+Ed J
+
+=head1 DATE
+
+2014-05-03
+
+=head1 LICENSE
+
+Same terms as Gimp-Perl.
diff --git a/examples/example-extension-no-fu b/examples/example-extension-no-fu
new file mode 100755
index 0000000..dbd3433
--- /dev/null
+++ b/examples/example-extension-no-fu
@@ -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/example-extension-tester b/examples/example-extension-tester
new file mode 100755
index 0000000..c29422d
--- /dev/null
+++ b/examples/example-extension-tester
@@ -0,0 +1,35 @@
+#!/usr/bin/perl -w
+
+use Gimp;
+use Gimp::Fu;
+#BEGIN { $Gimp::verbose = 1; }
+Gimp::set_trace(TRACE_ALL);
+
+podregister { die Gimp->extension_test_temp($Gimp::Fu::run_mode, 3) };
+
+exit main;
+__END__
+
+=head1 NAME
+
+test_plugin - Exercise extension temp proc
+
+=head1 SYNOPSIS
+
+<Image>/Filters/Languages/_Perl/Test _CB
+
+=head1 DESCRIPTION
+
+Exercise extension temp proc by calling it and die()ing with result.
+
+=head1 AUTHOR
+
+boilerplate id
+
+=head1 DATE
+
+20140505
+
+=head1 LICENSE
+
+Licence.


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