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:
committed by
Sven Neumann
parent
8ecf3cdf49
commit
7728c808e5
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user