[OLPC-Games] Embedding pygame in gtk.

Mike C. Fletcher mcfletch at vrplumber.com
Mon Dec 24 23:11:13 EST 2007


C. Scott Ananian wrote:
> I've been playing around with pygame in Pippy.  At the bottom please
> find a minimal example that runs a pygame in full-screen mode from
> Pippy, but when 'Keep as Activity Bundle' is used creates a proper
> activity toolbar & etc.  Unfortunately, the embedding currently
> doesn't pass mouse or keyboard events to the pygame.  I'm sure this
> problem has been solved before, perhaps even in the OLPCGames package
> which I just saw posted to this list.  Comments/advice welcome.
>   
It's the same basic solution as OLPCGames, i.e. a GTK Activity window
with a Pygame window displayed using the X-embed protocol (AKA ports in
GTK).  The bulk of OLPCGame's code is solving these other problems:

    * keyboard, expose, and mouse event forwarding (gtkEvent, eventwrap)
    * telepathy integration as pygame events (mesh)
    * easy camera access (camera)
    * pango-based font rendering to support a wider range of languages
      (pangofont)
    * svg rendering as sprites to support "standard" graphics (svgsprite)

Note that you should not be using a 1200x900 Pygame size when you are on
an OLPC if you are including a standard toolbar, as you will wind up
with some of your Pygame window cut off by the bottom of the screen.  We
could add (something like) your code for triggering Pippy on
view-source, but for most Pygame games that isn't going to be very
useful because Pippy won't be able to handle their non-trivial structure.

BTW, why can't Pippy handle .xo files or dev directories?  Seems like a
fairly straightforward bit of functionality and would get away from
trying to shoehorn every activity into a single file.  I can't say I've
ever seen a "real" Pygame game that was written all in a single file
with no resources required at all.  Pygame is all about raster graphics,
and that *normally* means bitmap files that need to be carried along
with the code.  AFAICS it should just be a matter of passing a directory
(if Pippy has special privileges to read other Activity's files) or a
.xo file (if Pippy runs inside a container and can't access other
activity's files).  Pippy's file-browsing tree would then show the files
in the package, rather than the examples.  Need some way to add/remove
files in the current bundle too.

Also, Pippy should probably not be storing activities using "friendly"
names.  To do that it will often have to (ask the journal to) overwrite
an existing friendly-name version of the activity.  Most of the time
during development your copy of the activity will be borked, but you
still want access to the original version.  The obvious solution would
be to teach Sugar and the Journal to allow for versioned directories
named as a dotted version of the base version (and dotted of the dotted
if you branch from an unstable release)... or better yet, use a .bzr
repository stored along with the directory that contains the whole
development tree, downloading it from upstream on first edit of the
repository (or maybe just doing a local repository, space considerations
and all that).

Have fun,
Mike

-- 
________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com



More information about the Games mailing list