开发者

Refreshing label in Python

开发者 https://www.devze.com 2023-01-05 01:23 出处:网络
I creating applet in gnome panel. All code is good. But info in panel is static. But need refresh this info in time. 1 secon or 5 second...

I creating applet in gnome panel. All code is good. But info in panel is static. But need refresh this info in time. 1 secon or 5 second...

Here is part of python code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import gobject
import gtk
import pygtk
import gnomeapplet
import time
import urllib2
pygtk.require('2.0')

def applet_factory(applet, iid):   
   label = gtk.Label("Simple text")
   applet.add(label)
   applet.show_all()

print('Factory started')

if __name__ == '__main__':   # testing for execution
   print('Startin开发者_如何学Gog factory')
   gnomeapplet.bonobo_factory('OAFIID:SampleApplet_Factory', 
                              gnomeapplet.Applet.__gtype__, 
                              'Sample Applet', '0.1', 
                              applet_factory)

I need refresh "simple text" label in time interval. How did that?


What about...:

def applet_factory(applet, iid):   
   label = gtk.Label("Simple text")
   applet.add(label)
   applet.show_all()
   return label

thelabel = applet_factory(applet, iid)

def redrawlabel(*args):
    thelabel.queue_draw()
    # process all events
    while gtk.events_pending():
        gtk.main_iteration(False)
    return True

# call redrawlabel every 5 minutes
gtk.timeout_add(5*60*1000, redrawlabel)

If you also need to set the text to something different, thelabel.set_text('something else') will do that.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号