def main(): numpass, numfail = pg.init() print(f'pass:{numpass}, fail:{numfail}') inited = pg.get_init() print(f'Inited: {inited}') try: raise pg.error('Custom Error') except RuntimeError as re: print(f'Exception: {re}') pg.set_error('Set Error') err = pg.get_error() print(f'Error: {err}') major, minor, path = pg.get_sdl_version() print(f'SDL: {major}.{minor}.{path}') pg.register_quit(quit) unencoded = '你好' encoded = pg.encode_string(unencoded, encoding='utf-8') print(f'Encoded: {encoded}, Original: {unencoded}') encoded_path = pg.encode_file_path(os.path.join(__file__)) print(f'Encoded Path: {encoded_path}') print(f'{pg.version.PygameVersion(1, 2, 3)}, {pg.vernum}')
def main(): pygame.encode_file_path() display = (640, 480) pygame.display.set_mode(display, DOUBLEBUF | OPENGL) gluPerspective(45, (display[0] / display[1]), 0.1, 50.0) glTranslatef(0.0, 0.0, -5) glRotatef(0, 0, 0, 0) glEnable(GL_DEPTH_TEST) # makes cube solid while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() glRotatef(1, 3, 1, 1) # Makes Cube rotate glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) cube() pygame.display.flip() pygame.time.wait(10)
def test_encoding(self): u = as_unicode(r"Hello") self.assert_(isinstance(encode_file_path(u), bytes_))
def test_path_with_null_bytes(self): b = as_bytes("a\x00b\x00c") self.assert_(encode_file_path(b) is None)
class Font(_Font): """Font(filename, size) -> Font Font(object, size) -> Font create a new Font object from a file (freetype alternative) This Font type differs from font.Font in that it can render glyphs for Unicode code points in the supplementary planes (> 0xFFFF). """ __encode_file_path = staticmethod(encode_file_path) __get_default_resolution = staticmethod(get_default_resolution) __default_font = encode_file_path(get_default_font()) __unull = as_unicode(r"\x00") __bnull = as_bytes("\x00") def __init__(self, file, size=-1): if size <= 1: size = 1 if isinstance(file, unicode_): try: bfile = self.__encode_file_path(file, ValueError) except ValueError: bfile = '' else: bfile = file if isinstance(bfile, bytes_) and bfile == self.__default_font: file = None if file is None: resolution = int(self.__get_default_resolution() * 0.6875) if resolution == 0: resolution = 1 else: resolution = 0 super(Font, self).__init__(file, size=size, resolution=resolution) self.strength = 1.0 / 12.0 self.kerning = False self.origin = True self.pad = True self.ucs4 = True self.underline_adjustment = 1.0 def render(self, text, antialias, color, background=None): """render(text, antialias, color, background=None) -> Surface draw text on a new Surface""" if text is None: text = "" if (isinstance(text, unicode_) and self.__unull in text): raise ValueError("A null character was found in the text") if (isinstance(text, bytes_) and self.__bnull in text): raise ValueError("A null character was found in the text") save_antialiased = self.antialiased self.antialiased = bool(antialias) try: s, r = super(Font, self).render(text, color, background) return s finally: self.antialiased = save_antialiased def set_bold(self, value): """set_bold(bool) -> None enable fake rendering of bold text""" self.wide = bool(value) def get_bold(self): """get_bold() -> bool check if text will be rendered bold""" return self.wide bold = property(get_bold, set_bold) def set_italic(self, value): """set_italic(bool) -> None enable fake rendering of italic text""" self.oblique = bool(value) def get_italic(self): """get_italic() -> bool check if the text will be rendered italic""" return self.oblique italic = property(get_italic, set_italic) def set_underline(self, value): """set_underline(bool) -> None control if text is rendered with an underline""" self.underline = bool(value) def get_underline(self): """set_bold(bool) -> None enable fake rendering of bold text""" return self.underline def metrics(self, text): """metrics(text) -> list Gets the metrics for each character in the passed string.""" return self.get_metrics(text) def get_ascent(self): """get_ascent() -> int get the ascent of the font""" return self.get_sized_ascender() def get_descent(self): """get_descent() -> int get the descent of the font""" return self.get_sized_descender() def get_height(self): """get_height() -> int get the height of the font""" return self.get_sized_ascender() - self.get_sized_descender() + 1 def get_linesize(self): """get_linesize() -> int get the line space of the font text""" return self.get_sized_height() def size(self, text): """size(text) -> (width, height) determine the amount of space needed to render text""" return self.get_rect(text).size
def test_path_with_null_bytes(self): b = as_bytes("a\x00b\x00c") encoded_file_path = encode_file_path(b) self.assertIsNone(encoded_file_path)
def test_encoding(self): u = as_unicode(r"Hello") encoded_file_path = encode_file_path(u) self.assertIsInstance(encoded_file_path, bytes_)
def test_encoding(self): u = "Hello" encoded_file_path = encode_file_path(u) self.assertIsInstance(encoded_file_path, bytes)