Module color

Various color conversions utilities.

class ooodev.utils.color.Color

Color Type. Int RGB Value

alias of int

namedtuple ooodev.utils.color.CommonColor[source]

Named Colors.

Example

def set_chart(sheet: XSpreadsheet, range_addr: CellRangeAddress) -> None:
    chart = Chart2.insert_chart(sheet, range_addr, "A22", 20, 11, Chart2.ChartLookup.Column.TEMPLATE_PERCENT.COLUMN_DEEP_3D)
    Chart2.set_background_colors(chart, CommonColor.LIGHT_GREEN, CommonColor.BROWN)

Changed in version 0.10.4: Added AUTO_COLOR

Fields:

classmethod from_str(str_color)[source]

Convert string value to a Color value

str_color can be a hex value, a integer value as string or any named value in CommonColor

str_color can contain single spaces or _ or -. MEDIUM_SEA_GREEN, MEDIUM-SEA-GREEN, MEDIUM SEA GREEN, medium sea green, mediumSeaGreen , MediumSeaGreen are all equivalent.

Parameters:

str_color (str) – Value to convert. Case insensitive

Raises:

ValueError – If unable to convert.

Returns:

Convert value as Color

Return type:

Color

static get_random_color()[source]

Gets a random common color

Return type:

NewType()(Color, int)

ALICE_BLUE = 15792383
ANTIQUE_WHITE = 16444375
AQUA = 65535
AQUAMARINE = 8388564
AUTO_COLOR = -1

Automatic Color Value.

In most cases, LibreOffice API will use -1 for automatic or no color. This is the same as the value of Color(-1).

AZURE = 15794175
BEIGE = 16119260
BISQUE = 16770244
BLACK = 0
BLANCHED_ALMOND = 16772045
BLUE = 255
BLUE_VIOLET = 9055202
BROWN = 10824234
BURLY_WOOD = 14596231
CADET_BLUE = 6266528
CHARTREUSE = 8388352
CHOCOLATE = 13789470
CORAL = 16744272
CORNFLOWER_BLUE = 6591981
CORNSILK = 16775388
CRIMSON = 14423100
CYAN = 65535
DARK_BLUE = 139
DARK_CYAN = 35723
DARK_GOLDENROD = 12092939
DARK_GRAY = 11119017
DARK_GREEN = 25600
DARK_GREY = 11119017
DARK_KHAKI = 12433259
DARK_MAGENTA = 9109643
DARK_OLIVE_GREEN = 5597999
DARK_ORANGE = 16747520
DARK_ORCHID = 10040012
DARK_RED = 9109504
DARK_SALMON = 15308410
DARK_SEA_GREEN = 9419919
DARK_SLATE_BLUE = 4734347
DARK_SLATE_GRAY = 3100495
DARK_SLATE_GREY = 3100495
DARK_TURQUOISE = 52945
DARK_VIOLET = 9699539
DEEP_PINK = 16716947
DEEP_SKY_BLUE = 49151
DEFAULT_BLUE = 7512015
DIM_GRAY = 6908265
DIM_GREY = 6908265
DODGER_BLUE = 2003199
FIRE_BRICK = 11674146
FLORAL_WHITE = 16775920
FOREST_GREEN = 2263842
FUCHSIA = 16711935
GAINSBORO = 14474460
GHOST_WHITE = 16316671
GOLD = 16766720
GOLDENROD = 14329120
GRAY = 8421504
GREEN = 32768
GREEN_YELLOW = 11403055
GREY = 8421504
HONEYDEW = 15794160
HOT_PINK = 16738740
INDIAN_RED = 13458524
INDIGO = 4915330
IVORY = 16777200
KHAKI = 15787660
LAVENDER = 15132410
LAVENDER_BLUSH = 16773365
LAWN_GREEN = 8190976
LEMON_CHIFFON = 16775885
LIGHT_BLUE = 11393254
LIGHT_CORAL = 15761536
LIGHT_CYAN = 14745599
LIGHT_GOLDENROD_YELLOW = 16448210
LIGHT_GRAY = 13882323
LIGHT_GREEN = 9498256
LIGHT_GREY = 13882323
LIGHT_PINK = 16758465
LIGHT_SALMON = 16752762
LIGHT_SEA_GREEN = 2142890
LIGHT_SKY_BLUE = 8900346
LIGHT_SLATE_GRAY = 7833753
LIGHT_SLATE_GREY = 7833753
LIGHT_STEEL_BLUE = 11584734
LIGHT_YELLOW = 16777184
LIME = 65280
LIME_GREEN = 3329330
LINEN = 16445670
MAGENTA = 16711935
MAROON = 8388608
MEDIUM_AQUAMARINE = 6737322
MEDIUM_BLUE = 205
MEDIUM_ORCHID = 12211667
MEDIUM_PURPLE = 9662683
MEDIUM_SEA_GREEN = 3978097
MEDIUM_SLATE_BLUE = 8087790
MEDIUM_SPRING_GREEN = 64154
MEDIUM_TURQUOISE = 4772300
MEDIUM_VIOLET_RED = 13047173
MIDNIGHT_BLUE = 1644912
MINT_CREAM = 16121850
MISTY_ROSE = 16770273
MOCCASIN = 16770229
NAVAJO_WHITE = 16768685
NAVY = 128
OLD_LACE = 16643558
OLIVE = 8421376
OLIVE_DRAB = 7048739
ORANGE = 16753920
ORANGE_RED = 16729344
ORCHID = 14315734
PALE_BLUE = 14085119
PALE_GOLDENROD = 15657130
PALE_GREEN = 10025880
PALE_TURQUOISE = 11529966
PALE_VIOLET_RED = 14381203
PAPAYA_WHIP = 16773077
PEACH_PUFF = 16767673
PERU = 13468991
PINK = 16761035
PLUM = 14524637
POWDER_BLUE = 11591910
PURPLE = 8388736
REBECCA_PURPLE = 6697881
RED = 16711680
ROSY_BROWN = 12357519
ROYAL_BLUE = 4286945
SADDLE_BROWN = 9127187
SALMON = 16416882
SANDY_BROWN = 16032864
SEASHELL = 16774638
SEA_GREEN = 3050327
SIENNA = 10506797
SILVER = 12632256
SKY_BLUE = 8900331
SLATE_BLUE = 6970061
SLATE_GRAY = 7372944
SLATE_GREY = 7372944
SNOW = 16775930
SPRING_GREEN = 65407
STEEL_BLUE = 4620980
TAN = 13808780
TEAL = 32896
THISTLE = 14204888
TOMATO = 16737095
TURQUOISE = 4251856
VIOLET = 15631086
WHEAT = 16113331
WHITE = 16777215
WHITE_SMOKE = 16119285
YELLOW = 16776960
YELLOW_GREEN = 10145074
namedtuple ooodev.utils.color.HSL(hue, saturation, lightness)[source]

HSL(hue, saturation, lightness)

Fields:
  1.  hue (float) – Alias for field number 0

  2.  saturation (float) – Alias for field number 1

  3.  lightness (float) – Alias for field number 2

namedtuple ooodev.utils.color.HSV(hue, saturation, value)[source]

HSV(hue, saturation, value)

Fields:
  1.  hue (float) – Alias for field number 0

  2.  saturation (float) – Alias for field number 1

  3.  value (float) – Alias for field number 2

namedtuple ooodev.utils.color.RGB(red, green, blue)[source]

RGB(red, green, blue)

Fields:
  1.  red (int) – Red color as int

  2.  green (int) – Green color as int

  3.  blue (int) – Blue color as int

classmethod from_color(c)[source]

Gets a color instance from input color that represents a rgb color.

Parameters:

c (Color) – Color that contains rgb color data.

Returns:

Color information as RGB struct.

Return type:

RGB

static from_hex(rgb_hex)[source]

Gets a color instance from int that represents a rgb color.

Parameters:

rgb_int (int) – int that contains rgb color data.

Returns:

Color information as RGB struct.

Return type:

RGB

static from_int(rgb_int)[source]

Gets a color instance from int that represents a rgb color.

Parameters:

rgb_int (int) – int that contains rgb color data.

Returns:

Color information as RGB struct.

Return type:

RGB

get_brightness()[source]

Gets brightness from 0 (dark) to 255 (light)

Returns:

brightness level

Return type:

int

get_luminance()[source]

Gets luminance value for current color

Returns:

luminance value

Return type:

float

is_dark()[source]

Get is current color is dark. If color has a brightness less than 128 it is considered dark.

Returns:

True if color is dark; Otherwise, False

Return type:

bool

is_light()[source]

Get is current color is light. If color has a brightness Greater than 128 it is considered light.

Returns:

True if color is light; Otherwise, False

Return type:

bool

isvalid()[source]

Gets if the value of red, green and blue are valid.

Returns:

True if valid; Otherwise, False

Return type:

bool

to_color()[source]

Gets instance as rgb Color

Returns:

red, green, blue encoded as Color.

Return type:

Color

to_hex()[source]

Gets instance as hex string in format of ff3322

Returns:

red, green, blue encoded as hex string.

Return type:

str

to_int()[source]

Gets instance as rgb int

Returns:

red, green, blue encoded as int.

Return type:

int

namedtuple ooodev.utils.color.RGBA(red, green, blue, alpha)[source]

RGBA(red, green, blue, alpha)

Fields:
  1.  red (int) – Red color as int

  2.  green (int) – Green color as int

  3.  blue (int) – Blue color as int

  4.  alpha (int) – Alias for field number 3

static from_int(value)[source]

Gets RGAB from int value

Parameters:

value (int) – Value that represents a RGBA

Returns:

Instance converted from integer.

Return type:

RGBA

to_int()[source]

Gets integer representing RGBA value

Return type:

int

namedtuple ooodev.utils.color.StandardColor[source]

Standard palette Colors

Changed in version 0.10.4: Added AUTO_COLOR

Fields:

static get_random_color()[source]

Gets a random Standard Palette color

Return type:

NewType()(Color, int)

AUTO_COLOR = -1

Automatic Color Value.

In most cases, LibreOffice API will use -1 for automatic or no color. This is the same as the value of Color(-1).

BLACK = 0
BLUE = 2777241
BLUE_DARK1 = 3433892
BLUE_DARK2 = 3494505
BLUE_DARK3 = 3685692
BLUE_DARK4 = 3548179
BLUE_LIGHT1 = 5866416
BLUE_LIGHT2 = 7512015
BLUE_LIGHT3 = 11847644
BLUE_LIGHT4 = 14608111
BRICK = 16728064
BRICK_DARK1 = 15551493
BRICK_DARK2 = 12470282
BRICK_DARK3 = 8468233
BRICK_DARK4 = 4923908
BRICK_LIGHT1 = 16733225
BRICK_LIGHT2 = 16743257
BRICK_LIGHT3 = 16755349
BRICK_LIGHT4 = 16767182
DEFAULT_BLUE = 7512015
GOLD = 16760576
GOLD_DARK1 = 15245826
GOLD_DARK2 = 11827204
GOLD_DARK3 = 7883524
GOLD_DARK4 = 4663042
GOLD_LIGHT1 = 16765992
GOLD_LIGHT2 = 16768601
GOLD_LIGHT3 = 16771476
GOLD_LIGHT4 = 16774606
GRAY = 8421504
GRAY_DARK1 = 6710886
GRAY_DARK2 = 3355443
GRAY_DARK3 = 1842204
GRAY_DARK4 = 1118481
GRAY_LIGHT1 = 10066329
GRAY_LIGHT2 = 11711154
GRAY_LIGHT3 = 13421772
GRAY_LIGHT4 = 14540253
GRAY_LIGHT5 = 15658734
GREEN = 43315
GREEN_DARK1 = 432686
GREEN_DARK2 = 1209890
GREEN_DARK3 = 2247442
GREEN_DARK4 = 3024646
GREEN_LIGHT1 = 4173638
GREEN_LIGHT2 = 7847013
GREEN_LIGHT3 = 11522197
GREEN_LIGHT4 = 14543051
INDIGO = 5582989
INDIGO_DARK1 = 5973885
INDIGO_DARK2 = 5579099
INDIGO_DARK3 = 4726066
INDIGO_DARK4 = 3807759
INDIGO_LIGHT1 = 7036571
INDIGO_LIGHT2 = 9340590
INDIGO_LIGHT3 = 12039114
INDIGO_LIGHT4 = 14605542
LIME = 8508442
LIME_DARK1 = 6207774
LIME_DARK2 = 4622874
LIME_DARK3 = 3757329
LIME_DARK4 = 3418630
LIME_LIGHT1 = 12313405
LIME_LIGHT2 = 13953643
LIME_LIGHT3 = 15266465
LIME_LIGHT4 = 16185812
MAGENTA = 12517441
MAGENTA_DARK1 = 10946379
MAGENTA_DARK2 = 8786241
MAGENTA_DARK3 = 6362921
MAGENTA_DARK4 = 4266253
MAGENTA_LIGHT1 = 14036558
MAGENTA_LIGHT2 = 14770547
MAGENTA_LIGHT3 = 15506340
MAGENTA_LIGHT4 = 16241109
ORANGE = 16744448
ORANGE_DARK1 = 15365376
ORANGE_DARK2 = 12082176
ORANGE_DARK3 = 8076544
ORANGE_DARK4 = 4793088
ORANGE_LIGHT1 = 16745997
ORANGE_LIGHT2 = 16750383
ORANGE_LIGHT3 = 16758380
ORANGE_LIGHT4 = 16767926
PURPLE = 8388736
PURPLE_DARK1 = 7865203
PURPLE_DARK2 = 6621523
PURPLE_DARK3 = 5115949
PURPLE_DARK4 = 3872270
PURPLE_LIGHT1 = 9248117
PURPLE_LIGHT2 = 10569342
PURPLE_LIGHT3 = 12550558
PURPLE_LIGHT4 = 14729933
RED = 16711680
RED_DARK1 = 15797516
RED_DARK2 = 13181214
RED_DARK3 = 9250846
RED_DARK4 = 5251084
RED_LIGHT1 = 16726072
RED_LIGHT2 = 16739693
RED_LIGHT3 = 16754342
RED_LIGHT4 = 16766935
TEAL = 1410150
TEAL_DARK1 = 1475155
TEAL_DARK2 = 1993273
TEAL_DARK3 = 2639647
TEAL_DARK4 = 3155721
TEAL_LIGHT1 = 5280650
TEAL_LIGHT2 = 8498342
TEAL_LIGHT3 = 11782855
TEAL_LIGHT4 = 14608357
WHITE = 16777215
YELLOW = 16776960
YELLOW_DARK1 = 15132933
YELLOW_DARK2 = 11317772
YELLOW_DARK3 = 7368204
YELLOW_DARK4 = 4469253
YELLOW_LIGHT1 = 16777016
YELLOW_LIGHT2 = 16777069
YELLOW_LIGHT3 = 16777126
YELLOW_LIGHT4 = 16777175
ooodev.utils.color.clamp(value, min_value, max_value)[source]

Constrains a value to a min and an max value

Parameters:
  • value (float) – Value to constrain

  • min_value (float) – Min allowed value

  • max_value (float) – Max allowed value

Returns:

constrained value if value is outside of min_value or max_value; Otherwise, value.

Return type:

float

ooodev.utils.color.clamp01(value)[source]

Gets a value that is constrained between 0.0 and 1.0

Parameters:

value (float) – Value

Returns:

A value that is no less than 0.0 and no greater then 1.0

Return type:

float

ooodev.utils.color.darken(rgb_color: int, percent: int | float) ooodev.utils.color.RGB[source]
ooodev.utils.color.darken(rgb_color: ooodev.utils.color.RGB, percent: int | float) ooodev.utils.color.RGB
ooodev.utils.color.darken(rgb_color, percent)

Darkens an rgb instance

Parameters:
  • rgb_color (rgb | int) – instance containing data

  • percent (Number) – Amount between 0 and 100 int darken rgb by.

Raises:

ValueError – if percent is out of range

Returns:

rgb instance with darkened values applied.

Return type:

rgb

ooodev.utils.color.get_gray_rgb(percent, rgb=None)[source]

Gets a Gray RGB. The higher the percent the lighter the color.

100 percent returns RGB of White color. 0 percent return Black color

Parameters:
  • percent (int) – Percent from 0 to 100

  • rgb (RGB, optional) – Optional RGB used for calculations.

Raises:

ValueError – If percent is out of range.

Returns:

RGB representing red, green blue.

Return type:

RGB

Note

The returned RGB has all channels are set to the same value.

New in version 0.9.0.

ooodev.utils.color.hsl_to_hsv(c)[source]

Convert hue, saturation, lightness to hue, saturation, value

Parameters:

c (HSL) – instance containing hue, saturation, lightness

Returns:

instance containing hue, saturation, value

Return type:

HSV

ooodev.utils.color.hsl_to_rgb(c)[source]

Converts hue, saturation, lightness to red, green, blue

Parameters:

c (hsv) – instance containing hue, saturation, lightness

Returns:

instance containing red, green, blue

Return type:

rgb

ooodev.utils.color.hsv_to_hsl(c)[source]

Convert hue, saturation, value to hue, saturation, lightness

Parameters:

c (HSV) – instance containing hue, saturation, value

Returns:

instance containing hue, saturation, lightness

Return type:

HSL

ooodev.utils.color.hsv_to_rgb(c)[source]

Converts hue, saturation, value to red, green, blue

Parameters:

c (hsv) – instance containing hue, saturation, value

Returns:

instance containing red, green, blue

Return type:

rgb

ooodev.utils.color.hue_to_rgb(h)[source]

Converts a hue to instance of red, green, blue

Parameters:

h (float) – hue to convert

Returns:

instance containing red, green, blue

Return type:

rgb

ooodev.utils.color.int_to_rgb(rgb_int)[source]

Converts an integer that represents a rgb color into rgb object.

Parameters:

rgb_int (int) – int that represents rgb color

Returns:

rgb with red, green and blue properties.

Return type:

rgb

ooodev.utils.color.lighten(rgb_color: int, percent: int | float) ooodev.utils.color.RGB[source]
ooodev.utils.color.lighten(rgb_color: ooodev.utils.color.RGB, percent: int | float) ooodev.utils.color.RGB
ooodev.utils.color.lighten(rgb_color, percent)

Lightens an RGB instance

Parameters:
  • rgb_color (RGB | int) – instance containing data

  • percent (Number) – Amount between 0 and 100 int lighten rgb by.

Raises:

ValueError – if percent is out of range

Returns:

RGB instance with lightened values applied.

Return type:

RGB

ooodev.utils.color.rgb_to_hex(rgb)[source]

Converts rgb colors to int

Parameters:

rgb (color) – Tuple of int with values from 0 to 255

Returns:

rgb as hex string

Return type:

str

ooodev.utils.color.rgb_to_hsl(c)[source]

Converts red, green, blue to hue, saturation, value

Parameters:

c (RGB) – instance containing red, green, blue

Returns:

instance containing hue, saturation, lightness

Return type:

HSL

ooodev.utils.color.rgb_to_hsv(c)[source]

Converts red, green, blue to hue, saturation, value

Parameters:

c (RGB) – instance containing red, green, blue

Returns:

instance containing hue, saturation, value

Return type:

HSV

ooodev.utils.color.rgb_to_int(rgb)[source]

Converts rgb colors to int

Parameters:

rgb (color) – Tuple of int with values from 0 to 255

Returns:

rgb as int

Return type:

int

ooodev.utils.color.MAX_COLOR = 255

Max Color Value

ooodev.utils.color.MIN_COLOR = 0

Min Color Value