libgimp, libgimpconfig: recognize RGB boxed args containing GimpRGB.

Still the same problem as ever with the Python binding where we have a
hard time creating GParamSpec, hence we make them from object
properties.
See: https://gitlab.gnome.org/GNOME/pygobject/-/issues/227#note_570031

But then again, the Python binding way to create GObject properties does
not seem to give us a way to use our custom param types (or I didn't
find how). So when I create a property with Gimp.RGB type in Python, it
doesn't appear as a GIMP_PARAM_SPEC_RGB to our C code, but as a
G_PARAM_SPEC_BOXED. So my trick is to check the value type instead.
Note that I check the default value, but in reality it doesn't seem to
work much either. Better than no support at all anyway.
This commit is contained in:
Jehan
2021-04-20 14:10:37 +02:00
parent 72d4b91cc1
commit 5d210667c5
2 changed files with 23 additions and 0 deletions

View File

@ -64,6 +64,11 @@ _gimp_gp_param_def_to_param_spec (const GPParamDef *param_def)
if (! strcmp (param_def->type_name, "GParamObject") &&
! strcmp (param_def->value_type_name, "GFile"))
return g_param_spec_object (name, nick, blurb, G_TYPE_FILE, flags);
if (! strcmp (param_def->type_name, "GParamBoxed") &&
! strcmp (param_def->value_type_name, "GimpRGB"))
/* Unfortunately this type loses default and alpha info. */
return gimp_param_spec_rgb (name, nick, blurb, TRUE, NULL, flags);
break;
case GP_PARAM_DEF_TYPE_INT:

View File

@ -251,6 +251,24 @@ gimp_config_param_spec_duplicate (GParamSpec *pspec)
&color,
flags);
}
/* In some cases, such as some GIR bindings, creating a GimpRGB
* argument is impossible (or at least I have not found how, at least
* in the Python binding which is doing some weird shortcuts when
* handling GValue and param specs. So instead, the parameter appears
* as a Boxed param with a GimpRGB value type.
*/
else if (G_IS_PARAM_SPEC_BOXED (pspec) &&
G_PARAM_SPEC_VALUE_TYPE (pspec) == GIMP_TYPE_RGB)
{
GValue *value;
GimpRGB color;
value = (GValue *) g_param_spec_get_default_value (pspec);
gimp_value_get_rgb (value, &color);
copy = gimp_param_spec_rgb (name, nick, blurb,
TRUE, &color, flags);
}
else if (GEGL_IS_PARAM_SPEC_COLOR (pspec))
{
GeglColor *gegl_color;