sugar4.graphics.xocolor

This class represents all of the colors that the XO can take on. Each pair of colors represents the fill color and the stroke color.

Modern implementation with improved color handling and CSS support.

Attributes

print

colors

match

Classes

XoColor

Defines color for XO

Module Contents

sugar4.graphics.xocolor.print[source]
sugar4.graphics.xocolor.colors = [['#B20008', '#FF2B34'], ['#FF2B34', '#B20008'], ['#E6000A', '#FF2B34'], ['#FF2B34', '#E6000A'],...[source]
class sugar4.graphics.xocolor.XoColor(color_string=None)[source]

Defines color for XO

This class represents a pair of colors (stroke and fill) that can be used throughout Sugar activities. Colors can be parsed from strings, loaded from user settings, or chosen randomly.

Parameters:

color_string (str, optional) – Color specification in one of these formats: - “stroke_hex,fill_hex” (e.g., “#FF0000,#00FF00”) - “white” for white theme - “insensitive” for disabled/grayed theme - None to use user’s color from settings or random if not available

Examples

>>> #from string
>>> color = XoColor("#FF0000,#00FF00")
>>> print(color.get_stroke_color())  # "#FF0000"
>>> print(color.get_fill_color())    # "#00FF00"
>>> # create user's color (or random if not set)
>>> color = XoColor()
>>> # themed colors
>>> white_color = XoColor("white")
>>> disabled_color = XoColor("insensitive")
__eq__(other)[source]

Check if two XoColor objects are equal.

Parameters:

other (object) – Another XoColor object to compare

Returns:

True if both stroke and fill colors match

Return type:

bool

__ne__(other)[source]

Check if two XoColor objects are not equal.

__hash__()[source]

Make XoColor hashable for use in sets and as dict keys.

__str__()[source]

String representation of XoColor.

__repr__()[source]

Detailed string representation of XoColor.

get_stroke_color()[source]
Returns:

stroke color in HTML hex format (#RRGGBB)

Return type:

str

get_fill_color()[source]
Returns:

fill color in HTML hex format (#RRGGBB)

Return type:

str

to_string()[source]
Returns:

formatted string in the format “#STROKEHEX,#FILLHEX”

Return type:

str

classmethod from_string(color_string)[source]

Create XoColor from string representation.

Parameters:

color_string (str) – Color string to parse

Returns:

New XoColor instance

Return type:

XoColor

Raises:

ValueError – If color_string cannot be parsed

classmethod get_random_color()[source]

Get a random XO color.

Returns:

Random XoColor instance from the standard palette

Return type:

XoColor

to_rgba_tuple(alpha=1.0)[source]

Convert colors to RGBA tuples for use with Cairo and modern graphics.

Parameters:

alpha (float) – Alpha value (0.0 - 1.0)

Returns:

((r, g, b, a), (r, g, b, a)) for stroke and fill colors

Return type:

tuple

sugar4.graphics.xocolor.match[source]