mirror of https://github.com/GNOME/gimp.git
plug-ins: remove the hardcoded compat enums from script-fu and pygimp
Instead, simply look them up via the type system, and register their values like they were normal enums.
This commit is contained in:
parent
178794f6f1
commit
0a0acc9f2a
|
@ -89,135 +89,6 @@ add_misc_enums(PyObject *m)
|
|||
static void
|
||||
add_compat_enums(PyObject *m)
|
||||
{
|
||||
PyModule_AddIntConstant(m, "ADD_WHITE_MASK",
|
||||
GIMP_ADD_MASK_WHITE);
|
||||
PyModule_AddIntConstant(m, "ADD_BLACK_MASK",
|
||||
GIMP_ADD_MASK_BLACK);
|
||||
PyModule_AddIntConstant(m, "ADD_ALPHA_MASK",
|
||||
GIMP_ADD_MASK_ALPHA);
|
||||
PyModule_AddIntConstant(m, "ADD_ALPHA_TRANSFER_MASK",
|
||||
GIMP_ADD_MASK_ALPHA_TRANSFER);
|
||||
PyModule_AddIntConstant(m, "ADD_SELECTION_MASK",
|
||||
GIMP_ADD_MASK_SELECTION);
|
||||
PyModule_AddIntConstant(m, "ADD_COPY_MASK",
|
||||
GIMP_ADD_MASK_COPY);
|
||||
PyModule_AddIntConstant(m, "ADD_CHANNEL_MASK",
|
||||
GIMP_ADD_MASK_CHANNEL);
|
||||
|
||||
PyModule_AddIntConstant(m, "FG_BG_RGB_MODE",
|
||||
GIMP_BLEND_FG_BG_RGB);
|
||||
PyModule_AddIntConstant(m, "FG_BG_HSV_MODE",
|
||||
GIMP_BLEND_FG_BG_HSV);
|
||||
PyModule_AddIntConstant(m, "FG_TRANSPARENT_MODE",
|
||||
GIMP_BLEND_FG_TRANSPARENT);
|
||||
PyModule_AddIntConstant(m, "CUSTOM_MODE",
|
||||
GIMP_BLEND_CUSTOM);
|
||||
|
||||
PyModule_AddIntConstant(m, "FG_BUCKET_FILL",
|
||||
GIMP_BUCKET_FILL_FG);
|
||||
PyModule_AddIntConstant(m, "BG_BUCKET_FILL",
|
||||
GIMP_BUCKET_FILL_BG);
|
||||
PyModule_AddIntConstant(m, "PATTERN_BUCKET_FILL",
|
||||
GIMP_BUCKET_FILL_PATTERN);
|
||||
|
||||
PyModule_AddIntConstant(m, "BLUR_CONVOLVE",
|
||||
GIMP_CONVOLVE_BLUR);
|
||||
PyModule_AddIntConstant(m, "SHARPEN_CONVOLVE",
|
||||
GIMP_CONVOLVE_SHARPEN);
|
||||
|
||||
PyModule_AddIntConstant(m, "IMAGE_CLONE",
|
||||
GIMP_CLONE_IMAGE);
|
||||
PyModule_AddIntConstant(m, "PATTERN_CLONE",
|
||||
GIMP_CLONE_PATTERN);
|
||||
|
||||
PyModule_AddIntConstant(m, "FOREGROUND_FILL",
|
||||
GIMP_FILL_FOREGROUND);
|
||||
PyModule_AddIntConstant(m, "BACKGROUND_FILL",
|
||||
GIMP_FILL_BACKGROUND);
|
||||
PyModule_AddIntConstant(m, "WHITE_FILL",
|
||||
GIMP_FILL_WHITE);
|
||||
PyModule_AddIntConstant(m, "TRANSPARENT_FILL",
|
||||
GIMP_FILL_TRANSPARENT);
|
||||
PyModule_AddIntConstant(m, "PATTERN_FILL",
|
||||
GIMP_FILL_PATTERN);
|
||||
|
||||
PyModule_AddIntConstant(m, "DODGE",
|
||||
GIMP_DODGE_BURN_TYPE_DODGE);
|
||||
PyModule_AddIntConstant(m, "BURN",
|
||||
GIMP_DODGE_BURN_TYPE_BURN);
|
||||
|
||||
PyModule_AddIntConstant(m, "SHADOWS",
|
||||
GIMP_TRANSFER_SHADOWS);
|
||||
PyModule_AddIntConstant(m, "MIDTONES",
|
||||
GIMP_TRANSFER_MIDTONES);
|
||||
PyModule_AddIntConstant(m, "HIGHLIGHTS",
|
||||
GIMP_TRANSFER_HIGHLIGHTS);
|
||||
|
||||
PyModule_AddIntConstant(m, "DESATURATE_LUMINOSITY",
|
||||
GIMP_DESATURATE_LUMA);
|
||||
|
||||
PyModule_AddIntConstant (m, "ALL_HUES",
|
||||
GIMP_HUE_RANGE_ALL);
|
||||
PyModule_AddIntConstant (m, "RED_HUES",
|
||||
GIMP_HUE_RANGE_RED);
|
||||
PyModule_AddIntConstant (m, "YELLOW_HUES",
|
||||
GIMP_HUE_RANGE_YELLOW);
|
||||
PyModule_AddIntConstant (m, "GREEN_HUES",
|
||||
GIMP_HUE_RANGE_GREEN);
|
||||
PyModule_AddIntConstant (m, "CYAN_HUES",
|
||||
GIMP_HUE_RANGE_CYAN);
|
||||
PyModule_AddIntConstant (m, "BLUE_HUES",
|
||||
GIMP_HUE_RANGE_BLUE);
|
||||
PyModule_AddIntConstant (m, "MAGENTA_HUES",
|
||||
GIMP_HUE_RANGE_MAGENTA);
|
||||
|
||||
PyModule_AddIntConstant (m, "NORMAL_MODE",
|
||||
GIMP_LAYER_MODE_NORMAL);
|
||||
PyModule_AddIntConstant (m, "DISSOLVE_MODE",
|
||||
GIMP_LAYER_MODE_DISSOLVE);
|
||||
PyModule_AddIntConstant (m, "BEHIND_MODE",
|
||||
GIMP_LAYER_MODE_BEHIND);
|
||||
PyModule_AddIntConstant (m, "MULTIPLY_MODE",
|
||||
GIMP_LAYER_MODE_MULTIPLY_LEGACY);
|
||||
PyModule_AddIntConstant (m, "SCREEN_MODE",
|
||||
GIMP_LAYER_MODE_SCREEN_LEGACY);
|
||||
PyModule_AddIntConstant (m, "OVERLAY_MODE",
|
||||
GIMP_LAYER_MODE_OVERLAY_LEGACY);
|
||||
PyModule_AddIntConstant (m, "DIFFERENCE_MODE",
|
||||
GIMP_LAYER_MODE_DIFFERENCE_LEGACY);
|
||||
PyModule_AddIntConstant (m, "ADDITION_MODE",
|
||||
GIMP_LAYER_MODE_ADDITION_LEGACY);
|
||||
PyModule_AddIntConstant (m, "SUBTRACT_MODE",
|
||||
GIMP_LAYER_MODE_SUBTRACT_LEGACY);
|
||||
PyModule_AddIntConstant (m, "DARKEN_ONLY_MODE",
|
||||
GIMP_LAYER_MODE_DARKEN_ONLY_LEGACY);
|
||||
PyModule_AddIntConstant (m, "LIGHTEN_ONLY_MODE",
|
||||
GIMP_LAYER_MODE_LIGHTEN_ONLY_LEGACY);
|
||||
PyModule_AddIntConstant (m, "HUE_MODE",
|
||||
GIMP_LAYER_MODE_HSV_HUE_LEGACY);
|
||||
PyModule_AddIntConstant (m, "SATURATION_MODE",
|
||||
GIMP_LAYER_MODE_HSV_SATURATION_LEGACY);
|
||||
PyModule_AddIntConstant (m, "COLOR_MODE",
|
||||
GIMP_LAYER_MODE_HSV_COLOR_LEGACY);
|
||||
PyModule_AddIntConstant (m, "VALUE_MODE",
|
||||
GIMP_LAYER_MODE_HSV_VALUE_LEGACY);
|
||||
PyModule_AddIntConstant (m, "DIVIDE_MODE",
|
||||
GIMP_LAYER_MODE_DIVIDE_LEGACY);
|
||||
PyModule_AddIntConstant (m, "DODGE_MODE",
|
||||
GIMP_LAYER_MODE_DODGE_LEGACY);
|
||||
PyModule_AddIntConstant (m, "BURN_MODE",
|
||||
GIMP_LAYER_MODE_BURN_LEGACY);
|
||||
PyModule_AddIntConstant (m, "HARDLIGHT_MODE",
|
||||
GIMP_LAYER_MODE_HARDLIGHT_LEGACY);
|
||||
PyModule_AddIntConstant (m, "SOFTLIGHT_MODE",
|
||||
GIMP_LAYER_MODE_SOFTLIGHT_LEGACY);
|
||||
PyModule_AddIntConstant (m, "GRAIN_EXTRACT_MODE",
|
||||
GIMP_LAYER_MODE_GRAIN_EXTRACT_LEGACY);
|
||||
PyModule_AddIntConstant (m, "GRAIN_MERGE_MODE",
|
||||
GIMP_LAYER_MODE_GRAIN_MERGE_LEGACY);
|
||||
PyModule_AddIntConstant (m, "COLOR_ERASE_MODE",
|
||||
GIMP_LAYER_MODE_COLOR_ERASE);
|
||||
|
||||
PyModule_AddIntConstant(m, "EXPORT_CAN_HANDLE_RGB",
|
||||
GIMP_EXPORT_CAN_HANDLE_RGB);
|
||||
PyModule_AddIntConstant(m, "EXPORT_CAN_HANDLE_GRAY",
|
||||
|
@ -248,8 +119,9 @@ add_compat_enums(PyObject *m)
|
|||
static void
|
||||
add_registered_enums(PyObject *m)
|
||||
{
|
||||
int num_names, i;
|
||||
const char **names;
|
||||
gint num_names, i;
|
||||
const gchar **names;
|
||||
GQuark quark = g_quark_from_static_string ("gimp-compat-enum");
|
||||
|
||||
names = gimp_enums_get_type_names (&num_names);
|
||||
|
||||
|
@ -257,7 +129,16 @@ add_registered_enums(PyObject *m)
|
|||
pyg_enum_add_constants (m, GIMP_TYPE_CHECK_TYPE, "GIMP_");
|
||||
|
||||
for (i = 0; i < num_names; i++)
|
||||
pyg_enum_add_constants(m, g_type_from_name(names[i]), "GIMP_");
|
||||
{
|
||||
GType enum_type = g_type_from_name (names[i]);
|
||||
|
||||
pyg_enum_add_constants (m, enum_type, "GIMP_");
|
||||
|
||||
enum_type = (GType) g_type_get_qdata (enum_type, quark);
|
||||
|
||||
if (enum_type)
|
||||
pyg_enum_add_constants (m, enum_type, "GIMP_");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -50,6 +50,8 @@
|
|||
#undef cons
|
||||
|
||||
static void ts_init_constants (scheme *sc);
|
||||
static void ts_init_enum (scheme *sc,
|
||||
GType enum_type);
|
||||
static void ts_init_procedures (scheme *sc,
|
||||
gboolean register_scipts);
|
||||
static void convert_string (gchar *str);
|
||||
|
@ -125,87 +127,6 @@ static const NamedConstant const script_constants[] =
|
|||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
/* The following constants are deprecated. They are included to keep
|
||||
* backwards compatibility with older scripts used with older versions
|
||||
* of GIMP.
|
||||
*/
|
||||
static const NamedConstant const old_constants[] =
|
||||
{
|
||||
/* the following enums got cleaned up with properly named values in 2.10 */
|
||||
|
||||
{ "ADD-WHITE-MASK", GIMP_ADD_MASK_WHITE },
|
||||
{ "ADD-BLACK-MASK", GIMP_ADD_MASK_BLACK },
|
||||
{ "ADD-ALPHA-MASK", GIMP_ADD_MASK_ALPHA },
|
||||
{ "ADD-ALPHA-TRANSFER-MASK", GIMP_ADD_MASK_ALPHA_TRANSFER },
|
||||
{ "ADD-SELECTION-MASK", GIMP_ADD_MASK_SELECTION },
|
||||
{ "ADD-COPY-MASK", GIMP_ADD_MASK_COPY },
|
||||
{ "ADD-CHANNEL-MASK", GIMP_ADD_MASK_CHANNEL },
|
||||
|
||||
{ "FG-BG-RGB-MODE", GIMP_BLEND_FG_BG_RGB },
|
||||
{ "FG-BG-HSV-MODE", GIMP_BLEND_FG_BG_HSV },
|
||||
{ "FG-TRANSPARENT-MODE", GIMP_BLEND_FG_TRANSPARENT },
|
||||
{ "CUSTOM-MODE", GIMP_BLEND_CUSTOM },
|
||||
|
||||
{ "FG-BUCKET-FILL", GIMP_BUCKET_FILL_FG },
|
||||
{ "BG-BUCKET-FILL", GIMP_BUCKET_FILL_BG },
|
||||
{ "PATTERN-BUCKET-FILL", GIMP_BUCKET_FILL_PATTERN },
|
||||
|
||||
{ "BLUR-CONVOLVE", GIMP_CONVOLVE_BLUR },
|
||||
{ "SHARPEN-CONVOLVE", GIMP_CONVOLVE_SHARPEN },
|
||||
|
||||
{ "IMAGE-CLONE", GIMP_CLONE_IMAGE },
|
||||
{ "PATTERN-CLONE", GIMP_CLONE_PATTERN },
|
||||
|
||||
{ "FOREGROUND-FILL", GIMP_FILL_FOREGROUND },
|
||||
{ "BACKGROUND-FILL", GIMP_FILL_BACKGROUND },
|
||||
{ "WHITE-FILL", GIMP_FILL_WHITE },
|
||||
{ "TRANSPARENT-FILL", GIMP_FILL_TRANSPARENT },
|
||||
{ "PATTERN-FILL", GIMP_FILL_PATTERN },
|
||||
|
||||
{ "DODGE", GIMP_DODGE_BURN_TYPE_DODGE },
|
||||
{ "BURN", GIMP_DODGE_BURN_TYPE_BURN },
|
||||
|
||||
{ "SHADOWS", GIMP_TRANSFER_SHADOWS },
|
||||
{ "MIDTONES", GIMP_TRANSFER_MIDTONES },
|
||||
{ "HIGHLIGHTS", GIMP_TRANSFER_HIGHLIGHTS },
|
||||
|
||||
{ "DESATURATE-LUMINOSITY", GIMP_DESATURATE_LUMA },
|
||||
|
||||
{ "ALL-HUES", GIMP_HUE_RANGE_ALL },
|
||||
{ "RED-HUES", GIMP_HUE_RANGE_RED },
|
||||
{ "YELLOW-HUES", GIMP_HUE_RANGE_YELLOW },
|
||||
{ "GREEN-HUES", GIMP_HUE_RANGE_GREEN },
|
||||
{ "CYAN-HUES", GIMP_HUE_RANGE_CYAN },
|
||||
{ "BLUE-HUES", GIMP_HUE_RANGE_BLUE },
|
||||
{ "MAGENTA-HUES", GIMP_HUE_RANGE_MAGENTA },
|
||||
|
||||
{ "NORMAL-MODE", GIMP_LAYER_MODE_NORMAL },
|
||||
{ "DISSOLVE-MODE", GIMP_LAYER_MODE_DISSOLVE },
|
||||
{ "BEHIND-MODE", GIMP_LAYER_MODE_BEHIND },
|
||||
{ "MULTIPLY-MODE", GIMP_LAYER_MODE_MULTIPLY_LEGACY },
|
||||
{ "SCREEN-MODE", GIMP_LAYER_MODE_SCREEN_LEGACY },
|
||||
{ "OVERLAY-MODE", GIMP_LAYER_MODE_OVERLAY_LEGACY },
|
||||
{ "DIFFERENCE-MODE", GIMP_LAYER_MODE_DIFFERENCE_LEGACY },
|
||||
{ "ADDITION-MODE", GIMP_LAYER_MODE_ADDITION_LEGACY },
|
||||
{ "SUBTRACT-MODE", GIMP_LAYER_MODE_SUBTRACT_LEGACY },
|
||||
{ "DARKEN-ONLY-MODE", GIMP_LAYER_MODE_DARKEN_ONLY_LEGACY },
|
||||
{ "LIGHTEN-ONLY-MODE", GIMP_LAYER_MODE_LIGHTEN_ONLY_LEGACY },
|
||||
{ "HUE-MODE", GIMP_LAYER_MODE_HSV_HUE_LEGACY },
|
||||
{ "SATURATION-MODE", GIMP_LAYER_MODE_HSV_SATURATION_LEGACY },
|
||||
{ "COLOR-MODE", GIMP_LAYER_MODE_HSV_COLOR_LEGACY },
|
||||
{ "VALUE-MODE", GIMP_LAYER_MODE_HSV_VALUE_LEGACY },
|
||||
{ "DIVIDE-MODE", GIMP_LAYER_MODE_DIVIDE_LEGACY },
|
||||
{ "DODGE-MODE", GIMP_LAYER_MODE_DODGE_LEGACY },
|
||||
{ "BURN-MODE", GIMP_LAYER_MODE_BURN_LEGACY },
|
||||
{ "HARDLIGHT-MODE", GIMP_LAYER_MODE_HARDLIGHT_LEGACY },
|
||||
{ "SOFTLIGHT-MODE", GIMP_LAYER_MODE_SOFTLIGHT_LEGACY },
|
||||
{ "GRAIN-EXTRACT-MODE", GIMP_LAYER_MODE_GRAIN_EXTRACT_LEGACY },
|
||||
{ "GRAIN-MERGE-MODE", GIMP_LAYER_MODE_GRAIN_MERGE_LEGACY },
|
||||
{ "COLOR-ERASE-MODE", GIMP_LAYER_MODE_COLOR_ERASE },
|
||||
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
|
||||
static scheme sc;
|
||||
|
||||
|
@ -360,6 +281,7 @@ ts_init_constants (scheme *sc)
|
|||
gint n_enum_type_names;
|
||||
gint i;
|
||||
pointer symbol;
|
||||
GQuark quark;
|
||||
|
||||
symbol = sc->vptr->mk_symbol (sc, "gimp-directory");
|
||||
sc->vptr->scheme_define (sc, sc->global_env, symbol,
|
||||
|
@ -387,33 +309,19 @@ ts_init_constants (scheme *sc)
|
|||
sc->vptr->setimmutable (symbol);
|
||||
|
||||
enum_type_names = gimp_enums_get_type_names (&n_enum_type_names);
|
||||
quark = g_quark_from_static_string ("gimp-compat-enum");
|
||||
|
||||
for (i = 0; i < n_enum_type_names; i++)
|
||||
{
|
||||
const gchar *enum_name = enum_type_names[i];
|
||||
GType enum_type = g_type_from_name (enum_name);
|
||||
GEnumClass *enum_class = g_type_class_ref (enum_type);
|
||||
GEnumValue *value;
|
||||
|
||||
for (value = enum_class->values; value->value_name; value++)
|
||||
{
|
||||
if (g_str_has_prefix (value->value_name, "GIMP_"))
|
||||
{
|
||||
gchar *scheme_name;
|
||||
ts_init_enum (sc, enum_type);
|
||||
|
||||
scheme_name = g_strdup (value->value_name + strlen ("GIMP_"));
|
||||
convert_string (scheme_name);
|
||||
enum_type = (GType) g_type_get_qdata (enum_type, quark);
|
||||
|
||||
symbol = sc->vptr->mk_symbol (sc, scheme_name);
|
||||
sc->vptr->scheme_define (sc, sc->global_env, symbol,
|
||||
sc->vptr->mk_integer (sc, value->value));
|
||||
sc->vptr->setimmutable (symbol);
|
||||
|
||||
g_free (scheme_name);
|
||||
}
|
||||
}
|
||||
|
||||
g_type_class_unref (enum_class);
|
||||
if (enum_type)
|
||||
ts_init_enum (sc, enum_type);
|
||||
}
|
||||
|
||||
/* Constants used in the register block of scripts */
|
||||
|
@ -453,15 +361,35 @@ ts_init_constants (scheme *sc)
|
|||
sc->vptr->scheme_define (sc, sc->global_env, symbol,
|
||||
sc->vptr->mk_string (sc, gimp_plug_in_directory ()));
|
||||
sc->vptr->setimmutable (symbol);
|
||||
|
||||
for (i = 0; old_constants[i].name != NULL; ++i)
|
||||
{
|
||||
symbol = sc->vptr->mk_symbol (sc, old_constants[i].name);
|
||||
sc->vptr->scheme_define (sc, sc->global_env, symbol,
|
||||
sc->vptr->mk_integer (sc,
|
||||
old_constants[i].value));
|
||||
sc->vptr->setimmutable (symbol);
|
||||
}
|
||||
|
||||
static void
|
||||
ts_init_enum (scheme *sc,
|
||||
GType enum_type)
|
||||
{
|
||||
GEnumClass *enum_class = g_type_class_ref (enum_type);
|
||||
GEnumValue *value;
|
||||
|
||||
for (value = enum_class->values; value->value_name; value++)
|
||||
{
|
||||
if (g_str_has_prefix (value->value_name, "GIMP_"))
|
||||
{
|
||||
gchar *scheme_name;
|
||||
pointer symbol;
|
||||
|
||||
scheme_name = g_strdup (value->value_name + strlen ("GIMP_"));
|
||||
convert_string (scheme_name);
|
||||
|
||||
symbol = sc->vptr->mk_symbol (sc, scheme_name);
|
||||
sc->vptr->scheme_define (sc, sc->global_env, symbol,
|
||||
sc->vptr->mk_integer (sc, value->value));
|
||||
sc->vptr->setimmutable (symbol);
|
||||
|
||||
g_free (scheme_name);
|
||||
}
|
||||
}
|
||||
|
||||
g_type_class_unref (enum_class);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in New Issue