我正在尝试编写一个脚本来检查某些事情并在出现问题时在托盘中显示通知。在此示例中,我正在查看文件的年龄。
我似乎无法弄清楚如何在 gtk.main() 运行后更改图标。
import os, gtk
from time import time, sleep
from datetime import datetime
class HeartbeatTrayIcon(object):
"""
Use GTK to create an object in the system tray
and manipulate icon shown if there is an issue.
"""
def __init__(self):
rx = os.path.getmtime("test")
self.statusIcon = gtk.StatusIcon()
if (time() - rx) > (60*60*24):
self.statusIcon.set_from_stock(gtk.STOCK_CANCEL)
else:
self.statusIcon.set_from_stock(gtk.STOCK_APPLY)
self.statusIcon.set_tooltip("Last heartbeat received at %s" % datetime.fromtimestamp(int(rx)).strftime('%H:%M:%S %d-%m-%Y'))
def tray(self):
gtk.main()
if __name__ == "__main__":
i = HeartbeatTrayIcon()
i.tray()