[pygtk] pixbuf loading in a thread -- release the GIL!
Ed Catmur
ed at catmur.co.uk
Mon Dec 17 04:23:51 WST 2007
On Wed, 2007-12-12 at 07:31 +0100, evan battaglia wrote:
> Hi,
> * is there a better way to accomplish what I am trying to do -- load
> large images in the background without freezing the UI? It seems like
> this must be a common problem (don't programs have to load thumbnails
> in the background?!)
Yes; use gnomevfs.async and gtk.gdk.PixbufLoader.
For example, to load an image 10KiB at a time:
import gnomevfs
import gtk
FILE = "/usr/share/pixmaps/backgrounds/gnome/branded/GNOME-Curves.png"
def close_cb(handle, result, loader):
loader.close()
def read_cb(handle, buffer, result, size, loader):
if result:
handle.close(close_cb, loader)
else:
loader.write(buffer, size)
handle.read(10000, read_cb, loader)
def open_cb(handle, result, loader):
if result:
print "open failed: ", result
else:
handle.read(10000, read_cb, loader)
w = gtk.Window()
image = gtk.Image()
w.add(image)
w.show_all()
loader = gtk.gdk.PixbufLoader()
def updated_cb(loader, x, y, width, height, image):
image.set_from_pixbuf(loader.get_pixbuf())
def closed_cb(loader, image):
image.set_from_pixbuf(loader.get_pixbuf())
loader.connect("area-updated", updated_cb, image)
loader.connect("closed", closed_cb, image)
gnomevfs.async.open(FILE, open_cb, gnomevfs.OPEN_READ,
gnomevfs.PRIORITY_DEFAULT, loader)
gtk.main()
More information about the pygtk
mailing list