comparison gamelib/main.py @ 151:082868bea873

Refactor UI so that only a single gui.App is used. Pass all UI events via main_app. Change Toolbar table to use .td() everywhere. Move toolbar to top.
author Simon Cross <hodgestar@gmail.com>
date Thu, 03 Sep 2009 20:32:56 +0000
parents 1d73de63bd71
children 4cc0b3627f83
comparison
equal deleted inserted replaced
150:89d2360d4350 151:082868bea873
8 8
9 import pygame 9 import pygame
10 from pgu import gui 10 from pgu import gui
11 from pygame.locals import SWSURFACE 11 from pygame.locals import SWSURFACE
12 12
13 from mainmenu import MenuContainer, MainMenu 13 #from engine import Engine, MainMenuState
14 from engine import Engine, MainMenuState
15 from sound import init_sound 14 from sound import init_sound
16 import constants 15 import constants
17 16
18 17 def create_main_app(screen):
19 18 """Create an app with a background widget."""
20 def create_app():
21 """Create the app."""
22 app = gui.App() 19 app = gui.App()
20 background = pygame.Surface(screen.get_size())
21 widget = gui.Image(background)
22 app.init(widget, screen)
23 return app 23 return app
24 24
25 def main(): 25 def main():
26 """Main script.""" 26 """Main script."""
27 init_sound() 27 init_sound()
28 screen = pygame.display.set_mode(constants.SCREEN, SWSURFACE) 28 screen = pygame.display.set_mode(constants.SCREEN, SWSURFACE)
29 main_app = create_app() 29 main_app = create_main_app(screen)
30
31 from engine import Engine, MainMenuState
32
30 engine = Engine(main_app) 33 engine = Engine(main_app)
31 try: 34 try:
32 engine.run(MainMenuState(engine), screen) 35 engine.run(MainMenuState(engine), screen)
33 except KeyboardInterrupt: 36 except KeyboardInterrupt:
34 pass 37 pass