Skip to content

Commit f500ed6

Browse files
committed
Add a cross-platform tray icon with Exit menu entry
1 parent a91a41d commit f500ed6

File tree

10 files changed

+355
-3
lines changed

10 files changed

+355
-3
lines changed

config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ display:
4747
DISPLAY_REVERSE: false
4848

4949
# Display resolution in portrait orientation
50-
# Do not use this setting to rotate display! Use DISPLAY_REVERSE
50+
# Do not use this setting to rotate display! The selected theme handles landscape/portrait orientation
5151
DISPLAY_WIDTH: 320 # Do not change unless you have a good reason
5252
DISPLAY_HEIGHT: 480 # Do not change unless you have a good reason
5353

main.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
# https://github.com/mathoudebine/turing-smart-screen-python
44
import locale
55
import os
6+
import pystray
67
import signal
78
import sys
89
import time
910

11+
from PIL import Image
12+
1013
MIN_PYTHON = (3, 7)
1114
if sys.version_info < MIN_PYTHON:
1215
print("[ERROR] Python %s.%s or later is required." % MIN_PYTHON)
@@ -24,9 +27,8 @@
2427
# Apply system locale to this program
2528
locale.setlocale(locale.LC_ALL, '')
2629

27-
def sighandler(signum, frame):
28-
logger.info(" Caught signal %d, exiting" % signum)
2930

31+
def clean_stop(tray_icon=None):
3032
# Do not stop the program now in case data transmission was in progress
3133
# Instead, ask the scheduler to empty the action queue before stopping
3234
scheduler.STOPPING = True
@@ -41,13 +43,27 @@ def sighandler(signum, frame):
4143

4244
logger.debug("(%.1fs)" % (5 - wait_time))
4345

46+
# Remove icon just before the exit
47+
if tray_icon:
48+
tray_icon.visible = False
49+
4450
# We force the exit to avoid waiting for other scheduled tasks: they may have a long delay!
4551
try:
4652
sys.exit(0)
4753
except:
4854
os._exit(0)
4955

5056

57+
def sighandler(signum, frame=None):
58+
logger.info("Caught signal %d, exiting" % signum)
59+
clean_stop()
60+
61+
62+
def on_exit_tray(tray_icon, item):
63+
logger.info("Exit from tray icon")
64+
clean_stop(tray_icon)
65+
66+
5167
# Set the signal handlers, to send a complete frame to the LCD before exit
5268
signal.signal(signal.SIGINT, sighandler)
5369
signal.signal(signal.SIGTERM, sighandler)
@@ -81,3 +97,14 @@ def sighandler(signum, frame):
8197
scheduler.NetStats()
8298
scheduler.DateStats()
8399
scheduler.QueueHandler()
100+
101+
# Create a tray icon for the program, with an Exit entry in menu
102+
tray_icon = pystray.Icon(
103+
name='Turing System Monitor',
104+
title='Turing System Monitor',
105+
icon=Image.open("res/icons/724873501557740364-64.png"),
106+
menu=pystray.Menu(
107+
pystray.MenuItem(
108+
'Exit',
109+
on_exit_tray))
110+
).run()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pyserial~=3.5 # Serial linl to communicate with the display
44
PyYAML~=6.0 # For themes files
55
psutil~=5.9.4 # CPU / disk / network metrics
66
GPUtil~=1.4.0 # Nvidia GPU
7+
pystray~=0.19.4 # Tray icon (all OS)
78

89
# Following packages are for AMD GPU on Linux
910
# Note: you may need to manually install Cython first
2.61 KB
Loading
517 Bytes
Loading
752 Bytes
Loading
946 Bytes
Loading
1.36 KB
Loading

res/icons/AUTHOR.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Icon by <a href="https://freeicons.io/profile/730">Anu Rocks</a> on <a href="https://freeicons.io">freeicons.io</a>
2+
3+
https://freeicons.io/regular-life-icons/monitor-icon-17865
4+
5+
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</a>.

res/icons/LICENSE

Lines changed: 319 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)