3 # Gimp-Python - allows the writing of Gimp plugins in Python.
4 # Copyright (C) 2007 Renato Chencarek <renato.chencarek@openbossa.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 # cp gimp-edje-export.py ~/.gimp/plug-ins/
23 # chmod +x ~/.gimp/plug-ins/gimp-edje-export.py
26 # - ~/.gimp may change depending on gimp version, ie: ~/.gimp-2.4.
27 # - Make sure this file is marked as executable!
30 # Load an image and go to "Python-Fu > Edje Save" that will
31 # appear on the image's window.
39 def save_layer(layer, filename):
40 temp_image = pdb.gimp_image_new (layer.width, layer.height, layer.image.base_type)
41 temp_drawable = pdb.gimp_layer_new_from_drawable (layer, temp_image)
42 temp_image.add_layer (temp_drawable, -1)
43 pdb.gimp_file_save(temp_image, temp_drawable, filename, filename)
44 gimp.delete(temp_image)
47 def write_image_section(layers, edje_file, filenames):
48 edje_file.write("images {\n")
50 edje_file.write(' image: "%s" COMP;\n' % filenames[layer.name])
51 edje_file.write("\n}\n")
53 def write_layer_data(layer, edje_file, filename):
54 expr = re.compile('\W')
55 name = expr.sub("_", layer.name)
56 data = {'name':name, 'width':layer.width, 'height':layer.height,
57 'x0':layer.offsets[0], 'y0':layer.offsets[1],
58 'x1':layer.offsets[0] + layer.width, 'y1':layer.offsets[1] + layer.height,
59 'path':filename, 'visible':int(layer.visible)
68 min: %(width)d %(height)d;
69 max: %(width)d %(height)d;
72 offset: %(x0)d %(y0)d;
76 offset: %(x1)d %(y1)d;
86 def fix_layers_name(img, save_path):
88 for layer in img.layers:
89 expr = re.compile('\W')
90 name = expr.sub("_", layer.name)
94 if name in filenames.keys():
96 filename = os.path.join(save_path, name + ".png")
97 filenames[name] = filename
101 def edje_save(img, drawable, save_path, save_layers, edje_filename, invisible):
104 for layer in img.layers:
105 if layer.visible or invisible:
106 expr = re.compile('\W')
107 name = expr.sub("_", layer.name)
109 if name in filenames.keys():
111 filename = os.path.join(save_path, name + ".png")
112 filenames[name] = filename
115 edje_file = open(os.path.join(save_path, edje_filename), 'w')
116 write_image_section(layers, edje_file, filenames)
118 edje_file.write('collections {\n group {\n name: "%s";\n' % img.name)
119 edje_file.write(' min: %d %d;\n max: %d %d;\n parts {\n' % (img.width, img.height,img.width, img.height))
123 save_layer(l, filenames[l.name])
124 write_layer_data(l, edje_file,filenames[l.name])
125 edje_file.write(' }\n }\n}\n')
129 "python_fu_edje_save",
130 "Export the Image as Edje file",
131 "Export the Image as Edje file",
135 "<Image>/Python-Fu/_Edje Save",
138 (PF_STRING, "save_path", "Path", "/tmp/"),
139 (PF_TOGGLE, "save_layers", "Save Layers ?", True),
140 (PF_STRING, "edje_filename", "Filename for edje", "edje.edc"),
141 (PF_TOGGLE, "export_invisible_layers", "Export invisible layers", False)