sugar4.graphics
Visual components, styling, and UI widgets for Sugar activities.
Submodules
- sugar4.graphics.alert
- sugar4.graphics.animator
- sugar4.graphics.colorbutton
- sugar4.graphics.combobox
- sugar4.graphics.icon
- sugar4.graphics.menuitem
- sugar4.graphics.objectchooser
- sugar4.graphics.palette
- sugar4.graphics.palettegroup
- sugar4.graphics.palettemenu
- sugar4.graphics.palettewindow
- sugar4.graphics.radiopalette
- sugar4.graphics.radiotoolbutton
- sugar4.graphics.style
- sugar4.graphics.toggletoolbutton
- sugar4.graphics.toolbarbox
- sugar4.graphics.toolbox
- sugar4.graphics.toolbutton
- sugar4.graphics.toolcombobox
- sugar4.graphics.tray
- sugar4.graphics.window
- sugar4.graphics.xocolor
Attributes
Classes
Defines color for XO |
|
Basic Sugar icon widget. |
|
Icon widget with mouse event handling using gesture controllers. |
|
An EventIcon with active and prelight states, and a styleable background. |
|
Icon renderer for use in list/tree views. |
Functions
|
Resolve icon name to file path using icon theme. |
|
Get cairo surface for an icon with specified properties. |
|
Get the closest icon name for a given state in percent. |
Package Contents
- class sugar4.graphics.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")
- 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:
- Raises:
ValueError – If color_string cannot be parsed
- class sugar4.graphics.Icon(icon_name: str | None = None, file_name: str | None = None, pixel_size: int = STANDARD_ICON_SIZE, **kwargs)[source]
Bases:
gi.repository.Gtk.WidgetBasic Sugar icon widget.
Displays themed icons with Sugar’s color customization features. Uses modern snapshot-based rendering for improved performance.
- Properties:
icon_name (str): Icon name from theme file_name (str): Path to icon file pixel_size (int): Size in pixels fill_color (str): Fill color as hex string stroke_color (str): Stroke color as hex string xo_color (XoColor): Sugar color pair badge_name (str): Badge icon name alpha (float): Icon transparency (0.0-1.0) scale (float): Icon scale factor sensitive (bool): Whether icon appears sensitive
- __gtype_name__ = 'SugarIcon'
- do_snapshot(snapshot: gi.repository.Gtk.Snapshot)[source]
Render icon using snapshot-based drawing.
- do_measure(orientation: gi.repository.Gtk.Orientation, for_size: int) Tuple[int, int, int, int][source]
Calculate widget size requirements.
- get_xo_color() sugar4.graphics.xocolor.XoColor | None[source]
- set_xo_color(xo_color: sugar4.graphics.xocolor.XoColor | None)[source]
- icon_name
- file_name
- pixel_size
- fill_color
- stroke_color
- xo_color
- badge_name
- alpha
- scale
- class sugar4.graphics.EventIcon(**kwargs)[source]
Bases:
IconIcon widget with mouse event handling using gesture controllers.
Provides click, press, and release events through modern gesture handling for better touch and accessibility support.
- Signals:
clicked: Emitted when icon is clicked pressed: Emitted when icon is pressed released: Emitted when icon is released activate: Emitted when icon is activated
- __gtype_name__ = 'SugarEventIcon'
- __gsignals__
- background_color
- cache
- class sugar4.graphics.CanvasIcon(**kwargs)[source]
Bases:
EventIconAn EventIcon with active and prelight states, and a styleable background.
This icon responds to mouse hover and press states with visual feedback.
- __gtype_name__ = 'SugarCanvasIcon'
- class sugar4.graphics.CellRendererIcon[source]
Icon renderer for use in list/tree views.
Modern implementations use different approaches for cell rendering. This provides compatibility for legacy code that may need adaptation.
Note: Consider using modern list/tree widget patterns instead.
- set_xo_color(xo_color: sugar4.graphics.xocolor.XoColor)[source]
- sugar4.graphics.get_icon_file_name(icon_name: str) str | None[source]
Resolve icon name to file path using icon theme.
Uses the system icon theme to find the appropriate icon file for the given icon name.
- Parameters:
icon_name – Name of icon to resolve
- Returns:
Path to icon file or None if not found
- sugar4.graphics.get_surface(icon_name: str | None = None, file_name: str | None = None, fill_color: str | None = None, stroke_color: str | None = None, pixel_size: int = STANDARD_ICON_SIZE, **kwargs) cairo.ImageSurface | None[source]
Get cairo surface for an icon with specified properties.
- Parameters:
icon_name – Icon name from theme
file_name – Path to icon file
fill_color – Fill color as hex string
stroke_color – Stroke color as hex string
pixel_size – Size in pixels
**kwargs – Additional properties
- Returns:
Cairo surface or None if icon not found
- sugar4.graphics.get_icon_state(base_name: str, perc: float, step: int = 5) str | None[source]
Get the closest icon name for a given state in percent.
- Parameters:
base_name – Base icon name (e.g., ‘network-wireless’)
perc – Desired percentage between 0 and 100
step – Step increment to find possible icons
- Returns:
Icon name that represents given state, or None if not found