(widget, maxsize=None)
return(scaledpixbuf)
Generate a pixbuf of a widget
Generate a pixbuf of a widget
Generate a pixbuf of a widget
def widget_pixbuf(widget, maxsize=None):
    """Generate a pixbuf of a widget"""
    # FIXME: Can this be changed from using "import cairo" to "from gi.repository import cairo"?
    window = widget.get_window()
    width, height = window.get_width(), window.get_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

    preview_width, preview_height = int(width * factor), int(height * factor)

    preview_surface = Gdk.Window.create_similar_surface(window,
        cairo.CONTENT_COLOR, preview_width, preview_height)

    cairo_context = cairo.Context(preview_surface)
    cairo_context.scale(factor, factor)
    Gdk.cairo_set_source_window(cairo_context, window, 0, 0)
    cairo_context.paint()

    scaledpixbuf = Gdk.pixbuf_get_from_surface(preview_surface, 0, 0, preview_width, preview_height);
    
    return(scaledpixbuf)
def widget_pixbuf ( widget , maxsize = None ) : # FIXME: Can this be changed from using "import cairo" to "from gi.repository import cairo"? window = widget . get_window ( ) width , height = window . get_width ( ) , window . get_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 preview_width , preview_height = int ( width * factor ) , int ( height * factor ) preview_surface = Gdk . Window . create_similar_surface ( window , cairo . CONTENT_COLOR , preview_width , preview_height ) cairo_context = cairo . Context ( preview_surface ) cairo_context . scale ( factor , factor ) Gdk . cairo_set_source_window ( cairo_context , window , 0 , 0 ) cairo_context . paint ( ) scaledpixbuf = Gdk . pixbuf_get_from_surface ( preview_surface , 0 , 0 , preview_width , preview_height ) return ( scaledpixbuf )