Gimp 2.8 Plugin Script - How do you add a new GroupLayer?

The PDB documentation / naming convention is quite the opposite if you are trying to do something with python in gimp and are hard to understand. I ended up finding gimp.GroupLayer (PDB lists gimp-layer-group-new ) to create a new layer group. How do you paste this into an image, and do you display it as a group of layers?

I tried things 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 bothers me is that it expects me to specify height and width for GroupLayer, although it should just act as a container for other real layers (it expects this because it inherits from Layer , but that’s another matter) .

The real problem is that when I insert the newly created GroupLayer , it appears as a normal layer (there is no folder on the layer icon). I checked this by creating two layers: one is normal, one is group. I add a group layer to the image, and then try to add a normal layer to the image with the group layer as the 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 an 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

Joao S.O. Bueno

I just fixed this problem in gimp-git. Frgom gimp 2.8.12 on,
The call to gimp.GroupLayer works with the gimp.GroupLayer(img, [name="", opacity=100.0, mode=gimp.NORMAL_MODE]) signature.

+4
source share
1 answer

There seems to be a mistake in creating gimp.GroupLayer - and it behaves like a normal level, although the type of an object in Python is shown as a group type.

You can create a workgroup layer via PDB, but when using pdb.gimp_layer_group_new(img) - this time tehre is another mistake, the object appears in Python as a Nromal Layer object, but after pasting it into the image with pdb.gimp_image_insert_layer(image, layer, <parent (use None for top level)>, <position>) it works correctly (and retrieving an object through the "layer" attribute of the image will give you the corresponding GroupLayer object).

Sorry for this - most of them are my mistake - I will see if I can get the behavior fixed for the next GIMP 2.8 - GIMP 2.8, almost sent without the support of layer groups from Python in general.

update : with GIMP 2.8.12, calling gimp.GroupLayer (image, ...) creates a suitable layer group.

+3
source

Source: https://habr.com/ru/post/1436439/


All Articles