34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
# whisper_app/tray.py
|
|
import pystray
|
|
from PIL import Image, ImageDraw
|
|
from whisper_app import app
|
|
from whisper_app.app import AppState
|
|
|
|
def _make_icon(color: tuple) -> Image.Image:
|
|
img = Image.new("RGBA", (64, 64), (0, 0, 0, 0))
|
|
d = ImageDraw.Draw(img)
|
|
d.ellipse([4, 4, 60, 60], fill=color)
|
|
return img
|
|
|
|
ICONS = {
|
|
AppState.IDLE: _make_icon((40, 200, 80)),
|
|
AppState.RECORDING: _make_icon((220, 50, 50)),
|
|
AppState.TRANSCRIBING: _make_icon((220, 180, 30)),
|
|
}
|
|
|
|
def update_icon(state: AppState) -> None:
|
|
if app.tray_icon:
|
|
app.tray_icon.icon = ICONS[state]
|
|
|
|
def create(on_settings, on_vocab, on_show_log, on_quit) -> pystray.Icon:
|
|
menu = pystray.Menu(
|
|
pystray.MenuItem("Anzeigen", on_show_log, default=True),
|
|
pystray.MenuItem("Einstellungen", on_settings),
|
|
pystray.MenuItem("Vokabular", on_vocab),
|
|
pystray.Menu.SEPARATOR,
|
|
pystray.MenuItem("Beenden", on_quit),
|
|
)
|
|
icon = pystray.Icon("whisper", ICONS[AppState.IDLE], "Whisper Dictation", menu)
|
|
app.tray_icon = icon
|
|
return icon
|