Commit Graph

15 Commits

Author SHA1 Message Date
Niels De Graef 89c359ce47 Remove GimpUint8Array in favor of GBytes
GLib has a specific type for byte arrays: `GBytes` (and it's underlying
GType `G_TYPE_BYTES`).

By using this type, we can avoid having a `GimpUint8Array` which is a
bit cumbersome to use for both the C API, as well as bindings. By using
`GBytes`, we allow other languages to pass on byte arrays as they are
used to, while the bindings will make sure to do the right thing.

In the end, it makes the API a little bit simpler for everyone, and
reduces confusion for people who are used to working with byte arrays
in other C/GLib based code (and not having 2 different types to denote
the same thing).

Related: https://gitlab.gnome.org/GNOME/gimp/-/issues/5919
2023-05-23 23:37:50 +02:00
Niels De Graef 8eb7f6df9e Remove GimpStringArray in favor of GStrv
GLib has a specific type of NULL-terminated string arrays:
`G_TYPE_STRV`, which is the `GType` of `char**` aka `GStrv`.

By using this type, we can avoid having a `GimpStringArray` which is a
bit cumbersome to use for both the C API, as well as bindings. By using
`GStrv`, we allow other languages to pass on string lists as they are
used to, while the bindings will make sure to do the right thing.

In the end, it makes the API a little bit simpler for everyone, and
reduces confusion for people who are used to working with string arrays
in other C/GLib based code (and not having 2 different types to denote
the same thing).

Related: https://gitlab.gnome.org/GNOME/gimp/-/issues/5919
2022-02-12 00:07:53 +00:00
Jehan 43f44288ef 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)
2022-02-11 17:56:42 +01:00
Niels De Graef 43d0f0fbd2 gimppdb: Allow more easy bindable API
Plug-ins that work from different bindings probably want to use their
own list-type to specify arguments, rather than working with a more
cumbersome `GimpValueArray`.

This new API should make it less verbose. For example:

```
args = Gimp.ValueArray.new(5)
args.insert(0, GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE))
args.insert(1, GObject.Value(Gimp.Image, image))
args.insert(2, GObject.Value(Gimp.Drawable, mask))
args.insert(3, GObject.Value(GObject.TYPE_INT, int(time.time())))
args.insert(4, GObject.Value(GObject.TYPE_DOUBLE, turbulence))
Gimp.get_pdb().run_procedure('plug-in-plasma', args)
```

becomes

```
Gimp.get_pdb().run_procedure('plug-in-plasma', [
    GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE),
    GObject.Value(Gimp.Image, image),
    GObject.Value(Gimp.Drawable, mask),
    GObject.Value(GObject.TYPE_INT, int(time.time())),
    GObject.Value(GObject.TYPE_DOUBLE, turbulence),
])
```
2020-09-20 11:36:01 +00:00
Michael Natterer 79d92a5d05 libgimp: remove a lot of cruft because script-fu is ported now
Also remove all legacy code from GimpProcView and
GimpProcBrowserDialog.
2019-08-12 20:49:08 +02:00
Michael Natterer 1c9b3c7055 libgimp: add gimp_pdb_get_last_error() and _get_last_status()
and move the old API to gimplegacy.[ch].
2019-08-11 16:41:58 +02:00
Michael Natterer 244b52bf0d pdb, libgimp: make the "pdb" PDB group private
and don't install its header. Temporarily add its only two remaining
needed functions to gimppdb.[ch].

Also some Makefile cleanup.
2019-08-08 21:55:11 +02:00
Michael Natterer 0aa2dcfadb libgimp: replace gimp_pdb_dump() and gimp_pdb_query() by new API
and move them to gimplegacy.[ch].
2019-08-08 01:14:35 +02:00
Michael Natterer 7b58cb1d28 libgimp: move most old gimp_pdb functions to gimplegacy.[ch] 2019-08-07 00:27:34 +02:00
Michael Natterer 64d880f1fe libgimp: add gimp_pdb_temp_procedure_name() and hide the PDB wrapper 2019-08-07 00:19:38 +02:00
Michael Natterer 2599c6e071 libgimp: add some const to input parameters, like const GimpValueArray*
for procedure arguments. This implies creating a new value array in
gimp_procedure_run() if the passed array is too short, instead of
just appending to the passed array, which was ugly anyway.
2019-08-07 00:04:58 +02:00
Michael Natterer 84cb07f995 libgimp: add more comfortable ways to run procedures to GimpPDB
return_vals = gimp_pdb_run_procedure (pdb, "procedure-name",
                                      G_TYPE_STRING,  "string arg",
				      G_TYPE_INT      23,
				      G_TYPE_BOOLEAN, FALSE,
				      G_TYPE_NONE);
2019-08-06 19:13:06 +02:00
Michael Natterer 8860d78979 libgimp: more progress on the GimpPDB object
- add gimp_pdb_run_procedure()
- hide more functions in gimppdb_pdb.[ch], and add proper API
- add gimp_get_pdb() which returns the singleton
2019-08-06 19:13:06 +02:00
Michael Natterer 05baadcd1d pdb: rename the "procedural_db" PDB group to just "pdb" 2019-08-06 12:51:56 +02:00
Michael Natterer 450a9f90b4 libgimp: add a GimpPDB class and subclass GimpProcedure as GimpPDBProcedure
The idea is that we already have a GimpProcedure object in libgimp
which has name, help, blurb, arguments, return values and everything,
so we really don't need a parallel API to query PDB procedures for
their properties.

- make run() a virtual function of GimpProcedure
- move GIMP_PDB_ERROR to GimpPDB
- GimpPDBProcedure is a trivial subblass which populates
  GimpProcedure's members by querying the PDB.
- make "plug-in", "procedure-type" and "name" construct-only
  properties of GimpProcedure.

This is all work in progress.
2019-08-06 12:22:23 +02:00