Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIMP Python-fu nested group layers

Tags:

gimp

python-fu

I can't seem to find any methods for adding a Group Layer to another Group Layer anywhere in the python-fu interface.

I've tried to find methods on the Gimp.Layer objects as well but with no luck.

How do I add a group layer to another group layer with python-fu?

like image 507
Larpon Avatar asked Dec 14 '12 16:12

Larpon


1 Answers

The support to layer groups on Python-fu was added on the last minutes before 2.8 release, and is rather incomplete.

So, the only way to create a proper layer group in GIMP 2.8 is to use the pdb call:

group = pdb.gimp_layer_group_new(img)
group.name = "my group"

(Using the img.GroupLayer call is buggy on gimp 2.8 - should be the way to go in the future)

Once you have your group, you can insert it anywhere on the image using a

pdb.gimp_image_insert_layer(<img>, <layer>, <parent>, <position>)

Like in:

>>> img = gimp.Image(640, 480, RGB)
>>> pdb.gimp_display_new(img)
<display>
>>> parent_group = pdb.gimp_layer_group_new(img)
>>> child_group_1 = pdb.gimp_layer_group_new(img)
>>> child_group_2 = pdb.gimp_layer_group_new(img)
>>> grand_child_group = pdb.gimp_layer_group_new(img)
>>> img.add_layer(parent_group, 0)
>>> pdb.gimp_image_insert_layer(img, child_group_1, parent_group,0)
>>> pdb.gimp_image_insert_layer(img, child_group_2, parent_group,1)
>>> pdb.gimp_image_insert_layer(img, grand_child_group, child_group_1,0)
>>> l1 = gimp.Layer(img, "test", 320,240)
>>> pdb.gimp_image_insert_layer(img,l1, grand_child_group,0)

So, indeed, there is this extreme API asymmetry, in which you add layers and groups to the image through an "add_layer" method on the parent, but have to add either to a layer group, you have to go troguh the pdb.gimp_image_insert_layer call.

update (Feb/2015) - The bug for gimp.GroupLayer() is fixed in GIMP's git and it will work properly from GIMP 2.8.16 onward. Now all one has to do to add a new group layer is:

>>> g = gimp.GroupLayer(img)
>>> pdb.gimp_image_insert_layer(img, g, None, 0)
like image 74
jsbueno Avatar answered Oct 05 '22 07:10

jsbueno