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
Exemplo n.º 2
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
Exemplo n.º 3
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)
Exemplo n.º 4
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)