[pygtk] Refresh window

John Ehresman jpe at wingware.com
Sat Dec 3 08:04:58 WST 2005


Genie Fomina wrote:
> John, my problem is not about reading from sockets (this part works 
> good), and I do not have anything that should be done fair amount of 
> time, it's more about writing into sockets (to two of them I need to 
> write too). 

You may want to add the IO_IN watch only when you're unable to write to 
them for some reason and then remove the watch when they become writable 
so that your callback is only invoked when needed.

> I really need to uderstand where is the right place to put
> 
> while/if gtk.events_pending():
>     gtk.main_iteration()

This should be rarely used -- it's better if you let the primary 
mainloop handle all the events.  gtk.main_iteration should only be used 
if you don't want to return to the primary mainloop.  There are 
legitimate uses of it, but it doesn't sound like you need to use it.

> Another quesion, is there a way to call a callback to write into a 
> socket only when I have data to write? Do I have to use io_add_watch 
> method to write into a socket or it will be better without it?

Add & remove the watch as needed.  You can write to the socket without 
adding a watch and getting a callback.

Hope this helps,

John


More information about the pygtk mailing list