[gimp/wip/Jehan/classy-GIMP: 35/45] plug-ins: implement handling of "destroyed" in the 3 goat-exercises.



commit 75dc5a626daa128e4a3a30aeb7f1efe62cc18b56
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    | 18 ++++++++++++++++++
 plug-ins/goat-exercises/goat-exercise-gjs.js |  8 ++++++++
 plug-ins/goat-exercises/goat-exercise-py3.py | 10 ++++++++++
 3 files changed, 36 insertions(+)
---
diff --git a/plug-ins/goat-exercises/goat-exercise-c.c b/plug-ins/goat-exercises/goat-exercise-c.c
index baae32a640..b4196f6621 100644
--- a/plug-ins/goat-exercises/goat-exercise-c.c
+++ b/plug-ins/goat-exercises/goat-exercise-c.c
@@ -67,6 +67,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)
 
@@ -153,11 +156,19 @@ goat_run (GimpProcedure        *procedure,
 {
   GimpPDBStatusType status = GIMP_PDB_SUCCESS;
   GimpRunMode       run_mode;
+  GimpImage        *image;
   GimpDrawable     *drawable;
   gint              x, y, width, height;
 
   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. */
   run_mode = g_value_get_enum (gimp_value_array_index (args, 0));
   if (run_mode == GIMP_RUN_INTERACTIVE)
@@ -293,3 +304,10 @@ goat_error_quark (void)
 {
   return g_quark_from_static_string ("goat-error-quark");
 }
+
+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]