Pygtk, widget refreshing

J

John Hunter

Arne> hi, I am using python and pygtk. In my program I want to
Arne> realize a status thing with a DrawingArea. But my problem
Arne> is that this area is not updated while my program is
Arne> running. Is there a way I can force pygtk to refresh to
Arne> widgets?

Two good ways, one is to use a timer and the other an idle. A timer
will call your function of choice every so many milliseconds, and an
idle func will do it whenever the gtk event loop is idle

For the timer

def update_widget(*args):
pass # do something here

gtk.timeout_add(250, update_widget) # call update_widget every 250 ms

For the idle func, you can pass an arg that will be passed to your
idle func

gtk.idle_add(update_widget)


Here is how I update a status bar -- this may not be ideal, it's just
what I came up with when I confronted it the first time

Create the status bar

self.statbar = gtk.Statusbar()
self.statbar.show()
self.statbarCID = self.statbar.get_context_id('my stat bar')
self.vbox.pack_end(self.statbar)
self.timeoutId = gtk.timeout_add(5000,self.update_status_bar)

where update_status_bar looks like

def update_status_bar(self, msg=None):
if msg is None:
# generate default message

try: self.statbarCID, self.statbarMID
except AttributeError: pass
else: self.statbar.remove(self.statbarCID, self.statbarMID)

self.statbarMID = self.statbar.push(self.statbarCID, msg)
return gtk.TRUE

and then later when the dialog is destroyed

gtk.timeout_remove(self.timeoutId)

Hope this helps,
John Hunter
 
A

Arne Schwabe

hi,

I am using python and pygtk.
In my program I want to realize a status thing with a DrawingArea.
But my problem is that this area is not updated while my program is running.
Is there a way I can force pygtk to refresh to widgets?

Arne
 
E

Emmanuele Bassi

* Arne Schwabe [2003-09-23 22:33]:
But my problem is that this area is not updated while my program is running.
Is there a way I can force pygtk to refresh to widgets?

while gtk.events_pending(): gtk.main_iteration()

Bye,
Emmanuele.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top