[gimp/wip/Jehan/classy-GIMP: 32/55] plug-ins: improve parameter creation on Python 3 goat-exercise.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/wip/Jehan/classy-GIMP: 32/55] plug-ins: improve parameter creation on Python 3 goat-exercise.
- Date: Tue, 20 Aug 2019 10:20:37 +0000 (UTC)
commit df24695801a6b03f6fe53e324a1963247edce687
Author: Jehan <jehan girinstud io>
Date: Thu Aug 15 09:04:37 2019 +0200
plug-ins: improve parameter creation on Python 3 goat-exercise.
PyGObject seems to have at least 3 syntaxes to create object properties.
Though the one I used previously was apparently the recommended syntax,
it was clearly a bit messy and not clear. This alternative syntax ends
up much more compact, really look alike the C-style, which is a good
thing and is very visual. From what I can see, we should also override
the get|set_property() methods, but since we are not going to actually
set any value (this is only a workaround to make a GParamSpec), it seems
to work fine without.
plug-ins/goat-exercises/goat-exercise-py3.py | 54 ++++++++++------------------
1 file changed, 19 insertions(+), 35 deletions(-)
---
diff --git a/plug-ins/goat-exercises/goat-exercise-py3.py b/plug-ins/goat-exercises/goat-exercise-py3.py
index 77d71ea870..7e293ee64d 100755
--- a/plug-ins/goat-exercises/goat-exercise-py3.py
+++ b/plug-ins/goat-exercises/goat-exercise-py3.py
@@ -28,41 +28,22 @@ _ = gettext.gettext
def N_(message): return message
class Goat (Gimp.PlugIn):
- ## Parameter: run-mode ##
- @GObject.Property(type=Gimp.RunMode,
- default=Gimp.RunMode.NONINTERACTIVE,
- nick="Run mode", blurb="The run mode")
- def run_mode(self):
- """Read-write integer property."""
- return self._run_mode
-
- @run_mode.setter
- def run_mode(self, run_mode):
- self._run_mode = run_mode
-
- ## Parameter: image ##
- @GObject.Property(type=Gimp.Image,
- default=0,
- nick= _("Image"),
- blurb= _("The input image"))
- def image(self):
- return self._image
-
- @image.setter
- def image(self, image):
- self._image = image
-
- ## Parameter: drawable ##
- @GObject.Property(type=Gimp.Drawable,
- default=0,
- nick= _("Drawable"),
- blurb= _("The input drawable"))
- def drawable(self):
- return self._drawable
-
- @drawable.setter
- def drawable(self, drawable):
- self._drawable = drawable
+ ## 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):
@@ -83,6 +64,9 @@ class Goat (Gimp.PlugIn):
"");
procedure.add_menu_path('<Image>/Filters/Development/Goat exercises/');
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")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]