Interaction with gtk.container at runtime of gtk.main ()?

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

It seems I can add an icon and tooltip text, but when it reaches the gtk.main() stage, I need a way to change them so that it can show updated values.

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

Does anyone have any ideas?

EDIT . Perhaps this is not a clear question.

I need to loop, extract information from acpi during operation and apply it to widgets inside the gtk container.

EDIT 2 : Ok, now that's right. The thing is, I didn’t return anything in my callback. I just gave it "return 123" and now it happily comes off in my system tray, notifying me of my battery percentage :)

+4
source share
1 answer

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 say what doesn't work.

+3
source

All Articles