GNOME Bugzilla – Bug 777092
Image.insert_layer() doesn't accept an unspecified parent
Last modified: 2018-05-24 17:19:44 UTC
With the PDB procedure a layer can be inserted in the main stack using None as the parent: >>>pdb.gimp_image_insert_layer(image, layer, None, -1)
But when using the equivalent gimp.Image method, a layer object must be specified: >>> image.insert_layer(layer, None, -1) Traceback (most recent call last):
+ Trace 237051
TypeError: insert_layer() argument 2 must be gimp.Layer, not None
(also tried with 0 and got similar results) (bug posted in two parts due to a bugzilla problem)
The problem lies with the way GIMP Python validates parameters - unlike Python, these methods are made in C, and there is some static type checking that sees that "Python's None is not a GimpLayer" thing there. The argument for the method is, though, optional - you simply don't pass the`parent` argument, and pass in the position as a names parameter. That is: image.insert_layer(layer, position=-1) I will try to fix it to accept None as the parent as well, to keep the signature on pair with the PDB call - but omitting the parameter will use the default "None" (-1) internally and will work from GIMP 2.8.5 or something.
While you are at it: use image.new_layer instead of creating a layer and inserting it on the image. - it does create a new layer already added to the image and has suitable defaults. The optional parameters are: "name", "width", "height", "offset_x", "offset_y", "alpha", "pos", "opacity", "mode", "fill_mode", (It does not accept specifying a parent layer group, though)
Nice workaround. Thanks.
Joao, and progress here?
*any* :)
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gimp/issues/1036.