From 7a8f465b2d70c6f94497e1d8a585d9579e6e27f9 Mon Sep 17 00:00:00 2001 From: Jacob Boerema Date: Fri, 5 Jan 2024 13:28:36 -0500 Subject: [PATCH] Issue #10588: enumerations for RotationType can't be used in Python Due to GObject Introspection we can't have the last part of an identifier start with a digit, since that part will be used in Python as the identifier, and Python doesn't allow that to start with a digit. e.g. GIMP_ROTATE_90 would be used in Python as image.rotate(Gimp.RotationType.90) To fix this we add DEGREES in front of the number, without a '_', even though that looks ugly. --- app/actions/drawable-actions.c | 6 +++--- app/actions/image-actions.c | 6 +++--- app/core/gimp-transform-utils.c | 6 +++--- app/core/gimpdrawable-transform.c | 28 ++++++++++++------------- app/core/gimpimage-rotate.c | 34 +++++++++++++++---------------- app/pdb/image-transform-cmds.c | 2 +- app/pdb/item-transform-cmds.c | 2 +- app/tests/test-core.c | 2 +- libgimp/gimpimagemetadata.c | 10 ++++----- libgimpbase/gimpbaseenums.c | 12 +++++------ libgimpbase/gimpbaseenums.h | 15 ++++++++------ pdb/enums.pl | 9 ++++---- 12 files changed, 68 insertions(+), 64 deletions(-) diff --git a/app/actions/drawable-actions.c b/app/actions/drawable-actions.c index c525ce49a9..ac9b902248 100644 --- a/app/actions/drawable-actions.c +++ b/app/actions/drawable-actions.c @@ -99,19 +99,19 @@ static const GimpEnumActionEntry drawable_rotate_actions[] = { "drawable-rotate-90", GIMP_ICON_OBJECT_ROTATE_90, NC_("drawable-action", "Rotate 90° _clockwise"), NULL, { NULL }, NC_("drawable-action", "Rotate drawable 90 degrees to the right"), - GIMP_ROTATE_90, FALSE, + GIMP_ROTATE_DEGREES90, FALSE, GIMP_HELP_LAYER_ROTATE_90 }, { "drawable-rotate-180", GIMP_ICON_OBJECT_ROTATE_180, NC_("drawable-action", "Rotate _180°"), NULL, { NULL }, NC_("drawable-action", "Turn drawable upside-down"), - GIMP_ROTATE_180, FALSE, + GIMP_ROTATE_DEGREES180, FALSE, GIMP_HELP_LAYER_ROTATE_180 }, { "drawable-rotate-270", GIMP_ICON_OBJECT_ROTATE_270, NC_("drawable-action", "Rotate 90° counter-clock_wise"), NULL, { NULL }, NC_("drawable-action", "Rotate drawable 90 degrees to the left"), - GIMP_ROTATE_270, FALSE, + GIMP_ROTATE_DEGREES270, FALSE, GIMP_HELP_LAYER_ROTATE_270 } }; diff --git a/app/actions/image-actions.c b/app/actions/image-actions.c index ba8f548777..6f188efcc9 100644 --- a/app/actions/image-actions.c +++ b/app/actions/image-actions.c @@ -277,19 +277,19 @@ static const GimpEnumActionEntry image_rotate_actions[] = { "image-rotate-90", GIMP_ICON_OBJECT_ROTATE_90, NC_("image-action", "Rotate 90° _clockwise"), NULL, { NULL }, NC_("image-action", "Rotate the image 90 degrees to the right"), - GIMP_ROTATE_90, FALSE, + GIMP_ROTATE_DEGREES90, FALSE, GIMP_HELP_IMAGE_ROTATE_90 }, { "image-rotate-180", GIMP_ICON_OBJECT_ROTATE_180, NC_("image-action", "Rotate _180°"), NULL, { NULL }, NC_("image-action", "Turn the image upside-down"), - GIMP_ROTATE_180, FALSE, + GIMP_ROTATE_DEGREES180, FALSE, GIMP_HELP_IMAGE_ROTATE_180 }, { "image-rotate-270", GIMP_ICON_OBJECT_ROTATE_270, NC_("image-action", "Rotate 90° counter-clock_wise"), NULL, { NULL }, NC_("image-action", "Rotate the image 90 degrees to the left"), - GIMP_ROTATE_270, FALSE, + GIMP_ROTATE_DEGREES270, FALSE, GIMP_HELP_IMAGE_ROTATE_270 } }; diff --git a/app/core/gimp-transform-utils.c b/app/core/gimp-transform-utils.c index 0e459ee06d..eed555a6f8 100644 --- a/app/core/gimp-transform-utils.c +++ b/app/core/gimp-transform-utils.c @@ -139,13 +139,13 @@ gimp_transform_matrix_rotate (GimpMatrix3 *matrix, switch (rotate_type) { - case GIMP_ROTATE_90: + case GIMP_ROTATE_DEGREES90: angle = G_PI_2; break; - case GIMP_ROTATE_180: + case GIMP_ROTATE_DEGREES180: angle = G_PI; break; - case GIMP_ROTATE_270: + case GIMP_ROTATE_DEGREES270: angle = - G_PI_2; break; } diff --git a/app/core/gimpdrawable-transform.c b/app/core/gimpdrawable-transform.c index 76492b03a6..5ad2c99102 100644 --- a/app/core/gimpdrawable-transform.c +++ b/app/core/gimpdrawable-transform.c @@ -355,17 +355,17 @@ gimp_drawable_transform_rotate_point (gint x, switch (rotate_type) { - case GIMP_ROTATE_90: + case GIMP_ROTATE_DEGREES90: *new_x = RINT (center_x - (gdouble) y + center_y); *new_y = RINT (center_y + (gdouble) x - center_x); break; - case GIMP_ROTATE_180: + case GIMP_ROTATE_DEGREES180: *new_x = RINT (center_x - ((gdouble) x - center_x)); *new_y = RINT (center_y - ((gdouble) y - center_y)); break; - case GIMP_ROTATE_270: + case GIMP_ROTATE_DEGREES270: *new_x = RINT (center_x + (gdouble) y - center_y); *new_y = RINT (center_y - (gdouble) x + center_x); break; @@ -420,7 +420,7 @@ gimp_drawable_transform_buffer_rotate (GimpDrawable *drawable, switch (rotate_type) { - case GIMP_ROTATE_90: + case GIMP_ROTATE_DEGREES90: gimp_drawable_transform_rotate_point (orig_x, orig_y + orig_height, rotate_type, center_x, center_y, @@ -429,7 +429,7 @@ gimp_drawable_transform_buffer_rotate (GimpDrawable *drawable, new_height = orig_width; break; - case GIMP_ROTATE_180: + case GIMP_ROTATE_DEGREES180: gimp_drawable_transform_rotate_point (orig_x + orig_width, orig_y + orig_height, rotate_type, center_x, center_y, @@ -438,7 +438,7 @@ gimp_drawable_transform_buffer_rotate (GimpDrawable *drawable, new_height = orig_height; break; - case GIMP_ROTATE_270: + case GIMP_ROTATE_DEGREES270: gimp_drawable_transform_rotate_point (orig_x + orig_width, orig_y, rotate_type, center_x, center_y, @@ -501,10 +501,10 @@ gimp_drawable_transform_buffer_rotate (GimpDrawable *drawable, switch (rotate_type) { - case GIMP_ROTATE_90: + case GIMP_ROTATE_DEGREES90: gimp_drawable_transform_rotate_point (clip_x + clip_width, clip_y, - GIMP_ROTATE_270, + GIMP_ROTATE_DEGREES270, center_x, center_y, &orig_x, @@ -515,17 +515,17 @@ gimp_drawable_transform_buffer_rotate (GimpDrawable *drawable, orig_height = clip_width; break; - case GIMP_ROTATE_180: + case GIMP_ROTATE_DEGREES180: orig_x = clip_x - orig_x; orig_y = clip_y - orig_y; orig_width = clip_width; orig_height = clip_height; break; - case GIMP_ROTATE_270: + case GIMP_ROTATE_DEGREES270: gimp_drawable_transform_rotate_point (clip_x, clip_y + clip_height, - GIMP_ROTATE_90, + GIMP_ROTATE_DEGREES90, center_x, center_y, &orig_x, @@ -576,7 +576,7 @@ gimp_drawable_transform_buffer_rotate (GimpDrawable *drawable, switch (rotate_type) { - case GIMP_ROTATE_90: + case GIMP_ROTATE_DEGREES90: { guchar *buf = g_new (guchar, new_height * orig_bpp); gint i; @@ -608,7 +608,7 @@ gimp_drawable_transform_buffer_rotate (GimpDrawable *drawable, } break; - case GIMP_ROTATE_180: + case GIMP_ROTATE_DEGREES180: { guchar *buf = g_new (guchar, new_width * orig_bpp); gint i, j, k; @@ -654,7 +654,7 @@ gimp_drawable_transform_buffer_rotate (GimpDrawable *drawable, } break; - case GIMP_ROTATE_270: + case GIMP_ROTATE_DEGREES270: { guchar *buf = g_new (guchar, new_width * orig_bpp); gint i; diff --git a/app/core/gimpimage-rotate.c b/app/core/gimpimage-rotate.c index 36610e9e94..c231c6b1ac 100644 --- a/app/core/gimpimage-rotate.c +++ b/app/core/gimpimage-rotate.c @@ -96,8 +96,8 @@ gimp_image_rotate (GimpImage *image, /* Resize the image (if needed) */ switch (rotate_type) { - case GIMP_ROTATE_90: - case GIMP_ROTATE_270: + case GIMP_ROTATE_DEGREES90: + case GIMP_ROTATE_DEGREES270: new_image_width = gimp_image_get_height (image); new_image_height = gimp_image_get_width (image); size_changed = TRUE; @@ -105,7 +105,7 @@ gimp_image_rotate (GimpImage *image, offset_y = (gimp_image_get_height (image) - new_image_height) / 2; break; - case GIMP_ROTATE_180: + case GIMP_ROTATE_DEGREES180: new_image_width = gimp_image_get_width (image); new_image_height = gimp_image_get_height (image); size_changed = FALSE; @@ -304,17 +304,17 @@ gimp_image_rotate_item_offset (GimpImage *image, switch (rotate_type) { - case GIMP_ROTATE_90: + case GIMP_ROTATE_DEGREES90: x = gimp_image_get_height (image) - off_y - gimp_item_get_width (item); y = off_x; break; - case GIMP_ROTATE_270: + case GIMP_ROTATE_DEGREES270: x = off_y; y = gimp_image_get_width (image) - off_x - gimp_item_get_height (item); break; - case GIMP_ROTATE_180: + case GIMP_ROTATE_DEGREES180: return; default: @@ -347,7 +347,7 @@ gimp_image_rotate_guides (GimpImage *image, switch (rotate_type) { - case GIMP_ROTATE_90: + case GIMP_ROTATE_DEGREES90: switch (orientation) { case GIMP_ORIENTATION_HORIZONTAL: @@ -367,7 +367,7 @@ gimp_image_rotate_guides (GimpImage *image, } break; - case GIMP_ROTATE_180: + case GIMP_ROTATE_DEGREES180: switch (orientation) { case GIMP_ORIENTATION_HORIZONTAL: @@ -387,7 +387,7 @@ gimp_image_rotate_guides (GimpImage *image, } break; - case GIMP_ROTATE_270: + case GIMP_ROTATE_DEGREES270: switch (orientation) { case GIMP_ORIENTATION_HORIZONTAL: @@ -432,19 +432,19 @@ gimp_image_rotate_sample_points (GimpImage *image, switch (rotate_type) { - case GIMP_ROTATE_90: + case GIMP_ROTATE_DEGREES90: gimp_sample_point_set_position (sample_point, gimp_image_get_height (image) - old_y, old_x); break; - case GIMP_ROTATE_180: + case GIMP_ROTATE_DEGREES180: gimp_sample_point_set_position (sample_point, gimp_image_get_width (image) - old_x, gimp_image_get_height (image) - old_y); break; - case GIMP_ROTATE_270: + case GIMP_ROTATE_DEGREES270: gimp_sample_point_set_position (sample_point, old_y, gimp_image_get_width (image) - old_x); @@ -470,7 +470,7 @@ gimp_image_metadata_rotate (GimpImage *image, break; case GEXIV2_ORIENTATION_ROT_180: - gimp_image_rotate (image, context, GIMP_ROTATE_180, progress); + gimp_image_rotate (image, context, GIMP_ROTATE_DEGREES180, progress); break; case GEXIV2_ORIENTATION_VFLIP: @@ -478,21 +478,21 @@ gimp_image_metadata_rotate (GimpImage *image, break; case GEXIV2_ORIENTATION_ROT_90_HFLIP: /* flipped diagonally around '\' */ - gimp_image_rotate (image, context, GIMP_ROTATE_90, progress); + gimp_image_rotate (image, context, GIMP_ROTATE_DEGREES90, progress); gimp_image_flip (image, context, GIMP_ORIENTATION_HORIZONTAL, progress); break; case GEXIV2_ORIENTATION_ROT_90: /* 90 CW */ - gimp_image_rotate (image, context, GIMP_ROTATE_90, progress); + gimp_image_rotate (image, context, GIMP_ROTATE_DEGREES90, progress); break; case GEXIV2_ORIENTATION_ROT_90_VFLIP: /* flipped diagonally around '/' */ - gimp_image_rotate (image, context, GIMP_ROTATE_90, progress); + gimp_image_rotate (image, context, GIMP_ROTATE_DEGREES90, progress); gimp_image_flip (image, context, GIMP_ORIENTATION_VERTICAL, progress); break; case GEXIV2_ORIENTATION_ROT_270: /* 90 CCW */ - gimp_image_rotate (image, context, GIMP_ROTATE_270, progress); + gimp_image_rotate (image, context, GIMP_ROTATE_DEGREES270, progress); break; default: /* shouldn't happen */ diff --git a/app/pdb/image-transform-cmds.c b/app/pdb/image-transform-cmds.c index 27fbed55dd..229119af8c 100644 --- a/app/pdb/image-transform-cmds.c +++ b/app/pdb/image-transform-cmds.c @@ -441,7 +441,7 @@ register_image_transform_procs (GimpPDB *pdb) "rotate type", "Angle of rotation", GIMP_TYPE_ROTATION_TYPE, - GIMP_ROTATE_90, + GIMP_ROTATE_DEGREES90, GIMP_PARAM_READWRITE)); gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); diff --git a/app/pdb/item-transform-cmds.c b/app/pdb/item-transform-cmds.c index c5dc42ed78..8418e1d3dc 100644 --- a/app/pdb/item-transform-cmds.c +++ b/app/pdb/item-transform-cmds.c @@ -1219,7 +1219,7 @@ register_item_transform_procs (GimpPDB *pdb) "rotate type", "Type of rotation", GIMP_TYPE_ROTATION_TYPE, - GIMP_ROTATE_90, + GIMP_ROTATE_DEGREES90, GIMP_PARAM_READWRITE)); gimp_procedure_add_argument (procedure, g_param_spec_boolean ("auto-center", diff --git a/app/tests/test-core.c b/app/tests/test-core.c index 6cdf4b04f9..69788e8e61 100644 --- a/app/tests/test-core.c +++ b/app/tests/test-core.c @@ -137,7 +137,7 @@ rotate_non_overlapping (GimpTestFixture *fixture, 0, FALSE); - gimp_item_rotate (GIMP_ITEM (layer), context, GIMP_ROTATE_90, 0., -10., TRUE); + gimp_item_rotate (GIMP_ITEM (layer), context, GIMP_ROTATE_DEGREES90, 0., -10., TRUE); g_assert_cmpint (result, ==, TRUE); g_assert_cmpint (gimp_image_get_n_layers (image), ==, 1); diff --git a/libgimp/gimpimagemetadata.c b/libgimp/gimpimagemetadata.c index 805ccaf4d7..b2f69b91b8 100644 --- a/libgimp/gimpimagemetadata.c +++ b/libgimp/gimpimagemetadata.c @@ -316,7 +316,7 @@ gimp_image_metadata_rotate (GimpImage *image, break; case GEXIV2_ORIENTATION_ROT_180: - gimp_image_rotate (image, GIMP_ROTATE_180); + gimp_image_rotate (image, GIMP_ROTATE_DEGREES180); break; case GEXIV2_ORIENTATION_VFLIP: @@ -324,21 +324,21 @@ gimp_image_metadata_rotate (GimpImage *image, break; case GEXIV2_ORIENTATION_ROT_90_HFLIP: /* flipped diagonally around '\' */ - gimp_image_rotate (image, GIMP_ROTATE_90); + gimp_image_rotate (image, GIMP_ROTATE_DEGREES90); gimp_image_flip (image, GIMP_ORIENTATION_HORIZONTAL); break; case GEXIV2_ORIENTATION_ROT_90: /* 90 CW */ - gimp_image_rotate (image, GIMP_ROTATE_90); + gimp_image_rotate (image, GIMP_ROTATE_DEGREES90); break; case GEXIV2_ORIENTATION_ROT_90_VFLIP: /* flipped diagonally around '/' */ - gimp_image_rotate (image, GIMP_ROTATE_90); + gimp_image_rotate (image, GIMP_ROTATE_DEGREES90); gimp_image_flip (image, GIMP_ORIENTATION_VERTICAL); break; case GEXIV2_ORIENTATION_ROT_270: /* 90 CCW */ - gimp_image_rotate (image, GIMP_ROTATE_270); + gimp_image_rotate (image, GIMP_ROTATE_DEGREES270); break; default: /* shouldn't happen */ diff --git a/libgimpbase/gimpbaseenums.c b/libgimpbase/gimpbaseenums.c index 69cec681dd..a89ed3db6e 100644 --- a/libgimpbase/gimpbaseenums.c +++ b/libgimpbase/gimpbaseenums.c @@ -1496,17 +1496,17 @@ gimp_rotation_type_get_type (void) { static const GEnumValue values[] = { - { GIMP_ROTATE_90, "GIMP_ROTATE_90", "90" }, - { GIMP_ROTATE_180, "GIMP_ROTATE_180", "180" }, - { GIMP_ROTATE_270, "GIMP_ROTATE_270", "270" }, + { GIMP_ROTATE_DEGREES90, "GIMP_ROTATE_DEGREES90", "degrees90" }, + { GIMP_ROTATE_DEGREES180, "GIMP_ROTATE_DEGREES180", "degrees180" }, + { GIMP_ROTATE_DEGREES270, "GIMP_ROTATE_DEGREES270", "degrees270" }, { 0, NULL, NULL } }; static const GimpEnumDesc descs[] = { - { GIMP_ROTATE_90, "GIMP_ROTATE_90", NULL }, - { GIMP_ROTATE_180, "GIMP_ROTATE_180", NULL }, - { GIMP_ROTATE_270, "GIMP_ROTATE_270", NULL }, + { GIMP_ROTATE_DEGREES90, "GIMP_ROTATE_DEGREES90", NULL }, + { GIMP_ROTATE_DEGREES180, "GIMP_ROTATE_DEGREES180", NULL }, + { GIMP_ROTATE_DEGREES270, "GIMP_ROTATE_DEGREES270", NULL }, { 0, NULL, NULL } }; diff --git a/libgimpbase/gimpbaseenums.h b/libgimpbase/gimpbaseenums.h index fcae5e0ff0..7d922d9d60 100644 --- a/libgimpbase/gimpbaseenums.h +++ b/libgimpbase/gimpbaseenums.h @@ -1015,9 +1015,9 @@ typedef enum /** * GimpRotationType: - * @GIMP_ROTATE_90: 90 degrees - * @GIMP_ROTATE_180: 180 degrees - * @GIMP_ROTATE_270: 270 degrees + * @GIMP_ROTATE_DEGREES90: 90 degrees + * @GIMP_ROTATE_DEGREES180: 180 degrees + * @GIMP_ROTATE_DEGREES270: 270 degrees * * Types of simple rotations. **/ @@ -1025,11 +1025,14 @@ typedef enum GType gimp_rotation_type_get_type (void) G_GNUC_CONST; +/* Due to GObject Introspection we can't have the last part of an identifier + * start with a digit, since that part will be used in Python as the + * identifier, and Python doesn't allow that to start with a digit. */ typedef enum { - GIMP_ROTATE_90, - GIMP_ROTATE_180, - GIMP_ROTATE_270 + GIMP_ROTATE_DEGREES90, + GIMP_ROTATE_DEGREES180, + GIMP_ROTATE_DEGREES270 } GimpRotationType; diff --git a/pdb/enums.pl b/pdb/enums.pl index 5ba19906ff..c715d754b4 100644 --- a/pdb/enums.pl +++ b/pdb/enums.pl @@ -489,10 +489,11 @@ package Gimp::CodeGen::enums; GimpRotationType => { contig => 1, header => 'libgimpbase/gimpbaseenums.h', - symbols => [ qw(GIMP_ROTATE_90 GIMP_ROTATE_180 GIMP_ROTATE_270) ], - mapping => { GIMP_ROTATE_90 => '0', - GIMP_ROTATE_180 => '1', - GIMP_ROTATE_270 => '2' } + symbols => [ qw(GIMP_ROTATE_DEGREES90 GIMP_ROTATE_DEGREES180 + GIMP_ROTATE_DEGREES270) ], + mapping => { GIMP_ROTATE_DEGREES90 => '0', + GIMP_ROTATE_DEGREES180 => '1', + GIMP_ROTATE_DEGREES270 => '2' } }, GimpRunMode => { contig => 1,