Created
December 28, 2021 09:44
-
-
Save wkordalski/fb29500473afdb2f2c758941745cc48f to your computer and use it in GitHub Desktop.
Tray icon showing status of a watch-like command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import signal | |
signal.signal(signal.SIGINT, signal.SIG_DFL) | |
from PySide6.QtGui import QIcon | |
from PySide6.QtWidgets import QApplication, QSystemTrayIcon | |
import re | |
import sys | |
import threading | |
if __name__ == '__main__': | |
app = QApplication([]) | |
app.setQuitOnLastWindowClosed(False) | |
PROCESSING_ICON = QIcon('/usr/share/icons/Adwaita/24x24/emblems/emblem-synchronizing-symbolic.symbolic.png') | |
SUCCESS_ICON = QIcon('/usr/share/icons/Adwaita/24x24/emblems/emblem-ok-symbolic.symbolic.png') | |
FAILURE_ICON = QIcon('/usr/share/icons/Adwaita/24x24/emblems/emblem-important-symbolic.symbolic.png') | |
SUCCESS_PAT = re.compile('Compiled successfully') | |
FAILURE_PAT = re.compile('Failed to compile') | |
TOOLTIP = "Webpack build status" | |
def reader(tray): | |
for line in sys.stdin: | |
sys.stdout.write(line) | |
if line.strip() == '': | |
continue | |
if re.search(SUCCESS_PAT, line) is not None: | |
tray.setIcon(SUCCESS_ICON) | |
continue | |
if re.search(FAILURE_PAT, line) is not None: | |
tray.setIcon(FAILURE_ICON) | |
continue | |
tray.setIcon(PROCESSING_ICON) | |
tray = QSystemTrayIcon() | |
tray.setIcon(PROCESSING_ICON) | |
tray.setVisible(True) | |
thread = threading.Thread(target=reader, args=(tray,), daemon=True) | |
thread.start() | |
app.exec() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment