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


Python Window.dispatch_events方法代码示例

本文整理汇总了Python中pyglet.window.Window.dispatch_events方法的典型用法代码示例。如果您正苦于以下问题:Python Window.dispatch_events方法的具体用法?Python Window.dispatch_events怎么用?Python Window.dispatch_events使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyglet.window.Window的用法示例。


在下文中一共展示了Window.dispatch_events方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import dispatch_events [as 别名]
def main():
    global win
    clock.schedule(rabbyt.add_time)

    win = Window(width=800, height=600)
    rabbyt.set_default_attribs()

    lawn = Lawn()
    wind = Wind()

    magicEventRegister(win, events, list(lawn))

    while not win.has_exit:
        tick = clock.tick()
        win.dispatch_events()

        lawn.update(tick)
        wind.update(tick)
        events.ConsumeEventQueue()

        rabbyt.clear((1, 1, 1))

        lawn.draw()

        win.flip()
开发者ID:pdevine,项目名称:suburbia,代码行数:27,代码来源:gutter.py

示例2: main

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import dispatch_events [as 别名]
def main():
    global fps_display

    win = Window(width=800, height=600)

    clock.schedule(rabbyt.add_time)

    rabbyt.set_default_attribs()

    bg = Background()

    fps_display = clock.ClockDisplay()

    while not win.has_exit:
        tick = clock.tick()
        win.dispatch_events()

        bg.update(tick)

        rabbyt.clear((bg.color))

        bg.draw()
        fps_display.draw()

        win.flip()
开发者ID:pdevine,项目名称:suburbia,代码行数:27,代码来源:sky.py

示例3: main

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import dispatch_events [as 别名]
def main():
    clock.schedule(rabbyt.add_time)

    win = Window(width=800, height=600)
    rabbyt.set_default_attribs()

    lawn = NewLawn()

    while not win.has_exit:
        tick = clock.tick()
        win.dispatch_events()

        lawn.update(tick)

        rabbyt.clear((1, 1, 1))

        lawn.draw()

        win.flip()
开发者ID:pdevine,项目名称:suburbia,代码行数:21,代码来源:grass.py

示例4: App

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import dispatch_events [as 别名]
class App(object):

    def __init__(self, pmap):
        self.world = World(pmap)
        self.win = Window(width=pmap['bounds'][2], height=pmap['bounds'][3])
#        pyglet.clock.set_fps_limit(10)
#        pyglet.clock.set_fps_limit(60)
        self.win.push_handlers(self.on_key_press)
        self.fullscreen = False

    def main_loop(self):
        self.world.annealing.kickoff()
        while not (self.win.has_exit or self.world.finished):
            self.win.dispatch_events()
            if (not self.world.finished) and (not self.world.pause):
                self.world.update()
                if (self.world.showvisuals):
                    self.world.draw()
            pyglet.clock.tick()
            self.win.flip()
        self.win.close()

    def on_key_press(self, symbol, modifiers):        
        # IDEA more key toggles, make it a dictionary
        if symbol == key.D:
            self.world.showdebug = not self.world.showdebug
        elif symbol == key.F:
            self.fullscreen = not self.fullscreen
            self.win.set_fullscreen(fullscreen=self.fullscreen)
            self.world.draw()
        elif symbol == key.G:
            self.world.showgrid = not self.world.showgrid
        elif symbol == key.S:
            self.world.pause = not self.world.pause
        elif symbol == key.U:
            self.world.showUI = not self.world.showUI
        elif symbol == key.V:
            self.world.showvisuals = not self.world.showvisuals
开发者ID:ajhalme,项目名称:maplabel,代码行数:40,代码来源:Maplabel.py

示例5: consol

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import dispatch_events [as 别名]
class Client:
    """
    While we aren't networking this game it's better to learn this structure now
    rather than later. Even if you never plan on learning how to network your
    games this is still a very good architecture to use.

    This Client class should be considered completely separate from the Game. It
    is just a way of interacting with the game. The game should not depend on
    anything in this class. Working like this will help you keep your code much
    cleaner and, as stated before, networkable. You could also make multiple
    clients using different technologies. In our case we are using pyglet and
    rabbyt libraries, but it wouldn't be difficult to make a client using pygame
    or even just the consol (for a text mode).
    """
    def __init__(self, game):
        # While the game needs to work independently of the client the client
        # can't work independently of the game. The client will be sending
        # input to the game as well as looking up different elements (such as
        # all the blocks so we can draw them and tell the game when we click on
        # one).
        self.game = game

        # Setup our pyglet window.
        self.window = Window(width=self.game.size_xy[0]*20,
                height=self.game.size_xy[1]*20+50)
        self.window.set_caption("Mines")
        self.window.on_close = sys.exit
        # The default pyglet OpenGL display is setup a bit different than how
        # rabbyt would like, thus rabbyt.set_default_attribs
        rabbyt.set_default_attribs()

        # Using pyglet for input is really easy. When you get further down
        # you'll see GameContorl inherits from EventDispatcher. That's how
        # window.push_handlers does the magic as we'll see further down.
        self.ctrl = GameContorl(self)
        self.window.push_handlers(self.ctrl)


        # Here we have some sprites we are going to use for the client. For
        # bigger games I think it's better to separate stuff like this out;
        # but this is quite small and not an issue.
        self.smile_face = rabbyt.Sprite("data/smile.png")
        self.smile_face.x = self.window.width/2
        self.smile_face.y = self.window.height-25

        self.dead_face = rabbyt.Sprite("data/smile_dead.png")
        self.dead_face.xy = self.smile_face.xy

        self.won_face = rabbyt.Sprite("data/smile_won.png")
        self.won_face.xy = self.smile_face.xy
        # That sprite stuff was pretty self explanatory. It is also very basic.
        # I'm not going to be going into much depth with rabbyt in these
        # tutorials so you may want to check out the rabbyt documentation from
        # http://matthewmarshall.org/projects/rabbyt/
        # Very cool and elegant stuff there. Check it out!

        self.clock = Clock()
        self.clock.set_fps_limit(20)
        self.window.push_handlers(self.clock)
        self.time = 0
        self.clock.schedule(self._add_time)

        self.setup()


    def setup(self):
        """
        Just like the setup in the Game class this one fills out the block data.
        But wait, why do we have to do this again? Remeber how in the GameBlock
        we only had stuff related to the game engine; no display stuff? Well,
        we need display stuff for the client - that's why we have ClientBlock!
        As you'll see soon the ClientBlock sorta wraps the GameBlock to provide
        the graphical stuff we need.
        """
        self.blocks = {}
        for key,b in self.game.blocks.items():
            self.blocks[key] = ClientBlock(self, b)


    def _add_time(self, dt):
        """
        This is kept track of so we can pass it onto rabbyt (so animation works)
        """
        self.time += dt


    def loop(self):
        """
        And here is our main game loop! In case you are new to game programming
        this is what is called every frame. This is where we will handle the
        display and stuff.
        """
        # clock.tick is used for keeping track of time and limiting the frame
        # rate.
        self.clock.tick()
        self.window.dispatch_events()
        # And this is where that mysterious "time" comes in. This way rabbyt
        # knows how much time has passed and can do the awesome animations.
        rabbyt.set_time(self.time)

#.........这里部分代码省略.........
开发者ID:msarch,项目名称:py,代码行数:103,代码来源:lesson1.py

示例6: draw

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import dispatch_events [as 别名]
            for tag in tag.getElementsByTagName('path'):
                self.objects.append(Curve(tag.getAttribute('d')))

    def draw(self):
        glPushMatrix()
        glTranslatef(0, 1024, 0)
        glScalef(1, -1, 1)
        for object in self.objects:
            object.draw()
        glPopMatrix()

w = Window(width=1024, height=768)

# XXX move this into display list
glEnable(GL_LINE_SMOOTH)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE)

dirname = os.path.dirname(__file__)
svg = SVG(os.path.join(dirname, 'hello_world.svg'))

clock.set_fps_limit(10)
while not w.has_exit:
    clock.tick()
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    w.dispatch_events()
    svg.draw()
    w.flip()

开发者ID:msarch,项目名称:py,代码行数:31,代码来源:svg_test.py

示例7: Window

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import dispatch_events [as 别名]
# But note that all times will be in *seconds*, not milliseconds like when we
# use pygame.time.get_ticks().
clock.schedule(rabbyt.add_time)

window = Window(width=640, height=480)
rabbyt.set_default_attribs()

car = rabbyt.Sprite("car.png")

# Rabbyt automatically detected that we are using pyglet, and used pyglet
# to load the texture.
assert isinstance(car.texture, image.Texture)

car.xy = (320, 240)

# Fade the car in after one second.
car.alpha = rabbyt.lerp(0.0, 1.0, startt=1, endt=2)

# Rotate the car from 0 to 360 over three seconds, then repeat.
car.rot = rabbyt.lerp(0, 360, dt=3, extend="repeat")

while not window.has_exit:
    clock.tick()
    window.dispatch_events()
  
    rabbyt.clear((1,1,1))

    car.render()

    window.flip()
开发者ID:0918901,项目名称:PY-Projects,代码行数:32,代码来源:basic4_pyglet.py

示例8: Client

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import dispatch_events [as 别名]
class Client( object ):
    def __init__(self, app):
		self.app = app
		self.window = Window(	width=self.app.size[0],
		        				height=self.app.size[1], 
		        				style='dialog',
		        				resizable=False )

		self.window.set_caption("ASTAR MAZE")
		self.window.on_close = sys.exit
		self.ctrl = InputHandler(self)
		self.window.push_handlers(self.ctrl)

		self.clock = Clock()
		self.clock.set_fps_limit(30)
		self.window.push_handlers(self.clock)

		self.grid = ClientGrid( self.app.grid )

		# S q u a r e s
		self.entities = {}
		self.setup()


    def setup(self):
		glClearColor( .113, .121, .1289, 1 )
		glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA )
		glDisable( GL_LIGHTING )
		glCullFace( GL_BACK )
		glDisable( GL_DEPTH_TEST )

		self.runner = None
		self.goal = None
		self.isSearching = False
		self.found = False
		self.solution = []
		self.prev = None

		self.entitiesBatch = pyglet.graphics.Batch()
		group = ClientGroup()
		for k,v in self.app.squares.iteritems():
			verts = self.entitiesBatch.add( 4, GL_QUADS, group, 'v2i/static', 'c4B/dynamic' )
			verts.vertices 		= v.vertices['positions']
			verts.colors 		= v.vertices['colors']
			self.entities[k] 	= ClientSquare( v, verts )


    def draw(self):
		self.grid.draw()
		self.entitiesBatch.draw()
		if self.found: 
			curr = None
			if self.prev:
				self.setVisited( self.entities[self.prev] )
			if len(self.solution):
				curr = self.solution.pop()
				self.entities[curr].update( SquareType.RUNNER )
				self.prev = curr


    def update(self):
        self.clock.tick()
        self.window.dispatch_events()
        self.window.clear()
        self.draw()
        self.window.flip()


    def reset(self):
    	self.app.setup()
    	self.setup()


    def astar(self):
		startState = ASState( self.runner.pos, self.goal.pos, self )
		nodesGenerated = 1
		frontier = Heap()
		expanded = set()
		frontier.push( 0, ASNode( startState ) )

		while len(frontier):
			n = frontier.pop()

			if n.state.isGoal():
				self.solution = n.execute()
				print "%d node(s) generated.\n" % nodesGenerated
				return True

			successors = n.state.expand()
			for succ in successors:
				if succ['successor'] not in expanded:
					nodesGenerated = nodesGenerated + 1
					nprime = ASNode( succ['successor'], succ['action'], n )
					frontier.push( nprime.hCost, nprime )
					expanded.add( succ['successor'] )
		return False


    def search(self):
    	if not self.runner or not self.goal:
#.........这里部分代码省略.........
开发者ID:brandonl,项目名称:a-maze,代码行数:103,代码来源:astar.py

示例9: Camera_test

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import dispatch_events [as 别名]
class Camera_test(MyTestCase):

    def setUp(self):
        self.window = Window(
            width=200, height=100, visible=False, caption="Camera_test setup")
        self.window.dispatch_events()
        glClearColor(0, 0, 0, 1)
        self.window.clear()
        self.world = World()
        self.camera = Camera((0, 0), 1)


    def tearDown(self):
        self.window.close()


    def test_constructor(self):
        camera = Camera((1, 2), 3, 4)
        self.assertEquals(camera.x, 1, "should init x")
        self.assertEquals(camera.y, 2, "should init y")
        self.assertEquals(camera.scale, 3, "should init scale")
        self.assertEquals(camera.angle, 4, "should init angle")


    def test_constructor_defaults_angle(self):
        camera = Camera((10, 20), 30)
        self.assertEquals(camera.angle, 0.0, "should init angle")


    def _draw_rect(self, backColor, polyColor, left, bottom, right, top):
        glClearColor(
            backColor[0]/255,
            backColor[1]/255,
            backColor[2]/255,
            1.0)
        self.window.clear()

        verts = [
            (left, bottom),
            (right, bottom),
            (right, top),
            (left, top),
        ]
        glColor3ub(*polyColor)
        glBegin(GL_TRIANGLE_FAN)
        for vert in verts:
            glVertex2f(*vert)
        glEnd()


    def test_world_projection_default(self):
        rect = (-0.2, -0.4, +0.6, +0.8)
        expectedRect = (90, 10, 129, 69)
        self.assert_world_projection(rect, expectedRect)


    def test_defect_pyglet_get_color_buffer_for_resized_windows(self):
        self.window.set_size(111, 222)
        self.window.dispatch_events()
        mgr = get_buffer_manager()
        col_buf = mgr.get_color_buffer()
        col_buf_size = col_buf.width, col_buf.height
        self.assertEquals(col_buf_size, (111, 222), "pyglet bug regression")


    def test_world_projection_strange_aspect(self):
        # create a new window, since
        # resizing the existing window doesn't work for some reason
        # even if we dispatch events. Default handlers?
        self.window.close()
        self.window = Window(
            width=100, height=200, visible=False,
            caption="world.test_projection_strange_aspect")
        self.window.dispatch_events()
        rect = (-0.2, -0.4, +0.6, +0.8)
        expectedRect = (40, 60, 79, 119)
        self.assert_world_projection(rect, expectedRect)


    def test_world_projection_offset(self):
        self.camera.x, self.camera.y = (+0.5, +0.3)
        rect = (-0.2, -0.4, +0.6, +0.8)
        expectedRect = (65, 25, 104, 84)
        self.assert_world_projection(rect, expectedRect)


    def test_world_projection_scale(self):
        self.camera.scale = 10
        rect = (-1, -2, +3, +4)
        expectedRect = (95, 30, 114, 59)
        self.assert_world_projection(rect, expectedRect)


    def test_world_projection_angle(self):
        self.camera.angle = pi/2
        rect = (-0.2, -0.4, +0.6, +0.8)
        expectedRect = (60, 20, 119, 59)
        self.assert_world_projection(rect, expectedRect)


#.........这里部分代码省略.........
开发者ID:tartley,项目名称:sole-scion,代码行数:103,代码来源:camera_test.py

示例10: Gameloop

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import dispatch_events [as 别名]
class Gameloop(object):

    instance = None

    def __init__(self):
        Gameloop.instance = self
        self.window = None
        self.camera = None
        self.world = None
        self.renderer = None
        self.paused = False
        self.fps_display = None
        Keyboard.handlers.update({
            key.PAGEUP: lambda: self.camera.zoom(2.0),
            key.PAGEDOWN: lambda: self.camera.zoom(0.5),
            key.ESCAPE: self.quit_game,
            key.PAUSE: self.toggle_pause,
            key.F12: lambda: save_screenshot(self.window),
        })


    def init(self, name, version):
        clock.set_fps_limit(FPS_LIMIT)
        self.fps_display = clock.ClockDisplay()

        self.camera = Camera((0, 0), 800)
        self.renderer = Renderer(self.camera)
        caption = '%s v%s' % (name, version)
        self.window = Window(
            caption=caption, fullscreen=True, visible=False)
        self.window.on_key_press = on_key_press
        self.window.push_handlers(Keyboard.keystate)

        graphics = load_graphics()

        self.world = World()
        builder = LevelBuilder()
        seed(1)
        builder.build(self.world, 75, graphics)

        self.world.player = Player()
        self.world.player.add_to_space(self.world.space, (0, 200), 0)
        self.world.chunks.update(self.world.player.chunks)


    def dispose(self):
        if self.window:
            self.window.close()


    def run(self):
        try:
            self.window.set_visible()
            while not self.window.has_exit:
                self.window.dispatch_events()
                clock.tick()
                if self.world and not self.paused:
                    self.world.tick(1/FPS_LIMIT)
                if self.world and hasattr(self.world, 'player'):
                    player_position = self.world.player.chunks[0].body.position
                    self.camera.x, self.camera.y = player_position
                    self.camera.angle = atan2(
                        player_position.x,
                        player_position.y)

                self.camera.update()
                if self.renderer:
                    aspect = (
                        self.window.width / self.window.height)
                    self.renderer.draw(self.world, aspect)
                self.camera.hud_projection(
                    (self.window.width, self.window.height))
                self.fps_display.draw()
                self.window.flip()
        finally:
            self.dispose()


    def toggle_pause(self):
        self.paused = not self.paused


    def quit_game(self):
        self.window.has_exit = True
开发者ID:tartley,项目名称:sole-scion,代码行数:86,代码来源:gameloop.py


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