本文整理汇总了Python中Xlib.X属性的典型用法代码示例。如果您正苦于以下问题:Python Xlib.X属性的具体用法?Python Xlib.X怎么用?Python Xlib.X使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类Xlib
的用法示例。
在下文中一共展示了Xlib.X属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _shift_mask
# 需要导入模块: import Xlib [as 别名]
# 或者: from Xlib import X [as 别名]
def _shift_mask(self, modifiers):
"""The *X* modifier mask to apply for a set of modifiers.
:param set modifiers: A set of active modifiers for which to get the
shift mask.
"""
return (
0
| (self.ALT_MASK
if Key.alt in modifiers else 0)
| (self.ALT_GR_MASK
if Key.alt_gr in modifiers else 0)
| (self.CTRL_MASK
if Key.ctrl in modifiers else 0)
| (self.SHIFT_MASK
if Key.shift in modifiers else 0))
示例2: _keycode_to_keysym
# 需要导入模块: import Xlib [as 别名]
# 或者: from Xlib import X [as 别名]
def _keycode_to_keysym(self, display, keycode, index):
"""Converts a keycode and shift state index to a keysym.
This method uses a simplified version of the *X* convention to locate
the correct keysym in the display table: since this method is only used
to locate special keys, alphanumeric keys are not treated specially.
:param display: The current *X* display.
:param keycode: The keycode.
:param index: The shift state index.
:return: a keysym
"""
keysym = display.keycode_to_keysym(keycode, index)
if keysym:
return keysym
elif index & 0x2:
return self._keycode_to_keysym(display, keycode, index & ~0x2)
elif index & 0x1:
return self._keycode_to_keysym(display, keycode, index & ~0x1)
else:
return 0
示例3: _send_key
# 需要导入模块: import Xlib [as 别名]
# 或者: from Xlib import X [as 别名]
def _send_key(self, event, keycode, shift_state):
"""Sends a single keyboard event.
:param event: The *X* keyboard event.
:param int keycode: The calculated keycode.
:param int shift_state: The shift state. The actual value used is
:attr:`shift_state` or'd with this value.
"""
with display_manager(self._display) as dm, self.modifiers as modifiers:
# Under certain cimcumstances, such as when running under Xephyr,
# the value returned by dm.get_input_focus is an int
window = dm.get_input_focus().focus
send_event = getattr(
window,
'send_event',
lambda event: dm.send_event(window, event))
send_event(event(
detail=keycode,
state=shift_state | self._shift_mask(modifiers),
time=0,
root=dm.screen().root,
window=window,
same_screen=0,
child=Xlib.X.NONE,
root_x=0, root_y=0, event_x=0, event_y=0))
示例4: _handle
# 需要导入模块: import Xlib [as 别名]
# 或者: from Xlib import X [as 别名]
def _handle(self, display, event):
# Convert the event to a KeyCode; this may fail, and in that case we
# pass None
try:
key = self._event_to_key(display, event)
except IndexError:
key = None
if event.type == Xlib.X.KeyPress:
self.on_press(key)
elif event.type == Xlib.X.KeyRelease:
self.on_release(key)
示例5: _suppress_start
# 需要导入模块: import Xlib [as 别名]
# 或者: from Xlib import X [as 别名]
def _suppress_start(self, display):
display.screen().root.grab_keyboard(
self._event_mask, Xlib.X.GrabModeAsync, Xlib.X.GrabModeAsync,
Xlib.X.CurrentTime)
示例6: set_state
# 需要导入模块: import Xlib [as 别名]
# 或者: from Xlib import X [as 别名]
def set_state(self, state=NORMAL, size=(-1, -1), pos=(-1, -1), update=True):
"""Set wheter the window is maximized or not, or minimized or full screen.
If no argument is given, assume the state will be windowed and not maximized.
If arguments are given, only the first is relevant. The other ones are ignored.
** Only maximized and normal states are implemented for now. **
:state: valid arguments:
'minimized', MINIMIZED, 0.
'normal', NORMAL, 1: windowed, not maximized.
'maximized', MAXIMIZED, 2.
'fullscreen, FULLSCREEN, 3.
:size: list, tuple: the new size; if (-1, -1) self.get_size() is used.
If one element is -1 it is replaced by the corresponding valur from self.get_size().
:pos: list, tuple: the new position; if (-1, -1), self.get_position is used.
If one element is -1 it is replaced by the corresponding valur from self.get_position().
:update: bool: whether to call the internal flush method."""
if state not in (0, MINIMIZED, 'minimized', 1, NORMAL, 'normal', 2, MAXIMIZED, 'maximized', 3, FULLSCREEN, 'fullscreen'):
# Raise a value error.
raise ValueError, "Invalid state argument: %s is not a correct value" % state
if type(size) not in (list, tuple):
raise TypeError, "Invalid size argument: %s is not a list or a tuple."
if type(pos) not in (list, tuple):
raise TypeError, "Invalid pos argument: %s is not a list or a tuple."
if state in (1, NORMAL, 'normal'):
size = list(size)
sz = self.get_size()
if size[0] == -1:
size[0] = sz[0]
if size[1] == -1:
size[1] = sz[1]
pos = list(pos)
ps = self.get_position()
if pos[0] == -1:
pos[0] = ps[0]
if pos[1] == -1:
pos[1] = ps[1]
self.set_mode(size, self.mode)
self.set_position(pos)
elif state in (0, MINIMIZED, 'minimized'):
pass
elif state in (2, MAXIMIZED, 'maximized'):
data = [1, self.display.intern_atom("_NET_WM_STATE_MAXIMIZED_VERT", False), self.display.intern_atom("_NET_WM_STATE_MAXIMIZED_HORZ", False)]
data = (data + ([0] * (5 - len(data))))[:5]
if DEBUG_WM:
print self.stateHandler.get_wm_state()
print "creating event", Xlib.protocol.event.ClientMessage
print dir(self.stateHandler)
x_event = Xlib.protocol.event.ClientMessage(window=self.stateHandler, client_type=self.display.intern_atom("_NET_WM_STATE", False), data=(32, (data)))
if DEBUG_WM:
print "sending event"
self.display.screen().root.send_event(x_event, event_mask=Xlib.X.SubstructureRedirectMask)
if DEBUG_WM:
print self.stateHandler.get_wm_state()
elif state in (3, FULLSCREEN, 'fullscreen'):
pass
if update:
self.flush()
示例7: _event_to_key
# 需要导入模块: import Xlib [as 别名]
# 或者: from Xlib import X [as 别名]
def _event_to_key(self, display, event):
"""Converts an *X* event to a :class:`KeyCode`.
:param display: The current *X* display.
:param event: The event to convert.
:return: a :class:`pynput.keyboard.KeyCode`
:raises IndexError: if the key code is invalid
"""
keycode = event.detail
index = shift_to_index(display, event.state)
# First try special keys...
keysym = self._keycode_to_keysym(display, keycode, index)
if keysym in self._SPECIAL_KEYS:
return self._SPECIAL_KEYS[keysym]
elif keysym in self._KEYPAD_KEYS:
# We must recalculate the index if numlock is active; index 1 is the
# one to use
try:
return self._KEYPAD_KEYS[
self._keycode_to_keysym(
display,
keycode,
bool(event.state & numlock_mask(display)))]
except KeyError:
# Since we recalculated the key, this may happen
pass
# ...then try characters...
name = KEYSYMS.get(keysym, None)
if name is not None and name in SYMBOLS:
char = SYMBOLS[name][1].upper() if index & 1 else SYMBOLS[name][1]
if char in DEAD_KEYS:
return KeyCode.from_dead(DEAD_KEYS[char], vk=keysym)
else:
return KeyCode.from_char(char, vk=keysym)
# ...and fall back on a virtual key code
return KeyCode.from_vk(keysym)
示例8: set_state
# 需要导入模块: import Xlib [as 别名]
# 或者: from Xlib import X [as 别名]
def set_state(self, state=NORMAL, size=(-1, -1), pos=(-1, -1), update=True):
"""Set whether the window is maximized or not, or minimized or full screen.
If no argument is given, assume the state will be windowed and not maximized.
If arguments are given, only the first is relevant. The other ones are ignored.
** Only maximized and normal states are implemented for now. **
:state: valid arguments:
'minimized', MINIMIZED, 0.
'normal', NORMAL, 1: windowed, not maximized.
'maximized', MAXIMIZED, 2.
'fullscreen, FULLSCREEN, 3.
:size: list, tuple: the new size; if (-1, -1) self.get_size() is used.
If one element is -1 it is replaced by the corresponding valur from self.get_size().
:pos: list, tuple: the new position; if (-1, -1), self.get_position is used.
If one element is -1 it is replaced by the corresponding valur from self.get_position().
:update: bool: whether to call the internal flush method."""
if state not in (0, MINIMIZED, 'minimized', 1, NORMAL, 'normal', 2, MAXIMIZED, 'maximized', 3, FULLSCREEN, 'fullscreen'):
# Raise a value error.
raise ValueError("Invalid state argument: %s is not a correct value" % state)
if not isinstance(size, (list, tuple)):
raise TypeError("Invalid size argument: %s is not a list or a tuple.")
if not isinstance(pos, (list, tuple)):
raise TypeError("Invalid pos argument: %s is not a list or a tuple.")
if state in (1, NORMAL, 'normal'):
size = list(size)
sz = self.get_size()
if size[0] == -1:
size[0] = sz[0]
if size[1] == -1:
size[1] = sz[1]
pos = list(pos)
ps = self.get_position()
if pos[0] == -1:
pos[0] = ps[0]
if pos[1] == -1:
pos[1] = ps[1]
self.set_mode(size, self.mode)
self.set_position(pos)
elif state in (0, MINIMIZED, 'minimized'):
pass
elif state in (2, MAXIMIZED, 'maximized'):
data = [1, self.display.intern_atom("_NET_WM_STATE_MAXIMIZED_VERT", False), self.display.intern_atom("_NET_WM_STATE_MAXIMIZED_HORZ", False)]
data = (data + ([0] * (5 - len(data))))[:5]
if DEBUG_WM:
print self.stateHandler.get_wm_state()
print "creating event", Xlib.protocol.event.ClientMessage
print dir(self.stateHandler)
x_event = Xlib.protocol.event.ClientMessage(window=self.stateHandler, client_type=self.display.intern_atom("_NET_WM_STATE", False), data=(32, data))
if DEBUG_WM:
print "sending event"
self.display.screen().root.send_event(x_event, event_mask=Xlib.X.SubstructureRedirectMask)
if DEBUG_WM:
print self.stateHandler.get_wm_state()
elif state in (3, FULLSCREEN, 'fullscreen'):
pass
if update:
self.flush()