Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGary Martin <gary@garycmartin.com>2010-10-03 17:54:04 (GMT)
committer Gary Martin <gary@garycmartin.com>2010-10-03 17:54:04 (GMT)
commitb125364dfa6cca1511e2e2b31a6c50fb72d0076a (patch)
tree6556ff7921d7fb195f5da254591f5d18a371bbf4
parent08bdea73f62c9b0bc6efe701c6fdbe441e9e21ad (diff)
Custom get_preview code using pygame to generate the preview image for Journal SL#2114.
-rw-r--r--activity.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/activity.py b/activity.py
index 9524b11..0d0a720 100644
--- a/activity.py
+++ b/activity.py
@@ -45,6 +45,26 @@ class PhysicsActivity(olpcgames.PyGameActivity):
super(PhysicsActivity, self).__init__(handle)
self.metadata['mime_type'] = 'application/x-physics-activity'
+ def get_preview(self):
+ """Custom preview code to get image from pygame.
+ """
+ surface = pygame.display.get_surface()
+ width, height = surface.get_width(), surface.get_height()
+ pixbuf = gtk.gdk.pixbuf_new_from_data(pygame.image.tostring(surface, "RGB"),
+ gtk.gdk.COLORSPACE_RGB, 0, 8,
+ width, height,
+ 3 * width)
+ pixbuf = pixbuf.scale_simple(300, 225, gtk.gdk.INTERP_BILINEAR)
+
+ preview_data = []
+ def save_func(buf, data):
+ data.append(buf)
+
+ pixbuf.save_to_callback(save_func, 'png', user_data=preview_data)
+ preview_data = ''.join(preview_data)
+
+ return preview_data
+
def write_file(self, file_path):
"""Over-ride olpcgames write_file so that title keeps working.
"""