本文整理汇总了Python中gi.repository.Atspi类的典型用法代码示例。如果您正苦于以下问题:Python Atspi类的具体用法?Python Atspi怎么用?Python Atspi使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Atspi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deregisterKeystrokeListener
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)
示例2: stop
def stop(self, *args):
"""
Quits the main loop.
"""
if not self.has_implementations:
self._set_default_registry ()
Atspi.event_quit()
示例3: _register_atspi_keystroke_listeners
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
示例4: registerKeystrokeListener
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)
示例5: getLocalizedRoleName
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)
示例6: generateMouseEvent
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)
示例7: generateKeyboardEvent
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)
示例8: getDesktop
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)
示例9: start
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
示例10: _generateRoleName
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 []
示例11: absMotion
def absMotion(x_offset=0, y_offset=0):
Atspi.generate_mouse_event(x_offset, y_offset, "abs")
return True
示例12: releaseGIL
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 ()
示例13: click
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)
示例14: release
def release(button=1, x_offset=0, y_offset=0):
Atspi.generate_mouse_event(x_offset, y_offset, "b%sr" % button)
return True
示例15: get_root
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