Reputation: 2016
Some Gimp methods exposed via GI (GObject introspection) expect a GValue whose value is a GArray of float. In Python, can I create an array.array of float and expect PyGObject to marshal it correctly to a GArray? (loosely speaking, to a pointer to a float and an integer count of elements in the array.)
Specifically, Gimp 2.99 (the development branch) has in its API:
@accepts(GObject.Value, float, gsize)
@returns(none)
def value_set_float_array(value, array, length):
# Python wrapper for gimp_value_set_float_array()
IOW it really expects an address (pointer) to the first float of many floats contiguous in memory, an 'array'. If in Python I create an array.array containing four floats, and pass it as the second argument to Gimp.value_set_float_array(), will PyGObject do the right thing?
I know I could just try it, or read the PyGObject code. But even if I could get it to work, I believe that the Gimp API might be better if it had a constructor for a GValue (or a constructor for another Gimp type Gimp.FloatArray) that accepted a GArray. Then my understanding is that PyGObject would automatically marshal a Python list of floats into a GArray. In other words, my question is about guidance for architecture of GObject introspected API's.
Gimp supports other bindings, such as Lua and Scheme. It seems to me that Gimp should support GArray arguments, which would probably support all the bindings.
(The question springs from trying to use type Gimp.FloatArray, which doesn't seem to be a GObject. Maybe the problem is larger, that Gimp should base Gimp.FloatArray on GObject?)
Upvotes: 1
Views: 285
Reputation: 2312
I believe it can work, you just need to use the (element-type float)
annotation in the docs: https://wiki.gnome.org/Projects/GObjectIntrospection/Annotations
Upvotes: 0