异步更新PyGTK托盘图标 [英] Asynchronously updating PyGTK tray icon
问题描述
正如这里所解释的,我使用PyGTK有一个简单的托盘图标。
gtk.main()
是同步的,阻止任何进一步的处理,直到那么我怎样才能定期(例如每5秒钟)更新/刷新 StatusIcon
' s icon - 我必须求助于Twisted et al。你可以使用 gobject.timeout_add()
来获得这个结果吗? 添加定期任务。第一个参数是以秒为单位的间隔,第二个参数是要调用的回调。只要回调函数的返回值为 True 用作 bool
时,就会调用回调函数。
另请参阅 PyGTK常见问题解答,特别是问题20.7 。
As explained here, I have a simple tray icon using PyGTK.
Being very new to GTK, it appears to me that gtk.main()
is synchronous, blocking any further processing until the respective UI is closed.
So how can I periodically (e.g. every 5 seconds) update/refresh StatusIcon
's icon - do I have to resort to Twisted et al. for this?
解决方案 You can use gobject.timeout_add()
to add periodical tasks. The first parameter is the interval in seconds, the second parameter is the callback you want to be called. The callback is called as long as it returns something that evaluates to True
when used as a bool
.
See also section 20 of the PyGTK FAQ, in particular question 20.7.
这篇关于异步更新PyGTK托盘图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!