Monday, April 20, 2009

Embed flash movies with gnash in your gtk apps

Has been a week full of hacking fun since I started to work on a Gnash gtk widget. Some frustration as well because it's the first time I deal with C++ code using boost and modern stuff like std_ptr and, of course, libtool and friends. This bit of work comes in line with my earlier posts about embedding Evince, Abiword and Mozilla.

But the effort has born its fruits, and now we can run all of Gnash as a gtk widget inside a Sugar activity:

And this is the code:

import os

import gtk
import gnash

from sugar.activity import activity

class EatBoomActivity(activity.Activity):
def __init__(self, handle, browser=None):
activity.Activity.__init__(self, handle)

toolbox = activity.ActivityToolbox(self)

view = gnash.View()
view.load_movie(os.path.join(activity.get_bundle_path(), 'EatBoom.swf'))

For non-Sugar-enabled gtk people, you will be able to embed gnash doing something like this:

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

view = gnash_view_new ();

gtk_container_add (GTK_CONTAINER (window), view);
gtk_widget_show (view);

gtk_widget_show (window);

gnash_view_load_movie(GNASH_VIEW(view), argv[1]);

This is without using GtkPlug and, of course, running inside the same process. So by adding methods to the C widget we can control all of the Gnash engine and expose it trivially to python with pygtk. And through the use of Gnash extensions, we can extend the ActionScript class library with Sugar specifics so it integrates well with the rest of the environment.

This is still a proof of concept, but plan to start working right now in finding a way to integrate it in upstream Gnash.