move modules to subdirectory
[imago.git] / imago_pack / im_debug.py
diff --git a/imago_pack/im_debug.py b/imago_pack/im_debug.py
new file mode 100644 (file)
index 0000000..9916e92
--- /dev/null
@@ -0,0 +1,27 @@
+try:
+    import pygame
+except ImportError, msg:
+    import sys
+    print >>sys.stderr, msg
+    sys.exit(1)
+
+def show(image, caption='', name=None):
+    if image.mode != 'RGB':
+        image = image.convert('RGB')
+    pygame.init()
+    if caption:
+        caption = "Imago: " + caption
+    else:
+        caption = "Imago"
+    pygame.display.set_caption(caption)
+    pygame.display.set_mode(image.size)
+    main_surface = pygame.display.get_surface()
+    picture = pygame.image.frombuffer(image.tostring(), image.size, image.mode)
+    main_surface.blit(picture, (0, 0))
+    pygame.display.update()
+    while True:
+        events = pygame.event.get()
+        for event in events:
+            if event.type == pygame.QUIT or event.type == pygame.KEYDOWN:
+                pygame.quit()
+                return