From f7d0d957cd3df94e9936d5c0d679d9cad3154c41 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 27 Oct 2009 21:03:11 +0000 Subject: [PATCH] Add function to snapshot a widget and its children as a pixbuf --- terminatorlib/util.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/terminatorlib/util.py b/terminatorlib/util.py index b4d8db64..86ecb525 100755 --- a/terminatorlib/util.py +++ b/terminatorlib/util.py @@ -95,3 +95,23 @@ def shell_lookup(): return(rshell) dbg('shell_lookup: Unable to locate a shell') +def widget_pixbuf(widget, maxsize=None): + """Generate a pixbuf of a widget""" + pixmap = widget.get_snapshot() + (width, height) = pixmap.get_size() + pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height) + pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(), 0, 0, 0, 0, width, + height) + + longest = max(width, height) + + if maxsize is not None: + factor = float(maxsize) / float(longest) + + if not maxsize or (width * factor) > width or (height * factor) > height: + factor = 1 + + scaledpixbuf = pixbuf.scale_simple(int(width * factor), int(height * factor), gtk.gdk.INTERP_BILINEAR) + + return(scaledpixbuf) +