diff --git a/ChangeLog b/ChangeLog index 2616983cd5..1de2c5b1eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2005-09-25 Carol Spears + + * plug-ins/common/max_rgb.c moved menu entry from Colors to + Colors/Info. + + * plug-ins/common/smooth_palette.c moved menu entry from Colors to + Colors/Info. + + * plug-ins/common/semiflatten.c removed menu entry from Colors and + added it to Filters/Web + + * plug-ins/pygimp/plug-ins/py-slice.py added the patch from + Joao S. O. Bueno Calligaris that was attached to + http://bugzilla.gnome.org/show_bug.cgi?id=159564 + 2005-09-25 Michael Natterer * app/actions/edit-actions.c @@ -24,6 +39,7 @@ * app/tools/gimpforegroundselecttool.c: changed tooltip, the tool doesn't any longer extract single objects only. +>>>>>>> 1.11734 2005-09-25 Sven Neumann * libgimpwidgets/gimpwidgetsenums.[ch]: removed GimpZoomWidgetType. diff --git a/plug-ins/common/max_rgb.c b/plug-ins/common/max_rgb.c index 4a562d43d4..395a4edf5f 100644 --- a/plug-ins/common/max_rgb.c +++ b/plug-ins/common/max_rgb.c @@ -101,7 +101,7 @@ query (void) G_N_ELEMENTS (args), 0, args, NULL); - gimp_plugin_menu_register (PLUG_IN_PROC, "/Colors"); + gimp_plugin_menu_register (PLUG_IN_PROC, "/Colors/Info"); } static void diff --git a/plug-ins/common/semiflatten.c b/plug-ins/common/semiflatten.c index a4bf6d4b9a..1c2be04ac5 100644 --- a/plug-ins/common/semiflatten.c +++ b/plug-ins/common/semiflatten.c @@ -80,7 +80,7 @@ query (void) G_N_ELEMENTS (args), 0, args, NULL); - gimp_plugin_menu_register (PLUG_IN_PROC, "/Colors"); + gimp_plugin_menu_register (PLUG_IN_PROC, "/Filters/Web"); gimp_plugin_menu_register (PLUG_IN_PROC, "/Layer/Transparency/Modify"); } diff --git a/plug-ins/common/smooth_palette.c b/plug-ins/common/smooth_palette.c index 7ab405f18a..86c348be2f 100644 --- a/plug-ins/common/smooth_palette.c +++ b/plug-ins/common/smooth_palette.c @@ -91,7 +91,7 @@ query (void) G_N_ELEMENTS (args), G_N_ELEMENTS (return_vals), args, return_vals); - gimp_plugin_menu_register (PLUG_IN_PROC, "/Colors"); + gimp_plugin_menu_register (PLUG_IN_PROC, "/Colors/Info"); } static struct diff --git a/plug-ins/pygimp/plug-ins/py-slice.py b/plug-ins/pygimp/plug-ins/py-slice.py index 733ee28b16..cd7a8ea290 100755 --- a/plug-ins/pygimp/plug-ins/py-slice.py +++ b/plug-ins/pygimp/plug-ins/py-slice.py @@ -1,4 +1,8 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- + +#Copyright (c) Manish Singh +#javascript animation support by Joao S. O. Bueno Calligaris (2004) # Gimp-Python - allows the writing of Gimp plugins in Python. # Copyright (C) 2003, 2005 Manish Singh @@ -17,13 +21,31 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# (c) 2003 Manish Singh. +#"Guillotine implemented ala python, with html output +# (based on perlotine by Seth Burgess)", +# Modified by João S. O. Bueno Calligaris to allow dhtml animations (2005) + import os from gimpfu import * +import os.path def pyslice(image, drawable, save_path, html_filename, image_basename, image_extension, separate, - image_path, capitalize, cellspacing): + image_path, cellspacing, animate, skip_caps): + if animate: + count = 0 + drw = [] + #image.layers is a reversed list of the layers on the image + #so, count indexes from number of layers to 0. + for i in xrange (len (image.layers) -1, -1, -1): + if image.layers[i].visible: + drw.append(image.layers[i]) + count += 1 + if count == 3: + break + vert, horz = get_guides(image) @@ -41,7 +63,7 @@ def pyslice(image, drawable, save_path, html_filename, os.mkdir(path) return path - + save_path = check_path(save_path) if not os.path.isdir(save_path): @@ -49,13 +71,15 @@ def pyslice(image, drawable, save_path, html_filename, if separate: image_relative_path = image_path + if not image_relative_path.endswith("/"): + image_relative_path += "/" image_path = check_path(os.path.join(save_path, image_path)) else: image_relative_path = '' image_path = save_path tw = TableWriter(os.path.join(save_path, html_filename), - cellspacing=cellspacing, capitalize=capitalize) + cellspacing=cellspacing, animate=animate) top = 0 @@ -74,19 +98,30 @@ def pyslice(image, drawable, save_path, html_filename, right = image.width else: right = image.get_guide_position(vert[j]) - - src = slice(image, image_path, image_basename, image_extension, - left, right, top, bottom, i, j) - - if image_relative_path: - if image_relative_path.endswith('/'): - src_path = image_relative_path + src - else: - src_path = image_relative_path + '/' + src + if (skip_caps and + ( + (len(horz) >= 2 and (i == 0 or i == len(horz) )) or + (len(vert) >= 2 and (j == 0 or j == len(vert) )) + ) + ): + skip_stub = True else: - src_path = src + skip_stub = False - tw.cell(src_path, right - left, bottom - top) + if (not animate or skip_stub): + src = (image_relative_path + + slice (image, None, image_path, + image_basename, image_extension, + left, right, top, bottom, i, j, "")) + else: + src = [] + for layer, postfix in zip (drw, ("", "hover", "clicked")): + src.append (image_relative_path + + slice(image, layer, image_path, + image_basename, image_extension, + left, right, top, bottom, i, j, postfix)) + + tw.cell(src, right - left, bottom - top, i, j, skip_stub) left = right + cellspacing @@ -99,20 +134,49 @@ def pyslice(image, drawable, save_path, html_filename, tw.close() -def slice(image, image_path, image_basename, image_extension, - left, right, top, bottom, i, j): - src = "%s-%d-%d.%s" % (image_basename, i, j, image_extension) +def slice(image, drawable, image_path, image_basename, image_extension, + left, right, top, bottom, i, j, postfix): + if postfix: + postfix = "_" + postfix + src = "%s_%d_%d%s.%s" % (image_basename, i, j, postfix, image_extension) filename = os.path.join(image_path, src) - temp_image = image.duplicate() + if not drawable: + temp_image = image.duplicate() + temp_drawable = temp_image.active_layer + else: + if image.base_type == INDEXED: + #gimp_layer_new_from_drawable doesn't work for indexed images. + #(no colormap on new images) + original_active = image.active_layer + image.active_layer = drawable + temp_image = image.duplicate() + temp_drawable = temp_image.active_layer + image.active_layer = original_active + temp_image.disable_undo() + #remove all layers but the intended one + while len (temp_image.layers) > 1: + if temp_image.layers[0] != temp_drawable: + pdb.gimp_image_remove_layer (temp_image, temp_image.layers[0]) + else: + pdb.gimp_image_remove_layer (temp_image, temp_image.layers[1]) + else: + temp_image = pdb.gimp_image_new (drawable.width, drawable.height, + image.base_type) + temp_drawable = pdb.gimp_layer_new_from_drawable (drawable, temp_image) + temp_image.add_layer (temp_drawable, -1) + temp_image.disable_undo() - temp_image.crop(right - left, bottom - top, left, top) - - pdb.gimp_file_save(temp_image, temp_image.active_layer, filename, filename) - + if image_extension == "gif" and image.base_type == RGB: + pdb.gimp_image_convert_indexed (temp_image,NO_DITHER, MAKE_PALETTE, 255, + True, False, False) + if image_extension == "jpg" and image.base_type == INDEXED: + pdb.gimp_image_convert_rgb (temp_image) + + pdb.gimp_file_save(temp_image, temp_drawable, filename, filename) + gimp.delete(temp_image) - return src class GuideIter: @@ -157,60 +221,206 @@ def get_guides(image): class TableWriter: def __init__(self, filename, cellpadding=0, cellspacing=0, border=0, - capitalize=False): + animate=False): + + self.filename = filename self.table_attrs = {} + #Hellraisen IE 6 doesn't support CSS for table control. self.table_attrs['cellpadding'] = cellpadding self.table_attrs['cellspacing'] = cellspacing self.table_attrs['border'] = border - self.capitalize = capitalize + self.image_prefix = os.path.basename (filename) + self.image_prefix = self.image_prefix.split(".")[0] + self.image_prefix = self.image_prefix.replace ("-", "_") + self.image_prefix = self.image_prefix.replace (" ", "_") - self.html = file(filename, 'w') + + if animate: + self.animate = True + self.images = [] + else: + self.animate = False + if os.path.exists (filename): + #The plug-in is running to overwrite a previous + #version of the file. This will parse the href targets already + #in the file to preserve them. + self.urls = self.parse_urls () + else: + self.urls = [] + + self.url_index = 0 + + self.html = open(filename, 'wt') self.open() + + def next_url (self): + if self.url_index < len (self.urls): + self.url_index += 1 + return self.urls [self.url_index - 1] + else: + #Default url to use in the anchor tags: + return ("#") def write(self, s, vals=None): - if self.capitalize: - s = s.upper() - s = s.replace('%S', '%s') - else: - s = s.lower() - if vals: s = s % vals self.html.write(s + '\n') def open(self): - out = ') for your URLS to have it working +as a menu. + -->\n''' + out += '') - self.html.close() + self.write('\n') + prefix = self.image_prefix + if self.animate: + out = """ + + +""" + self.write (out) + def row_start(self): - self.write('\t') + self.write(' ') def row_end(self): - self.write('\t') + self.write('\n') - def cell(self, src, width, height): - out = ('\t\t ' % - (width, height)) - self.write(out, src) + def cell(self, src, width, height, row=0, col=0, skip_stub = False): + if isinstance (src, list): + prefix = "images_%s" % self.image_prefix + self.images.append ({"index" : (row, col), "plain" : src[0]}) + out = (' = 2: + self.images[-1]["hover"] = src [1] + out += """ onmouseout="exchange(this, '%s', 0);"\n""" % \ + prefix + out += """ onmouseover="exchange(this, '%s', 1);"\n""" % \ + prefix + if len(src) >= 3: + self.images[-1]["clicked"] = src [2] + out += """ onmousedown="exchange(this, '%s', 2);"\n""" % \ + prefix + out += """ onmouseup="exchange(this, '%s', 3);"\n""" % \ + prefix + + + + out += "/>\n" + + else: + if skip_stub: + out = ('  ') % \ + (src, width, height) + else: + out = ('  ' + + '') % (src, width, height) + self.write(out) + def parse_urls (self): + """ + This will parse any url targets in the href="XX" fields + of the given file and return then as a list + """ + import re + url_list = [] + try: + html_file = open (self.filename) + + #Regular expression to pick everything up to the next doublequote + #character after finding the sequence 'href="'. The found sequences + #will be returned as a list by the "findall" method. + expr = re.compile (r"""href\=\"([^\"]*?)\"""") + url_list = expr.findall (html_file.read (2 ** 18)) + html_file.close() + + except: + #silently ignore any errors parsing this. The file being + #ovewriten may not be a file genrated by py-slice. + pass + + return url_list + register( "py_slice", - "Guillotine implemented ala python, with html output (based on perlotine by Seth Burgess)", - "Add guides to an image. Then run this. It will cut along the guides, and give you the html to reassemble the resulting images.", + """Cuts an image along its guides and save subimages and a HTML \ +table snippet. If "generate javascript..." is enabled, the 3 topmost visible \ +layers are used as clicked, mouse over and normal views.""", + + """Add guides to an image. Then run this. It will cut along the guides, + and give you the html to reassemble the resulting images. If you + choose to generate javascript for onmouseover and clicked events, it + will use the lower three visible layers on the image for normal, + onmouseover and clicked states, in that order. If skip caps is + enabled, table cells on the edge of the table won't become animated, + and its images will be taken from the active layer.""", "Manish Singh", "Manish Singh", "2003", @@ -220,11 +430,18 @@ register( (PF_STRING, "save_path", "The path to export the HTML to", os.getcwd()), (PF_STRING, "html_filename", "Filename to export", "py-slice.html"), (PF_STRING, "image_basename", "What to call the images", "pyslice"), - (PF_RADIO, "image_extension", "The format of the images: {gif, jpg, png}", "gif", (("gif", "gif"), ("jpg", "jpg"), ("png", "png"))), - (PF_TOGGLE, "separate_image_dir", "Use a separate directory for images?", False), - (PF_STRING, "relative_image_path", "The path to export the images to, relative to the Save Path", "images/"), - (PF_TOGGLE, "capitalize_tags", "Capitalize HTML tags?", False), - (PF_SPINNER, "cellspacing", "Add space between the table elements", 0, (0,15,1)) + (PF_RADIO, "image_extension", "The format of the images: {gif, jpg, png}", + "gif", (("gif", "gif"), ("jpg", "jpg"), ("png", "png"))), + (PF_TOGGLE, "separate_image_dir", "Use a separate directory for images?", + False), + (PF_STRING, "relative_image_path", "The path where to export the" + + " images, relative to the Save Path", "images/"), + (PF_SPINNER, "cellspacing", "Add space between the table elements", 0, + (0,15,1)), + (PF_TOGGLE, "animate", "Generate javascript for onmouseover and clicked?", + False), + (PF_TOGGLE, "skip_caps", "Skip animation for table caps?", True) + ], [], pyslice)