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

Python _error.SDLError类代码示例

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

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



在下文中一共展示了SDLError类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: new_surface_from_surface

def new_surface_from_surface(c_surface, w, h):
    if 4 < c_surface.format.BytesPerPixel <= 0:
        raise ValueError("unsupported Surface bit depth for transform")

    format = c_surface.format
    newsurf = sdl.SDL_CreateRGBSurface(c_surface.flags, w, h,
                                       format.BitsPerPixel,
                                       format.Rmask, format.Gmask,
                                       format.Bmask, format.Amask)
    if not newsurf:
        SDLError.from_sdl_error()

    if format.BytesPerPixel == 1 and format.palette:
        sdl.SDL_SetColors(newsurf, format.palette.colors, 0,
                          format.palette.ncolors)

    if c_surface.flags & sdl.SDL_SRCCOLORKEY:
        sdl.SDL_SetColorKey(newsurf, (c_surface.flags & sdl.SDL_RLEACCEL) |
                            sdl.SDL_SRCCOLORKEY, format.colorkey)

    if c_surface.flags & sdl.SDL_SRCALPHA:
        result = sdl.SDL_SetAlpha(newsurf, c_surface.flags, format.alpha)
        if result == -1:
            raise SDLError.from_sdl_error()

    return newsurf
开发者ID:vavilon,项目名称:pygame_cffi,代码行数:26,代码来源:transform.py


示例2: save

def save(surface, filename):
    """ save(Surface, filename) -> None
    save an image to disk
    """
    surf = surface._c_surface
    if surf.flags & sdl.SDL_OPENGL:
        raise NotImplementedError()
    if not isinstance(filename, string_types):
        raise TypeError("Expected a string for the file arugment: got %s"
                        % type(filename).__name__)

    filename = rwops_encode_file_path(filename)
    fn_normalized = filename.lower()
    result = 0
    # TODO: prep/unprep surface
    if fn_normalized.endswith(b'bmp'):
        # save as BMP
        result = sdl.SDL_SaveBMP(surf, filename)
    elif (fn_normalized.endswith(b'jpg')
          or fn_normalized.endswith(b'jpeg')):
        # save as JPEG
        result = save_jpg(surf, filename)
    elif fn_normalized.endswith(b'png'):
        # save as PNG
        result = save_png(surf, filename)
    else:
        # save as TGA
        result = save_tga(surf, filename, True)
    if result == -1:
        raise SDLError.from_sdl_error()
开发者ID:berteaa,项目名称:pygame_cffi,代码行数:30,代码来源:image.py


示例3: set_cursor

def set_cursor(size, hotspot, xormasks, andmasks):
    """ set_cursor(size, hotspot, xormasks, andmasks) -> None
    set the image for the system mouse cursor
    """
    check_video()

    spotx, spoty = int(hotspot[0]), int(hotspot[1])
    w, h = int(size[0]), int(size[1])
    if w % 8 != 0:
        raise ValueError("Cursor width must be divisible by 8")

    if not hasattr(xormasks, '__iter__') or not hasattr(andmasks, '__iter__'):
        raise TypeError("xormask and andmask must be sequences")
    if len(xormasks) != w * h / 8.0 or len(andmasks) != w * h / 8.0:
        raise ValueError("bitmasks must be sized width*height/8")
    try:
        xordata = ffi.new('uint8_t[]', [int(m) for m in xormasks])
        anddata = ffi.new('uint8_t[]', [int(andmasks[i]) for i
                                        in range(len(xormasks))])
    except (ValueError, TypeError):
        raise TypeError("Invalid number in mask array")
    except OverflowError:
        raise TypeError("Number in mask array is larger than 8 bits")

    cursor = sdl.SDL_CreateCursor(xordata, anddata, w, h, spotx, spoty)
    if not cursor:
        raise SDLError.from_sdl_error()
    lastcursor = sdl.SDL_GetCursor()
    sdl.SDL_SetCursor(cursor)
    sdl.SDL_FreeCursor(lastcursor)
开发者ID:GertBurger,项目名称:pygame_cffi,代码行数:30,代码来源:mouse.py


示例4: fill

    def fill(self, color, rect=None, special_flags=0):
        """ fill(color, rect=None, special_flags=0) -> Rect
        fill Surface with a solid color
        """
        self.check_opengl()

        c_color = create_color(color, self._format)
        sdlrect = ffi.new('SDL_Rect*')
        if rect is not None:
            sdlrect.x, sdlrect.y, sdlrect.w, sdlrect.h = rect_vals_from_obj(rect)
        else:
            sdlrect.w = self._w
            sdlrect.h = self._h

        if self.crop_to_surface(sdlrect):
            if special_flags:
                res = sdl.surface_fill_blend(self._c_surface, sdlrect,
                                             c_color, special_flags)
            else:
                with locked(self._c_surface):
                    # TODO: prep/unprep
                    res = sdl.SDL_FillRect(self._c_surface, sdlrect, c_color)

            if res == -1:
                raise SDLError.from_sdl_error()

        return Rect._from4(sdlrect.x, sdlrect.y, sdlrect.w, sdlrect.h)
开发者ID:caseyc37,项目名称:pygame_cffi,代码行数:27,代码来源:surface.py


示例5: wait

def wait():
    """ wait() -> EventType instance
    wait for a single event from the queue
    """
    event = ffi.new('SDL_Event*')
    if not sdl.SDL_WaitEvent(event):
        raise SDLError.from_sdl_error()
    return EventType(event[0])
开发者ID:vavilon,项目名称:pygame_cffi,代码行数:8,代码来源:event.py


示例6: _win_rwops_from_file

def _win_rwops_from_file(fileobj):
    """Windows compatible implementation of rwops_from_file."""
    # sdl.SDL_RWFromFP doesn't setup the correct handlers on
    # windows, so we fall back to our helpers
    rwops = _lib_rwops_from_file(fileobj)
    if not rwops:
        raise SDLError.from_sdl_error()
    return rwops
开发者ID:CTPUG,项目名称:pygame_cffi,代码行数:8,代码来源:rwobject.py


示例7: init

def init():
    """ init() -> None
    Initialize the display module
    """
    if not video_autoinit():
        raise SDLError.from_sdl_error()
    if not autoinit():
        raise RuntimeError("autoinit failed")
开发者ID:berteaa,项目名称:pygame_cffi,代码行数:8,代码来源:display.py


示例8: set_repeat

def set_repeat(delay=0, interval=0):
    """ set_repeat() -> None
    control how held keys are repeated
    """
    check_video()
    if delay and not interval:
        interval = delay
    if sdl.SDL_EnableKeyRepeat(delay, interval) == -1:
        raise SDLError.from_sdl_error()
开发者ID:CTPUG,项目名称:pygame_cffi,代码行数:9,代码来源:key.py


示例9: init

 def init(self):
     """ init() -> None
     initialize the Joystick
     """
     if self._id not in self._OPEN_JOYSTICKS:
         joydata = sdl.SDL_JoystickOpen(self._id)
         if not joydata:
             raise SDLError.from_sdl_error()
         self._OPEN_JOYSTICKS[self._id] = joydata
开发者ID:vavilon,项目名称:pygame_cffi,代码行数:9,代码来源:joystick.py


示例10: set_colorkey

    def set_colorkey(self, color=None, flags=0):
        self.check_opengl()
        c_color = 0
        if color is not None:
            c_color = create_color(color, self._format)
            flags |= sdl.SDL_SRCCOLORKEY

        with locked(self._c_surface):
            if sdl.SDL_SetColorKey(self._c_surface, flags, c_color) == -1:
                raise SDLError.from_sdl_error()
开发者ID:caseyc37,项目名称:pygame_cffi,代码行数:10,代码来源:surface.py


示例11: gl_set_attribute

def gl_set_attribute(flag, value):
    """ gl_set_attribute(flag, value) -> None
    Request an OpenGL display attribute for the display mode
    """
    check_video()
    # check_opengl()

    if flag == -1:
        return None
    if sdl.SDL_GL_SetAttribute(flag, value) == -1:
        raise SDLError.from_sdl_error()
开发者ID:berteaa,项目名称:pygame_cffi,代码行数:11,代码来源:display.py


示例12: gl_get_attribute

def gl_get_attribute(flag):
    """ gl_get_attribute(flag) -> value
    Get the value for an OpenGL flag for the current display
    """
    check_video()
    # pygame seg faults instead of doing this
    # check_opengl()

    value = ffi.new('int *')
    if sdl.SDL_GL_GetAttribute(flag, value) == -1:
        raise SDLError.from_sdl_error()
    return value[0]
开发者ID:berteaa,项目名称:pygame_cffi,代码行数:12,代码来源:display.py


示例13: _unix_rwops_from_file

def _unix_rwops_from_file(fileobj):
    """Non-windows implementation of rwops_from_file."""
    try:
        # We try use the SDL helper first, since
        # it's the simplest code path
        rwops = sdl.SDL_RWFromFP(fileobj, 0)
    except (TypeError, IOError):
        # Construct a suitable rwops object
        rwops = _lib_rwops_from_file(fileobj)
    if not rwops:
        raise SDLError.from_sdl_error()
    return rwops
开发者ID:CTPUG,项目名称:pygame_cffi,代码行数:12,代码来源:rwobject.py


示例14: set_timer

def set_timer(eventid, milliseconds):
    """set_timer(eventid, milliseconds) -> None
    repeatedly create an event on the event queue"
    """
    if eventid <= sdl.SDL_NOEVENT or eventid >= sdl.SDL_NUMEVENTS:
        raise ValueError("Event id must be between NOEVENT(0) and" " NUMEVENTS(32)")

    old_event = _event_timers.pop(eventid, None)
    if old_event:
        sdl.SDL_RemoveTimer(old_event)

    if milliseconds <= 0:
        return

    _try_init()

    handle = ffi.cast("void *", eventid)
    newtimer = sdl.SDL_AddTimer(milliseconds, _timer_callback, handle)
    if not newtimer:
        SDLError.from_sdl_error()

    _event_timers[eventid] = newtimer
开发者ID:vavilon,项目名称:pygame_cffi,代码行数:22,代码来源:time.py


示例15: set_clip

 def set_clip(self, rect):
     """ set_clip(rect) -> None
     set the current clipping area of the Surface
     """
     self.check_surface()
     if rect:
         sdlrect = ffi.new('SDL_Rect*')
         sdlrect.x, sdlrect.y, sdlrect.w, sdlrect.h = \
                 rect_vals_from_obj(rect)
         res = sdl.SDL_SetClipRect(self._c_surface, sdlrect)
     else:
         res = sdl.SDL_SetClipRect(self._c_surface, ffi.NULL)
     if res == -1:
         raise SDLError.from_sdl_error()
开发者ID:caseyc37,项目名称:pygame_cffi,代码行数:14,代码来源:surface.py


示例16: init

def init():
    """ init() -> (numpass, numfail)
    initialize all imported pygame modules
    """
    # check that the SDL version is supported
    # TODO: preserve backwards compatibility in mixer, RWops, etc
    major, minor, patch = get_sdl_version()
    try:
        assert major == 1
        assert minor == 2
        assert patch >= 9
    except AssertionError:
        raise RuntimeError("Current version of SDL is %i.%i.%i. Only SDL "
                           "versions >= 1.2.9, < 2.0.0 are supported." %
                           (major, minor, patch))

    global _sdl_was_init
    if not platform.system().startswith('Windows') and _with_thread:
        _sdl_was_init = sdl.SDL_Init(sdl.SDL_INIT_TIMER |
                                     sdl.SDL_INIT_NOPARACHUTE |
                                     sdl.SDL_INIT_EVENTTHREAD)
    else:
        _sdl_was_init = sdl.SDL_Init(sdl.SDL_INIT_TIMER |
                                     sdl.SDL_INIT_NOPARACHUTE)
    if _sdl_was_init == -1:
        raise SDLError.from_sdl_error()

    # initialize all the things!
    success, fail = 0, 0
    if video_autoinit():
        success += 1
    else:
        fail += 1

    # pygame inspects sys.modules and finds all __PYGAMEinit__ functions.
    # We look for autoinit and only consider submodules of pygame.
    # pygame normally initializes 6 modules.
    # We are at 4 modules: cdrom and joystick are missing
    modules = [v for k, v in sys.modules.iteritems() if k.startswith('pygame.')
               and v is not None and v != sys.modules[__name__]]
    for module in modules:
        init_call = getattr(module, 'autoinit', None)
        if hasattr(init_call, '__call__'):
            if init_call():
                success += 1
            else:
                fail += 1

    return success, fail
开发者ID:GertBurger,项目名称:pygame_cffi,代码行数:49,代码来源:base.py


示例17: set_mode

def set_mode(resolution=(0, 0), flags=0, depth=0):
    """ set_mode(resolution=(0,0), flags=0, depth=0) -> Surface
    Initialize a window or screen for display
    """
    w, h = unpack_rect(resolution)
    if w < 0 or h < 0:
        raise SDLError("Cannot set negative sized display mode")

    if flags == 0:
        flags = sdl.SDL_SWSURFACE

    if not get_init():
        init()

    # depth and double buffering attributes need to be set specially for OpenGL
    if flags & sdl.SDL_OPENGL:
        if flags & sdl.SDL_DOUBLEBUF:
            gl_set_attribute(sdl.SDL_GL_DOUBLEBUFFER, 1)
        else:
            gl_set_attribute(sdl.SDL_GL_DOUBLEBUFFER, 0)
        if depth:
            gl_set_attribute(sdl.SDL_GL_DEPTH_SIZE, depth)

        c_surface = sdl.SDL_SetVideoMode(w, h, depth, flags)
        if c_surface and gl_get_attribute(sdl.SDL_GL_DOUBLEBUFFER):
            c_surface.flags |= sdl.SDL_DOUBLEBUF

    else:
        if depth == 0:
            flags |= sdl.SDL_ANYFORMAT
        c_surface = sdl.SDL_SetVideoMode(w, h, depth, flags)

    if not c_surface:
        raise SDLError.from_sdl_error()

    title = ffi.new("char*[1]")
    icon = ffi.new("char*[1]")

    sdl.SDL_WM_GetCaption(title, icon)
    if not title:
        sdl.SDL_WM_SetCaption("pygame window", "pygame")

    # pygame does this, so it's possibly a good idea
    sdl.SDL_PumpEvents()

    global _display_surface
    _display_surface = SurfaceNoFree._from_sdl_surface(c_surface)
    # TODO: set icon stuff
    return _display_surface
开发者ID:berteaa,项目名称:pygame_cffi,代码行数:49,代码来源:display.py


示例18: get_cursor

def get_cursor():
    """ get_cursor() -> (size, hotspot, xormasks, andmasks)
    get the image for the system mouse cursor
    """
    check_video()
    cursor = sdl.SDL_GetCursor()
    if not cursor:
        raise SDLError.from_sdl_error()

    w = cursor.area.w
    h = cursor.area.h
    size = w * h / 8
    xordata = [int(cursor.data[i]) for i in range(size)]
    anddata = [int(cursor.mask[i]) for i in range(size)]
    return (w, h), (cursor.hot_x, cursor.hot_y), xordata, anddata
开发者ID:GertBurger,项目名称:pygame_cffi,代码行数:15,代码来源:mouse.py


示例19: rwops_from_file

def rwops_from_file(fileobj):
    try:
        # We try use the SDL helper first, since
        # it's the simplest code path
        rwops = sdl.SDL_RWFromFP(fileobj, 0)
    except (TypeError, IOError):
        # Construct a suitable rwops object
        rwops = sdl.SDL_AllocRW()
        rwops.hidden.unknown.data1 = ffi.new_handle(fileobj)
        rwops.seek = obj_seek
        rwops.read = obj_read
        rwops.write = obj_write
        rwops.close = obj_close
    if not rwops:
        raise SDLError.from_sdl_error()
    return rwops
开发者ID:vavilon,项目名称:pygame_cffi,代码行数:16,代码来源:rwobject.py


示例20: post

def post(event):
    """post(Event): return None
       place a new event on the queue"""
    # SDL requires video to be initialised before PushEvent does the right thing
    check_video()
    is_blocked = sdl.SDL_EventState(event.type, sdl.SDL_QUERY) == sdl.SDL_IGNORE
    if is_blocked:
        raise RuntimeError("event post blocked for %s" % event_name(event.type))

    sdl_event = ffi.new("SDL_Event *")
    sdl_event.type = event.type
    sdl_event.user.code = _USEROBJECT_CHECK1
    sdl_event.user.data1 = _USEROBJECT_CHECK2
    sdl_event.user.data2 = ffi.cast("void*", sdl_event)
    _user_events[sdl_event] = event
    if sdl.SDL_PushEvent(sdl_event) == -1:
        raise SDLError.from_sdl_error()
开发者ID:GertBurger,项目名称:pygame_cffi,代码行数:17,代码来源:event.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python ffi.cast函数代码示例发布时间:2022-05-25
下一篇:
Python pygame.Surface类代码示例发布时间: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