[gimp/wip/Jehan/signals-GIMP: 2/4] plug-ins: implement handling of "destroyed" in the 3 goat-exercises.



commit 97641f0a804c41ab304c5316b10be4576d9ca4e9
Author: Jehan <jehan girinstud io>
Date:   Thu Aug 15 22:22:11 2019 +0200

    plug-ins: implement handling of "destroyed" in the 3 goat-exercises.
    
    This is a crude handling, mostly as demo. I just quit when the original
    image was destroyed.

 plug-ins/goat-exercises/goat-exercise-c.c    | 17 +++++++++++++++++
 plug-ins/goat-exercises/goat-exercise-gjs.js |  8 ++++++++
 plug-ins/goat-exercises/goat-exercise-py3.py | 10 ++++++++++
 3 files changed, 35 insertions(+)
---
diff --git a/plug-ins/goat-exercises/goat-exercise-c.c b/plug-ins/goat-exercises/goat-exercise-c.c
index 1ec6354171..1c38f059a7 100644
--- a/plug-ins/goat-exercises/goat-exercise-c.c
+++ b/plug-ins/goat-exercises/goat-exercise-c.c
@@ -68,6 +68,9 @@ static GimpValueArray * goat_run              (GimpProcedure        *procedure,
                                                const GimpValueArray *args,
                                                gpointer              run_data);
 
+static void             goat_image_destroyed  (GimpImage            *image,
+                                               gpointer              data);
+
 
 G_DEFINE_TYPE (Goat, goat, GIMP_TYPE_PLUG_IN)
 
@@ -138,6 +141,13 @@ goat_run (GimpProcedure        *procedure,
 
   INIT_I18N();
 
+  gimp_plug_in_extension_enable (gimp_get_plug_in());
+
+  image = g_value_get_object (gimp_value_array_index (args, 1));
+  g_signal_connect (image, "destroyed",
+                    G_CALLBACK (goat_image_destroyed),
+                    NULL);
+
   /* In interactive mode, display a dialog to advertize the exercise. */
   if (run_mode == GIMP_RUN_INTERACTIVE)
     {
@@ -264,3 +274,10 @@ goat_run (GimpProcedure        *procedure,
 
   return gimp_procedure_new_return_values (procedure, status, NULL);
 }
+
+static void
+goat_image_destroyed (GimpImage *image,
+                      gpointer   data)
+{
+  gimp_quit();
+}
diff --git a/plug-ins/goat-exercises/goat-exercise-gjs.js b/plug-ins/goat-exercises/goat-exercise-gjs.js
index 67e799ad16..7de3382df9 100755
--- a/plug-ins/goat-exercises/goat-exercise-gjs.js
+++ b/plug-ins/goat-exercises/goat-exercise-gjs.js
@@ -84,8 +84,16 @@ var Goat = GObject.registerClass({
     }
 
     run(procedure, args, data) {
+        Gimp.get_plug_in().extension_enable();
+
         /* TODO: localization. */
         let run_mode = args.index(0);
+        let image    = args.index(1);
+
+        image.connect("destroyed", (image) => {
+            Gimp.quit();
+        });
+
         if (run_mode == Gimp.RunMode.INTERACTIVE) {
             Gimp.ui_init("goat-exercise-gjs", false);
             /* TODO: help function and ID. */
diff --git a/plug-ins/goat-exercises/goat-exercise-py3.py b/plug-ins/goat-exercises/goat-exercise-py3.py
index 7e293ee64d..ec5401ab22 100755
--- a/plug-ins/goat-exercises/goat-exercise-py3.py
+++ b/plug-ins/goat-exercises/goat-exercise-py3.py
@@ -73,8 +73,18 @@ class Goat (Gimp.PlugIn):
 
         return procedure
 
+    def on_image_destroyed(self, image):
+        # This is a very simple demonstration on signals. Here I simply
+        # quit the plug-in if the image we were working on has been
+        # destroyed.
+        Gimp.quit()
+
     def run(self, procedure, args, data):
+        Gimp.get_plug_in().extension_enable()
         runmode = args.index(0)
+        image   = args.index(1)
+
+        image.connect("destroyed", self.on_image_destroyed);
 
         if runmode == Gimp.RunMode.INTERACTIVE:
             gi.require_version('Gtk', '3.0')


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