[gimp-perl] Make Gimp::UI use sliders/spinners for PF_INT*. Bug 728070



commit 225ccadd9d8b7e68d55c1d90e7163e3873ef44ca
Author: Ed J <m8r-35s8eo mailinator com>
Date:   Sat Apr 12 02:27:24 2014 +0100

    Make Gimp::UI use sliders/spinners for PF_INT*. Bug 728070

 Gimp/Config.pm.in    |    2 +-
 Gimp/Fu.pm           |   33 +++++++++++++++++++++------------
 Makefile.PL          |    2 +-
 UI/UI.pm             |   21 ++++++++++++---------
 config.pl            |    2 +-
 examples/Makefile.PL |   22 +++++++++++++++++-----
 examples/dialogtest  |    1 +
 t/gimpsetup.pl       |    2 +-
 t/perlplugin.t       |   11 -----------
 9 files changed, 55 insertions(+), 41 deletions(-)
---
diff --git a/Gimp/Config.pm.in b/Gimp/Config.pm.in
index bb0946e..35aa8e8 100644
--- a/Gimp/Config.pm.in
+++ b/Gimp/Config.pm.in
@@ -14,7 +14,7 @@ C<$Gimp::Config{KEY}>. Some important keys are:
   IN_GIMP      => true when gimp-perl was part of the Gimp distribution.
   GIMP         => the path of the gimp executable
   GIMPTOOL     => the path of the gimptool executable
-  gimpplugindir        => the gimp plug-in directory (without the /plug-ins-suffix)
+  gimpplugindir        => the actual gimp plug-in directory
 
 =head1 SEE ALSO
 
diff --git a/Gimp/Fu.pm b/Gimp/Fu.pm
index dc6ca2a..fd17a4d 100644
--- a/Gimp/Fu.pm
+++ b/Gimp/Fu.pm
@@ -46,7 +46,6 @@ use constant {
 
 use constant {
   PF_BOOL => PF_TOGGLE,
-  PF_INT => PF_INT32,
   PF_VALUE => PF_STRING,
 };
 
@@ -121,7 +120,7 @@ my @scripts;
 
 my @_params=qw(PF_INT8 PF_INT16 PF_INT32 PF_FLOAT PF_VALUE PF_STRING PF_COLOR
             PF_COLOUR PF_TOGGLE PF_IMAGE PF_DRAWABLE PF_FONT PF_LAYER
-            PF_CHANNEL PF_BOOL PF_SLIDER PF_INT PF_SPINNER PF_ADJUSTMENT
+            PF_CHANNEL PF_BOOL PF_SLIDER PF_SPINNER PF_ADJUSTMENT
             PF_BRUSH PF_PATTERN PF_GRADIENT PF_RADIO PF_CUSTOM PF_FILE
             PF_TEXT);
 
@@ -536,18 +535,27 @@ written in other languages.
 
 =over 2
 
-=item PF_INT8, PF_INT16, PF_INT32, PF_INT, PF_FLOAT, PF_STRING, PF_VALUE
+=item PF_INT8, PF_INT16, PF_INT32
 
-Are all mapped to a string entry, since perl doesn't really distinguish
-between all these datatypes. The reason they exist is to help other scripts
-(possibly written in other languages! Really!). It's nice to be able to
-specify a float as 13.45 instead of "13.45" in C! C<PF_VALUE> is synonymous
-to C<PF_STRING>, and <PF_INT> is synonymous to <PF_INT32>.
+All mapped to sliders with suitable min/max.
+
+=item PF_FLOAT, PF_VALUE
+
+For C<PF_FLOAT> (or C<PF_VALUE>, a synonym), you should probably use a
+C<PF_ADJUSTMENT> with suitable values.
+
+=item PF_STRING
+
+A string.
 
 =item PF_COLOR, PF_COLOUR
 
 Will accept a colour argument. In dialogs, a colour preview will be created
-which will open a colour selection box when clicked.
+which will open a colour selection box when clicked. The default value
+needs to be a suitable Gimp-Perl colour; see L<Gimp::canonicalize_colour>.
+
+ [ PF_COLOR, 'colour', 'Input colour', 'white' ],
+ [ PF_COLOR, 'colour2', 'Input colour 2', [ 255, 128, 0 ] ],
 
 =item PF_IMAGE
 
@@ -948,11 +956,12 @@ sub main {
    $old_trace = Gimp::set_trace (0);
    if ($Gimp::help) {
       my $this=this_script;
-      print __"       interface-arguments are
-           -o | --output <filespec>   write image to disk, don't display
+      print __<<EOF;
+       interface-arguments are
+           -o | --output <filespec>   write image to disk
            -i | --interact            let the user edit the values first
        script-arguments are
-";
+EOF
       print_switches ($this);
    } else {
       Gimp::main;
diff --git a/Makefile.PL b/Makefile.PL
index 0bfde5e..f5d274f 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -4,7 +4,7 @@ use Data::Dumper qw(Dumper);
 use ExtUtils::MakeMaker;
 use IO::All;
 
-require 'config.pl';
+require './config.pl';
 
 sub MY::postamble {
    my $self=shift;
diff --git a/UI/UI.pm b/UI/UI.pm
index c574902..12e250b 100644
--- a/UI/UI.pm
+++ b/UI/UI.pm
@@ -496,20 +496,23 @@ sub interact($$$$@) {
            $extra=[ x];
         }
 
+        if ($type == PF_INT8) {
+          $type = PF_SLIDER;
+          $extra = [ 0, 255, 1 ];
+       }
+
+       if ($type == PF_INT16 || $type == PF_INT32) {
+          $type = PF_SPINNER;
+          my $max = ($type == PF_INT16 ? 1 << 15 : 1 << 31);
+          $extra = [ -$max, $max - 1, 1 ];
+       }
+
         $value=$default unless defined $value;
         # massage label text a small bit (works only for english)
         $label="$name: ";
         $label =~ y/_/ /; $label =~ s/^(\w)/\U$1/g;
 
-#TODO: While mapping all to one is nifty programming, it makes for a lousy
-# interface.  Sure would be nice to have dialog elements that reflected
-# the type a bit better (spinbuttons/range checking for integral for instance).
-
-        if ($type == PF_INT8           # perl just maps
-        || $type == PF_INT16           # all this crap
-        || $type == PF_INT32           # into the scalar
-        || $type == PF_FLOAT           # domain.
-        || $type == PF_STRING) {       # I love it
+        if ($type == PF_FLOAT || $type == PF_STRING) {
            &new_PF_STRING;
 
         } elsif ($type == PF_FONT) {
diff --git a/config.pl b/config.pl
index 652f9d1..db39e9b 100644
--- a/config.pl
+++ b/config.pl
@@ -17,7 +17,7 @@ die "Need GIMP version at least 2.8.0\n" unless $gimpbinname >= 2.8;
 %cfg = (
   GIMP => expand($gimppath . "gimp-" . $gimpbinname),
   GIMPTOOL => $gimptool,
-  gimpplugindir => $plugindir,
+  gimpplugindir => "$plugindir/plug-ins",
   GIMP_LIBS => exp_topdir($pluginlibs),
   GIMP_LIBS_NOUI => exp_topdir($gimpcfg{"libs"}),
   GIMP_CFLAGS => " -I$topdir -Ddatadir=\"\\\"".expand($datadir).'\\"" '
diff --git a/examples/Makefile.PL b/examples/Makefile.PL
index f1a185e..57dab89 100644
--- a/examples/Makefile.PL
+++ b/examples/Makefile.PL
@@ -35,7 +35,18 @@ require '../config.pl';
   pixelmap
 );
 
-sub plugin_target {
+sub install_plugin_target {
+  my $plugin = shift;
+  my $src = '$(INST_PLUGINS)/'.basename($plugin);
+  my $dest = '$(GIMP_PLUGINS)/'.basename($plugin);
+  <<EOF;
+$dest : $src
+       \$(NOECHO) $cfg{GIMPTOOL} --install-admin-bin "$src"
+
+EOF
+}
+
+sub build_plugin_target {
   my $plugin = shift;
   my $dest = '$(INST_PLUGINS)/'.basename($plugin);
   <<EOF;
@@ -50,18 +61,20 @@ EOF
 
 sub MY::postamble {
    my $self=shift;
-   my $GT = "$cfg{GIMPTOOL} --install-admin-bin";
    my $UT = "$cfg{GIMPTOOL} --uninstall-admin-bin";
    <<EOF;
 
 INST_PLUGINS = ../blib/plugins
+GIMP_PLUGINS = $cfg{gimpplugindir}
 
 \$(INST_PLUGINS)\$(DFSEP).exists :: Makefile.PL
        \$(NOECHO) \$(MKPATH) \$(INST_PLUGINS)
        \$(NOECHO) \$(CHMOD) \$(PERM_DIR) \$(INST_PLUGINS)
        \$(NOECHO) \$(TOUCH) \$(INST_PLUGINS)\$(DFSEP).exists
 
- {[ join '', map { plugin_target($_) } @pins ]}
+ {[ join '', map { build_plugin_target($_) } @pins ]}
+
+ {[ join '', map { install_plugin_target($_) } @pins ]}
 
 install :: install-plugins
 
@@ -69,8 +82,7 @@ pure_all :: pure_plugins
 
 pure_plugins : @{[ map { "\$(INST_PLUGINS)/".basename($_) } @pins ]}
 
-install-plugins :: pure_plugins
-       cd \$(INST_PLUGINS) ; for p in * ; do $GT "\$\$p" ; done
+install-plugins : @{[ map { "\$(GIMP_PLUGINS)/".basename($_) } @pins ]}
 
 uninstall ::
        cd \$(INST_PLUGINS); for plugin in *; do $UT "\$\$plugin"; done
diff --git a/examples/dialogtest b/examples/dialogtest
index 9356cd9..ef9569a 100755
--- a/examples/dialogtest
+++ b/examples/dialogtest
@@ -16,6 +16,7 @@ use Gimp::Fu;
     [ PF_INT16, "int16", "Int16", 100],
     [ PF_INT32, "int32", "Int32", 100],
     [ PF_FLOAT, "float", "FLOAT", 100],
+    [ PF_STRING, "string", "string", 'text'],
   ],
   sub { }
 );
diff --git a/t/gimpsetup.pl b/t/gimpsetup.pl
index b81a2df..9c872da 100644
--- a/t/gimpsetup.pl
+++ b/t/gimpsetup.pl
@@ -14,7 +14,7 @@ require Gimp::Config;
 
 our $DEBUG = 0 unless defined $DEBUG;
 
-my $sysplugins = $Gimp::Config{gimpplugindir} . '/plug-ins';
+my $sysplugins = $Gimp::Config{gimpplugindir};
 die "plugins dir: $!" unless -d $sysplugins;
 die "script-fu not executable: $!" unless -x "$sysplugins/script-fu";
 
diff --git a/t/perlplugin.t b/t/perlplugin.t
index e20bb3e..5e475a1 100644
--- a/t/perlplugin.t
+++ b/t/perlplugin.t
@@ -143,17 +143,6 @@ sub boilerplate_params {
   }
 );
 
-&register(
-  "test_dialogs",
-  boilerplate_params('dialogs', '<None>'),
-  [
-    [ PF_COLOR, "colour", "Image colour", [255, 127, 0], ],
-    [ PF_FONT, "font", "Font", 'Arial', ],
-    [ PF_INT32, "size", "Size", 100],
-  ],
-  sub { }
-);
-
 exit main;
 EOF
 }


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