33# https://github.com/mathoudebine/turing-smart-screen-python
44import locale
55import os
6+ import platform
67import signal
78import sys
89import time
@@ -47,7 +48,7 @@ def clean_stop(tray_icon=None):
4748
4849 logger .debug ("(%.1fs)" % (5 - wait_time ))
4950
50- # Remove icon just before the exit
51+ # Remove tray icon just before exit
5152 if tray_icon :
5253 tray_icon .visible = False
5354
@@ -68,6 +69,26 @@ def on_exit_tray(tray_icon, item):
6869 clean_stop (tray_icon )
6970
7071
72+ # Create a tray icon for the program, with an Exit entry in menu
73+ try :
74+ tray_icon = pystray .Icon (
75+ name = 'Turing System Monitor' ,
76+ title = 'Turing System Monitor' ,
77+ icon = Image .open ("res/icons/monitor-icon-17865/64.png" ),
78+ menu = pystray .Menu (
79+ pystray .MenuItem (
80+ 'Exit' ,
81+ on_exit_tray ))
82+ )
83+
84+ # For platforms != macOS, display the tray icon now with non-blocking function
85+ if platform .system () != "Darwin" :
86+ tray_icon .run_detached ()
87+ logger .info ("Tray icon has been displayed" )
88+ except :
89+ tray_icon = None
90+ logger .warning ("Tray icon is not supported on your platform" )
91+
7192 # Set the signal handlers, to send a complete frame to the LCD before exit
7293 signal .signal (signal .SIGINT , sighandler )
7394 signal .signal (signal .SIGTERM , sighandler )
@@ -102,16 +123,6 @@ def on_exit_tray(tray_icon, item):
102123 scheduler .DateStats ()
103124 scheduler .QueueHandler ()
104125
105- # Create a tray icon for the program, with an Exit entry in menu
106- try :
107- tray_icon = pystray .Icon (
108- name = 'Turing System Monitor' ,
109- title = 'Turing System Monitor' ,
110- icon = Image .open ("res/icons/724873501557740364-64.png" ),
111- menu = pystray .Menu (
112- pystray .MenuItem (
113- 'Exit' ,
114- on_exit_tray ))
115- ).run ()
116- except :
117- logger .warning ("Tray icon is not supported on your platform" )
126+ if tray_icon and platform .system () == "Darwin" :
127+ # For macOS: display the tray icon now with blocking function
128+ tray_icon .run ()
0 commit comments