Development Team/Almanac/Code Snippets: Difference between revisions
m Reverted edits by 61.19.222.7 (Talk) to last version by 80.90.160.194 |
|||
| (11 intermediate revisions by 7 users not shown) | |||
| Line 1: | Line 1: | ||
{{Translations}} | {{Translations}} | ||
The [[ | The [[Development_Team/Almanac|Sugar Almanac]] also has lots of code snippets. | ||
== Smooth animation == | == Smooth animation == | ||
| Line 8: | Line 7: | ||
[[PyGTK/Smooth_Animation_with_PyGTK]] | [[PyGTK/Smooth_Animation_with_PyGTK]] | ||
== WebView == | == WebKit WebView == | ||
from gi.repository import WebKit | |||
import | from gi.repository import Gtk | ||
from | |||
WINDOW_WIDTH, WINDOW_HEIGHT = 700, 500 | |||
# create window: | |||
def _destroy_cb(widget, data=None): | |||
Gtk.main_quit() | |||
window = Gtk.Window() | |||
window.resize(WINDOW_WIDTH, WINDOW_HEIGHT) | |||
window.connect("destroy", _destroy_cb) | |||
window.show() | |||
# create and add scrolled window: | |||
s = Gtk.ScrolledWindow() | |||
window.add(s) | |||
s.show() | |||
# create and add webview: | |||
v = WebKit.WebView() | |||
s.add(v) | |||
v.show() | |||
# load google page: | |||
v.load_uri('http://wiki.laptop.org') | |||
Gtk.main() | |||
== Toolbar == | == Toolbar == | ||
=== Toolbar icons === | |||
Setting a standard Sugar toolbar. | |||
from sugar.activity import activity | |||
... | |||
class MyActivity(activity.Activity): | |||
... | |||
toolbox = activity.ActivityToolbox(self) | |||
self.set_toolbox(toolbox) | |||
toolbox.show() | |||
Adding a custom toolbar and icons. | |||
from sugar.graphics.toolbutton import ToolButton | |||
from sugar.activity import activity | |||
... | |||
class MyActivity(activity.Activity): | |||
... | |||
mytoolbox = gtk.Toolbar() | |||
helpbut = ToolButton('help') #Stock help icon | |||
helpbut.set_tooltip(_("Get help")) | |||
helpbut.connect('clicked', self.help_button_pressed) | |||
mytoolbox.insert(helpbut, -1) | |||
helpbut.show() | |||
mytoolbox.show() | |||
toolbox = activity.ActivityToolbox(self) | |||
toolbox.add_toolbar("mytoolbar",mytoolbox) | |||
self.set_toolbox(toolbox) | |||
toolbox.show() | |||
In addition to the standard icons in /usr/share/icons/sugar/scalable/ (eg, "go-next"), you can create additional icons by putting an svg in your activity's icons/ directory. E.g., | |||
icons/my-icon.svg | |||
And then use it. | |||
mybut = ToolButton('my-icon')# without extension | |||
== Files == | == Files == | ||
| Line 191: | Line 229: | ||
[[Category:HowTo]] | [[Category:HowTo]] | ||
[[Category:Sugar]] | [[Category:Sugar]] | ||
[[Category: | [[Category:Developer]] | ||