Toolbar in OLPCGames
Ross Andrews
lists at geekfu.org
Fri Dec 28 00:21:20 EST 2007
> Recent versions of OLPCGames have a customisation point:
>
> def build_toolbar( self ):
> """Build our Activity toolbar for the Sugar system
>
> This is a customisation point for those games which want to
> provide custom toolbars when running under Sugar.
> """
>
> the default implementation (available in activity.py for your
> inspection) just creates an activity.ActivityToolbar and sets a few
> callbacks on the "share" widget. You can read the code in
> olpcgames/activity.py if you want to see how it all works.
>
> You will likely want to override build_toolbar something like this:
>
> def build_toolbar( self ):
> """Add my extra widgets to the toolbar
> """
> toolbar = super( MyActivityClass, self ).build_toolbar()
> # your custom widgets added here...
> return toolbar
>
> all of this code, including any callbacks you register, are going to
> happen in the GTK mainloop, so if you are passing messages to your
> Pygame code you will likely need to use a queue or Pygame events to
> get
> the messages over to the Pygame side. You can see an example of
> defining a toolbar in the terminal activity... hmm, and reading that
> it
> seems that someone has changed the original "toolbar" class to a
> "toolbox" class, so we'll probably have to update OLPCGames to
> support that.
>
> Anyway, hope that gets you started,
> Mike
>
> --
> ________________________________________________
> Mike C. Fletcher
> Designer, VR Plumber, Coder
> http://www.vrplumber.com
> http://blog.vrplumber.com
>
Thank you, this is exactly the sort of response I was looking for!
This seems to work:
def build_toolbar(self):
toolbar=super(Activity, self).build_toolbar()
helpbut = ToolButton('activity')#Stock help icon
helpbut.set_tooltip(_("Foo!"))
helpbut.connect('clicked', self.help_button_pressed)
toolbar.insert(helpbut, -1)
helpbut.show()
toolbar.show()
return toolbar
So I can communicate with the Pygame part of the code through
something like this:
def toolbar_button_pressed(self, button):
pygame.event.post(pygame.event.Event(pygame.USEREVENT))
And Pygame can just pick it up the next time it goes through the event
loop.
Only other question I have is that some (most) activities have more
than one toolbar, there's a tabbed pane sort of thing and toolbars
above it, so that the activity-related toolbar (sharing, save to
journal, etc) is separate from the stuff specific to your game, er,
activity. So how do I make one of those tab thingies?
Sorry if this is all very obvious; this is the first time I've ever
used Python or Pygame.
More information about the Devel
mailing list