示例#1
0
def Video_AutoInit():
    """Called from the base.c just before display module is initialized."""
    if 'Darwin' in platform.platform():
        if not sdlmain_osx.RunningFromBundleWithNSApplication():
            try:
                default_icon_data = getResource('pygame_icon.tiff').read()
            except IOError:
                default_icon_data = None
            except NotImplementedError:
                default_icon_data = None
            sdlmain_osx.InstallNSApplication(default_icon_data)
        if (os.getcwd() == '/') and len(sys.argv) > 1:
            os.chdir(os.path.dirname(sys.argv[0]))
    return True
示例#2
0
def Video_AutoInit():
    """Called from the base.c just before display module is initialized."""
    if "Darwin" in platform.platform():
        if not sdlmain_osx.RunningFromBundleWithNSApplication():
            try:
                default_icon_data = getResource("pygame_icon.tiff").read()
            except IOError:
                default_icon_data = None
            except NotImplementedError:
                default_icon_data = None
            sdlmain_osx.InstallNSApplication(default_icon_data)
        if (os.getcwd() == "/") and len(sys.argv) > 1:
            os.chdir(os.path.dirname(sys.argv[0]))
    return True
示例#3
0
def Video_AutoInit():
    """This is a function that's called from the c extension code
       just before the display module is initialized"""
    if MacOS and not MacOS.WMAvailable():
        if not sdlmain_osx.WMEnable():
            raise ImportError("Can not access the window manager.  Use py2app or execute with the pythonw script.")
    if not sdlmain_osx.RunningFromBundleWithNSApplication():
        try:
            default_icon_data = getResource('pygame_icon.tiff').read()
        except IOError:
            default_icon_data = None
        sdlmain_osx.InstallNSApplication(default_icon_data)
    if (os.getcwd() == '/') and len(sys.argv) > 1:
        os.chdir(os.path.dirname(sys.argv[0]))
    return True
示例#4
0
def Video_AutoInit():
    """This is a function that's called from the c extension code
       just before the display module is initialized"""
    if MacOS and not MacOS.WMAvailable():
        if not sdlmain_osx.WMEnable():
            raise ImportError(
                "Can not access the window manager.  Use py2app or execute with the pythonw script."
            )
    if not sdlmain_osx.RunningFromBundleWithNSApplication():
        try:
            default_icon_data = getResource('pygame_icon.tiff').read()
        except IOError:
            default_icon_data = None
        sdlmain_osx.InstallNSApplication(default_icon_data)
    if (os.getcwd() == '/') and len(sys.argv) > 1:
        os.chdir(os.path.dirname(sys.argv[0]))
    return True
示例#5
0
    def __init__(self, font, fontsize):
        check_font()
        if not isinstance(fontsize, int):
            raise TypeError("expected an integer, but got %r" % type(fontsize))

        if fontsize < 1:
            fontsize = 1

        file_obj = None
        if font is None or font == _font_defaultname:
            file_obj = getResource(_font_defaultname)
            self._font_file = file_obj
            # Scaling as from pygame/src/font.c
            fontsize = int(fontsize * 0.6875)
            if fontsize < 1:
                fontsize = 1
        elif isinstance(font, (bytes_, unicode_)):
            filepath = rwops_encode_file_path(font)
            # According to the pygame comments, we need to ensure the
            # file exists and is readable before calling out to SDL
            f = open(filepath, 'r')
            # pygame raises IOError if this fails, so we don't catch the
            # exception
            f.close()
            self._sdl_font = sdl.TTF_OpenFont(filepath, fontsize)
        else:
            file_obj = font

        if file_obj:
            # Get a new handle on the file to load the font from.
            # Otherwise, if the file handle is closed elsewhere, font
            # rendering will segfault.
            if self._font_file is None:
                file_obj = open(os.path.abspath(file_obj.name))
                self._font_file = file_obj

            rwops = rwops_from_file(file_obj)
            self._sdl_font = sdl.TTF_OpenFontRW(rwops, 1, fontsize)

        if not self._sdl_font:
            raise SDLError.from_sdl_error()
示例#6
0
    def __init__(self, font, fontsize):
        check_font()
        if not isinstance(fontsize, int):
            raise TypeError("expected an integer, but got %r" % type(fontsize))

        if fontsize < 1:
            fontsize = 1

        file_obj = None
        if font is None or font == _font_defaultname:
            file_obj = getResource(_font_defaultname)
            self._font_file = file_obj
            # Scaling as from pygame/src/font.c
            fontsize = int(fontsize * 0.6875)
            if fontsize < 1:
                fontsize = 1
        elif isinstance(font, (bytes_, unicode_)):
            filepath = rwops_encode_file_path(font)
            # According to the pygame comments, we need to ensure the
            # file exists and is readable before calling out to SDL
            f = open(filepath, 'r')
            # pygame raises IOError if this fails, so we don't catch the
            # exception
            f.close()
            self._sdl_font = sdl.TTF_OpenFont(filepath, fontsize)
        else:
            file_obj = font

        if file_obj:
            # Get a new handle on the file to load the font from.
            # Otherwise, if the file handle is closed elsewhere, font
            # rendering will segfault.
            if self._font_file is None:
                file_obj = open(os.path.abspath(file_obj.name))
                self._font_file = file_obj

            rwops = rwops_from_file(file_obj)
            self._sdl_font = sdl.TTF_OpenFontRW(rwops, 1, fontsize)

        if not self._sdl_font:
            raise SDLError.from_sdl_error()
示例#7
0
        return 0;
    }

    %(surface_h)s

    %(alphablit)s

    %(surface_fill)s

    %(scale2x)s

    %(rotate)s

    %(stretch)s
    """ % {
        'surface_h': getResource('lib/surface.h').read(),
        'alphablit': getResource('lib/alphablit.c').read(),
        'surface_fill': getResource('lib/surface_fill.c').read(),
        'scale2x': getResource('lib/scale2x.c').read(),
        'rotate': getResource('lib/rotate.c').read(),
        'stretch': getResource('lib/stretch.c').read(),
    }
)


def get_sdl_version():
    """ get_sdl_version() -> major, minor, patch
    get the version number of SDL
    """
    v = sdl.SDL_Linked_Version()
    return (v.major, v.minor, v.patch)
示例#8
0
        free (rlebuf);
        SDL_FreeSurface (linebuf);
        return 0;
    }

    %(surface_h)s

    %(alphablit)s

    %(surface_fill)s

    %(scale2x)s

    %(rotate)s
    """ % {
                     'surface_h': getResource('lib/surface.h').read(),
                     'alphablit': getResource('lib/alphablit.c').read(),
                     'surface_fill': getResource('lib/surface_fill.c').read(),
                     'scale2x': getResource('lib/scale2x.c').read(),
                     'rotate': getResource('lib/rotate.c').read()
                 })


def get_sdl_version():
    """ get_sdl_version() -> major, minor, patch
    get the version number of SDL
    """
    v = sdl.SDL_Linked_Version()
    return (v.major, v.minor, v.patch)