Commit before breaking everything
[matches/honours.git] / research / transmission_spectroscopy / simulator / pgu-0.18 / examples / layout1.py
1 """<title>an example of layout usage</title>"""
2 import pygame
3 from pygame.locals import *
4
5 # the following line is not needed if pgu is installed
6 import sys; sys.path.insert(0, "..")
7
8 from pgu import layout
9
10 pygame.font.init()
11
12 screen = pygame.display.set_mode((320,320),SWSURFACE)
13 bg = (255,255,255)
14 fg = (0,0,0)
15 screen.fill(bg)
16
17 class Obj: pass
18
19 l = layout.Layout(pygame.Rect(0,0,320,320))
20
21 e = Obj()
22 e.image = pygame.image.load("cuzco.png")
23 e.rect = pygame.Rect(0,0,e.image.get_width(),e.image.get_height())
24 e.align = 1
25 l.add(e) #aligned object
26
27 font = pygame.font.SysFont("default", 24)
28
29 w,h = font.size(" ")
30
31 l.add(-1) #start of new block
32 for word in """Welcome to my little demo of the layout module. The demo does not do a whole lot, but I'm sure you will be very impressed by it. blah blah blah. The demo does not do a whole lot, but I'm sure you will be very impressed by it. blah blah blah.""".split(" "):
33     e = Obj()
34     e.image = font.render(word,1,fg)
35     e.rect = pygame.Rect(0,0,e.image.get_width(),e.image.get_height())
36     l.add(e) #inline object
37     l.add((w,h)) #space
38     
39 l.add((0,h)) #br
40
41 ##The layout object will layout words, and document elements for you
42 ##::
43 l.add(-1) #start of new block
44 for word in """The demo does not do a whole lot, but I'm sure you will be very impressed by it. blah blah blah. The demo does not do a whole lot, but I'm sure you will be very impressed by it. blah blah blah.""".split(" "):
45     e = Obj()
46     e.image = font.render(word,1,fg)
47     e.rect = pygame.Rect(0,0,e.image.get_width(),e.image.get_height())
48     l.add(e) #inline object
49     l.add((w,h)) #space
50 ##
51
52 l.resize()
53
54 for e in l.widgets:
55     screen.blit(e.image,(e.rect.x,e.rect.y))
56     
57 pygame.display.flip()
58
59 _quit = 0
60 while not _quit:
61     for e in pygame.event.get():
62         if e.type is QUIT: _quit = 1
63     pygame.time.wait(10)

UCC git Repository :: git.ucc.asn.au