Skip to content

TickerItem

pywry.toolbar.TickerItem

Bases: BaseModel

A single updatable item within a Marquee (e.g., stock price, metric).

This is a lightweight helper for creating spans with data-ticker attributes that can be individually updated via toolbar:marquee-set-item events. Since marquee content is duplicated for seamless scrolling, updates target ALL matching data-ticker elements.

NOT a full ToolbarItem - this is a content helper for use inside Marquee.

ATTRIBUTE DESCRIPTION
ticker

Unique identifier for this item (e.g., "AAPL", "BTC", "cpu-usage"). Used as data-ticker attribute for targeting updates.

TYPE: str

text

Initial text content to display.

TYPE: str

html

Initial HTML content (alternative to text for rich content).

TYPE: str

class_name

Additional CSS classes for styling.

TYPE: str

style

Inline CSS styles.

TYPE: str

Examples:

Create ticker items for a stock marquee:

>>> items = [
...     TickerItem(ticker="AAPL", text="AAPL $185.50", class_name="stock-up"),
...     TickerItem(ticker="GOOGL", text="GOOGL $142.20"),
...     TickerItem(ticker="MSFT", text="MSFT $415.80", class_name="stock-down"),
... ]
>>> marquee = Marquee(
...     text=" • ".join(item.build_html() for item in items),
...     speed=20,
... )

Update individual prices:

>>> event, data = items[0].update_payload(
...     text="AAPL $186.25", class_add="stock-up", class_remove="stock-down"
... )
>>> widget.emit(event, data)

Functions

build_html

build_html() -> str

Build HTML span with data-ticker attribute.

RETURNS DESCRIPTION
str

HTML span element with data-ticker for update targeting.

update_payload

update_payload(text: str | None = None, html_content: str | None = None, styles: dict[str, str] | None = None, class_add: str | list[str] | None = None, class_remove: str | list[str] | None = None) -> tuple[str, dict[str, Any]]

Generate event name and payload for dynamic item updates.

Use with widget.emit() to update this ticker item's content/styles. Updates ALL elements matching this ticker (handles duplicated marquee content).

PARAMETER DESCRIPTION
text

New plain text content.

TYPE: str | None DEFAULT: None

html_content

New HTML content (use instead of text for rich content).

TYPE: str | None DEFAULT: None

styles

CSS styles to apply (e.g., {"color": "green", "fontWeight": "bold"}).

TYPE: dict[str, str] | None DEFAULT: None

class_add

CSS class(es) to add.

TYPE: str | list[str] | None DEFAULT: None

class_remove

CSS class(es) to remove.

TYPE: str | list[str] | None DEFAULT: None

RETURNS DESCRIPTION
tuple[str, dict[str, Any]]

Event name and payload dict for widget.emit().

Example
item = TickerItem(ticker="AAPL", text="AAPL $185.50")
# Price went up - update with green color
event, data = item.update_payload(
    text="AAPL $186.25 ▲",
    styles={"color": "#22c55e"},
    class_add="stock-up",
    class_remove="stock-down"
)
widget.emit(event, data)