异步更新PyGTK托盘图标 [英] Asynchronously updating PyGTK tray icon

查看:115
本文介绍了异步更新PyGTK托盘图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如这里所解释的,我使用PyGTK有一个简单的托盘图标。



对GTK来说很新,在我看来, 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆