def get_audio_driver(index): """Gets the name of a specific audio driver.""" if type(index) is not int: raise TypeError("index must be an int") retval = dll.SDL_GetAudioDriver(index) if retval is None or not bool(retval): raise SDLError() return stringify(retval, "utf-8")
def get_window_title(window): """Retrieves the title of a SDL_Window. Raises a SDLError, if the title could not be retrieved. """ retval = dll.SDL_GetWindowTitle(ctypes.byref(window)) if retval is None or not bool(retval): raise SDLError() return stringify(retval, "utf-8")
def get_string(device, param): """Returns a set of strings related to the context device.""" devptr = None if device is not None: devptr = ctypes.byref(device) retval = dll.alcGetString(devptr, param) if retval is None or not bool(retval): raise OpenALError(get_error(device)) return stringify(retval, "utf-8")
def get_video_driver(displayindex): """Gets the video driver used by a specific display. If the video driver for the display could not be determined, or if an invalid display index is used, a SDLError is raised. """ retval = dll.SDL_GetVideoDriver(displayindex) if retval is None: raise SDLError() return stringify(retval, "utf-8")
def joystick_name(index): """Retrieves the device name of the joystick at the specific index. If index is not an integer, a TypeError is raised. If the index is not in the range of joystick_num_joysticks(), a SDLError is raised. """ retval = dll.SDL_JoystickName(int(index)) if retval is None: raise SDLError() return stringify(retval, "utf-8")
def _cache_fonts_fontconfig(): """Caches font on POSIX-alike platforms.""" try: command = "fc-list : file family style fullname fullnamelang" proc = Popen(command, stdout=PIPE, shell=True, stderr=PIPE) pout = proc.communicate()[0] output = stringify(pout, "utf-8") except OSError: return for entry in output.split(os.linesep): if entry.strip() == "": continue values = entry.split(":") filename = values[0] # get the font type fname, fonttype = os.path.splitext(filename) if fonttype == ".gz": fonttype = os.path.splitext(fname)[1][1:].lower() else: fonttype = fonttype.lstrip(".").lower() # get the font name name = None if len(values) > 3: fullnames, fullnamelangs = values[3:] langs = fullnamelangs.split(",") offset = langs.index("fullnamelang=en") if offset == -1: offset = langs.index("en") if offset != -1: # got an english name, use that one name = fullnames.split(",")[offset] if name.startswith("fullname="): name = name[9:] if name is None: if fname.endswith(".pcf") or fname.endswith(".bdf"): name = os.path.basename(fname[:-4]) else: name = os.path.basename(fname) name = name.lower() # family and styles family = values[1].strip().lower() stylevals = values[2].strip() style = STYLE_NORMAL if stylevals.find("Bold") >= 0: style |= STYLE_BOLD if stylevals.find("Italic") >= 0 or stylevals.find("Oblique") >= 0: style |= STYLE_ITALIC _add_font(family, name, style, fonttype, filename)
def get_clipboard_text(): """Retrieves text from the OS clipboard, if available. NOTE: this might leak memory. """ retval = dll.SDL_GetClipboardText() if retval is None or not bool(retval): raise SDLError() # cast to get the whole content, then 'copy' to a new location, # so we can free retval safely val = stringify(ctypes.cast(retval, ctypes.c_char_p).value, "utf-8") free(retval) return val
def get_audio_device_name(index, iscapture=False): """Gets the name of an audio device. If iscapture is True, only input (capture) devices are queried, otherwise only output devices are queried. """ if bool(iscapture): retval = dll.SDL_GetAudioDeviceName(index, 1) else: retval = dll.SDL_GetAudioDeviceName(index, 0) if retval is None or not bool(retval): raise SDLError() return stringify(retval, "utf-8")
def get_current_video_driver(): """Gets the currently used video driver.""" retval = dll.SDL_GetCurrentVideoDriver() return stringify(retval, "utf-8")
def haptic_name(index): """Gets device name for a specific haptic device.""" retval = dll.SDL_HapticName(index) if retval is not None: return stringify(retval, "utf-8") raise SDLError()
def get_error(): """Gets the last SDL-related error message that occured.""" retval = dll.SDL_GetError() return stringify(retval, "utf-8")
def font_face_style_name(font): """Gets the current font face syle name.""" retval = dll.TTF_FontFaceStyleName(ctypes.byref(font)) return stringify(retval, "utf-8")
def font_face_family_name(font): """Get the current font face family name.""" retval = dll.TTF_FontFaceFamilyName(ctypes.byref(font)) return stringify(retval, "utf-8")
def get_current_audio_driver(): """Gets the currently used audio driver.""" retval = dll.SDL_GetCurrentAudioDriver() if retval is None or not bool(retval): return None return stringify(retval, "utf-8")
def get_platform(): """Gets the platform, the used SDL2 library was built on.""" retval = dll.SDL_GetPlatform() return stringify(retval, "utf-8")
def get_hint(name): """Gets the currently set value for the passed hint.""" retval = dll.SDL_GetHint(byteify(str(name), "utf-8")) if retval is not None: return stringify(retval, "utf-8") return None
def get_revision(): """Returns the unique revision of the used SDL library.""" return stringify(dll.SDL_GetRevision(), "utf-8")