How to create a GimpFloatArray in Python plugin?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to create a GimpFloatArray in Python plugin?

Developers mailing list
Specifically, to pass as third arg to Gimp.PDB.gimp_pencil(layer, 4 line).
Said argument should be GimpFloatArray according to PDBBrowser.

I create a GimpValueArray to pass args to the pdb.  To create a GValue for
the third arg, I tried:

GObject.Value(Gimp.FloatArray.__gtype__, (1.0, 1.0, 1.0, 1.0)

which throws exception .... Expected: Boxed.
Thrown by pygobject/gi/pygi-value.c about line 556.
At line 537, it seems like it should work if G_VALUE_HOLDS(value,
G_TYPE_ARRAY) for GimpFloatArray gtype.
My understanding is that PyGObject would then create a GArray from the
Python list of floats for the value of the GValue.

My best guess is Gimp is missing GI annotations or implementation for
GimpFloatArray.

Using Gimp 2.99, I am porting GimpFu.

There might be a related problem receiving GimpInt32Array *from* Gimp (not
*to* Gimp as above.)

I suppose I could try the Lua or Scheme binding.
_______________________________________________
gimp-developer-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list
List archives:   https://mail.gnome.org/archives/gimp-developer-list
Reply | Threaded
Open this post in threaded view
|

Re: How to create a GimpFloatArray in Python plugin?

Ofnuts-2
On 2/19/20 9:17 PM, Lloyd Konneker via gimp-developer-list wrote:

> Specifically, to pass as third arg to Gimp.PDB.gimp_pencil(layer, 4 line).
> Said argument should be GimpFloatArray according to PDBBrowser.
>
> I create a GimpValueArray to pass args to the pdb.  To create a GValue for
> the third arg, I tried:
>
> GObject.Value(Gimp.FloatArray.__gtype__, (1.0, 1.0, 1.0, 1.0)
>
> which throws exception .... Expected: Boxed.
> Thrown by pygobject/gi/pygi-value.c about line 556.
> At line 537, it seems like it should work if G_VALUE_HOLDS(value,
> G_TYPE_ARRAY) for GimpFloatArray gtype.
> My understanding is that PyGObject would then create a GArray from the
> Python list of floats for the value of the GValue.
>
> My best guess is Gimp is missing GI annotations or implementation for
> GimpFloatArray.
>
> Using Gimp 2.99, I am porting GimpFu.
>
> There might be a related problem receiving GimpInt32Array *from* Gimp (not
> *to* Gimp as above.)
>
You don't need to do complicated things like that in Python, just use a
Python array of floats.

 ¬†pdb.gimp_pencil(layer,6,[0.,0.,100.,100.,0.,200.])


(draws a '>')

_______________________________________________
gimp-developer-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list
List archives:   https://mail.gnome.org/archives/gimp-developer-list
Reply | Threaded
Open this post in threaded view
|

Re: How to create a GimpFloatArray in Python plugin?

Developers mailing list
In reply to this post by Developers mailing list
Complicated stuff is necessary to implement a new GimpFu, which is what
makes it simple to plugin authors.  I am not writing a plugin, I am testing
old plugins with a new implementation of GimpFu.

In the master branch (version 2.99) of gimp repository you will see some
python plugins that have been ported, and they use PyGObject module (
import gi,  gobject introspection), which, yes, is complicated for many new
authors of plugins. But not too complicated since an author must only use
gi in the boilerplate for registration of the plugin, and otherwise a
plugin looks like ordinary python.  (And maybe a ported GimpFu is necessary
only for backward compatibility of version 2 python plugins.)

But the 2.99 Gimp has many changes to support gobject introspection.  Maybe
my question is: does exist the changes in Gimp 2.99 to support
GimpFloatArray? And I should have said a "version 3" Python plugin.

Sorry if that was not clear by my question, I am so near to the work that I
didn't express the big picture.
_______________________________________________
gimp-developer-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list
List archives:   https://mail.gnome.org/archives/gimp-developer-list
Reply | Threaded
Open this post in threaded view
|

Re: How to create a GimpFloatArray in Python plugin?

Developers mailing list
In reply to this post by Developers mailing list
A small example, also shows the problem, with a slightly different error
message:

   args = Gimp.ValueArray.new(4)
    args.insert(0, GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE))
    args.insert(1, GObject.Value(Gimp.Drawable.__gtype__, drawable))
    args.insert(2, GObject.Value(GObject.TYPE_INT, 4))
    # There is no GObject.TYPE_ARRAY
    #args.insert(3, GObject.Value(GObject.TYPE_ARRAY, (100.0, 100.0, 100.0,
100.0)))
    args.insert(3, GObject.Value(Gimp.FloatArray.__gtype__, (100.0, 100.0,
100.0, 100.0)))
    img = Gimp.get_pdb().run_procedure('gimp-pencil', args)

and get:
    File
"/work/.home/.config/GIMP/2.99/plug-ins/test_float_array/test_float_array.py",
line 28, in foo
    args.insert(3, GObject.Value(Gimp.FloatArray.__gtype__, (100.0, 100.0,
100.0, 100.0)))
  File "/usr/lib/python3/dist-packages/gi/overrides/GObject.py", line 210,
in __init__
    self.set_value(py_value)
  File "/usr/lib/python3/dist-packages/gi/overrides/GObject.py", line 266,
in set_value
    _gi._gvalue_set(self, py_value)
TypeError: Expected Boxed
_______________________________________________
gimp-developer-list mailing list
List address:    [hidden email]
List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list
List archives:   https://mail.gnome.org/archives/gimp-developer-list