Mercurial > pygame-tutorial-slides
changeset 129:ad152e6060ea
move last two examples to next section
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Mon, 18 Jun 2012 20:10:38 +0200 |
| parents | 76f637cf47ba |
| children | 7018a4282316 |
| files | docs/002%2F007.py docs/002%2F008.py docs/003%2F000.py docs/003%2F001.py slides.py |
| diffstat | 5 files changed, 103 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/docs/002%2F007.py Mon Jun 18 20:07:29 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ - -class Game(object): - def control(self): - for event in pygame.event.get(): - if event.type == pg.QUIT: - self.quit() - elif event.type == pg.KEYDOWN: - try: - action = self.keys[event.key] - except KeyError: - pass - else: - action[0](*action[1:]) - - def run(self): - self.clock = pygame.time.Clock() - self.game_over = False - while not self.game_over: - self.display() - self.control() - self.clock.tick(30) \ No newline at end of file
--- a/docs/002%2F008.py Mon Jun 18 20:07:29 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -class HeroSprite(pygame.sprite.Sprite): - def __init__(self, (x, y)): - super(HeroSprite, self).__init__() - self.spritesheet = load_sheet('spritesheet.png', 64) - self.image = self.spritesheet[2] - self.rect = self.image.get_rect() - self.rect.midbottom = (x * 32 + 16, y * 32 + 32) - self.animations = [] - - def move(self, (dx, dy)): - self.animations.append(self.animation_slide((dx, dy))) - - def animation_slide(self, (dx, dy)): - for step in xrange(8): - self.rect.move_ip(dx * 4, dy * 4) - yield - - def update(self): - if self.animations: - try: - self.animations[0].next() - except StopIteration: - self.animations.pop(0) \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/003%2F000.py Mon Jun 18 20:10:38 2012 +0200 @@ -0,0 +1,21 @@ + +class Game(object): + def control(self): + for event in pygame.event.get(): + if event.type == pg.QUIT: + self.quit() + elif event.type == pg.KEYDOWN: + try: + action = self.keys[event.key] + except KeyError: + pass + else: + action[0](*action[1:]) + + def run(self): + self.clock = pygame.time.Clock() + self.game_over = False + while not self.game_over: + self.display() + self.control() + self.clock.tick(30) \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/003%2F001.py Mon Jun 18 20:10:38 2012 +0200 @@ -0,0 +1,23 @@ +class HeroSprite(pygame.sprite.Sprite): + def __init__(self, (x, y)): + super(HeroSprite, self).__init__() + self.spritesheet = load_sheet('spritesheet.png', 64) + self.image = self.spritesheet[2] + self.rect = self.image.get_rect() + self.rect.midbottom = (x * 32 + 16, y * 32 + 32) + self.animations = [] + + def move(self, (dx, dy)): + self.animations.append(self.animation_slide((dx, dy))) + + def animation_slide(self, (dx, dy)): + for step in xrange(8): + self.rect.move_ip(dx * 4, dy * 4) + yield + + def update(self): + if self.animations: + try: + self.animations[0].next() + except StopIteration: + self.animations.pop(0) \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/slides.py Mon Jun 18 20:10:38 2012 +0200 @@ -0,0 +1,59 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +""" +An example of extending Hatta: adding a slideshow functionality. +""" + +import werkzeug +import os + +import hatta + +_ = lambda x: x + +class WikiPageWiki(hatta.WikiPageWiki): + def footer(self, special_title, edit_url): + for part in super(WikiPageWiki, self).footer(special_title, edit_url): + yield part + yield werkzeug.html.a(werkzeug.html(_('Slides')), + href=self.get_url(self.title, self.wiki.slides), + class_='slides') + yield u'\n' + + +class Wiki(hatta.Wiki): + @hatta.wiki.URL('/+slides/<title:title>') + def slides(self, request, title): + """Dump the HTML content of the pages listed.""" + + items = self.index.page_links_and_labels(title) + contents = [] + for t, label in items: + page = self.get_page(request, t) + try: + html = ''.join(page.view_content()) + except hatta.error.NotFoundErr: + continue + slide_title = (u'<h1>%s</h1>' % werkzeug.escape(label)) + contents.append(slide_title + html) + content = ('<div class="slide">%s</div>' + % '</div><div class="slide">'.join(contents)) + html = """<!DOCTYPE html> +<link type="text/css" href="../+download/slides.css" rel="stylesheet"> +<link type="text/css" href="../+download/pygments.css" rel="stylesheet"> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> +<title>%s</title> +%s +<script src="../+download/jquery.js"></script> +<script src="../+download/slides.js"></script> +""" % (werkzeug.escape(title), content) + response = hatta.WikiResponse(html, mimetype='text/html') + return response + + +if __name__=='__main__': + config = hatta.read_config() + wiki = Wiki(config) + wiki.mime_map['text/x-wiki'] = WikiPageWiki + hatta.main(wiki=wiki)
