Exemplo n.º 1
0
def _get_color_in_window(win, x, y, size=3):
    """Attempts to get the color from a position within a GDK window"""
    # GTK2 used to return a bitdepth as well.
    # The C API docs for GTK3 3.14.5 don't mention that,
    # but its GI wrapper seems to attempt backwards compatibility.
    # Um, yeah.
    # Just write code that won't break when they fix it.
    geom_tuple = win.get_geometry()
    win_x, win_y, win_w, win_h = geom_tuple[0:4]
    # Rectangle to sample
    x = int(max(0, x - size / 2))
    y = int(max(0, y - size / 2))
    w = int(min(size, win_w - x))
    h = int(min(size, win_h - y))
    if w <= 0 or h <= 0:
        return RGBColor(0, 0, 0)
    # The call below can take over 20ms,
    # and it depends on the window size.
    # It must be causing a full-window pixmap copy somewhere.
    pixbuf = Gdk.pixbuf_get_from_window(win, x, y, w, h)
    if pixbuf is None:
        errcol = RGBColor(1, 0, 0)
        logger.warning(
            "Failed to get pixbuf from screen; returning "
            "error indicator color %r",
            errcol,
        )
        return errcol
    return RGBColor.new_from_pixbuf_average(pixbuf)
Exemplo n.º 2
0
def get_color_in_window(win, x, y, size=3):
    """Attempts to get the color from a position within a GDK window.
    """

    # [GTK3] GDK2 and GDK3 return different tuples: no bitdepth in GDK3
    # We use GTK3 now but for some reason users still get different results,
    # see https://gna.org/bugs/?20791
    geom_tuple = win.get_geometry()
    win_x, win_y, win_w, win_h = geom_tuple[0:4]

    x = int(max(0, x - size / 2))
    y = int(max(0, y - size / 2))
    w = int(min(size, win_w - x))
    h = int(min(size, win_h - y))
    if w <= 0 or h <= 0:
        return RGBColor(0, 0, 0)
    # The call below can take over 20ms, and it depends on the window size!
    # It must be causing a full-window pixmap copy somewhere.
    pixbuf = gdk.pixbuf_get_from_window(win, x, y, w, h)
    if pixbuf is None:
        errcol = RGBColor(1, 0, 0)
        logger.warning(
            "Failed to get pixbuf from screen; returning "
            "error indicator color %r", errcol)
        return errcol
    return RGBColor.new_from_pixbuf_average(pixbuf)
Exemplo n.º 3
0
def _get_color_in_window(win, x, y, size=3):
    """Attempts to get the color from a position within a GDK window"""
    # GTK2 used to return a bitdepth as well.
    # The C API docs for GTK3 3.14.5 don't mention that,
    # but its GI wrapper seems to attempt backwards compatibility.
    # Um, yeah.
    # Just write code that won't break when they fix it.
    geom_tuple = win.get_geometry()
    win_x, win_y, win_w, win_h = geom_tuple[0:4]
    # Rectangle to sample
    x = int(max(0, x - size/2))
    y = int(max(0, y - size/2))
    w = int(min(size, win_w - x))
    h = int(min(size, win_h - y))
    if w <= 0 or h <= 0:
        return RGBColor(0, 0, 0)
    # The call below can take over 20ms,
    # and it depends on the window size.
    # It must be causing a full-window pixmap copy somewhere.
    pixbuf = Gdk.pixbuf_get_from_window(win, x, y, w, h)
    if pixbuf is None:
        errcol = RGBColor(1, 0, 0)
        logger.warning(
            "Failed to get pixbuf from screen; returning "
            "error indicator color %r",
            errcol,
        )
        return errcol
    return RGBColor.new_from_pixbuf_average(pixbuf)
Exemplo n.º 4
0
def get_color_in_window(win, x, y, size=3):
    """Attempts to get the color from a position within a GDK window.
    """

    # [GTK3] GDK2 and GDK3 return different tuples: no bitdepth in GDK3
    # We use GTK3 now but for some reason users still get different results,
    # see https://gna.org/bugs/?20791
    geom_tuple = win.get_geometry()
    win_x, win_y, win_w, win_h = geom_tuple[0:4]

    x = int(max(0, x - size/2))
    y = int(max(0, y - size/2))
    w = int(min(size, win_w - x))
    h = int(min(size, win_h - y))
    if w <= 0 or h <= 0:
        return RGBColor(0, 0, 0)
    # The call below can take over 20ms, and it depends on the window size!
    # It must be causing a full-window pixmap copy somewhere.
    pixbuf = gdk.pixbuf_get_from_window(win, x, y, w, h)
    if pixbuf is None:
        errcol = RGBColor(1, 0, 0)
        logger.warning("Failed to get pixbuf from screen; returning "
                       "error indicator color %r", errcol)
        return errcol
    return RGBColor.new_from_pixbuf_average(pixbuf)