ScriptFu: add methods for running regular procs
A chain of methods starting with the run_fun script_fu_run_regular_procedure. To use GimpProcedureDialog for scripts that are not ImageProcedure.
This commit is contained in:

committed by
Lloyd Konneker

parent
a96211fcb7
commit
d361256977
@ -159,3 +159,18 @@ script_fu_interpret_image_proc (GimpProcedure *procedure,
|
||||
g_free (command);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Interpret a script that defines a GimpProcedure. */
|
||||
GimpValueArray *
|
||||
script_fu_interpret_regular_proc (GimpProcedure *procedure,
|
||||
SFScript *script,
|
||||
GimpProcedureConfig *config)
|
||||
{
|
||||
gchar *command;
|
||||
GimpValueArray *result = NULL;
|
||||
|
||||
command = script_fu_script_get_command_for_regular_proc (script, config);
|
||||
result = sf_wrap_run_command (procedure, script, command);
|
||||
g_free (command);
|
||||
return result;
|
||||
}
|
||||
|
@ -27,5 +27,9 @@ GimpValueArray *script_fu_interpret_image_proc (GimpProcedure *procedure,
|
||||
guint n_drawables,
|
||||
GimpDrawable **drawables,
|
||||
GimpProcedureConfig *config);
|
||||
GimpValueArray *script_fu_interpret_regular_proc (
|
||||
GimpProcedure *procedure,
|
||||
SFScript *script,
|
||||
GimpProcedureConfig *config);
|
||||
|
||||
#endif /* __SCRIPT_FU_COMMAND_H__ */
|
||||
|
@ -226,3 +226,28 @@ script_fu_dialog_run_image_proc (
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Run a dialog for an Procedure, then interpret the script. */
|
||||
GimpValueArray*
|
||||
script_fu_dialog_run_regular_proc (GimpProcedure *procedure,
|
||||
SFScript *script,
|
||||
GimpProcedureConfig *config)
|
||||
|
||||
{
|
||||
GimpValueArray *result = NULL;
|
||||
gboolean not_canceled;
|
||||
|
||||
if (! sf_dialog_can_be_run (procedure, script, config))
|
||||
return gimp_procedure_new_return_values (procedure, GIMP_PDB_EXECUTION_ERROR, NULL);
|
||||
|
||||
not_canceled = sf_dialog_run (procedure, script, config);
|
||||
/* Assert config holds validated arg values from a user interaction. */
|
||||
|
||||
if (not_canceled)
|
||||
result = script_fu_interpret_regular_proc (procedure, script, config);
|
||||
else
|
||||
result = gimp_procedure_new_return_values (procedure, GIMP_PDB_CANCEL, NULL);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -28,5 +28,8 @@ GimpValueArray *script_fu_dialog_run_image_proc (
|
||||
guint n_drawables,
|
||||
GimpDrawable **drawables,
|
||||
GimpProcedureConfig *config);
|
||||
|
||||
GimpValueArray *script_fu_dialog_run_regular_proc (
|
||||
GimpProcedure *procedure,
|
||||
SFScript *script,
|
||||
GimpProcedureConfig *config);
|
||||
#endif /* __SCRIPT_FU_DIALOG_H__ */
|
||||
|
@ -134,8 +134,85 @@ script_fu_run_image_procedure (GimpProcedure *procedure, /* GimpImageProc
|
||||
return result;
|
||||
}
|
||||
|
||||
/* run_func for a GimpProcedure
|
||||
*
|
||||
* Type is GimpRunFunc.
|
||||
*
|
||||
* Uses Gimp's config and gui.
|
||||
*
|
||||
* Since 3.0
|
||||
*/
|
||||
GimpValueArray *
|
||||
script_fu_run_regular_procedure (GimpProcedure *procedure,
|
||||
GimpRunMode run_mode,
|
||||
GimpProcedureConfig *config,
|
||||
gpointer data)
|
||||
{
|
||||
|
||||
/* run_func for a GimpProcedure.
|
||||
GimpValueArray *result = NULL;
|
||||
SFScript *script;
|
||||
|
||||
g_debug ("script_fu_run_regular_procedure");
|
||||
script = script_fu_find_script (gimp_procedure_get_name (procedure));
|
||||
|
||||
if (! script)
|
||||
return gimp_procedure_new_return_values (procedure, GIMP_PDB_CALLING_ERROR, NULL);
|
||||
|
||||
ts_set_run_mode (run_mode);
|
||||
|
||||
/* Need Gegl. Also inits ui, needed when mode is interactive. */
|
||||
gimp_ui_init ("script-fu");
|
||||
|
||||
begin_interpret_default_dialect ();
|
||||
|
||||
script_fu_progress_init ();
|
||||
|
||||
switch (run_mode)
|
||||
{
|
||||
case GIMP_RUN_INTERACTIVE:
|
||||
{
|
||||
guint n_specs;
|
||||
|
||||
g_free (g_object_class_list_properties (G_OBJECT_GET_CLASS (config), &n_specs));
|
||||
if (n_specs > 1)
|
||||
{
|
||||
/* Let user choose "other" args in a dialog, then interpret. Maintain a config. */
|
||||
result = script_fu_dialog_run_regular_proc (procedure, script, config);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No "other" args for user to choose. No config to maintain. */
|
||||
result = script_fu_interpret_regular_proc (procedure, script, config);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GIMP_RUN_NONINTERACTIVE:
|
||||
{
|
||||
/* A call from another PDB procedure.
|
||||
* Use the given config, without interacting with user.
|
||||
* Since no user interaction, no config to maintain.
|
||||
*/
|
||||
result = script_fu_interpret_regular_proc (procedure, script, config);
|
||||
break;
|
||||
}
|
||||
case GIMP_RUN_WITH_LAST_VALS:
|
||||
{
|
||||
/* User invoked from a menu "Filter>Run with last values".
|
||||
* Do not show dialog. config are already last values.
|
||||
*/
|
||||
result = script_fu_interpret_regular_proc (procedure, script, config);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
result = gimp_procedure_new_return_values (procedure, GIMP_PDB_CALLING_ERROR, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* run_func for a GimpProcedure registered using Scheme "script-fu-register"
|
||||
*
|
||||
* Type is GimpRunFunc
|
||||
*
|
||||
|
@ -29,5 +29,11 @@ GimpValueArray *script_fu_run_image_procedure (GimpProcedure *procedure,
|
||||
GimpDrawable **drawables,
|
||||
GimpProcedureConfig *config,
|
||||
gpointer data);
|
||||
GimpValueArray *script_fu_run_regular_procedure (
|
||||
GimpProcedure *procedure,
|
||||
GimpRunMode run_mode,
|
||||
GimpProcedureConfig *config,
|
||||
gpointer data);
|
||||
|
||||
|
||||
#endif /* __SCRIPT_FU_RUN_FUNC__ */
|
||||
|
@ -458,6 +458,49 @@ script_fu_script_get_command_for_image_proc (SFScript *script,
|
||||
return g_string_free (s, FALSE);
|
||||
}
|
||||
|
||||
gchar *
|
||||
script_fu_script_get_command_for_regular_proc (SFScript *script,
|
||||
GimpProcedureConfig *config)
|
||||
{
|
||||
GParamSpec **pspecs;
|
||||
guint n_pspecs;
|
||||
GString *s;
|
||||
gint i;
|
||||
|
||||
g_return_val_if_fail (script != NULL, NULL);
|
||||
g_return_val_if_fail (GIMP_IS_PROCEDURE_CONFIG (config), NULL);
|
||||
|
||||
s = g_string_new ("(");
|
||||
g_string_append (s, script->name);
|
||||
|
||||
/* The command has no run mode. */
|
||||
|
||||
/* config contains the "other" args
|
||||
* Iterate over the GimpValueArray.
|
||||
* But script->args should be the same length, and types should match.
|
||||
*/
|
||||
pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (config), &n_pspecs);
|
||||
|
||||
/* config will have 1 additional property: "procedure". */
|
||||
for (i = 1; i < n_pspecs; i++)
|
||||
{
|
||||
GParamSpec *pspec = pspecs[i];
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
g_string_append_c (s, ' ');
|
||||
|
||||
g_value_init (&value, pspec->value_type);
|
||||
g_object_get_property (G_OBJECT (config), pspec->name, &value);
|
||||
script_fu_arg_append_repr_from_gvalue (&script->args[i - 1], s, &value);
|
||||
g_value_unset (&value);
|
||||
}
|
||||
|
||||
g_string_append_c (s, ')');
|
||||
g_free (pspecs);
|
||||
|
||||
return g_string_free (s, FALSE);
|
||||
}
|
||||
|
||||
/* Infer whether the script, defined using v2 script-fu-register,
|
||||
* which does not specify the arity for drawables,
|
||||
* is actually a script that takes one and only one drawable.
|
||||
|
@ -54,7 +54,9 @@ gchar * script_fu_script_get_command_for_image_proc (
|
||||
guint n_drawables,
|
||||
GimpDrawable **drawables,
|
||||
GimpProcedureConfig *config);
|
||||
|
||||
gchar * script_fu_script_get_command_for_regular_proc (
|
||||
SFScript *script,
|
||||
GimpProcedureConfig *config);
|
||||
GimpProcedure * script_fu_script_create_PDB_procedure (GimpPlugIn *plug_in,
|
||||
SFScript *script,
|
||||
GimpPDBProcType plug_in_type);
|
||||
|
Reference in New Issue
Block a user