Exemple #1
0
    def __init__(self):

        self.display = GdkX11.X11Display.get_default()
        self.screen = Wnck.Screen.get_default()
        self.props = {
            "window": None,
            "fmt": "jpg",
            "x1": None,
            "y1": None,
            "x2": None,
            "y2": None,
        }
        Atspi.init()
Exemple #2
0
def main(argv):
    if Atspi.init() != 0:
        eprint("could not init")
        return 1

    pid = int(argv[1])
    command = argv[2]
    command_args = argv[3:]

    start_time = time.perf_counter()
    (client, drawing_area) = find(pid)
    while (client is None or drawing_area is None) and command == "wait":
        time.sleep(0.1)
        if time.perf_counter() - start_time > TIMEOUT_IN_S:
            return 1
        (client, drawing_area) = find(pid)

    if client is None:
        eprint("no such pid")
        return 1
    if drawing_area is None:
        eprint("client has no drawing area")
        return 1

    if command == "wait":
        return 0


#    extents = obj.get_extents(Atspi.CoordType.SCREEN)
#    print(extents.x, extents.y, extents.width, extents.height)
#    testPy.grab_focus()
#    print(Atspi.generate_mouse_event(extents.x, extents.y, "b1c")) #button 1 click

    screen_extents = drawing_area.get_extents(Atspi.CoordType.SCREEN)
    window_extents = drawing_area.get_extents(Atspi.CoordType.WINDOW)

    #needs can_focus on target widget
    drawing_area.grab_focus()

    if command == "mouse":
        if command_args[0] == "m":
            relative = command_args[1] == "rel"
            x = int(command_args[2])
            y = int(command_args[3])
            if not relative:
                x += screen_extents.x
                y += screen_extents.y
            return move_mouse(relative, x, y)
        else:
            return generate_mouse_event(command_args[0])
    elif command == "query-screen-size":
        eprint(window_extents.width, window_extents.height)
        return query_return_code(
            window_extents.width == int(command_args[0])
            and window_extents.height == int(command_args[1]))
    elif command == "take-screenshot":
        dest = command_args[0]
        screen = Gdk.get_default_root_window()
        pixbuf = Gdk.pixbuf_get_from_window(screen, screen_extents.x,
                                            screen_extents.y,
                                            screen_extents.width,
                                            screen_extents.height)
        pixbuf.savev(dest, "png", [], [])
    elif command == "focus":
        time.sleep(0.5)
        drawing_area.grab_focus()
        time.sleep(0.5)
    elif command.startswith("key"):
        return generate_keyboard_event(command, int(command_args[0]))
    elif command == "resize":
        width, height = (s for s in command_args[:2])
        if subprocess.run([
                "xdotool", "getactivewindow", "windowsize", "--sync", width,
                height
        ]).returncode != 0:
            return False
    else:
        eprint("no such command")
        return 2

    return 0