Toolbar in OLPCGames

Mike C. Fletcher mcfletch at vrplumber.com
Fri Dec 28 11:49:50 EST 2007


Ross Andrews wrote:
...
> Thank you, this is exactly the sort of response I was looking for!  
>   
Happy to help.
> 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.
>   
Precisely, you can also add a dictionary-of-properties after the
pygame.USEREVENT variable to communicate more information to your Pygame
code...

    pygame.event.post(pygame.event.Event(pygame.USEREVENT, dict(
foo='bar',pos=(23,45))))

and so on.
> 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?
>   
Turns out this is what the (newer-than-the-original-olpcgames-code)
"toolbox" class is:

   
http://www.vrplumber.com/sugar-docs/sugar.activity.activity.html#ActivityToolbox

will need to alter the PygameActivity class to use this instead of
ActivityToolbar around lines 97-99 in olpcgames/activity.py, will likely
need to return the toolbox instead of the toolbar as well (which means
you'll get a different object type out of that customisation point :( ,
maybe create a higher-level customisation point for the toolbox
creation, but that seems a bit over-engineered).  I doubt there are that
many activities using the customisation point yet, maybe just change the
API now and patch them.

Would be nice if we could avoid the tabs when there's no extra toolbars
defined (save screen real-estate), will have to experiment with that to
see if it works out-of-box or requires some hackery.

I'm thinking we'll also have the self.set_toolbox( x ) call happen in
the __init__ method so that whatever you return from build_toolbar will
be set as the toolbar.

Good luck,
Mike

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




More information about the Devel mailing list