本文整理汇总了Python中pyglet.compat.asbytes函数的典型用法代码示例。如果您正苦于以下问题:Python asbytes函数的具体用法?Python asbytes怎么用?Python asbytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了asbytes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _set_wm_state
def _set_wm_state(self, *states):
# Set property
net_wm_state = xlib.XInternAtom(self._x_display, asbytes('_NET_WM_STATE'), False)
atoms = []
for state in states:
atoms.append(xlib.XInternAtom(self._x_display, asbytes(state), False))
atom_type = xlib.XInternAtom(self._x_display, asbytes('ATOM'), False)
if len(atoms):
atoms_ar = (xlib.Atom * len(atoms))(*atoms)
xlib.XChangeProperty(self._x_display, self._window,
net_wm_state, atom_type, 32, xlib.PropModePrepend,
cast(pointer(atoms_ar), POINTER(c_ubyte)), len(atoms))
else:
xlib.XDeleteProperty(self._x_display, self._window, net_wm_state)
# Nudge the WM
e = xlib.XEvent()
e.xclient.type = xlib.ClientMessage
e.xclient.message_type = net_wm_state
e.xclient.display = cast(self._x_display, POINTER(xlib.Display))
e.xclient.window = self._window
e.xclient.format = 32
e.xclient.data.l[0] = xlib.PropModePrepend
for i, atom in enumerate(atoms):
e.xclient.data.l[i + 1] = atom
xlib.XSendEvent(self._x_display, self._get_root(),
False, xlib.SubstructureRedirectMask, byref(e))
示例2: set_icon
def set_icon(self, *images):
# Careful! XChangeProperty takes an array of long when data type
# is 32-bit (but long can be 64 bit!), so pad high bytes of format if
# necessary.
import sys
format = {
('little', 4): 'BGRA',
('little', 8): 'BGRAAAAA',
('big', 4): 'ARGB',
('big', 8): 'AAAAARGB'
}[(sys.byteorder, sizeof(c_ulong))]
data = asbytes('')
for image in images:
image = image.get_image_data()
pitch = -(image.width * len(format))
s = c_buffer(sizeof(c_ulong) * 2)
memmove(s, cast((c_ulong * 2)(image.width, image.height),
POINTER(c_ubyte)), len(s))
data += s.raw + image.get_data(format, pitch)
buffer = (c_ubyte * len(data))()
memmove(buffer, data, len(data))
atom = xlib.XInternAtom(self._x_display, asbytes('_NET_WM_ICON'), False)
xlib.XChangeProperty(self._x_display, self._window, atom, XA_CARDINAL,
32, xlib.PropModeReplace, buffer, len(data)//sizeof(c_ulong))
示例3: _event_clientmessage
def _event_clientmessage(self, ev):
atom = ev.xclient.data.l[0]
if atom == xlib.XInternAtom(ev.xclient.display, asbytes("WM_DELETE_WINDOW"), False):
self.dispatch_event("on_close")
elif self._enable_xsync and atom == xlib.XInternAtom(
ev.xclient.display, asbytes("_NET_WM_SYNC_REQUEST"), False
):
lo = ev.xclient.data.l[2]
hi = ev.xclient.data.l[3]
self._current_sync_value = xsync.XSyncValue(hi, lo)
示例4: _set_atoms_property
def _set_atoms_property(self, name, values, mode=xlib.PropModeReplace):
name_atom = xlib.XInternAtom(self._x_display, asbytes(name), False)
atoms = []
for value in values:
atoms.append(xlib.XInternAtom(self._x_display, asbytes(value), False))
atom_type = xlib.XInternAtom(self._x_display, asbytes('ATOM'), False)
if len(atoms):
atoms_ar = (xlib.Atom * len(atoms))(*atoms)
xlib.XChangeProperty(self._x_display, self._window,
name_atom, atom_type, 32, mode,
cast(pointer(atoms_ar), POINTER(c_ubyte)), len(atoms))
else:
xlib.XDeleteProperty(self._x_display, self._window, net_wm_state)
示例5: write_chunk
def write_chunk(self, outfile, tag, data):
"""
Write a PNG chunk to the output file, including length and checksum.
"""
# http://www.w3.org/TR/PNG/#5Chunk-layout
tag = asbytes(tag)
data = asbytes(data)
outfile.write(struct.pack("!I", len(data)))
outfile.write(tag)
outfile.write(data)
checksum = zlib.crc32(tag)
checksum = zlib.crc32(data, checksum)
# <ah> Avoid DeprecationWarning: struct integer overflow masking
# with Python2.5/Windows.
checksum = checksum & 0xffffffff
outfile.write(struct.pack("!I", checksum))
示例6: from_file
def from_file(cls, file_name):
ft_library = ft_get_library()
ft_face = FT_Face()
FT_New_Face(ft_library,
asbytes(file_name),
0,
byref(ft_face))
return cls(ft_face)
示例7: __init__
def __init__(self, *args, **kwargs):
super(RIFFType, self).__init__(*args, **kwargs)
self.file.seek(self.offset)
form = self.file.read(4)
if form != asbytes('WAVE'):
raise RIFFFormatException('Unsupported RIFF form "%s"' % form)
self.form = WaveForm(self.file, self.offset + 4)
示例8: _install_restore_mode_child
def _install_restore_mode_child():
global _mode_write_pipe
global _restore_mode_child_installed
if _restore_mode_child_installed:
return
# Parent communicates to child by sending "mode packets" through a pipe:
mode_read_pipe, _mode_write_pipe = os.pipe()
if os.fork() == 0:
# Child process (watches for parent to die then restores video mode(s).
os.close(_mode_write_pipe)
# Set up SIGHUP to be the signal for when the parent dies.
PR_SET_PDEATHSIG = 1
libc = ctypes.cdll.LoadLibrary('libc.so.6')
libc.prctl.argtypes = (ctypes.c_int, ctypes.c_ulong, ctypes.c_ulong,
ctypes.c_ulong, ctypes.c_ulong)
libc.prctl(PR_SET_PDEATHSIG, signal.SIGHUP, 0, 0, 0)
# SIGHUP indicates the parent has died. The child lock is unlocked, it
# stops reading from the mode packet pipe and restores video modes on
# all displays/screens it knows about.
def _sighup(signum, frame):
parent_wait_lock.release();
parent_wait_lock = threading.Lock();
parent_wait_lock.acquire()
signal.signal(signal.SIGHUP, _sighup)
# Wait for parent to die and read packets from parent pipe
packets = []
buffer = asbytes('')
while parent_wait_lock.locked():
try:
data = os.read(mode_read_pipe, ModePacket.size)
buffer += data
# Decode packets
while len(buffer) >= ModePacket.size:
packet = ModePacket.decode(buffer[:ModePacket.size])
packets.append(packet)
buffer = buffer[ModePacket.size:]
except OSError:
pass # Interrupted system call
for packet in packets:
packet.set()
os._exit(0)
else:
# Parent process. Clean up pipe then continue running program as
# normal. Send mode packets through pipe as additional
# displays/screens are mode switched.
os.close(mode_read_pipe)
_restore_mode_child_installed = True
示例9: _set_string
def _set_string(self, name, value):
assert self._pattern
assert name
assert self._fontconfig
if not value:
return
value = value.encode('utf8')
self._fontconfig.FcPatternAddString(self._pattern, name, asbytes(value))
示例10: resolve
def resolve(self):
from pyglet.gl import current_context
if not current_context:
raise Exception(
'Call to function "%s" before GL context created' % self.name)
address = wglGetProcAddress(asbytes(self.name))
if cast(address, POINTER(c_int)): # check cast because address is func
self.func = cast(address, self.ftype)
decorate_function(self.func, self.name)
else:
self.func = missing_function(
self.name, self.requires, self.suggestions)
示例11: __call__
def __call__(self, *args, **kwargs):
if self.func:
return self.func(*args, **kwargs)
from pyglet.gl import current_context
if not current_context:
raise Exception('Call to function "%s" before GL context created' % self.name)
address = wglGetProcAddress(asbytes(self.name))
if cast(address, POINTER(c_int)): # check cast because address is func
self.func = cast(address, self.ftype)
decorate_function(self.func, self.name)
else:
self.func = missing_function(self.name, self.requires, self.suggestions)
result = self.func(*args, **kwargs)
return result
示例12: get_logfont
def get_logfont(name, size, bold, italic, dpi):
# Create a dummy DC for coordinate mapping
dc = user32.GetDC(0)
if dpi is None:
dpi = 96
logpixelsy = dpi
logfont = LOGFONT()
# Conversion of point size to device pixels
logfont.lfHeight = int(-size * logpixelsy // 72)
if bold:
logfont.lfWeight = FW_BOLD
else:
logfont.lfWeight = FW_NORMAL
logfont.lfItalic = italic
logfont.lfFaceName = asbytes(name)
logfont.lfQuality = ANTIALIASED_QUALITY
return logfont
示例13: link_GL
def link_GL(name, restype, argtypes, requires=None, suggestions=None):
try:
func = getattr(gl_lib, name)
func.restype = restype
func.argtypes = argtypes
decorate_function(func, name)
return func
except AttributeError:
if _have_getprocaddress:
# Fallback if implemented but not in ABI
bname = cast(pointer(create_string_buffer(asbytes(name))), POINTER(c_ubyte))
addr = glXGetProcAddressARB(bname)
if addr:
ftype = CFUNCTYPE(*((restype,) + tuple(argtypes)))
func = cast(addr, ftype)
decorate_function(func, name)
return func
return missing_function(name, requires, suggestions)
示例14: _set_text_property
def _set_text_property(self, name, value, allow_utf8=True):
atom = xlib.XInternAtom(self._x_display, asbytes(name), False)
if not atom:
raise XlibException('Undefined atom "%s"' % name)
assert type(value) in (str, unicode)
property = xlib.XTextProperty()
if _have_utf8 and allow_utf8:
buf = create_string_buffer(value.encode("utf8"))
result = xlib.Xutf8TextListToTextProperty(
self._x_display, cast(pointer(buf), c_char_p), 1, xlib.XUTF8StringStyle, byref(property)
)
if result < 0:
raise XlibException("Could not create UTF8 text property")
else:
buf = create_string_buffer(value.encode("ascii", "ignore"))
result = xlib.XStringListToTextProperty(cast(pointer(buf), c_char_p), 1, byref(property))
if result < 0:
raise XlibException("Could not create text property")
xlib.XSetTextProperty(self._x_display, self._window, byref(property), atom)
示例15: get_next_video_frame
return self._video_packets[0].timestamp
def get_next_video_frame(self):
if not self.video_format:
return
if self._ensure_video_packets():
packet = self._video_packets.pop(0)
if _debug:
print 'Waiting for', packet
# Block until decoding is complete
self._condition.acquire()
while packet.image == 0:
self._condition.wait()
self._condition.release()
if _debug:
print 'Returning', packet
return packet.image
av.avbin_init()
if pyglet.options['debug_media']:
_debug = True
av.avbin_set_log_level(AVBIN_LOG_DEBUG)
else:
_debug = False
av.avbin_set_log_level(AVBIN_LOG_QUIET)
_have_frame_rate = av.avbin_have_feature(asbytes('frame_rate'))