当前位置: 首页>>代码示例>>Python>>正文


Python sdl2.SDL_QUIT属性代码示例

本文整理汇总了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 
开发者ID:bglgwyng,项目名称:pyVulkan,代码行数:19,代码来源:cube.py

示例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)] 
开发者ID:kampffrosch94,项目名称:pyAoEM,代码行数:20,代码来源:input_.py

示例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() 
开发者ID:solent-eng,项目名称:solent,代码行数:22,代码来源:sdl.py

示例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() 
开发者ID:cecton,项目名称:pysdl2-sdl2ui,代码行数:19,代码来源:audio.py

示例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) 
开发者ID:rswinkle,项目名称:inventwithpython_pysdl2,代码行数:24,代码来源:simulate_pysdl2.py

示例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 
开发者ID:christophercrouzet,项目名称:hienoi,代码行数:40,代码来源:gui.py

示例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 
开发者ID:udiboy1209,项目名称:fractal-creator,代码行数:34,代码来源:__init__.py

示例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 
开发者ID:marcusva,项目名称:py-sdl2,代码行数:28,代码来源:sdl2hello.py

示例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) 
开发者ID:cecton,项目名称:pysdl2-sdl2ui,代码行数:29,代码来源:app.py

示例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) 
开发者ID:cecton,项目名称:pysdl2-sdl2ui,代码行数:8,代码来源:app.py

示例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) 
开发者ID:cecton,项目名称:pysdl2-sdl2ui,代码行数:13,代码来源:mixer.py

示例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) 
开发者ID:cecton,项目名称:pysdl2-sdl2ui,代码行数:8,代码来源:joystick.py

示例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 [] 
开发者ID:rswinkle,项目名称:inventwithpython_pysdl2,代码行数:40,代码来源:myfunctions.py

示例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() 
开发者ID:rswinkle,项目名称:inventwithpython_pysdl2,代码行数:37,代码来源:myfunctions.py

示例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 
开发者ID:rswinkle,项目名称:inventwithpython_pysdl2,代码行数:15,代码来源:wormy_pysdl2.py


注:本文中的sdl2.SDL_QUIT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。