在gtk.main()执行时与gtk.container交互? [英] Interacting with a gtk.container while gtk.main() is executing?

查看:149
本文介绍了在gtk.main()执行时与gtk.container交互?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 pygtk egg.trayicon 在Python中尝试使用电池监视器图标创建一个图标,以显示电池图标/ tooltip。

我似乎可以添加图标和工具提示文本,但是当它到达 gtk.main()时, code> stage我需要一种方法来修改它们,以便它可以显示更新的值。



我试过 gobject.idle_add () gobject.timeout_add()没有太多的运气,不知道从哪里去。



任何人有任何想法?



编辑:也许不是最明显的问题。 b $ b

我需要循环,在运行时从acpi获取信息并将其应用于gtk容器内的小部件。

编辑2 >:好的,它现在正常了。问题在于我没有在回调中返回任何内容。我只是给了它返回123,现在它开心地在我的系统托盘中闲逛,通知我电池的比例:)

p>这个例子适用于我:

 # -  *  - 模式:Python  -  *  -  
#vi:si :et:sw = 4:sts = 4:ts = 4

导入gobject
导入gtk
从egg导入trayicon

label = gtk。标签(Over here)

def回调(widget,ev):
label.set_text(您找到了我)

def timeout():
label.set_text(你在等什么?)

tray = trayicon.TrayIcon(TrayIcon)
box = gtk.EventBox()
box.add(label)
tray.add(box)
tray.show_all()
$ b box.connect(button-press-event,callback)

gobject.timeout_add(3000L,超时)

gtk.main()

没有看到您的代码,很难分辨哪些行不通。


Experimenting with a battery monitor icon at the moment in Python using pygtk and egg.trayicon to create an icon to display a battery icon/tooltip.

I seem to be able to add the icon and the tooltip text, but when it then reaches the gtk.main() stage I need a way to modify these so it can then show the updated values.

I've tried gobject.idle_add() and gobject.timeout_add() without much luck, not sure where to go from this.

Anyone got any ideas?

EDIT: Perhaps not the clearest of questions.

I need to loop, fetching information from acpi while running and apply it to widgets inside the gtk container.

EDIT 2: Ok, it's properly down now. The issue was that I wasn't returning anything inside my callback. I just gave it "return 123" and now it's happily chugging away in my system tray, notifying me of my battery percentage :)

解决方案

This example works for me:

# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4

import gobject
import gtk
from egg import trayicon

label = gtk.Label("Over here")

def callback(widget, ev):
    label.set_text("You found me")

def timeout():
    label.set_text("What are you waiting for?")

tray = trayicon.TrayIcon("TrayIcon")
box = gtk.EventBox()
box.add(label)
tray.add(box)
tray.show_all()

box.connect("button-press-event", callback)

gobject.timeout_add(3000L, timeout)

gtk.main()

Without seeing your code, it's hard to tell what doesn't work.

这篇关于在gtk.main()执行时与gtk.container交互?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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