Difference between revisions of "Development Team/Almanac/Code Snippets"
< Development Team | Almanac
Jump to navigation
Jump to search
m (added Sugar category) |
|||
Line 1: | Line 1: | ||
= Toolbar = | = Toolbar = | ||
− | This snippet shows how an activity would have a toolbar with | + | This snippet shows how an activity would have a toolbar with a button and a gtk.TextView widget embedded in a hippo Canvas: |
+ | import logging | ||
import hippo | import hippo | ||
+ | import gtk | ||
from sugar.activity.Activity import Activity | from sugar.activity.Activity import Activity | ||
Line 16: | Line 18: | ||
self.add(canvas) | self.add(canvas) | ||
canvas.show() | canvas.show() | ||
− | + | ||
vbox = hippo.CanvasBox() | vbox = hippo.CanvasBox() | ||
canvas.set_root(vbox) | canvas.set_root(vbox) | ||
Line 23: | Line 25: | ||
vbox.append(toolbar) | vbox.append(toolbar) | ||
− | + | button = Button('theme:stock-close') | |
− | + | button.connect("activated", self._button_activated_cb) | |
− | + | toolbar.append(button) | |
+ | |||
+ | textViewWidget = hippo.CanvasWidget() | ||
+ | vbox.append(textViewWidget, hippo.PACK_EXPAND) | ||
+ | |||
+ | textView = gtk.TextView() | ||
+ | textView.get_buffer().set_text('Write here!', -1) | ||
+ | textViewWidget.props.widget = textView | ||
− | + | def _button_activated_cb(self, button): | |
− | + | logging.debug('FooActivity._button_activated_cb') | |
− | |||
[[Category:HowTo]] | [[Category:HowTo]] | ||
[[Category:Sugar]] | [[Category:Sugar]] |
Revision as of 06:22, 8 February 2007
Toolbar
This snippet shows how an activity would have a toolbar with a button and a gtk.TextView widget embedded in a hippo Canvas:
import logging import hippo import gtk 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) button = Button('theme:stock-close') button.connect("activated", self._button_activated_cb) toolbar.append(button) textViewWidget = hippo.CanvasWidget() vbox.append(textViewWidget, hippo.PACK_EXPAND) textView = gtk.TextView() textView.get_buffer().set_text('Write here!', -1) textViewWidget.props.widget = textView def _button_activated_cb(self, button): logging.debug('FooActivity._button_activated_cb')