[gimp-perl] Correctly handle returning of selected vals for storing



commit 9e4ce40f913d225166524384d5aa92f5ed5aecda
Author: Ed J <edj src gnome org>
Date:   Thu Nov 20 04:00:38 2014 +0000

    Correctly handle returning of selected vals for storing

 Gimp/Fu.pm |   69 ++++++++++++++++++++++++++++++-----------------------------
 UI/UI.pm   |   21 ++++++++---------
 2 files changed, 45 insertions(+), 45 deletions(-)
---
diff --git a/Gimp/Fu.pm b/Gimp/Fu.pm
index cd5caef..91981a7 100644
--- a/Gimp/Fu.pm
+++ b/Gimp/Fu.pm
@@ -230,10 +230,11 @@ Gimp::on_net {
       push @$params, [
         PF_FILE, 'gimp_fu_outputfile', 'Output file', $latest_imagefile
       ] unless $outputfile;
-      (my $res,@args)=interact(
-       $function, $blurb, $help, $params, $menupath, undef, @args
+      (my $res, my $input_vals, undef)=interact(
+       $function, $blurb, $help, $params, $menupath, undef, [], \ args
       );
       return unless $res;
+      @args = @$input_vals;
       $outputfile = pop @args unless $outputfile;
    }
    my $input_image = $args[0] if ref $args[0] eq "Gimp::Image";
@@ -300,7 +301,14 @@ sub make_ui_closure {
    sub {
       warn "$$-Gimp::Fu closure: (@_)\n" if $Gimp::verbose >= 2;
       $run_mode = defined($menupath) ? shift : Gimp::RUN_NONINTERACTIVE;
-      my(@pre,@defaults,@lastvals);
+      if (
+        $run_mode != Gimp::RUN_NONINTERACTIVE and
+        $run_mode != Gimp::RUN_INTERACTIVE and
+         $run_mode != Gimp::RUN_WITH_LAST_VALS
+      ) {
+         die __"run_mode must be INTERACTIVE, NONINTERACTIVE or RUN_WITH_LAST_VALS\n";
+      }
+      my @pre;
 
       # set default arguments
       for (0..$#{$params}) {
@@ -329,10 +337,12 @@ sub make_ui_closure {
          }
       }
       warn "perlsub: rm=$run_mode" if $Gimp::verbose >= 2;
+      warn "$$-Gimp::Fu-generated sub: $function(",join(",",(@pre,@_)),")\n"
+        if $Gimp::verbose >= 2;
+      my @retvals;
       if ($run_mode == Gimp::RUN_NONINTERACTIVE) {
-         # nop
-      } elsif ($run_mode == Gimp::RUN_INTERACTIVE
-          || $run_mode == Gimp::RUN_WITH_LAST_VALS) {
+        @retvals = $code->(@pre, @_);
+      } else {
          my $fudata = $Gimp::Data{"$function/_fu_data"};
         if ($fudata) {
            my $data_savetime = shift @$fudata;
@@ -345,37 +355,28 @@ sub make_ui_closure {
            require Data::Dumper;
            warn "$$-retrieved fudata: ", Data::Dumper::Dumper($fudata);
         }
-
          if ($run_mode == Gimp::RUN_WITH_LAST_VALS && $fudata) {
-            @_ = @$fudata;
-         } else {
-            if (@_) {
-               # prevent the standard arguments from showing up in interact
-               my @hide = splice @$params, 0, scalar @pre;
-
-               my $res;
-               ($res,@_) = interact(
-                 $function, $blurb, $help, $params, $menupath, undef, @$fudata
-              );
-               return (undef) x @$results unless $res;
-
-               unshift @$params, @hide;
-            }
+           @retvals = $code->(@pre, @$fudata);
+         } elsif (! _) {
+           @retvals = $code->(@pre, @_);
+        } else {
+           # prevent the standard arguments from showing up in interact
+           my @hide = splice @$params, 0, scalar @pre;
+           my ($res, $input_vals, $return_vals) = interact(
+              $function, $blurb, $help, $params, $menupath, $code,
+              \ pre, $fudata,
+           );
+           return (undef) x @$results unless $res;
+           unshift @$params, @hide;
+           @_ = @$input_vals;
+           @retvals = @$return_vals;
          }
-      } else {
-         die __"run_mode must be INTERACTIVE, NONINTERACTIVE or RUN_WITH_LAST_VALS\n";
-      }
-
-      if ($Gimp::verbose >= 2) {
-        require Data::Dumper;
-        warn "$$-storing fudata: ", Data::Dumper::Dumper(\ _);
+        if ($Gimp::verbose >= 2) {
+           require Data::Dumper;
+           warn "$$-storing fudata: ", Data::Dumper::Dumper(\ _);
+        }
+        $Gimp::Data{"$function/_fu_data"}=[time, @_];
       }
-      $Gimp::Data{"$function/_fu_data"}=[time, @_];
-
-      warn "$$-Gimp::Fu-generated sub: $function(",join(",",(@pre,@_)),")\n"
-        if $Gimp::verbose >= 2;
-
-      my @retvals = $code->(@pre,@_);
       Gimp->displays_flush;
       wantarray ? @retvals : $retvals[0];
    };
diff --git a/UI/UI.pm b/UI/UI.pm
index 45bf38b..bbf7842 100644
--- a/UI/UI.pm
+++ b/UI/UI.pm
@@ -622,6 +622,7 @@ my %PF2INFO = (
 sub interact {
   warn __PACKAGE__ . "::interact(@_)" if $Gimp::verbose >= 2;
   my ($function, $blurb, $help, $params, $menupath, $code) = splice @_, 0, 6;
+  my ($silent_vals, $start_vals) = @_;
   my (@getvals, @setvals, @lastvals, @defaults);
   my $helpwin;
 
@@ -651,7 +652,7 @@ sub interact {
   my $row = 0;
   for(@$params) {
     my ($type,$name,$desc,$default,$extra)= $_;
-    my ($value)=shift;
+    my ($value)=shift @$start_vals;
     $value=$default unless defined $value;
     die sprintf __"Unsupported argumenttype %s for %s\n", $type, $name
       unless $PF2INFO{$type};
@@ -689,7 +690,6 @@ sub interact {
   $button->signal_connect(clicked => sub {
     $mainloop->quit;
   });
-  my @uservals;
   can_default $button 1;
   $button = $w->add_button('gtk-ok', 1);
   $button->signal_connect(clicked => sub {
@@ -710,10 +710,11 @@ sub interact {
   show_all $w;
   $mainloop->run;
   die $exception_text if $exception_text;
-  @uservals = map {&$_} @getvals if $res;
+  my @input_vals = map {&$_} @getvals if $res;
+  my @return_vals = $code->(@$silent_vals, @input_vals) if $res and $code;
   $w->destroy;
-  return unless $res;
-  return (1, @uservals);
+  return (0, \ input_vals, []) unless $res;
+  return (1, \ input_vals, \ return_vals);
 }
 
 1;
@@ -744,14 +745,12 @@ C<examples/example-no-fu>.
  $button = new Gimp::UI::GradientSelect;
 
  # if $code = undef, just run the UI and return the Ok/Cancel and values
- ($result, @new_vals) = Gimp::UI::interact(
-   $functionname, $blurb, $help, $params, $menupath, undef, @previous_vals
+ ($result, \ input_vals, \ return_vals) = Gimp::UI::interact(
+   $functionname, $blurb, $help, $params, $menupath, $code,
+   \ silent_vals, # don't show in UI or return in \ input_vals
+   \ start_vals, # do show in UI and return in \ input_vals
  ); # $result = true if "Ok", false if "Cancel"
 
- @return_vals = Gimp::UI::interact(
-   $functionname, $blurb, $help, $params, $menupath, \&code, @previous_vals
- );
-
 =back
 
 =head1 AUTHOR


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