• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python compat.asbytes函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyglet.compat.asbytes函数的典型用法代码示例。如果您正苦于以下问题:Python asbytes函数的具体用法?Python asbytes怎么用?Python asbytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了asbytes函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:AJCraddock,项目名称:-ducking-octo-shame,代码行数:27,代码来源:__init__.py


示例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))
开发者ID:AJCraddock,项目名称:-ducking-octo-shame,代码行数:26,代码来源:__init__.py


示例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)
开发者ID:sangh,项目名称:LaserShow,代码行数:10,代码来源:__init__.py


示例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)
开发者ID:AJCraddock,项目名称:-ducking-octo-shame,代码行数:13,代码来源:__init__.py


示例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))
开发者ID:Benrflanders,项目名称:Pytris,代码行数:16,代码来源:pypng.py


示例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)
开发者ID:ajhager,项目名称:copycat,代码行数:8,代码来源:freetype.py


示例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)
开发者ID:PatrickDattilio,项目名称:tec_scoundrel,代码行数:9,代码来源:riff.py


示例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
开发者ID:AJCraddock,项目名称:-ducking-octo-shame,代码行数:55,代码来源:xlib_vidmoderestore.py


示例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))
开发者ID:ajhager,项目名称:copycat,代码行数:11,代码来源:fontconfig.py


示例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)
开发者ID:Matt-Esch,项目名称:anaconda,代码行数:12,代码来源:lib_wgl.py


示例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
开发者ID:rougier,项目名称:pyglet,代码行数:16,代码来源:lib_wgl.py


示例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
开发者ID:bitcraft,项目名称:pyglet,代码行数:18,代码来源:win32.py


示例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)
开发者ID:AJCraddock,项目名称:-ducking-octo-shame,代码行数:19,代码来源:lib_glx.py


示例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)
开发者ID:sangh,项目名称:LaserShow,代码行数:19,代码来源:__init__.py


示例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'))
开发者ID:AJCraddock,项目名称:-ducking-octo-shame,代码行数:30,代码来源:avbin.py


示例16: set

 def set(self):
     self._event.set()
     os.write(self._sync_file_write, asbytes('1'))
开发者ID:17night,项目名称:thbattle,代码行数:3,代码来源:xlib.py


示例17: check_file

 def check_file(self, path, file, result):
     loader = resource.Loader(path, script_home=self.script_home)
     self.assertTrue(loader.file(file).read() == asbytes('%s\n' % result))
开发者ID:DatRollingStone,项目名称:nwidget,代码行数:3,代码来源:RES_LOAD.py


示例18: asbytes

fontconfig.FcPatternCreate.restype = c_void_p
fontconfig.FcFontMatch.restype = c_void_p
fontconfig.FcFreeTypeCharIndex.restype = c_uint

fontconfig.FcPatternAddDouble.argtypes = [c_void_p, c_char_p, c_double]
fontconfig.FcPatternAddInteger.argtypes = [c_void_p, c_char_p, c_int]
fontconfig.FcPatternAddString.argtypes = [c_void_p, c_char_p, c_char_p]
fontconfig.FcConfigSubstitute.argtypes = [c_void_p, c_void_p, c_int]
fontconfig.FcDefaultSubstitute.argtypes = [c_void_p]
fontconfig.FcFontMatch.argtypes = [c_void_p, c_void_p, c_void_p]
fontconfig.FcPatternDestroy.argtypes = [c_void_p]

fontconfig.FcPatternGetFTFace.argtypes = [c_void_p, c_char_p, c_int, c_void_p]
fontconfig.FcPatternGet.argtypes = [c_void_p, c_char_p, c_int, c_void_p]

FC_FAMILY = asbytes('family')
FC_SIZE = asbytes('size')
FC_SLANT = asbytes('slant')
FC_WEIGHT = asbytes('weight')
FC_FT_FACE = asbytes('ftface')
FC_FILE = asbytes('file')

FC_WEIGHT_REGULAR = 80
FC_WEIGHT_BOLD = 200

FC_SLANT_ROMAN = 0
FC_SLANT_ITALIC = 100

FT_STYLE_FLAG_ITALIC = 1
FT_STYLE_FLAG_BOLD = 2
开发者ID:cajlarsson,项目名称:village,代码行数:30,代码来源:freetype.py


示例19: _load_font_face_from_file

 def _load_font_face_from_file(file_name):
     font_face = FT_Face()
     ft_library = ft_get_library()
     error = FT_New_Face(ft_library, asbytes(file_name), 0, byref(font_face))
     FreeTypeError.check_and_raise_on_error('Could not load font from "%s"' % file_name, error)
     return font_face
开发者ID:JacquesLucke,项目名称:still-lambda,代码行数:6,代码来源:freetype.py


示例20: read

    def read(self):
        """
        Read a simple PNG file, return width, height, pixels and image metadata

        This function is a very early prototype with limited flexibility
        and excessive use of memory.
        """
        signature = self.file.read(8)
        if (signature != struct.pack("8B", 137, 80, 78, 71, 13, 10, 26, 10)):
            raise Error("PNG file has invalid header")
        compressed = []
        image_metadata = {}
        while True:
            try:
                tag, data = self.read_chunk()
            except ValueError, e:
                raise Error('Chunk error: ' + e.args[0])

            # print >> sys.stderr, tag, len(data)
            if tag == asbytes('IHDR'): # http://www.w3.org/TR/PNG/#11IHDR
                (width, height, bits_per_sample, color_type,
                 compression_method, filter_method,
                 interlaced) = struct.unpack("!2I5B", data)
                bps = bits_per_sample // 8
                if bps == 0:
                    raise Error("unsupported pixel depth")
                if bps > 2 or bits_per_sample != (bps * 8):
                    raise Error("invalid pixel depth")
                if color_type == 0:
                    greyscale = True
                    has_alpha = False
                    has_palette = False
                    planes = 1
                elif color_type == 2:
                    greyscale = False
                    has_alpha = False
                    has_palette = False
                    planes = 3
                elif color_type == 3:
                    greyscale = False
                    has_alpha = False
                    has_palette = True
                    planes = 1
                elif color_type == 4:
                    greyscale = True
                    has_alpha = True
                    has_palette = False
                    planes = 2
                elif color_type == 6:
                    greyscale = False
                    has_alpha = True
                    has_palette = False
                    planes = 4
                else:
                    raise Error("unknown PNG colour type %s" % color_type)
                if compression_method != 0:
                    raise Error("unknown compression method")
                if filter_method != 0:
                    raise Error("unknown filter method")
                self.bps = bps
                self.planes = planes
                self.psize = bps * planes
                self.width = width
                self.height = height
                self.row_bytes = width * self.psize
            elif tag == asbytes('IDAT'): # http://www.w3.org/TR/PNG/#11IDAT
                compressed.append(data)
            elif tag == asbytes('bKGD'):
                if greyscale:
                    image_metadata["background"] = struct.unpack("!1H", data)
                elif has_palette:
                    image_metadata["background"] = struct.unpack("!1B", data)
                else:
                    image_metadata["background"] = struct.unpack("!3H", data)
            elif tag == asbytes('tRNS'):
                if greyscale:
                    image_metadata["transparent"] = struct.unpack("!1H", data)
                elif has_palette:
                    # may have several transparent colors
                    image_metadata["transparent"] = array('B', data)
                else:
                    image_metadata["transparent"] = struct.unpack("!3H", data)
            elif tag == asbytes('gAMA'):
                image_metadata["gamma"] = (
                    struct.unpack("!L", data)[0]) / 100000.0
            elif tag == asbytes('PLTE'): # http://www.w3.org/TR/PNG/#11PLTE
                if not len(data) or len(data) % 3 != 0 or len(data) > 3*(2**(self.bps*8)):
                    raise Error("invalid palette size")
                image_metadata["palette"] = array('B', data)
            elif tag == asbytes('IEND'): # http://www.w3.org/TR/PNG/#11IEND
                break
开发者ID:Benrflanders,项目名称:Pytris,代码行数:91,代码来源:pypng.py



注:本文中的pyglet.compat.asbytes函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python compat.BytesIO类代码示例发布时间:2022-05-25
下一篇:
Python clock.unschedule函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap