Difference between revisions of "Development Team/Almanac/Code Snippets"

From Sugar Labs
Jump to navigation Jump to search
(Added toolbar example.)
 
m (added Sugar category)
(One intermediate revision by the same user not shown)
Line 30: Line 30:
 
         button2.connect("activated", self._button2_activated_cb)
 
         button2.connect("activated", self._button2_activated_cb)
 
         self.append(button2)
 
         self.append(button2)
 +
 +
 +
[[Category:HowTo]]
 +
[[Category:Sugar]]

Revision as of 18:09, 7 February 2007

Toolbar

This snippet shows how an activity would have a toolbar with two buttons:

import hippo

from sugar.activity.Activity import Activity
from sugar.graphics.toolbar import Toolbar
from sugar.graphics.button import Button

class FooActivity(Activity):
    def __init__(self):
        Activity.__init__(self)

        canvas = hippo.Canvas()
        self.add(canvas)
        canvas.show()
       
        vbox = hippo.CanvasBox()
        canvas.set_root(vbox)

        toolbar = Toolbar()
        vbox.append(toolbar)

        button1 = Button('button1_icon')
        button1.connect("activated", self._button1_activated_cb)
        self.append(button1)

        button2 = Button('button2_icon')
        button2.connect("activated", self._button2_activated_cb)
        self.append(button2)