好吧,与其继续在wxPython和这个Phoenix胡说八道的项目上混日子,我改成只使用PyGTK,我不得不说,总的来说,我更喜欢这个。我的代码现在正按照我希望的方式运行,如下所示:#!/usr/bin/python
import gobject
import gtk
import os
import thread
import time
last_changed_time = 0
mode = "nice"
def set_mode (new_mode):
global mode
mode = new_mode
change_wall()
def make_menu(event_button, event_time, data=None):
menu = gtk.Menu()
nice_item = gtk.CheckMenuItem("Nice")
naughty_item = gtk.CheckMenuItem("Naughty")
kill_item = gtk.MenuItem("Quit")
if mode == "nice":
nice_item.set_active(True)
if mode == "naughty":
naughty_item.set_active(True)
menu.append(nice_item)
menu.append(naughty_item)
menu.append(kill_item)
nice_item.connect_object("activate", set_mode, ("nice"))
naughty_item.connect_object("activate", set_mode, ("naughty"))
kill_item.connect_object("activate", gtk.main_quit, ())
nice_item.show()
naughty_item.show()
kill_item.show()
menu.popup(None, None, None, event_button, event_time)
def change_wall():
global last_changed_time
os.system("./change_wall " + mode)
last_changed_time = time.time()
def on_right_click(data, event_button, event_time):
make_menu(event_button, event_time)
def on_left_click(event):
change_wall()
def auto_update():
while 1:
time.sleep(1)
if time.time() > last_changed_time + 600:
change_wall()
if __name__ == '__main__':
gobject.threads_init()
os.chdir("/home/caleb/walls")
icon = gtk.status_icon_new_from_file("walls.xpm")
icon.connect('popup-menu', on_right_click)
icon.connect('activate', on_left_click)
change_wall()
thread.start_new_thread(auto_update, ())
gtk.main()
我不得不插入时间。睡觉(1) 每次检查前打电话,看看是否该自动更新,以防止图标/菜单本身变得相当滞后。我在使用wx时从未遇到过这个问题;有没有更优雅的方法来解决这个问题?在
再次感谢您的帮助!在