From 1c9ddf47d97030294f88204662ee92cd8f1eb06d Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Mon, 31 Oct 2011 18:56:13 +0000 Subject: Examples for Alert, Animator, ComboBox and IconEntry --- diff --git a/examples/alert.py b/examples/alert.py new file mode 100644 index 0000000..4eda9ce --- /dev/null +++ b/examples/alert.py @@ -0,0 +1,25 @@ +from gi.repository import Gtk + +from sugar3.graphics.alert import Alert, TimeoutAlert + +def _destroy_cb(widget, data=None): + Gtk.main_quit() + +def __start_response_cb(widget, data=None): + print 'Response: start download' + +w = Gtk.Window() +w.connect("destroy", _destroy_cb) + +box = Gtk.VBox() +w.add(box) + +alert = TimeoutAlert(9) +alert.props.title = 'Download started' +alert.props.msg = 'Sugar' +box.pack_start(alert, False, False, 0) +alert.connect('response', __start_response_cb) + +w.show_all() + +Gtk.main() diff --git a/examples/animator.py b/examples/animator.py new file mode 100644 index 0000000..cc68ad6 --- /dev/null +++ b/examples/animator.py @@ -0,0 +1,44 @@ +from gi.repository import Gtk + +from sugar3.graphics import animator +from sugar3.graphics.icon import Icon +from sugar3.graphics import style + + +class _Animation(animator.Animation): + def __init__(self, icon, start_size, end_size): + animator.Animation.__init__(self, 0.0, 1.0) + + self._icon = icon + self.start_size = start_size + self.end_size = end_size + + def next_frame(self, current): + d = (self.end_size - self.start_size) * current + self._icon.props.pixel_size = int(self.start_size + d) + + +def __animation_completed_cb(anim): + print 'Animation completed' + +def _destroy_cb(widget, data=None): + Gtk.main_quit() + +w = Gtk.Window() +w.connect("destroy", _destroy_cb) + +box = Gtk.VBox() +w.add(box) + +anim = animator.Animator(5) +anim.connect('completed', __animation_completed_cb) + +my_icon = Icon(icon_name='go-next') +box.pack_start(my_icon, False, False, 0) + +anim.add(_Animation(my_icon, style.STANDARD_ICON_SIZE, style.XLARGE_ICON_SIZE)) +anim.start() + +w.show_all() + +Gtk.main() diff --git a/examples/combobox.py b/examples/combobox.py new file mode 100644 index 0000000..98d01d5 --- /dev/null +++ b/examples/combobox.py @@ -0,0 +1,27 @@ +from gi.repository import Gtk + +from sugar3.graphics.combobox import ComboBox + +def _destroy_cb(widget, data=None): + Gtk.main_quit() + +def __combo_changed_cb(widget, data=None): + print 'combo-changed' + +w = Gtk.Window() +w.connect("destroy", _destroy_cb) + +box = Gtk.VBox() +w.add(box) + +combo = ComboBox() +combo.append_item(0, 'one') +combo.append_item(1, 'two') +combo.append_item(2, 'three') +combo.set_active(1) +combo.connect('changed', __combo_changed_cb) +box.pack_start(combo, False, False, 0) + +w.show_all() + +Gtk.main() diff --git a/examples/iconentry.py b/examples/iconentry.py new file mode 100644 index 0000000..1760043 --- /dev/null +++ b/examples/iconentry.py @@ -0,0 +1,30 @@ +from gi.repository import Gtk + +from sugar3.graphics import iconentry + +def _destroy_cb(widget, data=None): + Gtk.main_quit() + +def __go_next_cb(entry, icon_pos, data=None): + print 'Go next' + +def __entry_activate_cb(widget, data=None): + print 'Entry activate' + +w = Gtk.Window() +w.connect("destroy", _destroy_cb) + +box = Gtk.VBox() +w.add(box) + +entry = iconentry.IconEntry() +entry.set_icon_from_name(iconentry.ICON_ENTRY_SECONDARY, + 'go-next') +entry.connect('icon-press', __go_next_cb) +entry.connect('activate', __entry_activate_cb) +entry.set_progress_fraction(0.3) +box.pack_start(entry, False, False, 0) + +w.show_all() + +Gtk.main() -- cgit v0.9.1