From f96049ae6efaffc0a852bf2eaf8798469400ffed Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Thu, 17 Aug 2006 14:52:13 +0000 Subject: [PATCH] added an optional menu parameter to the register call to simplify menu 2006-08-17 Sven Neumann * plug-ins/pygimp/gimpfu.py: added an optional menu parameter to the register call to simplify menu registration. Also restored menupath specific mangling of the procedure arguments. * plug-ins/pygimp/plug-ins/*.py: use the menu parameter instead of defining a function to call on query. * plug-ins/pygimp/plug-ins/sphere.py: do it old-style here for testing. --- ChangeLog | 12 ++++++ plug-ins/pygimp/gimpfu.py | 40 +++++++++++-------- plug-ins/pygimp/plug-ins/clothify.py | 5 +-- plug-ins/pygimp/plug-ins/colorxhtml.py | 4 +- plug-ins/pygimp/plug-ins/gimpcons.py | 6 +-- plug-ins/pygimp/plug-ins/palette-offset.py | 6 +-- plug-ins/pygimp/plug-ins/palette-sort.py | 6 +-- .../pygimp/plug-ins/palette-to-gradient.py | 5 +-- plug-ins/pygimp/plug-ins/pdbbrowse.py | 5 +-- plug-ins/pygimp/plug-ins/py-slice.py | 4 +- plug-ins/pygimp/plug-ins/shadow_bevel.py | 5 +-- plug-ins/pygimp/plug-ins/sphere.py | 8 +--- plug-ins/pygimp/plug-ins/whirlpinch.py | 5 +-- 13 files changed, 49 insertions(+), 62 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0967b55952..34f6d99540 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2006-08-17 Sven Neumann + + * plug-ins/pygimp/gimpfu.py: added an optional menu parameter to + the register call to simplify menu registration. Also restored + menupath specific mangling of the procedure arguments. + + * plug-ins/pygimp/plug-ins/*.py: use the menu parameter instead + of defining a function to call on query. + + * plug-ins/pygimp/plug-ins/sphere.py: do it old-style here for + testing. + 2006-08-17 Sven Neumann * plug-ins/script-fu/siod/sliba.c (aref1): when accessing members diff --git a/plug-ins/pygimp/gimpfu.py b/plug-ins/pygimp/gimpfu.py index 5197367355..eaa8197802 100644 --- a/plug-ins/pygimp/gimpfu.py +++ b/plug-ins/pygimp/gimpfu.py @@ -148,8 +148,8 @@ _type_mapping = { _registered_plugins_ = {} -def register(proc_name, blurb, help, author, copyright, date, menupath, - imagetypes, params, results, function, +def register(proc_name, blurb, help, author, copyright, date, label, + imagetypes, params, results, function, menu=None, on_query=None, on_run=None): '''This is called to register a new plugin.''' @@ -200,9 +200,9 @@ def register(proc_name, blurb, help, author, copyright, date, menupath, proc_name = 'python-fu-' + proc_name _registered_plugins_[proc_name] = (blurb, help, author, copyright, - date, menupath, imagetypes, + date, label, imagetypes, plugin_type, params, results, - function, on_query, on_run) + function, menu, on_query, on_run) file_params = [(PDB_STRING, "filename", "The name of the file"), (PDB_STRING, "raw-filename", "The name of the file")] @@ -210,8 +210,8 @@ file_params = [(PDB_STRING, "filename", "The name of the file"), def _query(): for plugin in _registered_plugins_.keys(): (blurb, help, author, copyright, date, - menupath, imagetypes, plugin_type, - params, results, function, + label, imagetypes, plugin_type, + params, results, function, menu, on_query, on_run) = _registered_plugins_[plugin] def make_params(params): @@ -221,31 +221,39 @@ def _query(): # add the run mode argument ... params.insert(0, (PDB_INT32, "run_mode", "Interactive, Non-Interactive")) + + if menu is None and not label is None: + fields = _string.split(label, '/') + label = fields.pop() + menu = _string.join(fields, '/') + if plugin_type == PLUGIN: - if menupath is None: + if menu is None: pass - elif menupath[:7] == '/': + elif menu[:7] == '/': params[1:1] = file_params - elif menupath[:10] != '/': + elif menu[:10] != '/': params.insert(1, (PDB_IMAGE, "image", "The image to work on")) params.insert(2, (PDB_DRAWABLE, "drawable", "The drawable to work on")) - if menupath[:7] == '/': + if menu[:7] == '/': params[3:3] = file_params results = make_params(results) gimp.install_procedure(plugin, blurb, help, author, copyright, - date, menupath, imagetypes, plugin_type, + date, label, imagetypes, plugin_type, params, results) + if menu: + gimp.menu_register(plugin, menu) if on_query: on_query() def _get_defaults(proc_name): import gimpshelf (blurb, help, author, copyright, date, - menupath, imagetypes, plugin_type, - params, results, function, + menu, imagetypes, plugin_type, + params, results, function, menu, on_query, on_run) = _registered_plugins_[proc_name] key = "python-fu-save--" + proc_name @@ -264,8 +272,8 @@ def _set_defaults(proc_name, defaults): def _interact(proc_name, start_params): (blurb, help, author, copyright, date, - menupath, imagetypes, plugin_type, - params, results, function, + menu, imagetypes, plugin_type, + params, results, function, menu, on_query, on_run) = _registered_plugins_[proc_name] def run_script(run_params): @@ -600,8 +608,8 @@ def _interact(proc_name, start_params): def _run(proc_name, params): run_mode = params[0] plugin_type = _registered_plugins_[proc_name][7] - menupath = _registered_plugins_[proc_name][5] func = _registered_plugins_[proc_name][10] + menupath = _registered_plugins_[proc_name][11] if plugin_type == PLUGIN and menupath and menupath[:10] != '/': if menupath[:7] == '/': diff --git a/plug-ins/pygimp/plug-ins/clothify.py b/plug-ins/pygimp/plug-ins/clothify.py index e77cba1707..d48c904996 100755 --- a/plug-ins/pygimp/plug-ins/clothify.py +++ b/plug-ins/pygimp/plug-ins/clothify.py @@ -53,9 +53,6 @@ def clothify(timg, tdrawable, bx=9, by=9, azimuth=135, elevation=45, depth=3): gimp.delete(img) -def query_clothify(): - gimp.menu_register("python-fu-clothify", "/Filters/Artistic") - register( "python-fu-clothify", "Make the specified layer look like it is printed on cloth", @@ -73,6 +70,6 @@ register( (PF_INT, "depth", "Depth", 3) ], [], - clothify, on_query=query_clothify) + clothify, menu="/Filters/Artistic") main() diff --git a/plug-ins/pygimp/plug-ins/colorxhtml.py b/plug-ins/pygimp/plug-ins/colorxhtml.py index 7d5731a871..4cf12fdb1f 100755 --- a/plug-ins/pygimp/plug-ins/colorxhtml.py +++ b/plug-ins/pygimp/plug-ins/colorxhtml.py @@ -183,7 +183,7 @@ register( "Manish Singh and Carol Spears", "Manish Singh and Carol Spears", "2003", - "/Colored XHTML", + "Colored XHTML", "RGB", [ (PF_RADIO, "source", "Where to take the characters from", 0, @@ -196,6 +196,6 @@ register( (PF_BOOL, "separate", "Separate CSS file", True) ], [], - colorxhtml, on_query=register_save) + colorxhtml, menu="", on_query=register_save) main() diff --git a/plug-ins/pygimp/plug-ins/gimpcons.py b/plug-ins/pygimp/plug-ins/gimpcons.py index fd19d9d38e..78b05934f1 100755 --- a/plug-ins/pygimp/plug-ins/gimpcons.py +++ b/plug-ins/pygimp/plug-ins/gimpcons.py @@ -93,10 +93,6 @@ def console(): gobject.timeout_add(500, timeout) gtk.main() -def query_console(): - gimp.menu_register("python-fu-console", - "/Xtns/Languages/Python-Fu") - register( "python-fu-console", "Python interactive interpreter with gimp extensions", @@ -108,6 +104,6 @@ register( "", [], [], - console, on_query=query_console) + console, menu="/Xtns/Languages/Python-Fu") main() diff --git a/plug-ins/pygimp/plug-ins/palette-offset.py b/plug-ins/pygimp/plug-ins/palette-offset.py index 80ed2e55c6..6057f5b202 100644 --- a/plug-ins/pygimp/plug-ins/palette-offset.py +++ b/plug-ins/pygimp/plug-ins/palette-offset.py @@ -42,9 +42,6 @@ def palette_offset(palette, amount, forward): return palette -def query_palette_offset(): - gimp.menu_register("python-fu-palette-offset", "") - register( "python-fu-palette-offset", "Offsets a given palette", @@ -60,8 +57,7 @@ register( (PF_BOOL, "forward", "Offset the palette forward?", True) ], [(PF_PALETTE, "new-palette", "Name of offset palette.")], - palette_offset, - on_query=query_palette_offset) + palette_offset, menu="") main () diff --git a/plug-ins/pygimp/plug-ins/palette-sort.py b/plug-ins/pygimp/plug-ins/palette-sort.py index 05bbe61d92..6aed59d673 100644 --- a/plug-ins/pygimp/plug-ins/palette-sort.py +++ b/plug-ins/pygimp/plug-ins/palette-sort.py @@ -45,9 +45,6 @@ def palette_sort (palette, model, channel, ascending): return palette -def query_sort(): - gimp.menu_register("python-fu-palette-sort", "") - register( "python-fu-palette-sort", "Sort the selected palette.", @@ -69,8 +66,7 @@ register( (PF_BOOL, "ascending", "Sort in ascending order", True) ], [], - palette_sort, - on_query=query_sort) + palette_sort, menu="") main () diff --git a/plug-ins/pygimp/plug-ins/palette-to-gradient.py b/plug-ins/pygimp/plug-ins/palette-to-gradient.py index 768f5842f5..aab06613cd 100644 --- a/plug-ins/pygimp/plug-ins/palette-to-gradient.py +++ b/plug-ins/pygimp/plug-ins/palette-to-gradient.py @@ -63,8 +63,6 @@ def palette_to_gradient(palette): num_segments = num_colors - 1 make_gradient(palette, num_segments, num_colors) -def query_palette_to_gradient(): - gimp.menu_register("python-fu-palette-to-gradient", "") register( "python-fu-palette-to-gradient", @@ -77,8 +75,7 @@ register( "", [(PF_PALETTE, "palette", "Name of palette to convert", "")], [(PF_GRADIENT, "new-gradient", "Name of the New Gradient:")], - palette_to_gradient, - on_query=query_palette_to_gradient) + palette_to_gradient, menu="") main () diff --git a/plug-ins/pygimp/plug-ins/pdbbrowse.py b/plug-ins/pygimp/plug-ins/pdbbrowse.py index 284006199c..6786649c91 100755 --- a/plug-ins/pygimp/plug-ins/pdbbrowse.py +++ b/plug-ins/pygimp/plug-ins/pdbbrowse.py @@ -31,9 +31,6 @@ def pdb_browse(): gtk.main() -def query_pdb_browse(): - gimp.menu_register("python-fu-pdb-browse", - "/Xtns/Languages/Python-Fu") register( "python-fu-pdb-browse", @@ -46,6 +43,6 @@ register( "", [], [], - pdb_browse, on_query=query_pdb_browse) + pdb_browse, menu="/Xtns/Languages/Python-Fu") main() diff --git a/plug-ins/pygimp/plug-ins/py-slice.py b/plug-ins/pygimp/plug-ins/py-slice.py index 6585867d36..0577d431ff 100755 --- a/plug-ins/pygimp/plug-ins/py-slice.py +++ b/plug-ins/pygimp/plug-ins/py-slice.py @@ -408,8 +408,6 @@ End of the part generated by the GIMP return url_list -def query_pyslice(): - gimp.menu_register("python-fu-slice", "/Filters/Web") register( "python-fu-slice", @@ -444,6 +442,6 @@ register( ], [], - pyslice, on_query=query_pyslice) + pyslice, menu="/Filters/Web") main() diff --git a/plug-ins/pygimp/plug-ins/shadow_bevel.py b/plug-ins/pygimp/plug-ins/shadow_bevel.py index bac3109681..13605da83d 100755 --- a/plug-ins/pygimp/plug-ins/shadow_bevel.py +++ b/plug-ins/pygimp/plug-ins/shadow_bevel.py @@ -53,9 +53,6 @@ def shadow_bevel(img, drawable, blur, bevel, do_shadow, drop_x, drop_y): # enable undo again img.undo_group_end() -def query_shadow_bevel(): - gimp.menu_register("python-fu-shadow-bevel", - "/Filters/Light and Shadow/Shadow") register( "python-fu-shadow-bevel", @@ -74,6 +71,6 @@ register( (PF_INT, "drop-y", "Drop shadow Y displacement", 6) ], [], - shadow_bevel, on_query=query_shadow_bevel) + shadow_bevel, menu="/Filters/Light and Shadow/Shadow") main() diff --git a/plug-ins/pygimp/plug-ins/sphere.py b/plug-ins/pygimp/plug-ins/sphere.py index 6374b9d739..e9eda61a5f 100755 --- a/plug-ins/pygimp/plug-ins/sphere.py +++ b/plug-ins/pygimp/plug-ins/sphere.py @@ -89,10 +89,6 @@ def sphere(radius, light, shadow, bg_colour, sphere_colour): disp = gimp.Display(img) -def query_sphere(): - gimp.menu_register("python-fu-sphere", - "/Xtns/Languages/Python-Fu/Test") - register( "python-fu-sphere", "Simple spheres with drop shadows", @@ -100,7 +96,7 @@ register( "James Henstridge", "James Henstridge", "1997-1999", - "_Sphere", + "/Xtns/Languages/Python-Fu/Test/_Sphere", "", [ (PF_INT, "radius", "Radius for sphere", 100), @@ -110,6 +106,6 @@ register( (PF_COLOR, "sphere-color", "Sphere", (255,0,0)) ], [], - sphere, on_query=query_sphere) + sphere) main() diff --git a/plug-ins/pygimp/plug-ins/whirlpinch.py b/plug-ins/pygimp/plug-ins/whirlpinch.py index b737ea1762..b1a4f62a97 100755 --- a/plug-ins/pygimp/plug-ins/whirlpinch.py +++ b/plug-ins/pygimp/plug-ins/whirlpinch.py @@ -196,9 +196,6 @@ def bilinear(x, y, values): return chr(int(m0 + y * (m1 - m0))) -def query_whirl_pinch(): - gimp.menu_register("python-fu-whirl-pinch", "/Filters/Distorts") - register( "python-fu-whirl-pinch", "Distorts an image by whirling and pinching", @@ -214,6 +211,6 @@ register( (PF_FLOAT, "radius", "radius", 1) ], [], - whirl_pinch, on_query=query_whirl_pinch) + whirl_pinch, menu="/Filters/Distorts") main()