allow '-' in procedure and parameter names.

2006-08-16  Sven Neumann  <sven@gimp.org>

	* plug-ins/pygimp/gimpfu.py: allow '-' in procedure and
parameter
	names.

	* plug-ins/pygimp/plug-ins/*.py: use canonical procedure and
	parameter names.
This commit is contained in:
Sven Neumann 2006-08-16 20:48:45 +00:00 committed by Sven Neumann
parent 8ecf3cdf49
commit 7728c808e5
16 changed files with 103 additions and 91 deletions

View file

@ -1,3 +1,11 @@
2006-08-16 Sven Neumann <sven@gimp.org>
* plug-ins/pygimp/gimpfu.py: allow '-' in procedure and parameter
names.
* plug-ins/pygimp/plug-ins/*.py: use canonical procedure and
parameter names.
2006-08-16 Sven Neumann <sven@gimp.org>
* plug-ins/pygimp/plug-ins/*.py: use gimp_plugin_menu_register().

View file

@ -148,22 +148,22 @@ _type_mapping = {
_registered_plugins_ = {}
def register(func_name, blurb, help, author, copyright, date, menupath,
def register(proc_name, blurb, help, author, copyright, date, menupath,
imagetypes, params, results, function,
on_query=None, on_run=None):
'''This is called to register a new plugin.'''
# First perform some sanity checks on the data
def letterCheck(str):
allowed = _string.letters + _string.digits + '_'
allowed = _string.letters + _string.digits + '_' + '-'
for ch in str:
if not ch in allowed:
return 0
return 0
else:
return 1
if not letterCheck(func_name):
raise error, "function name contains illegal characters"
if not letterCheck(proc_name):
raise error, "procedure name contains illegal characters"
for ent in params:
if len(ent) < 4:
@ -189,19 +189,23 @@ def register(func_name, blurb, help, author, copyright, date, menupath,
plugin_type = PLUGIN
if not func_name[:7] == 'python_' and \
not func_name[:10] == 'extension_' and \
not func_name[:8] == 'plug_in_' and \
not func_name[:5] == 'file_':
func_name = 'python_fu_' + func_name
if not proc_name[:7] == 'python-' and \
not proc_name[:7] == 'python_' and \
not proc_name[:10] == 'extension-' and \
not proc_name[:10] == 'extension_' and \
not proc_name[:8] == 'plug-in-' and \
not proc_name[:8] == 'plug_in_' and \
not proc_name[:5] == 'file-' and \
not proc_name[:5] == 'file_':
proc_name = 'python-fu-' + proc_name
_registered_plugins_[func_name] = (blurb, help, author, copyright,
_registered_plugins_[proc_name] = (blurb, help, author, copyright,
date, menupath, imagetypes,
plugin_type, params, results,
function, on_query, on_run)
file_params = [(PDB_STRING, "filename", "The name of the file"),
(PDB_STRING, "raw_filename", "The name of the file")]
(PDB_STRING, "raw-filename", "The name of the file")]
def _query():
for plugin in _registered_plugins_.keys():
@ -237,14 +241,14 @@ def _query():
if on_query:
on_query()
def _get_defaults(func_name):
def _get_defaults(proc_name):
import gimpshelf
(blurb, help, author, copyright, date,
menupath, imagetypes, plugin_type,
params, results, function,
on_query, on_run) = _registered_plugins_[func_name]
on_query, on_run) = _registered_plugins_[proc_name]
key = "python-fu-save--" + func_name
key = "python-fu-save--" + proc_name
if gimpshelf.shelf.has_key(key):
return gimpshelf.shelf[key]
@ -252,17 +256,17 @@ def _get_defaults(func_name):
# return the default values
return [x[3] for x in params]
def _set_defaults(func_name, defaults):
def _set_defaults(proc_name, defaults):
import gimpshelf
key = "python-fu-save--" + func_name
key = "python-fu-save--" + proc_name
gimpshelf.shelf[key] = defaults
def _interact(func_name, start_params):
def _interact(proc_name, start_params):
(blurb, help, author, copyright, date,
menupath, imagetypes, plugin_type,
params, results, function,
on_query, on_run) = _registered_plugins_[func_name]
on_query, on_run) = _registered_plugins_[proc_name]
def run_script(run_params):
params = start_params + tuple(run_params)
@ -279,7 +283,7 @@ def _interact(func_name, start_params):
import gtk
import pango
defaults = _get_defaults(func_name)
defaults = _get_defaults(proc_name)
class EntryValueError(Exception):
pass
@ -482,7 +486,7 @@ def _interact(func_name, start_params):
tooltips = gtk.Tooltips()
dialog = gimpui.Dialog(func_name, 'python-fu', None, 0, None, func_name,
dialog = gimpui.Dialog(proc_name, 'python-fu', None, 0, None, proc_name,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OK, gtk.RESPONSE_OK))
@ -525,7 +529,7 @@ def _interact(func_name, start_params):
except EntryValueError:
error_dialog(dialog, 'Invalid input for "%s"' % wid.desc)
else:
_set_defaults(func_name, params)
_set_defaults(proc_name, params)
dialog.res = run_script(params)
gtk.main_quit()
@ -593,11 +597,11 @@ def _interact(func_name, start_params):
dialog.destroy()
raise CancelError
def _run(func_name, params):
def _run(proc_name, params):
run_mode = params[0]
plugin_type = _registered_plugins_[func_name][7]
menupath = _registered_plugins_[func_name][5]
func = _registered_plugins_[func_name][10]
plugin_type = _registered_plugins_[proc_name][7]
menupath = _registered_plugins_[proc_name][5]
func = _registered_plugins_[proc_name][10]
if plugin_type == PLUGIN and menupath and menupath[:10] != '<Toolbox>/':
if menupath[:7] == '<Save>/':
@ -613,12 +617,12 @@ def _run(func_name, params):
if run_mode == RUN_INTERACTIVE:
try:
res = _interact(func_name, start_params)
res = _interact(proc_name, start_params)
except CancelError:
return
else:
if run_mode == RUN_WITH_LAST_VALS:
extra_params = _get_defaults(func_name)
extra_params = _get_defaults(proc_name)
params = start_params + tuple(extra_params)
res = apply(func, params)

View file

@ -181,11 +181,11 @@ def misclassified_pixels (mask, truth):
def query_benchmark ():
pdb.gimp_plugin_menu_register("python_fu_benchmark_foreground_extract",
pdb.gimp_plugin_menu_register("python-fu-benchmark-foreground-extract",
"<Toolbox>/Xtns/Benchmark")
register (
"python_fu_benchmark_foreground_extract",
"python-fu-benchmark-foreground-extract",
"Benchmark and regression test for the SIOX algorithm",
"",
"Sven Neumann",
@ -193,9 +193,9 @@ register (
"2005",
"Foreground Extraction",
"",
[ (PF_FILE, "image_folder", "Image folder",
[ (PF_FILE, "image-folder", "Image folder",
"~/segmentation/msbench/imagedata"),
(PF_TOGGLE, "save_output", "Save output images", False) ],
(PF_TOGGLE, "save-output", "Save output images", False) ],
[],
benchmark, on_query=query_benchmark)

View file

@ -20,8 +20,7 @@
import math
from gimpfu import *
def python_clothify(timg, tdrawable, bx=9, by=9,
azimuth=135, elevation=45, depth=3):
def clothify(timg, tdrawable, bx=9, by=9, azimuth=135, elevation=45, depth=3):
width = tdrawable.width
height = tdrawable.height
@ -55,11 +54,11 @@ def python_clothify(timg, tdrawable, bx=9, by=9,
gimp.delete(img)
def query_clothify():
pdb.gimp_plugin_menu_register("python_fu_clothify",
pdb.gimp_plugin_menu_register("python-fu-clothify",
"<Image>/Filters/Artistic")
register(
"python_fu_clothify",
"python-fu-clothify",
"Make the specified layer look like it is printed on cloth",
"Make the specified layer look like it is printed on cloth",
"James Henstridge",
@ -68,13 +67,13 @@ register(
"_Clothify...",
"RGB*, GRAY*",
[
(PF_INT, "x_blur", "X blur", 9),
(PF_INT, "y_blur", "Y blur", 9),
(PF_INT, "x-blur", "X blur", 9),
(PF_INT, "y-blur", "Y blur", 9),
(PF_INT, "azimuth", "Azimuth", 135),
(PF_INT, "elevation", "Elevation", 45),
(PF_INT, "depth", "Depth", 3)
],
[],
python_clothify, on_query=query_clothify)
clothify, on_query=query_clothify)
main()

View file

@ -55,8 +55,8 @@ preamble = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
postamble = """\n</pre>\n</html>\n"""
def python_colorxhtml(img, drawable, filename, raw_filename,
source_type, characters, size, separate):
def colorxhtml(img, drawable, filename, raw_filename,
source_type, characters, size, separate):
width = drawable.width
height = drawable.height
bpp = drawable.bpp
@ -149,7 +149,7 @@ def python_colorxhtml(img, drawable, filename, raw_filename,
css.close()
def register_save():
gimp.register_save_handler("file_colorxhtml_save", "colorxhtml", "")
gimp.register_save_handler("file-colorxhtml-save", "xhtml", "")
class RowIterator:
def __init__(self, row, bpp):
@ -177,13 +177,13 @@ class RowIterator:
return pixel
register(
"file_colorxhtml_save",
"Saves the image as colored xhtml text",
"Saves the image as colored xhtml text (based on perl version by Marc Lehmann)",
"file-colorxhtml-save",
"Saves the image as colored XHTML text",
"Saves the image as colored XHTML text (based on perl version by Marc Lehmann)",
"Manish Singh and Carol Spears",
"Manish Singh and Carol Spears",
"2003",
"Color XHTML",
"<Save>/Colored XHTML",
"RGB",
[
(PF_RADIO, "source", "Where to take the characters from", 0,
@ -192,11 +192,10 @@ register(
("Entry box", CHARS_PARAMETER))),
(PF_FILE, "characters", "The filename to read or the characters to use",
""),
(PF_INT, "font_size", "The font size in pixels", 10),
(PF_INT, "font-size", "The font size in pixels", 10),
(PF_BOOL, "separate", "Separate CSS file", True)
],
[],
python_colorxhtml,
on_query=register_save)
colorxhtml, on_query=register_save)
main()

View file

@ -20,7 +20,7 @@
from gimpfu import *
import time
def python_foggify(img, layer, name, colour, turbulence, opacity):
def foggify(img, layer, name, colour, turbulence, opacity):
img.undo_group_start()
fog = gimp.Layer(img, name, layer.width, layer.height, RGBA_IMAGE,
@ -45,10 +45,11 @@ def python_foggify(img, layer, name, colour, turbulence, opacity):
img.undo_group_end()
def query_foggify():
pdb.gimp_plugin_menu_register("python_fu_foggify",
pdb.gimp_plugin_menu_register("python-fu-foggify",
"<Image>/Filters/Render/Clouds")
register(
"python_fu_foggify",
"python-fu-foggify",
"Add a layer of fog to the image",
"Add a layer of fog to the image",
"James Henstridge",
@ -63,6 +64,6 @@ register(
(PF_SLIDER, "opacity", "The opacity", 100, (0, 100, 1)),
],
[],
python_foggify, on_query=query_foggify)
foggify, on_query=query_foggify)
main()

View file

@ -19,7 +19,7 @@
from gimpfu import *
def plug_in_python_fu_console():
def console():
import pygtk
pygtk.require('2.0')
@ -94,11 +94,11 @@ def plug_in_python_fu_console():
gtk.main()
def query_console():
pdb.gimp_plugin_menu_register("python_fu_console",
pdb.gimp_plugin_menu_register("python-fu-console",
"<Toolbox>/Xtns/Languages/Python-Fu")
register(
"python_fu_console",
"python-fu-console",
"Python interactive interpreter with gimp extensions",
"Type in commands and see results",
"James Henstridge",
@ -108,6 +108,6 @@ register(
"",
[],
[],
plug_in_python_fu_console, on_query=query_console)
console, on_query=query_console)
main()

View file

@ -26,8 +26,8 @@ def code_eval(code):
exec code
register(
"python_fu_eval",
"Evaluate python code",
"python-fu-eval",
"Evaluate Python code",
"Evaulate python code under the python interpreter (primarily for batch mode)",
"Manish Singh",
"Manish Singh",

View file

@ -46,7 +46,7 @@ def query_palette_offset():
pdb.gimp_plugin_menu_register("python-fu-palette-offset", "<Palettes>")
register(
"python_fu_palette_offset",
"python-fu-palette-offset",
"Offsets a given palette",
"palette_offset (palette, amount_to_offset) -> modified_palette",
"Joao S. O. Bueno Calligaris, Carol Spears",
@ -59,7 +59,7 @@ register(
(PF_INT, "amount", "Amount of colors to offset", ""),
(PF_BOOL, "forward", "Offset the palette forward?", True)
],
[(PF_PALETTE, "new_palette", "Name of offset palette.")],
[(PF_PALETTE, "new-palette", "Name of offset palette.")],
palette_offset,
on_query=query_palette_offset)

View file

@ -49,7 +49,7 @@ def query_sort():
pdb.gimp_plugin_menu_register("python-fu-palette-sort", "<Palettes>")
register(
"python_fu_palette_sort",
"python-fu-palette-sort",
"Sort the selected palette.",
"palette_merge (palette, model, channel, ascending) -> new_palette",
"Joao S. O. Bueno Calligaris, Carol Spears",

View file

@ -67,7 +67,7 @@ def query_palette_to_gradient():
pdb.gimp_plugin_menu_register("python-fu-palette-to-gradient", "<Palettes>")
register(
"python_fu_palette_to_gradient",
"python-fu-palette-to-gradient",
"Palette to gradient.",
"Use the colors in the current GIMP palette and make a new gradient.",
"Carol Spears, reproduced from previous work by Adrian Likins and Jeff Trefftz",
@ -76,7 +76,7 @@ register(
"Palette to _Gradient",
"",
[(PF_PALETTE, "palette", "Name of palette to convert", "")],
[(PF_GRADIENT, "new_gradient", "Name of the New Gradient:")],
[(PF_GRADIENT, "new-gradient", "Name of the New Gradient:")],
palette_to_gradient,
on_query=query_palette_to_gradient)

View file

@ -19,7 +19,7 @@
from gimpfu import *
def plug_in_pdb_browse():
def pdb_browse():
import pygtk
pygtk.require('2.0')
@ -32,11 +32,11 @@ def plug_in_pdb_browse():
gtk.main()
def query_pdb_browse():
pdb.gimp_plugin_menu_register("python_fu_pdb_browse",
pdb.gimp_plugin_menu_register("python-fu-pdb-browse",
"<Toolbox>/Xtns/Languages/Python-Fu")
register(
"python_fu_pdb_browse",
"python-fu-pdb-browse",
"Browse the Procedural Database",
"Pick a PDB proc, and read the information",
"James Henstridge",
@ -46,6 +46,6 @@ register(
"",
[],
[],
plug_in_pdb_browse, on_query=query_pdb_browse)
pdb_browse, on_query=query_pdb_browse)
main()

View file

@ -409,10 +409,10 @@ End of the part generated by the GIMP
return url_list
def query_pyslice():
pdb.gimp_plugin_menu_register("python_fu_slice", "<Image>/Filters/Web")
pdb.gimp_plugin_menu_register("python-fu-slice", "<Image>/Filters/Web")
register(
"python_fu_slice",
"python-fu-slice",
"Cuts an image along its guides and images and a HTML table snippet",
"""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
@ -427,20 +427,20 @@ register(
"_Py-Slice...",
"*",
[
(PF_DIRNAME, "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}",
(PF_DIRNAME, "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?",
(PF_TOGGLE, "separate-image-dir", "Use a separate directory for images?",
False),
(PF_STRING, "relative_image_path", "The path where to export the" +
(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)
(PF_TOGGLE, "skip-caps", "Skip animation for table caps?", True)
],
[],

View file

@ -54,10 +54,11 @@ def shadow_bevel(img, drawable, blur, bevel, do_shadow, drop_x, drop_y):
img.undo_group_end()
def query_shadow_bevel():
pdb.gimp_plugin_menu_register("python_fu_shadow_bevel",
pdb.gimp_plugin_menu_register("python-fu-shadow-bevel",
"<Image>/Filters/Light and Shadow/Shadow")
register(
"python_fu_shadow_bevel",
"python-fu-shadow-bevel",
"Add a drop shadow to a layer, and optionally bevel it",
"Add a drop shadow to a layer, and optionally bevel it",
"James Henstridge",
@ -69,8 +70,8 @@ register(
(PF_SLIDER, "blur", "Shadow blur", 6, (1, 30, 1)),
(PF_BOOL, "bevel", "Bevel the image", True),
(PF_BOOL, "shadow", "Make a drop shadow", True),
(PF_INT, "drop_x", "Drop shadow X displacement", 3),
(PF_INT, "drop_y", "Drop shadow Y displacement", 6)
(PF_INT, "drop-x", "Drop shadow X displacement", 3),
(PF_INT, "drop-y", "Drop shadow Y displacement", 6)
],
[],
shadow_bevel, on_query=query_shadow_bevel)

View file

@ -20,7 +20,7 @@
import math
from gimpfu import *
def python_sphere(radius, light, shadow, bg_colour, sphere_colour):
def sphere(radius, light, shadow, bg_colour, sphere_colour):
if radius < 1:
radius = 1
@ -90,11 +90,11 @@ def python_sphere(radius, light, shadow, bg_colour, sphere_colour):
disp = gimp.Display(img)
def query_sphere():
pdb.gimp_plugin_menu_register("python_fu_sphere",
pdb.gimp_plugin_menu_register("python-fu-sphere",
"<Toolbox>/Xtns/Languages/Python-Fu/Test")
register(
"python_fu_sphere",
"python-fu-sphere",
"Simple spheres with drop shadows",
"Simple spheres with drop shadows (based on script-fu version)",
"James Henstridge",
@ -106,10 +106,10 @@ register(
(PF_INT, "radius", "Radius for sphere", 100),
(PF_SLIDER, "light", "Light angle", 45, (0,360,1)),
(PF_TOGGLE, "shadow", "Shadow?", 1),
(PF_COLOR, "bg_colour", "Background", (255,255,255)),
(PF_COLOR, "sphere_colour", "Sphere", (255,0,0))
(PF_COLOR, "bg-color", "Background", (255,255,255)),
(PF_COLOR, "sphere-color", "Sphere", (255,0,0))
],
[],
python_sphere, on_query=query_sphere)
sphere, on_query=query_sphere)
main()

View file

@ -62,7 +62,7 @@ class pixel_fetcher:
class Dummy:
pass
def python_whirl_pinch(image, drawable, whirl, pinch, radius):
def whirl_pinch(image, drawable, whirl, pinch, radius):
self = Dummy()
self.width = drawable.width
self.height = drawable.height
@ -197,11 +197,11 @@ def bilinear(x, y, values):
def query_whirl_pinch():
pdb.gimp_plugin_menu_register("python_fu_whirl_pinch",
pdb.gimp_plugin_menu_register("python-fu-whirl-pinch",
"<Image>/Filters/Distorts")
register(
"python_fu_whirl_pinch",
"python-fu-whirl-pinch",
"Distorts an image by whirling and pinching",
"Distorts an image by whirling and pinching",
"James Henstridge (translated from C plugin)",
@ -215,6 +215,6 @@ register(
(PF_FLOAT, "radius", "radius", 1)
],
[],
python_whirl_pinch, on_query=query_whirl_pinch)
whirl_pinch, on_query=query_whirl_pinch)
main()