Skip to main content

Cross-platform tray icons and a tkinter app base for small GUIs.

Project description

sevaht-gui

Small cross-platform GUI building blocks: a system-tray icon and a tkinter application base, shared across Sevaht desktop tools.

Tray icon

create_tray_icon returns a single TrayIcon interface backed by the right implementation for the platform:

  • Windowspystray.
  • Linux — a StatusNotifierItem (D-Bus) item when a usable SNI host is present (KDE/GNOME, Wayland, or fluxbox with snixembed), falling back to a self-contained XEmbed icon on bare X11 window managers with no SNI host.

The feature model is deliberately small: a default activate action (left-click, and the default menu item where a menu is available) and a quit action. Backends that can show a menu (pystray, SNI) offer both on right-click; the menu-less XEmbed backend maps right-click straight to quit.

The icon is any IconSource — a prepared PIL.Image, a path to an image file (both static; the common case), or a renderer Callable[[int], Image] for apps that draw their own artwork. The tooltip and the icon can be changed live (set_icon accepts any IconSource), so an app can reflect state either by swapping prepared images or by re-rendering.

macOS is intentionally unsupported: a real menu-bar item there needs a single main-thread Cocoa loop shared with tk (custom PyObjC), which the threaded model used here cannot provide.

TkApp

TkApp owns a tkinter.Tk root and runs its mainloop() on the main thread, running the tray icon's own event loop on a worker thread. Work originating off the UI thread (e.g. tray menu callbacks) is marshalled back with run_on_ui_thread / call_on_ui_thread. show() / hide() and the run(start_hidden=...) flag manage window visibility (all thread-safe), and set_window_icon accepts the same IconSource as the tray.

from sevaht_gui import TkApp, create_tray_icon

app = TkApp()
app.root.title("Example")
app.set_window_icon("icon.png")  # static file; or a PIL image / renderer

icon = create_tray_icon(
    "example",
    "Example",
    "icon.png",          # any IconSource: path, PIL image, or renderer
    on_activate=app.show,
    on_quit=app.stop,
)
app.run(icon, start_hidden=True)  # only the tray shows until activated

The library manages the tray lifecycle, window visibility, and threading; choosing and (re)drawing the artwork is left to the application.

Documentation

Full documentation lives in docs/ and is published to GitHub Pages: https://sevaht.github.io/sevaht-gui/.

Building the docs locally

$ uv run --group docs sphinx-build -b html docs docs/_build/html

Then open docs/_build/html/index.html. (Publishing to GitHub Pages requires enabling Pages with the "GitHub Actions" source in the repository settings.)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sevaht_gui-1.0.0.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sevaht_gui-1.0.0-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

Details for the file sevaht_gui-1.0.0.tar.gz.

File metadata

  • Download URL: sevaht_gui-1.0.0.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sevaht_gui-1.0.0.tar.gz
Algorithm Hash digest
SHA256 59342c7fce74ccecb593a2ed954585f36d4a11c12d82d178ef21d80a84275819
MD5 279241b7a5f881dcd0d8f53a17ce2531
BLAKE2b-256 c319b2b9780ded3b48304f433943eee9ef6a28ffa3fb1f2c602adb411bef90fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for sevaht_gui-1.0.0.tar.gz:

Publisher: release.yml on sevaht/sevaht-gui

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sevaht_gui-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: sevaht_gui-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 27.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sevaht_gui-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75488fecc6e60bd08043a3617a85b6b6d97a6d8e25b33800b2bb5d7acbc0dd1e
MD5 5dfbf296df411c8773488ca68c807ef4
BLAKE2b-256 e4ef4ad8a019678faa1804212a453aa89307f9c61b8e7eb10d9645c62975d51a

See more details on using hashes here.

Provenance

The following attestation bundles were made for sevaht_gui-1.0.0-py3-none-any.whl:

Publisher: release.yml on sevaht/sevaht-gui

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page