From c26176ad81838fff958ec7fc055f1b2dd9ab87e9 Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Mon, 31 Oct 2011 18:56:13 +0000 Subject: Add examples for Alert, Animator, ComboBox, IconEntry and Notebook [squashed two patches into one] Signed-off-by: Sascha Silbe --- 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..a712810 --- /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', 'go-next') +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() diff --git a/examples/notebook.py b/examples/notebook.py new file mode 100644 index 0000000..8cacd39 --- /dev/null +++ b/examples/notebook.py @@ -0,0 +1,32 @@ +from gi.repository import Gtk + +from sugar3.graphics.notebook import Notebook + +def _destroy_cb(widget, data=None): + Gtk.main_quit() + +w = Gtk.Window() +w.connect("destroy", _destroy_cb) + +box = Gtk.VBox() +w.add(box) + +nb = Notebook(can_close_tabs=True) +box.pack_start(nb, False, False, 0) + +for i in range(5): + bufferf = "Prepend Frame %d" % (i+1) + bufferl = "PPage %d" % (i+1) + + frame = Gtk.Frame() + frame.set_border_width(10) + frame.set_size_request(100, 75) + label = Gtk.Label(bufferf) + frame.add(label) + label.show() + nb.add_page(bufferl, frame) + frame.show() + +w.show_all() + +Gtk.main() -- cgit v0.9.1