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.
This commit is contained in:
Jacob Boerema 2024-01-05 13:28:36 -05:00
parent 7e2a34bab8
commit 7a8f465b2d
12 changed files with 68 additions and 64 deletions

View File

@ -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 }
};

View File

@ -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 }
};

View File

@ -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;
}

View File

@ -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;

View File

@ -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 */

View File

@ -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);

View File

@ -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",

View File

@ -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);

View File

@ -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 */

View File

@ -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 }
};

View File

@ -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;

View File

@ -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,