llm / scripts /windows_taskbar_tray.py
Aswin480
feat: native taskbar tray icon and popup flyout window for web and windows desktop
d93c058
Raw History Blame Contribute Delete
3.87 kB
"""
Windows Native Taskbar System Tray Companion for Pabot.
Places a sleek Pabot icon directly into the Windows Taskbar Notification Area
(System Tray) right next to your clock and other system icons.
Clicking the icon immediately opens a native Windows 11 flyout popup window!
"""
import os
import subprocess
import sys
import threading
from pathlib import Path
from PIL import Image, ImageDraw
import pystray
from pystray import MenuItem as item
# Paths & URLs
REPO_ROOT = Path(__file__).resolve().parents[1]
BACKEND_URL = os.environ.get("PABOT_BACKEND_URL", "http://127.0.0.1:8000")
WIDGET_URL = f"{BACKEND_URL}/widget.html"
DASHBOARD_URL = f"{BACKEND_URL}/"
EDGE_PATH = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
if not os.path.exists(EDGE_PATH):
EDGE_PATH = r"C:\Program Files\Microsoft\Edge\Application\msedge.exe"
def create_tray_image(width=64, height=64) -> Image.Image:
"""Generate a high-res, crisp glowing Pabot icon for the Windows taskbar tray."""
img = Image.new("RGBA", (width, height), (0, 0, 0, 0))
draw = ImageDraw.Draw(img)
# Gradient background circle (Deep Violet to Indigo)
draw.ellipse([4, 4, width - 4, height - 4], fill=(124, 58, 237, 255), outline=(167, 139, 250, 200), width=2)
# Inner glowing polygon (Pabot core)
# Draw stylized diamond / polygon
cx, cy = width // 2, height // 2
points = [
(cx, 16),
(width - 16, cy),
(cx, height - 16),
(16, cy)
]
draw.polygon(points, fill=(245, 158, 11, 230))
# Center white dot
draw.ellipse([cx - 4, cy - 4, cx + 4, cy + 4], fill=(255, 255, 255, 255))
return img
def open_flyout_popup(url=WIDGET_URL):
"""
Open the widget in a native, frameless Windows 11 flyout popup window.
Edge --app mode renders a pristine, native popup without URL bars or tabs.
"""
try:
# Determine screen resolution to anchor window right above bottom-right taskbar
import ctypes
user32 = ctypes.windll.user32
screen_w = user32.GetSystemMetrics(0)
screen_h = user32.GetSystemMetrics(1)
win_w = 400
win_h = 640
pos_x = max(0, screen_w - win_w - 18)
pos_y = max(0, screen_h - win_h - 68) # Leave space for Windows 11 taskbar
if os.path.exists(EDGE_PATH):
cmd = [
EDGE_PATH,
f"--app={url}",
f"--window-size={win_w},{win_h}",
f"--window-position={pos_x},{pos_y}",
]
subprocess.Popen(cmd)
else:
import webbrowser
webbrowser.open(url)
except Exception as exc:
print(f"Error opening flyout: {exc}")
def on_open_flyout(icon, item):
open_flyout_popup(WIDGET_URL)
def on_open_dashboard(icon, item):
open_flyout_popup(DASHBOARD_URL)
def on_quick_task(icon, item):
open_flyout_popup(f"{WIDGET_URL}#tasks")
def on_security_approvals(icon, item):
open_flyout_popup(f"{WIDGET_URL}#approvals")
def on_quit(icon, item):
icon.stop()
def run_tray():
icon_image = create_tray_image()
menu = (
item("⚡ Open Pabot Flyout", on_open_flyout, default=True),
item("📋 Quick Tasks", on_quick_task),
item("🛡️ Security Approvals", on_security_approvals),
pystray.Menu.SEPARATOR,
item("🌐 Open Full Dashboard", on_open_dashboard),
pystray.Menu.SEPARATOR,
item("✕ Exit Tray", on_quit),
)
tray_icon = pystray.Icon(
"PabotAssistant",
icon_image,
"Pabot AI Assistant (Click to open flyout)",
menu
)
print("[PABOT] Windows Taskbar System Tray icon started.")
print("[PABOT] Single-click or double-click the icon in your taskbar to open the flyout popup!")
tray_icon.run()
if __name__ == "__main__":
run_tray()