Gimp.Palette

g GObject.GInterface GObject.GInterface Gimp.ConfigInterface Gimp.ConfigInterface GObject.GInterface->Gimp.ConfigInterface GObject.Object GObject.Object Gimp.Resource Gimp.Resource GObject.Object->Gimp.Resource Gimp.ConfigInterface->Gimp.Resource Gimp.Palette Gimp.Palette Gimp.Resource->Gimp.Palette

Subclasses:

None

Methods

Inherited:

Gimp.Resource (20), GObject.Object (37), Gimp.ConfigInterface (14)

Structs:

GObject.ObjectClass (5)

class

get_by_name (name)

class

new (name)

add_entry (entry_name, color)

delete_entry (entry_num)

get_color_count ()

get_colormap (format)

get_colors ()

get_columns ()

get_entry_color (entry_num)

get_entry_name (entry_num)

set_colormap (format, colormap, num_bytes)

set_columns (columns)

set_entry_color (entry_num, color)

set_entry_name (entry_num, entry_name)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Inherited:

Gimp.Resource (1)

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class Gimp.Palette(**kwargs)
Bases:

Gimp.Resource

Abstract:

No

Structure:

Gimp.PaletteClass

Installable object, a small set of colors a user can choose from.

classmethod get_by_name(name)
Parameters:

name (str) – The name of the palette.

Returns:

The palette.

Return type:

Gimp.Palette or None

Returns the palette with the given name.

Returns an existing palette having the given name. Returns None when no palette exists of that name.

New in version 3.0.

classmethod new(name)
Parameters:

name (str) – The requested name of the new palette.

Returns:

The palette.

Return type:

Gimp.Palette

Creates a new palette

Creates a new palette. The new palette has no color entries. You must add color entries for a user to choose. The actual name might be different than the requested name, when the requested name is already in use.

New in version 2.2.

add_entry(entry_name, color)
Parameters:
  • entry_name (str or None) – A name for the entry.

  • color (Gegl.Color) – The color for the added entry.

Returns:

True on success.

entry_num:

The index of the added entry.

Return type:

(bool, entry_num: int)

Appends an entry to the palette.

Appends an entry to the palette. Neither color nor name must be unique within the palette. When name is the empty string, this sets the entry name to \”Untitled\”. Returns the index of the entry. Returns an error when palette is not editable.

New in version 2.2.

delete_entry(entry_num)
Parameters:

entry_num (int) – The index of the entry to delete.

Returns:

True on success.

Return type:

bool

Deletes an entry from the palette.

This function will fail and return False if the index is out or range or if the palette is not editable. Additionally if the palette belongs to an indexed image, it will only be possible to delete palette colors not in use in the image.

New in version 2.2.

get_color_count()
Returns:

The number of colors in the palette.

Return type:

int

Get the count of colors in the palette.

Returns the number of colors in the palette.

New in version 2.2.

get_colormap(format)
Parameters:

format (Babl.Object) – The desired color format.

Returns:

The palette’s colormap.

num_colors:

The number of colors in the palette.

Return type:

(bytes, num_colors: int)

This procedure returns a palette’s colormap as an array of bytes with all colors converted to a given Babl.Object format.

The byte-size of the returned colormap depends on the number of colors and on the bytes-per-pixel size of format. E.g. that the following equality is ensured:

``C num_bytes == num_colors * babl_format_get_bytes_per_pixel (format) ``

Therefore num_colors and num_bytes are kinda redundant since both indicate the size of the return value in a different way. You may both set them to None but not at the same time.

New in version 3.0.

get_colors()
Returns:

The colors in the palette. The returned value must be freed with Gimp.color_array_free().

Return type:

[Gegl.Color]

Gets colors in the palette.

Returns an array of colors in the palette. Free the returned array with Gimp.color_array_free().

New in version 2.6.

get_columns()
Returns:

The number of columns used to display this palette.

Return type:

int

Gets the number of columns used to display the palette

Gets the preferred number of columns to display the palette.

New in version 2.4.

get_entry_color(entry_num)
Parameters:

entry_num (int) – The index of the entry to get the color of.

Returns:

The color at the index.

Return type:

Gegl.Color

Gets the color of an entry in the palette.

Returns the color of the entry at the given zero-based index into the palette. Returns None when the index is out of range.

New in version 2.2.

get_entry_name(entry_num)
Parameters:

entry_num (int) – The entry to get.

Returns:

True on success.

entry_name:

The name of the entry.

Return type:

(bool, entry_name: str)

Gets the name of an entry in the palette.

Gets the name of the entry at the zero-based index into the palette. Returns an error when the index is out of range.

New in version 2.2.

set_colormap(format, colormap, num_bytes)
Parameters:
  • format (Babl.Object) – The desired color format. colormap (array length=num_bytes): The new colormap values.

  • colormap (int) –

  • num_bytes (int) – The byte-size of colormap.

Returns:

True on success.

Return type:

bool

This procedure sets the entries in the specified palette in one go, though they must all be in the same format.

The number of entries depens on the num_bytes size of colormap and the bytes-per-pixel size of format. The procedure will fail if num_bytes is not an exact multiple of the number of bytes per pixel of format.

New in version 3.0.

set_columns(columns)
Parameters:

columns (int) – The new number of columns.

Returns:

True on success.

Return type:

bool

Sets the number of columns used to display the palette

Set the number of colors shown per row when the palette is displayed. Returns an error when the palette is not editable. The maximum allowed value is 64.

New in version 2.4.

set_entry_color(entry_num, color)
Parameters:
  • entry_num (int) – The entry to get.

  • color (Gegl.Color) – The new color.

Returns:

True on success.

Return type:

bool

Sets the color of an entry in the palette.

Sets the color of the entry at the zero-based index into the palette. Returns an error when the index is out of range. Returns an error when the palette is not editable.

New in version 2.2.

set_entry_name(entry_num, entry_name)
Parameters:
  • entry_num (int) – The entry to get.

  • entry_name (str or None) – The new name.

Returns:

True on success.

Return type:

bool

Sets the name of an entry in the palette.

Sets the name of the entry at the zero-based index into the palette. Returns an error if the index is out or range. Returns an error if the palette is not editable.

New in version 2.2.