SurfaceWindow

This is a pretty rough module, written in response to a random comment on #pygame, to allow programs written using pygame to utilise multiple windows.

The SurfaceWindow class acts as a proxy for a display surface of a child python+pygame process, passing method calls to the child and receiving responses and events back from it.

Features

Download

Latest version: 0.2.2

This module is released under the MIT license.

Usage example

import pygame
import surfwin
 
# Init main window
pygame.init()
main = pygame.display.set_mode((200, 200))
# Init secondary window
secondary = surfwin.SurfaceWindow((100, 100))
secondary.set_caption('Secondary pygame window')
 
# Something to blit to both windows, just to prove I'm not faking
smallred = pygame.Surface((10, 10))
smallred.fill((255, 0, 0))
 
# The main window gets smallred near the top-left corner
main.blit (smallred, (10, 10))
# The secondary window gets smallred in the middle
secondary.blit (smallred, (45, 45))
 
# Loop at 30 FPS, until we're told to quit
clock = pygame.time.Clock()
looping = True
while looping:
clock.tick(30)
 
# Prompt the secondary window to send events to us
secondary.process()
 
for event in pygame.event.get():
if getattr(event, 'window', None) is None:
print 'MAIN', event
else:
print 'SECOND', event
 
# Quit if any of our windows are closed.
if event.type == pygame.QUIT:
looping = False
 
pygame.display.flip()
secondary.flip()