Reputation: 4077
The PDB's documentation/naming convention is rather backwards if you're trying to do things with python in gimp and hard to figure out. I eventually found gimp.GroupLayer
(PDB lists gimp-layer-group-new
) to create a new layer group. How do you insert this into the image though and have it show up as a layer group?
I've been trying stuff like this:
img = gimp.image_list()[0]
gl = gimp.GroupLayer(img, "Should be a folder", 1, 1, 0)
img.insert_layer(gl)
The first thing that really confuses me is that it expects me to specify a height & width for the GroupLayer, even though it should just act as a container for other actual layers (it's expecting this because it inherits from Layer
, but that's another matter).
The real problem is that when I insert the newly created GroupLayer
, it shows up as a normal layer (no folder in the layer icon). I've verified this by making two layers, one a normal layer, and one a group layer. I add the group layer to the image, and then try to add the normal layer to the image with the group layer as a parent:
img = gimp.image_list()[0]
gl = gimp.GroupLayer(img, "Group Layer", 1, 1, 0)
l = gimp.Layer(img, "Real Layer", 1, 1, 0)
img.insert_layer(gl)
img.insert_layer(l, gl) # gl should be the parent
All I get is the error:
Calling error for procedure 'gimp-image-insert-layer':
Item 'group layer #1' (34) cannot be used because it is not a group item`
Has anyone else figured this out?
UPDATE
by Joao S. O. Bueno
I've just fixed this issue in gimp-git. Frgom gimp 2.8.12 on,
calling gimp.GroupLayer works with the
gimp.GroupLayer(img, [name="", opacity=100.0, mode=gimp.NORMAL_MODE])
signature.
Upvotes: 4
Views: 2054
Reputation: 110456
It seems that there is a bug in the creation of gimp.GroupLayer - and it behaves as a normal layer, even though the object type, in Python, is shown as a group-layer.
It is possible to create a working group layer through the PDB, though, using pdb.gimp_layer_group_new(img)
- this time, tehre is another bug, the object appears in Python as being a nromal Layer object - but after inserting it in the image with
pdb.gimp_image_insert_layer(image, layer, <parent (use None for top level)>, <position>)
it works properly (and retrieving the object through the image "layer" attribute will give you
a proper GroupLayer object).
Sorry for that - most of it is my fault - I will see if I can get the behavior fixed for the next GIMP 2.8 - GIMP 2.8 almost shipped with no support for layer groups from Python at all.
update: As of GIMP 2.8.12, calling gimp.GroupLayer(image, ...) creates a proper layer group.
Upvotes: 3