Created
August 24, 2015 10:52
-
-
Save ageldama/3b701b99bf803cbdffeb to your computer and use it in GitHub Desktop.
python3 + pysdl2 + unicode input done.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Simple example for using sdl2 directly.""" | |
import os | |
import sys | |
import ctypes | |
import sdl2 | |
def run(): | |
sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) | |
window = sdl2.SDL_CreateWindow(b"Hello World", | |
sdl2.SDL_WINDOWPOS_CENTERED, | |
sdl2.SDL_WINDOWPOS_CENTERED, | |
592, 460, sdl2.SDL_WINDOW_SHOWN) | |
fname = os.path.join(os.path.dirname(os.path.abspath(__file__)), | |
"resources", "foo.jpg") | |
image = sdl2.SDL_LoadBMP(fname.encode("utf-8")) | |
windowsurface = sdl2.SDL_GetWindowSurface(window) | |
sdl2.SDL_BlitSurface(image, None, windowsurface, None) | |
sdl2.SDL_UpdateWindowSurface(window) | |
sdl2.SDL_FreeSurface(image) | |
sdl2.SDL_StartTextInput() | |
running = True | |
event = sdl2.SDL_Event() | |
while running: | |
while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0: | |
if event.type == sdl2.SDL_QUIT: | |
running = False | |
break | |
elif event.type == sdl2.SDL_TEXTEDITING: | |
#print("text-edit", event.edit.text, bytes.decode(event.text.text, 'utf-8')) | |
#print(dir(event.edit)) | |
pass | |
elif event.type == sdl2.SDL_TEXTINPUT: | |
print("text-input", event.text.text, bytes.decode(event.text.text, 'utf-8')) | |
#print(dir(event.text)) | |
sdl2.SDL_Delay(10) | |
sdl2.SDL_DestroyWindow(window) | |
sdl2.SDL_Quit() | |
return 0 | |
if __name__ == "__main__": | |
sys.exit(run()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment