After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 777092 - Image.insert_layer() doesn't accept an unspecified parent
Image.insert_layer() doesn't accept an unspecified parent
Status: RESOLVED OBSOLETE
Product: GIMP
Classification: Other
Component: Gimp-Python
2.8.18
Other All
: Normal normal
: ---
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2017-01-10 13:52 UTC by Ofnuts
Modified: 2018-05-24 17:19 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Ofnuts 2017-01-10 13:52:41 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)
Comment 1 Ofnuts 2017-01-10 13:54:02 UTC
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):
  • File "<input>", line 1 in <module>
    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)
Comment 2 Joao S. O. Bueno 2017-01-10 18:25:41 UTC
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.
Comment 3 Joao S. O. Bueno 2017-01-10 18:28:40 UTC
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)
Comment 4 Ofnuts 2017-01-10 23:38:13 UTC
Nice workaround. Thanks.
Comment 5 Michael Natterer 2018-01-03 01:42:32 UTC
Joao, and progress here?
Comment 6 Michael Natterer 2018-01-03 01:47:20 UTC
*any* :)
Comment 7 GNOME Infrastructure Team 2018-05-24 17:19:44 UTC
-- 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.