本文整理匯總了Python中sdl2.SDL_QUIT屬性的典型用法代碼示例。如果您正苦於以下問題:Python sdl2.SDL_QUIT屬性的具體用法?Python sdl2.SDL_QUIT怎麽用?Python sdl2.SDL_QUIT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類sdl2
的用法示例。
在下文中一共展示了sdl2.SDL_QUIT屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_QUIT [as 別名]
def run(self):
#main loop
running = True
event = sdl2.SDL_Event()
last_ticks = 0
while running:
while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
if event.type == sdl2.SDL_QUIT:
running = False
new_ticks = sdl2.SDL_GetTicks()
if new_ticks - last_ticks > 1000 / 30:
self.draw()
last_ticks = new_ticks
示例2: handle_event
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_QUIT [as 別名]
def handle_event(self):
"""Busywait until SDL_Event in keyhandlers is received.
Then the corresponding value is returned."""
event = sdl2.SDL_Event()
while True:
if sdl2.SDL_WaitEvent(ctypes.byref(event)) == 0:
raise Exception(sdl2.SDL_GetError())
if event.type == sdl2.SDL_QUIT:
self.quit_handler()
return True
elif event.type == sdl2.SDL_KEYDOWN:
key = event.key.keysym.sym
mod = event.key.keysym.mod
if mod in (sdl2.KMOD_NUM, sdl2.KMOD_NUM + sdl2.KMOD_LSHIFT,
sdl2.KMOD_NUM + sdl2.KMOD_RSHIFT): # ignore numlock
mod -= sdl2.KMOD_NUM
if (key, mod) in self.key_handlers:
return self.key_handlers[(key, mod)]
示例3: orb_turn
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_QUIT [as 別名]
def orb_turn(self, activity):
events = sdl2.ext.get_events()
if events:
activity.mark(
l=self,
s='sdl2 event(s)')
for event in events:
if event.type == sdl2.SDL_QUIT:
raise SolentQuitException()
elif event.type == sdl2.SDL_KEYDOWN:
if event.key.keysym.sym == sdl2.SDLK_UP:
self.ent_player_b.velocity.vy = -3
elif event.key.keysym.sym == sdl2.SDLK_DOWN:
self.ent_player_b.velocity.vy = 3
elif event.key.keysym.sym == ord('\\'):
raise SolentQuitException()
elif event.type == sdl2.SDL_KEYUP:
if event.key.keysym.sym in (sdl2.SDLK_UP, sdl2.SDLK_DOWN):
self.ent_player_b.velocity.vy = 0
self.sdl_world.process()
示例4: init
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_QUIT [as 別名]
def init(self):
self.c_callback = sdl2.SDL_AudioCallback(self._audio_callback)
want = sdl2.SDL_AudioSpec(
self.props['frequency'], self.props['format'],
self.props['channels'], self.props['chunksize'], self.c_callback)
self.audio_spec = sdl2.SDL_AudioSpec(
self.props['frequency'], self.props['format'],
self.props['channels'], self.props['chunksize'])
self.logger.info("Opening audio device...")
self.index = sdl2.SDL_OpenAudioDevice(
None, 0, want, self.audio_spec,
self.props.get('allowed_changes', 0))
if self.index == 0:
raise ValueError(
"can't open audio device: %s" % sdl2.SDL_GetError().decode())
self.app.register_event_handler(sdl2.SDL_QUIT, self.quit)
self.load()
示例5: handle_events
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_QUIT [as 別名]
def handle_events():
global CLICKEDBUTTON
for event in sdl2.ext.get_events():
if event.type == sdl2.SDL_QUIT:
shutdown()
elif event.type == sdl2.SDL_MOUSEBUTTONUP:
mousex, mousey = event.button.x, event.button.y
button = getButtonClicked(mousex, mousey)
if button:
CLICKEDBUTTON.append(button)
elif event.type == sdl2.SDL_KEYDOWN:
sym = event.key.keysym.sym
if sym == sdl2.SDLK_ESCAPE:
shutdown()
elif sym == sdl2.SDLK_q:
CLICKEDBUTTON.append(YELLOW)
elif sym == sdl2.SDLK_w:
CLICKEDBUTTON.append(BLUE)
elif sym == sdl2.SDLK_a:
CLICKEDBUTTON.append(RED)
elif sym == sdl2.SDLK_s:
CLICKEDBUTTON.append(GREEN)
示例6: poll_events
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_QUIT [as 別名]
def poll_events(self, scene_state, data=None):
"""Process each event in the queue.
Parameters
----------
scene_state : hienoi.renderer.SceneState
Scene state.
data : object
Data to pass back and forth between the caller and the function set
for the 'on event' callback.
"""
self._has_view_changed = False
event = sdl2.SDL_Event()
while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
event_type = event.type
if event_type == sdl2.SDL_QUIT:
self._on_quit_event(event.quit)
elif event_type == sdl2.SDL_WINDOWEVENT:
self._on_window_event(event.window)
elif event_type == sdl2.SDL_KEYDOWN:
self._on_key_down_event(event.key, scene_state)
elif event_type == sdl2.SDL_KEYUP:
self._on_key_up_event(event.key)
elif event_type == sdl2.SDL_MOUSEBUTTONDOWN:
self._on_mouse_button_down_event(event.button)
elif event_type == sdl2.SDL_MOUSEBUTTONUP:
self._on_mouse_button_up_event(event.button)
elif event_type == sdl2.SDL_MOUSEWHEEL:
self._on_mouse_wheel_event(event.wheel)
elif event_type == sdl2.SDL_MOUSEMOTION:
self._on_mouse_motion_event(event.motion)
if self._on_event_callback:
self._on_event_callback(self, data, event)
if self.quit:
break
示例7: run
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_QUIT [as 別名]
def run(self):
self.window.show()
grid = self.renderer.grid
running = True
while running:
events = sdl2.ext.get_events()
for event in events:
if event.type == sdl2.SDL_QUIT:
running = False
break
if event.type == sdl2.SDL_KEYDOWN:
if event.key.keysym.sym == sdl2.SDLK_UP:
grid.velocity[1] = -6
elif event.key.keysym.sym == sdl2.SDLK_DOWN:
grid.velocity[1] = 6
elif event.key.keysym.sym == sdl2.SDLK_LEFT:
grid.velocity[0] = -6
elif event.key.keysym.sym == sdl2.SDLK_RIGHT:
grid.velocity[0] = 6
elif event.type == sdl2.SDL_KEYUP:
if event.key.keysym.sym in \
(sdl2.SDLK_UP, sdl2.SDLK_DOWN,
sdl2.SDLK_LEFT, sdl2.SDLK_RIGHT):
grid.velocity = [0,0]
elif event.key.keysym.sym == sdl2.SDLK_z:
grid.scale += 10
elif event.key.keysym.sym == sdl2.SDLK_x:
grid.scale -= 10
self.world.process()
return 0
示例8: run
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_QUIT [as 別名]
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", "hello.bmp")
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)
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
sdl2.SDL_Delay(10)
sdl2.SDL_DestroyWindow(window)
sdl2.SDL_Quit()
return 0
示例9: __init__
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_QUIT [as 別名]
def __init__(self, **options):
Component.__init__(self, self, None, **options)
self.viewport = sdl2.SDL_Rect()
self._components_activation = OrderedDict()
self.resources = {}
self.tints = []
self.timers = []
self._running = True
self.logger.info("Initializing application: %s", self.name)
sdl2.SDL_Init(self.props.get('init_flags', 0))
self.register_event_handler(sdl2.SDL_QUIT, self._quit)
self.register_event_handler(sdl2.SDL_WINDOWEVENT, self._window_event)
self.keys = sdl2.SDL_GetKeyboardState(None)
self.window = self._get_window()
self.renderer = self._get_renderer()
self.load_resource('font-6', 'font-6.png')
self.resources['font-6'].make_font(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!?("
")[][email protected]:/'., ")
self.enable()
try:
_deep_call(self, 'init')
except:
self.quit()
self._clean_up()
raise
sdl2.SDL_ShowWindow(self.window)
示例10: quit
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_QUIT [as 別名]
def quit(self, exception=None):
sdl2.SDL_PumpEvents()
sdl2.SDL_FlushEvents(sdl2.SDL_FIRSTEVENT, sdl2.SDL_LASTEVENT)
event = sdl2.SDL_Event()
event.type = sdl2.SDL_QUIT
self.poll_safe(event)
示例11: init
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_QUIT [as 別名]
def init(self):
self.logger.info("Initializing mixer component...")
status = sdlmixer.Mix_OpenAudio(
self.props.get('frequency', sdlmixer.MIX_DEFAULT_FREQUENCY),
self.props.get('format', sdlmixer.MIX_DEFAULT_FORMAT),
self.props.get('channels', sdlmixer.MIX_DEFAULT_CHANNELS),
self.props.get('chunksize', 1024))
if status != 0:
raise Exception(
"can't open mixer: %s" % sdlmixer.Mix_GetError().decode())
self.app.register_event_handler(sdl2.SDL_QUIT, self.quit)
示例12: init
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_QUIT [as 別名]
def init(self):
self.joysticks = []
sdl2.SDL_InitSubSystem(sdl2.SDL_INIT_JOYSTICK)
self.app.register_event_handler(sdl2.SDL_QUIT, self.quit)
self.app.register_event_handler(sdl2.SDL_JOYDEVICEADDED, self.added)
self.app.register_event_handler(sdl2.SDL_JOYDEVICEREMOVED, self.removed)
示例13: test_surface_sprites
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_QUIT [as 別名]
def test_surface_sprites():
test1 = sprite_factory.from_text("A text sprite")
degrees = 0
while degrees < 360:
if get_events([sdl2.SDL_QUIT]):
shutdown()
keylen = ctypes.c_int(10)
print(keylen.value)
keyboard_status = sdl2.SDL_GetKeyboardState(ctypes.byref(keylen))
print(type(keyboard_status))
print(keylen.value)
if keyboard_status[sdl2.SDL_SCANCODE_D]:
print("d is down")
ren.clear() #fill?
rot = sdlgfx.rotozoomSurface(test1.surface, degrees, 3, sdlgfx.SMOOTHING_ON)
#print(type(rot), type(rot.contents))
#<class 'sdl2.surface.LP_SDL_Surface'> <class 'sdl2.surface.SDL_Surface'>
#this is lame ... from_surface takes sdl2.surface.SDL_Surface which means calling contents
#which creates a copy
#Note that ctypes does not have OOR (original object return), it constructs a new, equivalent object each time you retrieve an attribute
#so rot.contents creates a new ~52 byte surface
rot = sprite_factory.from_surface(rot.contents)
rot.position = WIDTH//2 - rot.size[0]//2, HEIGHT//2 -rot.size[1]//2
degrees += 1
sdl2.SDL_Delay(1000//90)
sprite_renderer.render(rot)
ren.present()
#change types to OR'd flags? would mean I don't have to wrap a single
#type in []
示例14: main
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_QUIT [as 別名]
def main():
global ren, window, sprite_factory, sprite_renderer
sdl2.ext.init()
window = sdl2.ext.Window("testing", size=(WIDTH, HEIGHT))
window.show()
ren = sdl2.ext.Renderer(window, flags=sdl2.SDL_RENDERER_SOFTWARE)
font_file = sysfont.get_font("freesans")
print(font_file)
font_manager = sdl2.ext.FontManager(font_file, size=24)
#fontmanager=font_manager will be default_args passed to every sprite creation method
sprite_factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE, renderer=ren, fontmanager=font_manager, free=True)
sprite_renderer = sprite_factory.create_sprite_render_system(window)
#test1(1000)
#test_surface_drawing()
#sdl2.SDL_Delay(1000)
#test_surface_sprites()
ren.present()
while True:
for event in get_events():
if event.type == sdl2.SDL_QUIT:
shutdown()
elif event.type == sdl2.SDL_MOUSEBUTTONUP:
mousex, mousey = event.button.x, event.button.y
elif event.type == sdl2.SDL_KEYDOWN:
sym = event.key.keysym.sym
if sym == sdl2.SDLK_ESCAPE:
shutdown()
test_surface_sprites()
示例15: check_for_key_press
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_QUIT [as 別名]
def check_for_key_press():
ret = False
for event in sdl2.ext.get_events():
if event.type == sdl2.SDL_QUIT:
shutdown()
elif event.type == sdl2.SDL_MOUSEBUTTONUP:
mousex, mousey = event.button.x, event.button.y
elif event.type == sdl2.SDL_KEYDOWN:
sym = event.key.keysym.sym
ret = True
if sym == sdl2.SDLK_ESCAPE:
shutdown()
return ret