Python gi.repository.Gdk 模块,get_default_root_window() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用gi.repository.Gdk.get_default_root_window()

项目:indicator-tablet-mode    作者:Aerilius    | 项目源码 | 文件源码
def __pixel_at(x, y):
    """Returns (r, g, b) color code for a pixel with given coordinates (each value is in 0..256 limits)"""
    root_window = gdk.get_default_root_window()
    buf = gdk.pixbuf_get_from_window(root_window, x, y, 1, 1)
    pixels = buf.get_pixels()
    if type(pixels) == type(""):
        rgb = tuple([int(byte.encode('hex'), 16) for byte in pixels])
    else:
        rgb = tuple(pixels)
    return rgb
项目:my-weather-indicator    作者:atareao    | 项目源码 | 文件源码
def take_screenshot(widget):
    w = Gdk.get_default_root_window()
    left, top = widget.get_position()
    width, height = widget.get_size()
    pixbuf = Gdk.pixbuf_get_from_window(w, left, top, width, height)
    return pixbuf
项目:furi-kura    作者:benjamindean    | 项目源码 | 文件源码
def __pixel_at(x, y):
    """Returns (r, g, b) color code for a pixel with given coordinates (each value is in 0..256 limits)"""
    root_window = Gdk.get_default_root_window()

    if not root_window:
        return tuple([0, 0, 0])

    buf = Gdk.pixbuf_get_from_window(root_window, x, y, 1, 1)
    pixels = buf.get_pixels()
    if isinstance(pixels, str):
        rgb = tuple([int(byte.encode('hex'), 16) for byte in pixels])
    else:
        rgb = tuple(pixels)
    return rgb
项目:surface-orientation    作者:virtualguywithabowtie    | 项目源码 | 文件源码
def __pixel_at(x, y):
    #Returns (r, g, b) color code for a pixel with given coordinates (each value is in 0..256 limits)
    root_window = gdk.get_default_root_window()
    buf = gdk.pixbuf_get_from_window(root_window, x, y, 1, 1)
    pixels = buf.get_pixels()
    if type(pixels) == type(""):
        rgb = tuple([int(byte.encode('hex'), 16) for byte in pixels])[0:3]
    else:
        rgb = tuple(pixels)[0:3]
    return rgb
项目:any_ping_indicator    作者:leggedrobotics    | 项目源码 | 文件源码
def __pixel_at(x, y):
    """Returns (r, g, b) color code for a pixel with given
    coordinates (each value is in 0..256 limits)"""
    root_window = gdk.get_default_root_window()
    buf = gdk.pixbuf_get_from_window(root_window, x, y, 1, 1)
    pixels = buf.get_pixels()
    if type(pixels) == type(""):
        rgb = tuple([int(byte.encode('hex'), 16) for byte in pixels])
    else:
        rgb = tuple(pixels)
    return rgb
项目:dogtail    作者:vhumpa    | 项目源码 | 文件源码
def screenshot(file='screenshot.png', timeStamp=True):
    """
    This function wraps the ImageMagick import command to take a screenshot.

    The file argument may be specified as 'foo', 'foo.png', or using any other
    extension that ImageMagick supports. PNG is the default.

    By default, screenshot filenames are in the format of foo_YYYYMMDD-hhmmss.png .
    The timeStamp argument may be set to False to name the file foo.png.
    """
    if not isinstance(timeStamp, bool):
        raise TypeError("timeStampt must be True or False")
    # config is supposed to create this for us. If it's not there, bail.
    assert os.path.isdir(config.scratchDir)

    baseName = ''.join(file.split('.')[0:-1])
    fileExt = file.split('.')[-1].lower()
    if not baseName:
        baseName = file
        fileExt = 'png'

    if timeStamp:
        ts = TimeStamp()
        newFile = ts.fileStamp(baseName) + '.' + fileExt
        path = config.scratchDir + newFile
    else:
        newFile = baseName + '.' + fileExt
        path = config.scratchDir + newFile

    from gi.repository import Gdk
    from gi.repository import GdkPixbuf
    rootWindow = Gdk.get_default_root_window()
    geometry = rootWindow.get_geometry()
    pixbuf = GdkPixbuf.Pixbuf(colorspace=GdkPixbuf.Colorspace.RGB,
                              has_alpha=False,
                              bits_per_sample=8,
                              width=geometry[2],
                              height=geometry[3])

    pixbuf = Gdk.pixbuf_get_from_window(rootWindow, 0, 0, geometry[2], geometry[3])
    # GdkPixbuf.Pixbuf.save() needs 'jpeg' and not 'jpg'
    if fileExt == 'jpg':
        fileExt = 'jpeg'
    try:
        pixbuf.savev(path, fileExt, [], [])
    except GLib.GError:
        raise ValueError("Failed to save screenshot in %s format" % fileExt)
    assert os.path.exists(path)
    logger.log("Screenshot taken: " + path)
    return path