parameters
[imago.git] / src / im_debug.py
1 """Debugging image display.
2
3 This is a simple module, that shows images on screen using PyGame.
4 It is not used anywhere in the standard UI, serves only for debugging.
5 """
6
7 try:
8     import pygame
9 except ImportError, msg:
10     import sys
11     print >>sys.stderr, msg
12     sys.exit(1)
13
14 def show(image, caption='', name=None):
15     """Initialize PyGame and show the *image*."""
16     if image.mode != 'RGB':
17         image = image.convert('RGB')
18     pygame.init()
19     if caption:
20         caption = "Imago: " + caption
21     else:
22         caption = "Imago"
23     pygame.display.set_caption(caption)
24     pygame.display.set_mode(image.size)
25     main_surface = pygame.display.get_surface()
26     picture = pygame.image.frombuffer(image.tostring(), image.size, image.mode)
27     main_surface.blit(picture, (0, 0))
28     pygame.display.update()
29     while True:
30         events = pygame.event.get()
31         for event in events:
32             if event.type == pygame.QUIT or event.type == pygame.KEYDOWN:
33                 pygame.quit()
34                 return