使用Python3每5分钟在gtk.main内部运行一次函数

时间:2018-09-09 11:30:51

标签: python python-3.x gtk3

我试图在ubuntu环境中制作一个小的面板指示器,所以我写了这个脚本:

import os
import signal
import subprocess as notif
from gi.repository import Gtk as gtk
from gi.repository import AppIndicator3 as appindicator


APPINDICATOR_ID = 'myappindicator'

def main():
    indicator = appindicator.Indicator.new(APPINDICATOR_ID, os.path.abspath('sample_icon.svg'), appindicator.IndicatorCategory.SYSTEM_SERVICES)
    indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
    indicator.set_menu(build_menu())
    gtk.main()

def build_menu():
    menu = gtk.Menu()
    item_msgs = gtk.MenuItem('show msgs')
    item_msgs.connect('activate', msgs)
    menu.append(item_msgs)
    item_quit = gtk.MenuItem('Quit')
    item_quit.connect('activate', quit)
    menu.append(item_quit)
    menu.show_all()
    return menu

def msgs(_):
    notif.call(['notify-send','This is a new message !',])

def quit(_):
    gtk.main_quit()

if __name__ == "__main__":
    signal.signal(signal.SIGINT, signal.SIG_DFL)
main()

取决于this one

我的问题是如何使msgs()函数每5分钟或任何其他时间段在main()函数内部运行?

0 个答案:

没有答案