Toolbar in OLPCGames

Mike C. Fletcher mcfletch at vrplumber.com
Thu Dec 27 23:26:02 EST 2007


Ross Andrews wrote:
...
> It is much simpler than the Implode code, but I still have some  
> problems. Here is what I have in activity.py:
>
> class Activity(olpcgames.PyGameActivity):
>      """Your Sugar activity"""
>
>      game_name = 'run'
>      game_title = _('Game Of Life')
>      game_size = None
>
>      def __init__(self,handle):
>          activity.Activity.__init__(self, handle)
>          mytoolbox = gtk.Toolbar()
>          helpbut = ToolButton('activity')#Stock help icon
>          helpbut.set_tooltip(_("Foo!"))
>          helpbut.connect('clicked', self.help_button_pressed)
>          mytoolbox.insert(helpbut, -1)
>          helpbut.show()
>          self.set_toolbox(mytoolbox)
>          mytoolbox.show()
>
>      def help_button_pressed(self, button):
>          None
>
>
> This makes a blank window with a toolbar, the toolbar does indeed have  
> a single icon with a picture of a hammer on it (the contents of  
> activity.svg). But, nothing else happens! It seems that by overriding  
> __init__ I've broken whatever magic started up Pygame and ran the code  
> in run.py.
>   
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




More information about the Devel mailing list