libgimp: new gimp_pdb_run_procedure_config() function.

While we do have quite a few gimp_pdb_run_procedure*() functions now, I
always felt that one based on a config file was missing, even more as we
are getting further and further into using config objects in plug-ins.

In C, the gimp_pdb_run_procedure() function is without a doubt the
easiest one. But such variable arg functions are not available on
bindings, and having to deal with GValue and GimpValueArray is a real
pain.

Also using a config file has the very great advantage that we don't need
to care about order. For instance, if I need to set the 10th argument of
a PDB call (and leave the rest to default values), I don't have to set
all 9 previous arguments. I can set only this one if I want. This
advantage is useful also for C code by the way.

For the record, here is how you could load then export an image with the
"file-png-*" PDB procedures in Python:

> c = Gimp.get_pdb().lookup_procedure('file-png-load').create_config()
> c.set_property('file', Gio.file_new_for_path('/path/sample.png'))
> r = Gimp.get_pdb().run_procedure_config('file-png-load', c)
> d = Gimp.Display.new(r.index(1)) # Give it a display to work on it.

Now exporting:

> img = r.index(1)
> c = Gimp.get_pdb().lookup_procedure('file-png-save').create_config()
> c.set_property('image', img)
> c.set_property('file', Gio.file_new_for_path('/path/exported.png'))
> layers = img.get_layers()
> c.set_property('drawables', Gimp.ObjectArray.new(Gimp.Drawable, layers, False))
> c.set_property('num-drawables', len(layers))
> r = Gimp.get_pdb().run_procedure_config('file-png-save', c)
This commit is contained in:
Jehan 2022-02-11 17:44:26 +01:00
parent 0734ac2aec
commit 43f44288ef
3 changed files with 44 additions and 0 deletions

View file

@ -680,6 +680,7 @@ EXPORTS
gimp_pdb_run_procedure
gimp_pdb_run_procedure_argv
gimp_pdb_run_procedure_array
gimp_pdb_run_procedure_config
gimp_pdb_run_procedure_valist
gimp_pdb_set_data
gimp_pdb_temp_procedure_name

View file

@ -362,6 +362,46 @@ gimp_pdb_run_procedure_array (GimpPDB *pdb,
return return_values;
}
/**
* gimp_pdb_run_procedure_config:
* @pdb: the #GimpPDB object.
* @procedure_name: the registered name to call.
* @config: a config object obtained with gimp_procedure_create_config().
*
* Runs the procedure named @procedure_name with @config.
*
* Returns: (transfer full): the return values for the procedure call.
*
* Since: 3.0
*/
GimpValueArray *
gimp_pdb_run_procedure_config (GimpPDB *pdb,
const gchar *procedure_name,
GimpProcedureConfig *config)
{
GimpProcedure *procedure;
GimpValueArray *args;
GimpValueArray *return_values;
g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
g_return_val_if_fail (gimp_is_canonical_identifier (procedure_name), NULL);
g_return_val_if_fail (GIMP_IS_PROCEDURE_CONFIG (config), NULL);
procedure = gimp_pdb_lookup_procedure (pdb, procedure_name);
g_return_val_if_fail (gimp_procedure_config_get_procedure (config) == procedure,
NULL);
args = gimp_procedure_new_arguments (procedure);
gimp_procedure_config_get_values (config, args);
return_values = gimp_pdb_run_procedure_array (pdb, procedure_name, args);
gimp_value_array_unref (args);
return return_values;
}
/**
* gimp_pdb_temp_procedure_name:
* @pdb: the #GimpPDB object.

View file

@ -88,6 +88,9 @@ GimpValueArray * gimp_pdb_run_procedure_argv (GimpPDB *pdb,
GimpValueArray * gimp_pdb_run_procedure_array (GimpPDB *pdb,
const gchar *procedure_name,
const GimpValueArray *arguments);
GimpValueArray * gimp_pdb_run_procedure_config (GimpPDB *pdb,
const gchar *procedure_name,
GimpProcedureConfig *config);
gchar * gimp_pdb_temp_procedure_name (GimpPDB *pdb);