Ejemplo n.º 1
0
 def stop(self, *args):
         """
         Quits the main loop.
         """
         if not self.has_implementations:
                 self._set_default_registry ()
         Atspi.event_quit()
Ejemplo n.º 2
0
        def deregisterKeystrokeListener(self,
                                        client,
                                        key_set=[],
                                        mask=0,
                                        kind=(_KEY_PRESSED_EVENT, _KEY_RELEASED_EVENT)):
                """
                Deregisters a listener for key stroke events.

                @@param client: Callable to be invoked when the event occurs
                @@type client: callable
                @@param key_set: Set of hardware key codes to stop monitoring. Leave empty
                        to indicate all keys.
                @@type key_set: list of integer
                @@param mask: When the mask is None, the codes in the key_set will be 
                        monitored only when no modifier is held. When the mask is an 
                        integer, keys in the key_set will be monitored only when the modifiers in
                        the mask are held. When the mask is an iterable over more than one 
                        integer, keys in the key_set will be monitored when any of the modifier
                        combinations in the set are held.
                @@type mask: integer, iterable, None
                @@param kind: Kind of events to stop watching, KEY_PRESSED_EVENT or 
                        KEY_RELEASED_EVENT.
                @@type kind: list
                @@raise KeyError: When the client isn't already registered for events
                """
                if not self.has_implementations:
                        self._set_default_registry ()
                try:
                        listener = self.event_listeners[client]
                except:
                        return
                Atspi.deregister_keystroke_listener (listener, key_set, mask, kind)
Ejemplo n.º 3
0
 def stop(self, *args):
     """
             Quits the main loop.
             """
     if not self.has_implementations:
         self._set_default_registry()
     Atspi.event_quit()
Ejemplo n.º 4
0
    def _register_atspi_keystroke_listeners(self, register):
        if self._keystroke_listeners_registered != register:
            modifier_masks = range(16)

            if register:
                if not self._keystroke_listener:
                    self._keystroke_listener = \
                       Atspi.DeviceListener.new(self._on_atspi_keystroke, None)

                for modifier_mask in modifier_masks:
                    Atspi.register_keystroke_listener( \
                                        self._keystroke_listener,
                                        None,        # key set, None=all
                                        modifier_mask,
                                        Atspi.KeyEventType.PRESSED,
                                        Atspi.KeyListenerSyncType.SYNCHRONOUS)
            else:
                # Apparently any single deregister call will turn off
                # all the other registered modifier_masks too. Since
                # deregistering takes extremely long (~2.5s for 16 calls)
                # seize the opportunity and just pick a single arbitrary
                # mask (Quantal).
                modifier_masks = [2]

                for modifier_mask in modifier_masks:
                    Atspi.deregister_keystroke_listener(
                                        self._keystroke_listener,
                                        None, # key set, None=all
                                        modifier_mask,
                                        Atspi.KeyEventType.PRESSED)

        self._keystroke_listeners_registered = register
    def _register_atspi_keystroke_listeners(self, register):
        if not "Atspi" in globals():
            return

        if self._keystroke_listeners_registered != register:
            modifier_masks = range(16)

            if register:
                if not self._keystroke_listener:
                    self._keystroke_listener = \
                       Atspi.DeviceListener.new(self._on_atspi_keystroke, None)

                for modifier_mask in modifier_masks:
                    Atspi.register_keystroke_listener( \
                                        self._keystroke_listener,
                                        None,        # key set, None=all
                                        modifier_mask,
                                        Atspi.KeyEventType.PRESSED,
                                        Atspi.KeyListenerSyncType.SYNCHRONOUS)
            else:
                # Apparently any single deregister call will turn off
                # all the other registered modifier_masks too. Since
                # deregistering takes extremely long (~2.5s for 16 calls)
                # seize the opportunity and just pick a single arbitrary
                # mask (Quantal).
                modifier_masks = [2]

                for modifier_mask in modifier_masks:
                    Atspi.deregister_keystroke_listener(
                        self._keystroke_listener,
                        None,  # key set, None=all
                        modifier_mask,
                        Atspi.KeyEventType.PRESSED)

        self._keystroke_listeners_registered = register
Ejemplo n.º 6
0
        def registerKeystrokeListener(self,
                                      client,
                                      key_set=[],
                                      mask=0,
                                      kind=(_KEY_PRESSED_EVENT, _KEY_RELEASED_EVENT),
                                      synchronous=True,
                                      preemptive=True,
                                      global_=False):
                """
                Registers a listener for key stroke events.

                @@param client: Callable to be invoked when the event occurs
                @@type client: callable
                @@param key_set: Set of hardware key codes to stop monitoring. Leave empty
                        to indicate all keys.
                @@type key_set: list of integer
                @@param mask: When the mask is None, the codes in the key_set will be 
                        monitored only when no modifier is held. When the mask is an 
                        integer, keys in the key_set will be monitored only when the modifiers in
                        the mask are held. When the mask is an iterable over more than one 
                        integer, keys in the key_set will be monitored when any of the modifier
                        combinations in the set are held.
                @@type mask: integer, iterable, None
                @@param kind: Kind of events to watch, KEY_PRESSED_EVENT or 
                        KEY_RELEASED_EVENT.
                @@type kind: list
                @@param synchronous: Should the callback notification be synchronous, giving
                        the client the chance to consume the event?
                @@type synchronous: boolean
                @@param preemptive: Should the callback be allowed to preempt / consume the
                        event?
                @@type preemptive: boolean
                @@param global_: Should callback occur even if an application not supporting
                        AT-SPI is in the foreground? (requires xevie)
                @@type global_: boolean
                """
                if not self.has_implementations:
                        self._set_default_registry ()
                try:
                        listener = self.event_listeners[client]
                except:
                        listener = self.event_listeners[client] = Atspi.DeviceListener.new(self.eventWrapper, client)
                syncFlag = self.makeSyncType(synchronous, preemptive, global_)
                try:
                        iter(mask)
                        masks = mask
                except:
                        masks = [mask]
                for m in masks:
                        Atspi.register_keystroke_listener(listener,
                                                          key_set,
                                                          m,
                                                          self.makeKind (kind),
                                                          syncFlag)
Ejemplo n.º 7
0
        def registerKeystrokeListener(self,
                                      client,
                                      key_set=[],
                                      mask=0,
                                      kind=(_KEY_PRESSED_EVENT, _KEY_RELEASED_EVENT),
                                      synchronous=True,
                                      preemptive=True,
                                      global_=False):
                """
                Registers a listener for key stroke events.

                @@param client: Callable to be invoked when the event occurs
                @@type client: callable
                @@param key_set: Set of hardware key codes to stop monitoring. Leave empty
                        to indicate all keys.
                @@type key_set: list of integer
                @@param mask: When the mask is None, the codes in the key_set will be 
                        monitored only when no modifier is held. When the mask is an 
                        integer, keys in the key_set will be monitored only when the modifiers in
                        the mask are held. When the mask is an iterable over more than one 
                        integer, keys in the key_set will be monitored when any of the modifier
                        combinations in the set are held.
                @@type mask: integer, iterable, None
                @@param kind: Kind of events to watch, KEY_PRESSED_EVENT or 
                        KEY_RELEASED_EVENT.
                @@type kind: list
                @@param synchronous: Should the callback notification be synchronous, giving
                        the client the chance to consume the event?
                @@type synchronous: boolean
                @@param preemptive: Should the callback be allowed to preempt / consume the
                        event?
                @@type preemptive: boolean
                @@param global_: Should callback occur even if an application not supporting
                        AT-SPI is in the foreground? (requires xevie)
                @@type global_: boolean
                """
                if not self.has_implementations:
                        self._set_default_registry ()
                try:
                        listener = self.event_listeners[client]
                except:
                        listener = self.event_listeners[client] = Atspi.DeviceListener.new(self.eventWrapper, client)
                syncFlag = self.makeSyncType(synchronous, preemptive, global_)
                if hasattr(mask, '__iter__'):
                        masks = mask
                else:
                        masks = [mask]
                for m in masks:
                        Atspi.register_keystroke_listener(listener,
                                                          key_set,
                                                          m,
                                                          self.makeKind (kind),
                                                          syncFlag)
Ejemplo n.º 8
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()
Ejemplo n.º 9
0
    def execute(self, filename: str, keyval: int):

        if keyval:
            Atspi.generate_keyboard_event(keyval, None,
                                          Atspi.KeySynthType.PRESSRELEASE)
        self.capture(
            filename=filename,
            window=self.props["window"],
            type=self.props["type"],
            x1=self.props["x1"],
            y1=self.props["y1"],
            x2=self.props["x2"],
            y2=self.props["y2"],
        )
Ejemplo n.º 10
0
    def getLocalizedRoleName(self, obj, role=None):
        """Returns the localized name of the given Accessible object; the name
        is suitable to be brailled.

        Arguments:
        - obj: an Accessible object
        - role: an optional pyatspi role to use instead
        """

        if _settingsManager.getSetting('brailleRolenameStyle') \
                == settings.BRAILLE_ROLENAME_STYLE_SHORT:
            objRole = role or obj.getRole()
            rv = shortRoleNames.get(objRole)
            if rv:
                return rv

        if not isinstance(role, pyatspi.Role):
            try:
                return obj.getLocalizedRoleName()
            except:
                return ''

        if not role:
            return ''

        nonlocalized = Atspi.role_get_name(role)
        atkRole = Atk.role_for_name(nonlocalized)

        return Atk.role_get_localized_name(atkRole)
    def getLocalizedRoleName(self, obj, role=None):
        """Returns the localized name of the given Accessible object; the name
        is suitable to be brailled.

        Arguments:
        - obj: an Accessible object
        - role: an optional pyatspi role to use instead
        """

        if _settingsManager.getSetting('brailleRolenameStyle') \
                == settings.BRAILLE_ROLENAME_STYLE_SHORT:
            objRole = role or obj.getRole()
            rv = shortRoleNames.get(objRole)
            if rv:
                return rv

        if not isinstance(role, pyatspi.Role):
            try:
                return obj.getLocalizedRoleName()
            except:
                return ''

        if not role:
            return ''

        nonlocalized = Atspi.role_get_name(role)
        atkRole = Atk.role_for_name(nonlocalized)

        return Atk.role_get_localized_name(atkRole)
Ejemplo n.º 12
0
    def generateMouseEvent(self, x, y, name):
        """
                Generates a mouse event at the given absolute x and y coordinate. The kind
                of event generated is specified by the name. For example, MOUSE_B1P 
                (button 1 press), MOUSE_REL (relative motion), MOUSE_B3D (butten 3 
                double-click).

                @@param x: Horizontal coordinate, usually left-hand oriented
                @@type x: integer
                @@param y: Vertical coordinate, usually left-hand oriented
                @@type y: integer
                @@param name: Name of the event to generate
                @@type name: string
                """
        if not self.has_implementations:
            self._set_default_registry()
        Atspi.generate_mouse_event(x, y, name)
Ejemplo n.º 13
0
    def setReferenceWIndow(accessible):
        """
                Sets the reference window that will be used when
                generateMouseEvent is called. Coordinates will be assumed to
                be relative to this window. This * is needed because, due to
                Wayland's security model, it is not currently possible to
                possible to retrieve global coordinates.
                If NULL is passed, then AT-SPI will use the window that has
                focus at the time that atspi_generate_mouse_event is called.

                @@param accessible: the accessible corresponding to the window
                to select. should be a top-level window with a role of
                pyatspi.ROLE_APPLICATION.
                """
        if not self.has_implementations:
            self._set_default_registry()
        Atspi.setReferenceWindow(accessible)
Ejemplo n.º 14
0
        def generateMouseEvent(self, x, y, name):
                """
                Generates a mouse event at the given absolute x and y coordinate. The kind
                of event generated is specified by the name. For example, MOUSE_B1P 
                (button 1 press), MOUSE_REL (relative motion), MOUSE_B3D (butten 3 
                double-click).

                @@param x: Horizontal coordinate, usually left-hand oriented
                @@type x: integer
                @@param y: Vertical coordinate, usually left-hand oriented
                @@type y: integer
                @@param name: Name of the event to generate
                @@type name: string
                """
                if not self.has_implementations:
                        self._set_default_registry ()
                Atspi.generate_mouse_event (x, y, name)
Ejemplo n.º 15
0
def find_program(pid):
    desktop = Atspi.get_desktop(0)

    child_count = desktop.get_child_count()
    for i in range(child_count):
        child = desktop.get_child_at_index(i)
        if child.get_process_id() == pid:
            return child
Ejemplo n.º 16
0
        def generateKeyboardEvent(self, keycode, keysym, kind):
                """
                Generates a keyboard event. One of the keycode or the keysym parameters
                should be specified and the other should be None. The kind parameter is 
                required and should be one of the KEY_PRESS, KEY_RELEASE, KEY_PRESSRELEASE,
                KEY_SYM, or KEY_STRING.

                @@param keycode: Hardware keycode or None
                @@type keycode: integer
                @@param keysym: Symbolic key string or None
                @@type keysym: string
                @@param kind: Kind of event to synthesize
                @@type kind: integer
                """
                if not self.has_implementations:
                        self._set_default_registry ()
                if keysym is None:
                        keysym = ""
                Atspi.generate_keyboard_event (keycode, keysym, kind)
Ejemplo n.º 17
0
    def generateKeyboardEvent(self, keycode, keysym, kind):
        """
                Generates a keyboard event. One of the keycode or the keysym parameters
                should be specified and the other should be None. The kind parameter is 
                required and should be one of the KEY_PRESS, KEY_RELEASE, KEY_PRESSRELEASE,
                KEY_SYM, KEY_STRING, KEY_LOCKMODIFIERS, or KEY_UNLOCKMODIFIERS.

                @@param keycode: Hardware keycode or None
                @@type keycode: integer
                @@param keysym: Symbolic key string or None
                @@type keysym: string
                @@param kind: Kind of event to synthesize
                @@type kind: integer
                """
        if not self.has_implementations:
            self._set_default_registry()
        if keysym is None:
            keysym = ""
        Atspi.generate_keyboard_event(keycode, keysym, kind)
Ejemplo n.º 18
0
    def start(self, asynchronous=False, gil=True, **kwargs):
        """
                Enter the main loop to start receiving and dispatching events.

                @@param asynchronous: Should event dispatch be asynchronous
                        (decoupled) from event receiving from the AT-SPI registry?
                @@type asynchronous: boolean
                @@param gil: Add an idle callback which releases the Python GIL for a few
                        milliseconds to allow other threads to run? Necessary if other threads
                        will be used in this process.
                @@type gil: boolean
                """
        if 'async' in kwargs:
            # support previous API
            asynchronous = kwargs['async']
        if not self.has_implementations:
            self._set_default_registry()
        self.started = True

        if gil:

            def releaseGIL():
                try:
                    time.sleep(1e-2)
                except KeyboardInterrupt as e:
                    # store the exception for later
                    releaseGIL.keyboard_exception = e
                    self.stop()
                return True

            # make room for an exception if one occurs during the
            releaseGIL.keyboard_exception = None
            i = GLib.idle_add(releaseGIL)
            Atspi.event_main()
            GLib.source_remove(i)
            if releaseGIL.keyboard_exception is not None:
                # raise an keyboard exception we may have gotten earlier
                raise releaseGIL.keyboard_exception
        else:
            Atspi.event_main()

        self.started = False
Ejemplo n.º 19
0
        def getDesktop(self, i):
                """
                Gets a reference to the i-th desktop.

                @@param i: Which desktop to get
                @@type i: integer
                @@return: Desktop reference
                @@rtype: Accessibility.Desktop
                """
                if not self.has_implementations:
                        self._set_default_registry ()
                return Atspi.get_desktop(i)
Ejemplo n.º 20
0
def get_app(name):
    desktop = Atspi.get_desktop(0)
    start = time.time()
    timeout = 5
    app = None
    while app is None and (time.time() - start) < timeout:
        gen = (child for _i, child in children(desktop)
               if child and child.get_name() == name)
        app = next(gen, None)
        if app is None:
            time.sleep(0.6)
    return app
Ejemplo n.º 21
0
    def getDesktop(self, i):
        """
                Gets a reference to the i-th desktop.

                @@param i: Which desktop to get
                @@type i: integer
                @@return: Desktop reference
                @@rtype: Accessibility.Desktop
                """
        if not self.has_implementations:
            self._set_default_registry()
        return Atspi.get_desktop(i)
Ejemplo n.º 22
0
    def deregisterKeystrokeListener(self,
                                    client,
                                    key_set=[],
                                    mask=0,
                                    kind=(_KEY_PRESSED_EVENT,
                                          _KEY_RELEASED_EVENT)):
        """
                Deregisters a listener for key stroke events.

                @@param client: Callable to be invoked when the event occurs
                @@type client: callable
                @@param key_set: Set of hardware key codes to stop monitoring. Leave empty
                        to indicate all keys.
                @@type key_set: list of integer
                @@param mask: When the mask is None, the codes in the key_set will be 
                        monitored only when no modifier is held. When the mask is an 
                        integer, keys in the key_set will be monitored only when the modifiers in
                        the mask are held. When the mask is an iterable over more than one 
                        integer, keys in the key_set will be monitored when any of the modifier
                        combinations in the set are held.
                @@type mask: integer, iterable, None
                @@param kind: Kind of events to stop watching, KEY_PRESSED_EVENT or 
                        KEY_RELEASED_EVENT.
                @@type kind: list
                @@raise KeyError: When the client isn't already registered for events
                """
        if not self.has_implementations:
            self._set_default_registry()
        try:
            listener = self.event_listeners[client]
        except:
            return

        if hasattr(mask, '__iter__'):
            masks = mask
        else:
            masks = [mask]
        for m in masks:
            Atspi.deregister_keystroke_listener(listener, key_set, m,
                                                self.makeKind(kind))
Ejemplo n.º 23
0
        def start(self, asynchronous=False, gil=True, **kwargs):
                """
                Enter the main loop to start receiving and dispatching events.

                @@param asynchronous: Should event dispatch be asynchronous
                        (decoupled) from event receiving from the AT-SPI registry?
                @@type asynchronous: boolean
                @@param gil: Add an idle callback which releases the Python GIL for a few
                        milliseconds to allow other threads to run? Necessary if other threads
                        will be used in this process.
                @@type gil: boolean
                """
                if 'async' in kwargs:
                    # support previous API
                    asynchronous = kwargs['async']
                if not self.has_implementations:
                        self._set_default_registry ()
                self.started = True

                if gil:
                        def releaseGIL():
                                try:
                                        time.sleep(1e-2)
                                except KeyboardInterrupt as e:
                                        # store the exception for later
                                        releaseGIL.keyboard_exception = e
                                        self.stop()
                                return True
                        # make room for an exception if one occurs during the 
                        releaseGIL.keyboard_exception = None
                        i = GLib.idle_add(releaseGIL)
                        Atspi.event_main()
                        GLib.source_remove(i)
                        if releaseGIL.keyboard_exception is not None:
                                # raise an keyboard exception we may have gotten earlier
                                raise releaseGIL.keyboard_exception
                else:
                        Atspi.event_main()

                self.started = False
Ejemplo n.º 24
0
def run(path, name= None):
    name = name or f"{path}-test-{str(random.randint(0, 100000000))}"
    process = subprocess.Popen([path, '--name', name])
    desktop = Atspi.get_desktop(0)
    start = time.time()
    timeout = 5
    app = None
    while app is None and (time.time() - start) < timeout:
        gen = (child for _i, child in children(desktop) if child and child.get_name() == name)
        app = next(gen, None)
        if app is None:
            time.sleep(0.6)
    return (process, app)
Ejemplo n.º 25
0
    def _generateRoleName(self, obj, **args):
        """Returns an array of sounds indicating the role of obj."""

        if not _settingsManager.getSetting('playSoundForRole'):
            return []

        role = args.get('role', obj.getRole())
        filename = Atspi.role_get_name(role).replace(' ', '_')
        result = self._convertFilenameToIcon(filename)
        if result:
            return [result]

        return []
Ejemplo n.º 26
0
    def _generateRoleName(self, obj, **args):
        """Returns an array of sounds indicating the role of obj."""

        if not _settingsManager.getSetting('playSoundForRole'):
            return []

        role = args.get('role', obj.getRole())
        filename = Atspi.role_get_name(role).replace(' ', '_')
        result = self._convertFilenameToIcon(filename)
        if result:
            return [result]

        return []
Ejemplo n.º 27
0
                        self._set_default_registry ()
                self.started = True

                if gil:
                        def releaseGIL():
                                try:
                                        time.sleep(1e-2)
                                except KeyboardInterrupt as e:
                                        # store the exception for later
                                        releaseGIL.keyboard_exception = e
                                        self.stop()
                                return True
                        # make room for an exception if one occurs during the 
                        releaseGIL.keyboard_exception = None
                        i = GLib.idle_add(releaseGIL)
                        Atspi.event_main()
                        GLib.source_remove(i)
                        if releaseGIL.keyboard_exception is not None:
                                # raise an keyboard exception we may have gotten earlier
                                raise releaseGIL.keyboard_exception
                else:
                        Atspi.event_main()

                self.started = False

        def stop(self, *args):
                """
                Quits the main loop.
                """
                if not self.has_implementations:
                        self._set_default_registry ()
Ejemplo n.º 28
0
                        self._set_default_registry ()
                self.started = True

                if gil:
                        def releaseGIL():
                                try:
                                        time.sleep(1e-2)
                                except KeyboardInterrupt, e:
                                        # store the exception for later
                                        releaseGIL.keyboard_exception = e
                                        self.stop()
                                return True
                        # make room for an exception if one occurs during the 
                        releaseGIL.keyboard_exception = None
                        i = GObject.idle_add(releaseGIL)
                        Atspi.event_main()
                        GObject.source_remove(i)
                        if releaseGIL.keyboard_exception is not None:
                                # raise an keyboard exception we may have gotten earlier
                                raise releaseGIL.keyboard_exception
                else:
                        Atspi.event_main()

                self.started = False

        def stop(self, *args):
                """
                Quits the main loop.
                """
                if not self.has_implementations:
                        self._set_default_registry ()
Ejemplo n.º 29
0
def release(button=1, x_offset=0, y_offset=0):
    Atspi.generate_mouse_event(x_offset, y_offset, "b%sr" % button)
    return True
Ejemplo n.º 30
0
 def click(self, button=1, x_offset=0, y_offset=0):
     point = self._accessible.get_position(Atspi.CoordType.SCREEN)
     Atspi.generate_mouse_event(point.x+x_offset,
                                point.y+y_offset,
                                "b%sc" % button)
Ejemplo n.º 31
0
 def press_key_string(self, string):
     #print("press_key_string")
     Atspi.generate_keyboard_event(0, string, Atspi.KeySynthType.STRING)
Ejemplo n.º 32
0
 def release_keycode(self, keycode):
     #print("release_keycode")
     Atspi.generate_keyboard_event(keycode, "", Atspi.KeySynthType.RELEASE)
Ejemplo n.º 33
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
Ejemplo n.º 34
0
import logging
import time

from gi.repository import Atspi
from gi.repository import GLib

Atspi.set_timeout(-1, -1)


def get_root():
    return Node(Atspi.get_desktop(0))


def _retry_find(func):
    def wrapped(*args, **kwargs):
        result = None
        n_retries = 1

        while n_retries <= 50:
            logging.info("Try %d, name=%s role_name=%s" %
                         (n_retries, kwargs.get(
                             "name", None), kwargs.get("role_name", None)))

            try:
                result = func(*args, **kwargs)
            except GLib.GError, e:
                # The application is not responding, try again
                if e.code == Atspi.Error.IPC:
                    continue

                logging.error("GError code %d", e.code)
Ejemplo n.º 35
0
def press(button=1, x_offset=0, y_offset=0):
    Atspi.generate_mouse_event(x_offset, y_offset, "b%sp" % button)
    return True
Ejemplo n.º 36
0
def release(button=1, x_offset=0, y_offset=0):
    Atspi.generate_mouse_event(x_offset, y_offset, "b%sr" % button)
    return True
Ejemplo n.º 37
0
def absMotion(x_offset=0, y_offset=0):
    Atspi.generate_mouse_event(x_offset, y_offset, "abs")
    return True
Ejemplo n.º 38
0
 def click(self, button=1, x_offset=0, y_offset=0):
     point = self._accessible.get_position(Atspi.CoordType.SCREEN)
     Atspi.generate_mouse_event(point.x + x_offset, point.y + y_offset,
                                "b%sc" % button)
Ejemplo n.º 39
0
def get_root():
    return Node(Atspi.get_desktop(0))
Ejemplo n.º 40
0
 def click(self, button=1):
     point = self._accessible.get_position(Atspi.CoordType.SCREEN)
     Atspi.generate_mouse_event(point.x, point.y, "b%sc" % button)
Ejemplo n.º 41
0
import logging
import time

from gi.repository import Atspi
from gi.repository import GLib

Atspi.set_timeout(-1, -1)


def get_root():
    return Node(Atspi.get_desktop(0))


def _retry_find(func):
    def wrapped(*args, **kwargs):
        result = None
        n_retries = 1

        while n_retries <= 50:
            logging.info("Try %d, name=%s role_name=%s" %
                         (n_retries,
                          kwargs.get("name", None),
                          kwargs.get("role_name", None)))

            try:
                result = func(*args, **kwargs)
            except GLib.GError, e:
                # The application is not responding, try again
                if e.code == Atspi.Error.IPC:
                    continue
Ejemplo n.º 42
0
 def press_keycode(self, keycode):
     #print("press_keycode")
     Atspi.generate_keyboard_event(keycode, "", Atspi.KeySynthType.PRESS)
Ejemplo n.º 43
0
def get_root():
    return Node(Atspi.get_desktop(0))
Ejemplo n.º 44
0
def key_press(key_name):
    key_sym = name_to_sym(key_name)
    Atspi.generate_keyboard_event(key_sym,
                                  None,
                                  Atspi.KeySynthType.SYM)
Ejemplo n.º 45
0
 def click(self, button=1):
     point = self._accessible.get_position(Atspi.CoordType.SCREEN)
     Atspi.generate_mouse_event(point.x, point.y, "b%sc" % button)
Ejemplo n.º 46
0
def absMotion(x_offset=0, y_offset=0):
    Atspi.generate_mouse_event(x_offset, y_offset, "abs")
    return True
Ejemplo n.º 47
0
def StateSet_getStates(self):
    ret = []
    for i in range(0, 64):
        if (self.states & (1 << i)):
            ret.append(Atspi.StateType(i))
    return ret
Ejemplo n.º 48
0
def key_press(key_name):
    key_sym = name_to_sym(key_name)
    Atspi.generate_keyboard_event(key_sym, None, Atspi.KeySynthType.SYM)
Ejemplo n.º 49
0
def press(button=1, x_offset=0, y_offset=0):
    Atspi.generate_mouse_event(x_offset, y_offset, "b%sp" % button)
    return True