Skip to content

Style

Helpers for building GUI style strings.

API

apply_control_styles(control_name, extra_style, layout_item, task)

Apply a named control style and optional overrides to a layout item.

extra_style may be a raw CSS-style string ("key:value;...") or a style name. It is applied on top of the base control_name style.

Parameters:

Name Type Description Default
control_name str

Base control style name.

required
extra_style str | dict | None

Additional style string, name, or parsed dict applied after the base style.

required
layout_item LayoutItem

Layout item to receive the style.

required
task MastAsyncTask

GUI task used for string formatting.

required

apply_style_def(style_def, layout_item, task)

Apply a style definition dict directly to a layout item.

Handles area, orientation, row-height, col-width, margin, border, padding, color, font, justify, background, background-color, background-image, border-image, border-color, click_*, and tag keys.

Parameters:

Name Type Description Default
style_def dict

Parsed style definition (key → value).

required
layout_item LayoutItem

Layout item to receive the style.

required
task MastAsyncTask

GUI task used for string formatting.

required

apply_style_name(style_name, layout_item, task)

Look up a named style definition and apply it to a layout item.

Parameters:

Name Type Description Default
style_name str

Name of the style to apply.

required
layout_item LayoutItem

Layout item to receive the style.

required
task MastAsyncTask

GUI task used for string formatting.

required

compile_formatted_string(message)

Compile a format string into a Python code object for faster repeated evaluation.

Strings containing { are wrapped in an f-string and compiled with eval mode. Strings without { are returned unchanged.

Parameters:

Name Type Description Default
message str

The format string, optionally containing {var} placeholders.

required

Returns:

Type Description

CodeType | str | None: A compiled code object if the string contains {, the original string otherwise, or None if message is None.