import display from event import Dispatcher import pygame import logging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger("test") resolution = (400, 400) d = Dispatcher() def printEvent(e): print e def paintRect(e): print e pygame.display.get_surface().fill((100, 100, 150), pygame.Rect(e.pos, (10, 10))) d.addHandlers({pygame.MOUSEBUTTONDOWN:paintRect, pygame.MOUSEBUTTONUP:printEvent, pygame.VIDEORESIZE:lambda e: display.create(e.size)}) display.setFlags(resizable=True) display.setCaption("pygame-platform test") display.create(resolution) d.start(pygame.display.flip)
root = PygameRoot(resolution) def printCommand(): print "button clicked" button = CommandButton(printCommand, root, (10, 10), (50, 50)) switch = Switch([(255, 0, 0), (255, 255, 0), (0, 255, 0), (0, 255, 255), (0, 0, 255), (255, 0, 255), (255, 255, 255)], root, (40, 40), (80, 80)) d = Dispatcher() d.addHandlers({pygame.MOUSEBUTTONDOWN:root.mouse.onButtonDown, pygame.MOUSEBUTTONUP:root.mouse.onButtonUp, pygame.MOUSEMOTION:root.mouse.onMove, pygame.VIDEORESIZE:lambda e:root.resize(e.size)}) def draw(): # should fill display with a clearing color first each frame drawRect((0,0,0), root.region.pos, root.region.size) for element in root: # should eventually use sorted rendering element.presentation.draw() drawRect((128, 128, 128), root.cursor.pos, (10, 10)) pygame.display.flip() try: d.start(draw) pass except: pygame.quit() raise