10-31-2021, 01:59 PM
The API is originally for script-fu and only uses integer "handles" (that are handle to "items", i.e., image components: layers, masks, channels, paths...). For Python, the API creates façade objects, so that instead of using typeless handles and PDB calls everywhere, you can use methods on the facade objects. And for consistency, calls that return a handle in script-fu return a Python object of the adequate type, and calls with arguments that are handel/items in Script-fu are passed the Python objects.
If you do this:
You get the class hierarchy:
The gimp.Item defines an ID attribute that is the very same thing as the "handle" of items in script-fu (but you very rarely need to use it), and if necessary (read: never in practice...) there are gimp._id2drawable, gimp._id2vectors,gimp._id2image methods to obtain a Python object from its plain handle.
If you do this:
Code:
➤> gimp.image_list()[0].active_layer.__class__.__mro__
You get the class hierarchy:
Code:
(<type 'gimp.Layer'>, <type 'gimp.Drawable'>, <type 'gimp.Item'>, <type 'object'>)
The gimp.Item defines an ID attribute that is the very same thing as the "handle" of items in script-fu (but you very rarely need to use it), and if necessary (read: never in practice...) there are gimp._id2drawable, gimp._id2vectors,gimp._id2image methods to obtain a Python object from its plain handle.