By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,758 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,758 IT Pros & Developers. It's quick & easy.

Pygtk, widget refreshing

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
>>>>> "Arne" == Arne Schwabe <ar**@rfc2549.org> writes:

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


Jul 18 '05 #2

P: n/a
* 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.

--
Emmanuele Bassi | [ http://digilander.libero.it/ebassi/ ]
emmanuele.bassi(at)iol.it | Linux User #170621, http://counter.li.org
GnuPG Key fingerprint = 4DD0 C90D 4070 F071 5738 08BD 8ECC DB8F A432 0FF4
Jul 18 '05 #3

P: n/a
* 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.

--
Emmanuele Bassi | [ http://digilander.libero.it/ebassi/ ]
emmanuele.bassi(at)iol.it | Linux User #170621, http://counter.li.org
GnuPG Key fingerprint = 4DD0 C90D 4070 F071 5738 08BD 8ECC DB8F A432 0FF4
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.