onB*_*ner 9 indicator python programming application-development pygi
我已经将一些 Python 代码转换为使用 PYGI,但我不知道如何转换这一行:
gtk.timeout_add(PING_FREQUENCY * 1000, self.doWork)
Run Code Online (Sandbox Code Playgroud)
明确地说,由于我真的不知道 PYGTK 和 PYGI 之间的区别,我的新代码使用
from gi.repository import Gtk
from gi.repository import AppIndicator3 as appindicator
Run Code Online (Sandbox Code Playgroud)
如此处所示https://wiki.ubuntu.com/DesktopExperienceTeam/ApplicationIndicators#Python_version
我试图转换的完整代码在这里http://pastebin.com/raw.php?i=aUtASRpy
相当于什么
gtk.timeout_add(PING_FREQUENCY * 1000, self.doWork)
Run Code Online (Sandbox Code Playgroud)
在 PYGI 中?
我还假设 PYGI 是制作统一指标的最现代方式
我还假设最好让指标检查某物的状态,而不是让某物告诉指标状态(推 vs 拉)。让python程序每秒检查一些东西是否可以?
谢谢!
xub*_*tix 19
Just to make sure that the Gtk way is also present in an answer:
The equivalent of
gtk.timeout_add(PING_FREQUENCY * 1000, self.doWork)
Run Code Online (Sandbox Code Playgroud)
in gobject introspection (PyGI) is:
from gi.repository import GLib
GLib.timeout_add(PING_FREQUENCY * 1000, self.doWork)
Run Code Online (Sandbox Code Playgroud)
However, when checking something regularly every x seconds, you should use
GLib.timeout_add_seconds(PING_FREQUENCY, self.doWork)
Run Code Online (Sandbox Code Playgroud)
This allows the Glib to group timers and therefore save power, which is important for mobile devices. From the documentation:
The grouping of timers to fire at the same time results in a more power and CPU efficient behavior so if your timer is in multiples of seconds and you don't require the first timer exactly one second from now, the use of glib.timeout_add_seconds() is preferred over glib.timeout_add().
| 归档时间: |
|
| 查看次数: |
2840 次 |
| 最近记录: |