From b125364dfa6cca1511e2e2b31a6c50fb72d0076a Mon Sep 17 00:00:00 2001 From: Gary Martin Date: Sun, 03 Oct 2010 17:54:04 +0000 Subject: Custom get_preview code using pygame to generate the preview image for Journal SL#2114. --- (limited to 'activity.py') 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. """ -- cgit v0.9.1