[gimp] plug-ins: update/fix the 3 non-C goat-exercise.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: update/fix the 3 non-C goat-exercise.
- Date: Thu, 22 Aug 2019 21:03:32 +0000 (UTC)
commit 54dab3285d145761c5d0da11f8b2bcf032abe36a
Author: Jehan <jehan girinstud io>
Date: Thu Aug 22 22:49:45 2019 +0200
plug-ins: update/fix the 3 non-C goat-exercise.
The JS and Python 3 had to be ported to the new GimpImageProcedure API.
The Lua one was still using the old ID API hence was broken. Also not
sure why run_mode enum has become a string in Lua with the new
GimpImageProcedure API (probably some automatic conversion happening
during the C to Lua binding?), but well… it works like that, so what.
Sync also the late changes from the C goat exercise, like for instance
not returning an error when selection is empty as well as keeping the
order of calls to be the same across the 4 supported demo scripts.
plug-ins/goat-exercises/goat-exercise-gjs.js | 44 ++++++---------------
plug-ins/goat-exercises/goat-exercise-lua.lua | 57 +++++++++------------------
plug-ins/goat-exercises/goat-exercise-py3.py | 50 ++++++-----------------
3 files changed, 42 insertions(+), 109 deletions(-)
---
diff --git a/plug-ins/goat-exercises/goat-exercise-gjs.js b/plug-ins/goat-exercises/goat-exercise-gjs.js
index 67e799ad16..991441352c 100755
--- a/plug-ins/goat-exercises/goat-exercise-gjs.js
+++ b/plug-ins/goat-exercises/goat-exercise-gjs.js
@@ -51,41 +51,25 @@ var Goat = GObject.registerClass({
}
vfunc_create_procedure(name) {
- let procedure = Gimp.Procedure.new(this, name, Gimp.PDBProcType.PLUGIN, this.run);
+ let procedure = Gimp.ImageProcedure.new(this, name, Gimp.PDBProcType.PLUGIN, this.run);
+
+ procedure.set_image_types("*");
- procedure.set_image_types("RGB*, INDEXED*, GRAY*");
procedure.set_menu_label("Exercise a JavaScript goat");
+ procedure.set_icon_name(Gimp.ICON_GEGL);
+ procedure.add_menu_path ('<Image>/Filters/Development/Goat exercises/');
+
procedure.set_documentation("Exercise a goat in the JavaScript language (GJS)",
"Takes a goat for a walk in Javascript with the GJS interpreter",
- "");
- procedure.add_menu_path ('<Image>/Filters/Development/Goat exercises/');
+ name);
procedure.set_attribution("Jehan", "Jehan", "2019");
- procedure.set_icon_name(Gimp.ICON_GEGL);
-
-
- procedure.add_argument(GObject.param_spec_enum("run-mode",
- "Run mode",
- "The run mode",
- Gimp.RunMode.$gtype,
- Gimp.RunMode.NONINTERACTIVE,
- GObject.ParamFlags.READWRITE));
- procedure.add_argument(GObject.param_spec_object ("image",
- "Image",
- "The input image",
- Gimp.Image.$gtype,
- GObject.ParamFlags.READWRITE));
- procedure.add_argument(GObject.param_spec_object ("drawable",
- "Drawable",
- "The input drawable",
- Gimp.Drawable.$gtype,
- GObject.ParamFlags.READWRITE));
return procedure;
}
- run(procedure, args, data) {
+ run(procedure, run_mode, image, drawable, args, run_data) {
/* TODO: localization. */
- let run_mode = args.index(0);
+
if (run_mode == Gimp.RunMode.INTERACTIVE) {
Gimp.ui_init("goat-exercise-gjs", false);
/* TODO: help function and ID. */
@@ -156,9 +140,8 @@ var Goat = GObject.registerClass({
}
}
- let drawable = args.index(2);
- let [ success, x, y, width, height ] = drawable.mask_intersect();
- if (success) {
+ let [ intersect, x, y, width, height ] = drawable.mask_intersect();
+ if (intersect) {
Gegl.init(null);
let buffer = drawable.get_buffer();
@@ -185,11 +168,6 @@ var Goat = GObject.registerClass({
drawable.update(x, y, width, height);
Gimp.displays_flush();
}
- else {
- let error = GLib.Error.new_literal(GLib.quark_from_string("goat-error-quark"), 0,
- "No pixels to process in the selected area.");
- return procedure.new_return_values(Gimp.PDBStatusType.CALLING_ERROR, error);
- }
return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, null);
}
diff --git a/plug-ins/goat-exercises/goat-exercise-lua.lua b/plug-ins/goat-exercises/goat-exercise-lua.lua
index 72bc025d89..42952be738 100755
--- a/plug-ins/goat-exercises/goat-exercise-lua.lua
+++ b/plug-ins/goat-exercises/goat-exercise-lua.lua
@@ -32,12 +32,13 @@ local Gdk = lgi.Gdk
local Goat = lgi.package 'Goat'
local Goat = lgi.Goat
-function run(procedure, args, data)
+function run(procedure, run_mode, image, drawable, args, run_data)
-- procedure:new_return_values() crashes LGI so we construct the
-- GimpValueArray manually.
local retval = Gimp.ValueArray(1)
- local run_mode = GObject.Value.get_enum(args:index(0))
- if run_mode == Gimp.RunMode.INTERACTIVE then
+ -- Not sure why run_mode has become a string instead of testing
+ -- against Gimp.RunMode.INTERACTIVE.
+ if run_mode == "INTERACTIVE" then
Gimp.ui_init("goat-exercise-lua", false);
local dialog = Gimp.Dialog {
title = "Exercise a goat (Lua)",
@@ -68,7 +69,6 @@ function run(procedure, args, data)
box:pack_start(label, false, false, 1)
label:show()
- -- TODO: show source.
local contents = GLib.file_get_contents(arg[0])
if (contents) then
local scrolled = Gtk.ScrolledWindow()
@@ -103,13 +103,12 @@ function run(procedure, args, data)
end
end
- local drawable_id = args:index(2):get_int()
- local x, y, width, height = Gimp.drawable_mask_intersect (drawable_id)
+ local x, y, width, height = drawable:mask_intersect()
if width ~= nill and height ~= nil and width > 0 and height > 0 then
Gegl.init(nil)
- local buffer = Gimp.drawable_get_buffer (drawable_id)
- local shadow_buffer = Gimp.drawable_get_shadow_buffer (drawable_id)
+ local buffer = drawable:get_buffer()
+ local shadow_buffer = drawable:get_shadow_buffer()
local graph = Gegl.Node()
local input = graph:create_child("gegl:buffer-source")
@@ -123,15 +122,9 @@ function run(procedure, args, data)
shadow_buffer:flush()
- Gimp.drawable_merge_shadow(drawable_id, true)
- Gimp.drawable_update(drawable_id, x, y, width, height)
+ drawable:merge_shadow(true)
+ drawable:update(x, y, width, height)
Gimp.displays_flush()
- else
- local fail = GObject.Value(Gimp.PDBStatusType, Gimp.PDBStatusType.CALLING_ERROR)
- retval:append(fail)
- local err = GObject.Value(GObject.Type.STRING, "No pixels to process in the selected area.")
- retval:append(err)
- return retval
end
local success = GObject.Value(Gimp.PDBStatusType, Gimp.PDBStatusType.SUCCESS)
@@ -146,32 +139,20 @@ function Goat.Exercise:do_query_procedures()
end
function Goat.Exercise:do_create_procedure(name)
- local procedure = Gimp.Procedure.new(self, name,
- Gimp.PDBProcType.PLUGIN,
- run, nil)
- procedure:set_image_types("RGB*, INDEXED*, GRAY*");
+ local procedure = Gimp.ImageProcedure.new(self, name,
+ Gimp.PDBProcType.PLUGIN,
+ run, nil)
+
+ procedure:set_image_types("*");
+
procedure:set_menu_label("Exercise a Lua goat");
+ procedure:set_icon_name(Gimp.ICON_GEGL);
+ procedure:add_menu_path('<Image>/Filters/Development/Goat exercises/');
+
procedure:set_documentation("Exercise a goat in the Lua language",
"Takes a goat for a walk in Lua",
- "");
- procedure:add_menu_path('<Image>/Filters/Development/Goat exercises/');
+ name);
procedure:set_attribution("Jehan", "Jehan", "2019");
- procedure:add_argument(GObject.param_spec_enum("run-mode",
- "Run mode",
- "The run mode",
- GObject.Type.name(Gimp.RunMode),
- Gimp.RunMode.NONINTERACTIVE,
- GObject.ParamFlags.READWRITE));
- procedure:add_argument(Gimp.param_spec_image_id ("image",
- "Image",
- "The input image",
- false,
- GObject.ParamFlags.READWRITE));
- procedure:add_argument(Gimp.param_spec_drawable_id ("drawable",
- "Drawable",
- "The input drawable",
- false,
- GObject.ParamFlags.READWRITE));
return procedure
end
diff --git a/plug-ins/goat-exercises/goat-exercise-py3.py b/plug-ins/goat-exercises/goat-exercise-py3.py
index 7e293ee64d..bd81b7d1c1 100755
--- a/plug-ins/goat-exercises/goat-exercise-py3.py
+++ b/plug-ins/goat-exercises/goat-exercise-py3.py
@@ -28,23 +28,6 @@ _ = gettext.gettext
def N_(message): return message
class Goat (Gimp.PlugIn):
- ## Parameters ##
- __gproperties__ = {
- "run-mode": (Gimp.RunMode,
- "Run mode",
- "The run mode",
- Gimp.RunMode.NONINTERACTIVE,
- GObject.ParamFlags.READWRITE),
- "image": (Gimp.Image,
- _("Image"),
- _("The input image"),
- GObject.ParamFlags.READWRITE),
- "drawable": (Gimp.Drawable,
- _("Drawable"),
- _("The input drawable"),
- GObject.ParamFlags.READWRITE),
- }
-
## GimpPlugIn virtual methods ##
def do_query_procedures(self):
# Localization
@@ -54,29 +37,25 @@ class Goat (Gimp.PlugIn):
return [ "goat-exercise-python" ]
def do_create_procedure(self, name):
- procedure = Gimp.Procedure.new(self, name,
+ procedure = Gimp.ImageProcedure.new(self, name,
Gimp.PDBProcType.PLUGIN,
self.run, None)
- procedure.set_image_types("RGB*, INDEXED*, GRAY*");
+
+ procedure.set_image_types("*");
+
procedure.set_menu_label("Exercise a goat and a python");
+ procedure.set_icon_name(Gimp.ICON_GEGL);
+ procedure.add_menu_path('<Image>/Filters/Development/Goat exercises/');
+
procedure.set_documentation("Exercise a goat in the Python 3 language",
"Takes a goat for a walk in Python 3",
- "");
- procedure.add_menu_path('<Image>/Filters/Development/Goat exercises/');
+ name);
procedure.set_attribution("Jehan", "Jehan", "2019");
- # XXX pygobject has broken GParamSpec support (see bug
- # pygobject#227). As a special trick, to create arguments and
- # return values, we make them from object properties.
- procedure.add_argument_from_property(self, "run-mode")
- procedure.add_argument_from_property(self, "image")
- procedure.add_argument_from_property(self, "drawable")
return procedure
- def run(self, procedure, args, data):
- runmode = args.index(0)
-
- if runmode == Gimp.RunMode.INTERACTIVE:
+ def run(self, procedure, run_mode, image, drawable, args, run_data):
+ if run_mode == Gimp.RunMode.INTERACTIVE:
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
gi.require_version('Gdk', '3.0')
@@ -148,10 +127,8 @@ class Goat (Gimp.PlugIn):
return procedure.new_return_values(Gimp.PDBStatusType.CANCEL,
GLib.Error())
- drawable = args.index(2)
-
- success, x, y, width, height = drawable.mask_intersect();
- if success:
+ intersect, x, y, width, height = drawable.mask_intersect();
+ if intersect:
Gegl.init(None);
buffer = drawable.get_buffer()
@@ -176,9 +153,6 @@ class Goat (Gimp.PlugIn):
drawable.merge_shadow(True)
drawable.update(x, y, width, height)
Gimp.displays_flush()
- else:
- retval = procedure.new_return_values(Gimp.PDBStatusType.CALLING_ERROR,
- GLib.Error("No pixels to process in the selected area."))
return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]