creating a toolbox with menu items

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have made a python plugin that registers a couple of scripts (I
wanted something that does less than 'Make seamless' does; the script
is attached for the curious).

They scripts appear in the image's menu, but I would like to be able
to add them to a toolbox (even better, to the main toolbox).

Is this possible? For example, is it possible to:
* put a button in a toolbox
* attach an icon to the button
* attach a script to the button

Is there a way to register my scripts so that they appear next to the
compiled-in tools (like the 'Pencil', 'Paintbrush', etc) ?

Thanx,

Ionutz
#! /usr/bin/python

from gimpfu import *

def hide_visible(img):
	"hide visible layers and returns them as a list"
	ret = []
	for l in img.layers:
		if l.visible:
			ret.append(l)
			l.visible = 0
	return ret

def get_position(img, l0):
	"retrieve position for layer l0"
	ret = 0
	for l in img.layers[::-1]:
		if l == l0:
			return ret
		ret += 1
	return ret

def set_position(img, l0, pos):
	"move layer l0 to position pos"
	pos0 = get_position(img, l0)

	if pos > pos0:
		for x in range(pos - pos0):
			img.raise_layer(l0)
	elif pos < pos0:
		for x in range(pos0 - pos):
			img.lower_layer(l0)

def tileable(timage, tdrawable, x1, x2, y1, y2):
	img = timage

	# compute some values
	w = img.width
	h = img.height
	
	w1 = int(w * x1 / float(x1 + x2))
	w2 = w - w1

	h1 = int(h * y1 / float(y1 + y2))
	h2 = h - h1

	img.undo_group_start()

	l0 = timage.active_layer

	pos = get_position(img, l0) # store layer position
	visible = hide_visible(img) # hides existing layers, storing their visibility

	# create 4 layers and displace them
	l1 = l0.copy()
	l1.translate(w1,h1)
	l1.visible = 1
	img.add_layer(l1, 0)
	
	l2 = l0.copy()
	l2.translate(-w2,-h2)
	l2.visible = 1
	img.add_layer(l2, 0)

	l3 = l0.copy()
	l3.translate(w1,-h2)
	l3.visible = 1
	img.add_layer(l3, 0)

	l4 = l0.copy()
	l4.translate(-w2,h1)
	l4.visible = 1
	img.add_layer(l4, 0)
	
	# merge the visible layers
	l5 = img.merge_visible_layers(CLIP_TO_IMAGE)
	
	# restore old visibility
	for l in visible:
		l.visible = 1
	
	# remove the original layer and set the name of the 
	# new one the same with that of the original
	name = l0.name
	img.remove_layer(l0)
	l5.name = name

	# set the new layer in the same position as the old one
	set_position(img, l5, pos)

	img.undo_group_end()

def tileable31(timage, tdrawable):
	tileable(timage, tdrawable, 3, 1, 3, 1)

def tileable13(timage, tdrawable):
	tileable(timage, tdrawable, 1, 3, 1, 3)

def tileable22(timage, tdrawable):
	tileable(timage, tdrawable, 2, 2, 2, 2)

def tileable2V(timage, tdrawable):
	tileable(timage, tdrawable, 2, 0, 2, 2)

def tileable2H(timage, tdrawable):
	tileable(timage, tdrawable, 2, 2, 2, 0)

register(
	"python_fu_tileable13",
	"Split image in 2x2 rects and swap them (for creating tileable textures)",
	"Split image in 2x2 rects and swap them (for creating tileable textures)",
	"Ionutz Borcoman",
	"Ionutz Borcoman",
	"2009",
	"<Image>/IonSoft/Tileable texture 1-3...",
	"RGB*, GRAY*",
	[],
	[],
	tileable13
	)

register(
	"python_fu_tileable31",
	"Split image in 2x2 rects and swap them (for creating tileable textures)",
	"Split image in 2x2 rects and swap them (for creating tileable textures)",
	"Ionutz Borcoman",
	"Ionutz Borcoman",
	"2009",
	"<Image>/IonSoft/Tileable texture 3-1...",
	"RGB*, GRAY*",
	[],
	[],
	tileable31
	)

register(
	"python_fu_tileable22",
	"Split image in 2x2 equal rects and swap them (for creating tileable textures)",
	"Split image in 2x2 equal rects and swap them (for creating tileable textures)",
	"Ionutz Borcoman",
	"Ionutz Borcoman",
	"2009",
	"<Image>/IonSoft/Tileable texture 2-2...",
	"RGB*, GRAY*",
	[],
	[],
	tileable22
	)

register(
	"python_fu_tileable2V",
	"Split image in 2x2 equal rects and swap them (for creating tileable textures)",
	"Split image in 2x2 equal rects and swap them (for creating tileable textures)",
	"Ionutz Borcoman",
	"Ionutz Borcoman",
	"2009",
	"<Image>/IonSoft/Tileable texture 2V...",
	"RGB*, GRAY*",
	[],
	[],
	tileable2V
	)

register(
	"python_fu_tileable2H",
	"Split image in 2x2 equal rects and swap them (for creating tileable textures)",
	"Split image in 2x2 equal rects and swap them (for creating tileable textures)",
	"Ionutz Borcoman",
	"Ionutz Borcoman",
	"2009",
	"<Image>/IonSoft/Tileable texture 2H...",
	"RGB*, GRAY*",
	[],
	[],
	tileable2H
	)

main()
_______________________________________________
Gimp-developer mailing list
Gimp-developer@xxxxxxxxxxxxxxxxxxxxxx
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer

[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux