sugar4.graphics.style

The style module defines constants for spacing and sizing, as well as classes for Colors and Fonts. Text rendering is handled by Pango and colors are inputted by their HTML code (e.g. #FFFFFF)

All the constants are expressed in pixels. They are defined for the XO screen and are usually adapted to different resolution by applying a zoom factor.

Attributes

GTK_AVAILABLE

FOCUS_LINE_WIDTH

ELLIPSIZE_MODE_DEFAULT

ZOOM_FACTOR

DEFAULT_SPACING

DEFAULT_PADDING

GRID_CELL_SIZE

LINE_WIDTH

STANDARD_ICON_SIZE

SMALL_ICON_SIZE

MEDIUM_ICON_SIZE

LARGE_ICON_SIZE

XLARGE_ICON_SIZE

settings

FONT_NORMAL

FONT_BOLD

FONT_NORMAL_H

FONT_BOLD_H

FONT_ITALIC

TOOLBOX_SEPARATOR_HEIGHT

TOOLBOX_HORIZONTAL_PADDING

TOOLBOX_TAB_VBORDER

TOOLBOX_TAB_HBORDER

TOOLBOX_TAB_LABEL_WIDTH

COLOR_BLACK

COLOR_WHITE

COLOR_TRANSPARENT

COLOR_PANEL_GREY

COLOR_SELECTION_GREY

COLOR_TOOLBAR_GREY

COLOR_BUTTON_GREY

COLOR_INACTIVE_FILL

COLOR_INACTIVE_STROKE

COLOR_TEXT_FIELD_GREY

COLOR_HIGHLIGHT

COLOR_PRIMARY

COLOR_SUCCESS

COLOR_WARNING

COLOR_ERROR

PALETTE_CURSOR_DISTANCE

TOOLBAR_ARROW_SIZE

MENU_WIDTH_CHARS

BORDER_RADIUS

SHADOW_BLUR

TRANSITION_DURATION

Classes

Font

A font defines the style of how the text should be rendered.

Color

A Color object defines a specific color with RGBA values.

Functions

zoom(→ int)

Returns size of units pixels at current zoom level.

apply_css_to_widget(→ None)

Apply CSS styling to a widget.

Module Contents

sugar4.graphics.style.GTK_AVAILABLE = True[source]
sugar4.graphics.style.FOCUS_LINE_WIDTH = 2[source]
sugar4.graphics.style.ELLIPSIZE_MODE_DEFAULT[source]
class sugar4.graphics.style.Font(desc: str)[source]

A font defines the style of how the text should be rendered.

This implementation provides integration with Pango font descriptions and CSS styling.

Parameters:

desc (str) – A description of the Font object in Pango format

__str__() str[source]

Returns description of font.

__repr__() str[source]
get_pango_desc()[source]

Returns Pango description of font. Cached for performance.

get_css_string() str[source]

Returns a CSS font specification string for modern styling.

class sugar4.graphics.style.Color(color: str, alpha: float = 1.0)[source]

A Color object defines a specific color with RGBA values.

This implementation provides integration with modern color handling and CSS styling.

Parameters:
  • color (str) – String in the form #FFFFFF representing the color

  • alpha (float) – Transparency of color (0.0 to 1.0)

__str__() str[source]
__repr__() str[source]
get_rgba() Tuple[float, float, float, float][source]

Returns 4-tuple of red, green, blue, and alpha levels in range 0-1.

get_int() int[source]

Returns color encoded as an int, in the form rgba.

get_gdk_rgba()[source]

Returns GDK RGBA color object for GTK4. This replaces the deprecated get_gdk_color method.

get_gdk_color()[source]

Returns GDK standard color (deprecated in GTK4). Maintained for compatibility.

get_html() str[source]

Returns string in the standard HTML color format (#FFFFFF).

get_css_rgba() str[source]

Returns CSS rgba() string for GTK4 styling.

get_svg() str[source]

Returns HTML formatted color, unless the color is completely transparent, in which case returns “none”.

with_alpha(alpha: float) Color[source]

Returns a new Color with the specified alpha value.

sugar4.graphics.style.zoom(units: float) int[source]

Returns size of units pixels at current zoom level.

Parameters:

units (int or float) – Size of item at full size

sugar4.graphics.style.apply_css_to_widget(widget, css: str) None[source]

Apply CSS styling to a widget.

Parameters:
  • widget – Widget to style

  • css (str) – CSS string to apply

sugar4.graphics.style.ZOOM_FACTOR[source]
sugar4.graphics.style.DEFAULT_SPACING[source]
sugar4.graphics.style.DEFAULT_PADDING[source]
sugar4.graphics.style.GRID_CELL_SIZE[source]
sugar4.graphics.style.LINE_WIDTH[source]
sugar4.graphics.style.STANDARD_ICON_SIZE[source]
sugar4.graphics.style.SMALL_ICON_SIZE[source]
sugar4.graphics.style.MEDIUM_ICON_SIZE[source]
sugar4.graphics.style.LARGE_ICON_SIZE[source]
sugar4.graphics.style.XLARGE_ICON_SIZE[source]
sugar4.graphics.style.settings[source]
sugar4.graphics.style.FONT_NORMAL[source]
sugar4.graphics.style.FONT_BOLD[source]
sugar4.graphics.style.FONT_NORMAL_H[source]
sugar4.graphics.style.FONT_BOLD_H[source]
sugar4.graphics.style.FONT_ITALIC[source]
sugar4.graphics.style.TOOLBOX_SEPARATOR_HEIGHT[source]
sugar4.graphics.style.TOOLBOX_HORIZONTAL_PADDING[source]
sugar4.graphics.style.TOOLBOX_TAB_VBORDER[source]
sugar4.graphics.style.TOOLBOX_TAB_HBORDER[source]
sugar4.graphics.style.TOOLBOX_TAB_LABEL_WIDTH[source]
sugar4.graphics.style.COLOR_BLACK[source]
sugar4.graphics.style.COLOR_WHITE[source]
sugar4.graphics.style.COLOR_TRANSPARENT[source]
sugar4.graphics.style.COLOR_PANEL_GREY[source]
sugar4.graphics.style.COLOR_SELECTION_GREY[source]
sugar4.graphics.style.COLOR_TOOLBAR_GREY[source]
sugar4.graphics.style.COLOR_BUTTON_GREY[source]
sugar4.graphics.style.COLOR_INACTIVE_FILL[source]
sugar4.graphics.style.COLOR_INACTIVE_STROKE[source]
sugar4.graphics.style.COLOR_TEXT_FIELD_GREY[source]
sugar4.graphics.style.COLOR_HIGHLIGHT[source]
sugar4.graphics.style.COLOR_PRIMARY[source]
sugar4.graphics.style.COLOR_SUCCESS[source]
sugar4.graphics.style.COLOR_WARNING[source]
sugar4.graphics.style.COLOR_ERROR[source]
sugar4.graphics.style.PALETTE_CURSOR_DISTANCE[source]
sugar4.graphics.style.TOOLBAR_ARROW_SIZE[source]
sugar4.graphics.style.MENU_WIDTH_CHARS = 60[source]
sugar4.graphics.style.BORDER_RADIUS[source]
sugar4.graphics.style.SHADOW_BLUR[source]
sugar4.graphics.style.TRANSITION_DURATION = 200[source]