bootstack.images.AppIcon#

class bootstack.images.AppIcon(icon, *, background='primary', foreground='white', radius=0.22, shape='auto')#

Bases: object

A generated application icon.

Renders a Bootstrap glyph in one of two shapes:

  • a tile — the glyph in foreground on a filled, rounded background (the macOS look); or

  • glyph-only — the glyph alone in the background (brand) color on a transparent field (the typical Windows and Linux look).

By default (shape='auto') the shape follows the platform and the size: a tile for macOS targets (.icns, or running on macOS); on Windows and Linux, glyph-only at small sizes (a clean mark in a tiny title bar) and a tile at larger sizes (a branded icon in the taskbar and launchers). A multi-size .ico therefore carries both. Set shape to 'tile' or 'glyph' to force one shape at every size.

Pass an AppIcon as the icon= of an App or Window to set its taskbar and title-bar icon without supplying an icon file, or call save to export a packaging asset (for example, an icon for a PyInstaller build).

Colors may be theme color tokens (such as 'primary') or literal hex strings. Tokens are resolved once, when the icon is generated, so the icon does not change as the theme changes; supply a token while an application is active, or use hex values. Generating an icon outside a running application — such as during a build — must use hex values, since no theme is available to resolve a token against.

save(path)#

Write the icon to a file, choosing the format by file extension.

Use this to produce a packaging asset — for example, an icon to point a PyInstaller build at. The format follows the path suffix:

  • .ico — a multi-resolution Windows icon.

  • .icns — a macOS icon.

  • .png — a single 256-pixel image.

Parameters:

path (str | Path) – Destination file path ending in .ico, .icns, or .png.

Returns:

The path that was written, as a string.

Raises:

ValueError – If the file extension is not one of the supported types.

Return type:

str

to_image(size=256, *, tiled=None)#

Render the icon to an Image handle for on-screen display.

Use this to show the application icon inside the app itself — for example on an about screen or a splash panel.

Parameters:
  • size (int) – Rendered size in pixels. Defaults to 256.

  • tiled (bool | None) – Force the tile shape (True) or glyph-only (False). By default, follows the icon’s shape.

Returns:

An image handle wrapping the rendered icon.

Return type:

Image