[gimp/wip/nielsdg/args: 325/326] plug-ins: Use pygobject's auto GValue coversion




commit 2b0e442e69cf4b58514e6243865739a7a52639ee
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sun May 24 14:34:37 2020 +0200

    plug-ins: Use pygobject's auto GValue coversion
    
    In the previous commit, we introuced API that lets us use an array of
    `GValue`s rather than a `GimpValueArray` to make the bindings feel more
    native. In this commit, we go a step further and use the ability of
    pygobject to do automatic GValue conversion to make the API even
    simpler (note that this possibly might not work in each language binding
    though).

 plug-ins/python/colorxhtml.py      |  4 +--
 plug-ins/python/file-openraster.py | 57 +++++++++++++++++---------------------
 plug-ins/python/foggify.py         | 10 +++----
 plug-ins/python/spyro-plus.py      |  6 ++--
 4 files changed, 34 insertions(+), 43 deletions(-)
---
diff --git a/plug-ins/python/colorxhtml.py b/plug-ins/python/colorxhtml.py
index bb5946ab71..49374e1a4d 100755
--- a/plug-ins/python/colorxhtml.py
+++ b/plug-ins/python/colorxhtml.py
@@ -267,9 +267,7 @@ def save_colorxhtml(procedure, run_mode, image, drawable, file, args, data):
     if separate:
         css.close()
 
-    return Gimp.ValueArray.new([
-        GObject.Value(Gimp.PDBStatusType, Gimp.PDBStatusType.SUCCESS)
-    ])
+    return Gimp.ValueArray.new([ Gimp.PDBStatusType.SUCCESS ])
 
 
 class ColorXhtml(Gimp.PlugIn):
diff --git a/plug-ins/python/file-openraster.py b/plug-ins/python/file-openraster.py
index 2f2ef40623..8f149a28cd 100755
--- a/plug-ins/python/file-openraster.py
+++ b/plug-ins/python/file-openraster.py
@@ -92,8 +92,8 @@ def thumbnail_ora(procedure, file, thumb_size, args, data):
         fid.write(orafile.read('Thumbnails/thumbnail.png'))
 
     img = Gimp.get_pdb().run_procedure('file-png-load', [
-        GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE),
-        GObject.Value(GObject.TYPE_STRING, tmp),
+        Gimp.RunMode.NONINTERACTIVE,
+        tmp,
     ])
     img = img.index(1)
     img = Gimp.Image.get_by_id(img)
@@ -102,12 +102,12 @@ def thumbnail_ora(procedure, file, thumb_size, args, data):
     os.rmdir(tempdir)
 
     return Gimp.ValueArray.new_from_values([
-        GObject.Value(Gimp.PDBStatusType, Gimp.PDBStatusType.SUCCESS),
-        GObject.Value(Gimp.Image, img),
-        GObject.Value(GObject.TYPE_INT, w),
-        GObject.Value(GObject.TYPE_INT, h),
-        GObject.Value(Gimp.ImageType, Gimp.ImageType.RGB_IMAGE),
-        GObject.Value(GObject.TYPE_INT, 1)
+        Gimp.PDBStatusType.SUCCESS,
+        img,
+        w,
+        h,
+        Gimp.ImageType.RGB_IMAGE,
+        1
     ])
 
 def save_ora(procedure, run_mode, image, drawable, file, args, data):
@@ -138,18 +138,18 @@ def save_ora(procedure, run_mode, image, drawable, file, args, data):
         interlace, compression = 0, 2
 
         Gimp.get_pdb().run_procedure('file-png-save', [
-            GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE),
-            GObject.Value(Gimp.Image, image),
-            GObject.Value(Gimp.Drawable, drawable),
-            GObject.Value(GObject.TYPE_STRING, tmp),
-            GObject.Value(GObject.TYPE_STRING, 'tmp.png'),
-            GObject.Value(GObject.TYPE_BOOLEAN, interlace),
-            GObject.Value(GObject.TYPE_INT, compression),
+            Gimp.RunMode.NONINTERACTIVE,
+            image,
+            drawable,
+            tmp,
+            'tmp.png',
+            interlace,
+            compression,
             # write all PNG chunks except oFFs(ets)
-            GObject.Value(GObject.TYPE_BOOLEAN, True),
-            GObject.Value(GObject.TYPE_BOOLEAN, True),
-            GObject.Value(GObject.TYPE_BOOLEAN, False),
-            GObject.Value(GObject.TYPE_BOOLEAN, True),
+            True,
+            True,
+            False,
+            True,
         ])
         orafile.write(tmp, path)
         os.remove(tmp)
@@ -220,9 +220,7 @@ def save_ora(procedure, run_mode, image, drawable, file, args, data):
             add_layer(parent, x, y, opac, lay, path_name, lay.get_visible())
 
     # save mergedimage
-    thumb = Gimp.get_pdb().run_procedure('gimp-image-duplicate', [
-        GObject.Value(Gimp.Image, image),
-    ])
+    thumb = Gimp.get_pdb().run_procedure('gimp-image-duplicate', [ image ])
     thumb = thumb.index(1)
     thumb = Gimp.Image.get_by_id(thumb)
     thumb_layer = thumb.merge_visible_layers (Gimp.MergeType.CLIP_TO_IMAGE)
@@ -253,9 +251,7 @@ def save_ora(procedure, run_mode, image, drawable, file, args, data):
         os.remove(file.peek_path()) # win32 needs that
     os.rename(file.peek_path() + '.tmpsave', file.peek_path())
 
-    return Gimp.ValueArray.new_from_values([
-        GObject.Value(Gimp.PDBStatusType, Gimp.PDBStatusType.SUCCESS)
-    ])
+    return Gimp.ValueArray.new_from_values([ Gimp.PDBStatusType.SUCCESS ])
 
 def load_ora(procedure, run_mode, file, args, data):
     tempdir = tempfile.mkdtemp('gimp-plugin-file-openraster')
@@ -312,9 +308,9 @@ def load_ora(procedure, run_mode, file, args, data):
 
             # import layer, set attributes and add to image
             gimp_layer = Gimp.get_pdb().run_procedure('gimp-file-load-layer', [
-                GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE),
-                GObject.Value(Gimp.Image, img),
-                GObject.Value(GObject.TYPE_STRING, tmp),
+                Gimp.RunMode.NONINTERACTIVE,
+                img,
+                tmp
             ])
             gimp_layer = gimp_layer.index(1)
             gimp_layer = Gimp.Item.get_by_id(gimp_layer)
@@ -338,10 +334,7 @@ def load_ora(procedure, run_mode, file, args, data):
 
     os.rmdir(tempdir)
 
-    return Gimp.ValueArray.new_from_values([
-        GObject.Value(Gimp.PDBStatusType, Gimp.PDBStatusType.SUCCESS),
-        GObject.Value(Gimp.Image, img),
-    ])
+    return Gimp.ValueArray.new_from_values([ Gimp.PDBStatusType.SUCCESS, img ])
 
 
 class FileOpenRaster (Gimp.PlugIn):
diff --git a/plug-ins/python/foggify.py b/plug-ins/python/foggify.py
index 7f26a11c66..dbb20d29fe 100755
--- a/plug-ins/python/foggify.py
+++ b/plug-ins/python/foggify.py
@@ -59,11 +59,11 @@ def foggify(procedure, run_mode, image, drawable, args, data):
 
     # add some clouds to the layer
     Gimp.get_pdb().run_procedure('plug-in-plasma', [
-        GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE),
-        GObject.Value(Gimp.Image, image),
-        GObject.Value(Gimp.Drawable, mask),
-        GObject.Value(GObject.TYPE_INT, int(time.time())),
-        GObject.Value(GObject.TYPE_DOUBLE, turbulence),
+        Gimp.RunMode.NONINTERACTIVE,
+        image,
+        mask,
+        int(time.time()),
+        turbulence,
     ])
 
     # apply the clouds to the layer
diff --git a/plug-ins/python/spyro-plus.py b/plug-ins/python/spyro-plus.py
index f095b9130a..73ecdbfd18 100644
--- a/plug-ins/python/spyro-plus.py
+++ b/plug-ins/python/spyro-plus.py
@@ -377,9 +377,9 @@ class SelectionToPath:
             selection_was_empty = False
 
         result = Gimp.get_pdb().run_procedure('plug-in-sel2path', [
-            GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE),
-            GObject.Value(Gimp.Image, self.image),
-            GObject.Value(Gimp.Drawable, self.image.get_active_layer()),
+            Gimp.RunMode.NONINTERACTIVE,
+            self.image,
+            self.image.get_active_layer(),
         ])
 
         self.path = self.image.get_vectors()[0]


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