From b9a19e952fc0764225b2082a36874fcc2896942b Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Mon, 31 Oct 2011 19:56:13 +0100 Subject: [PATCH] Add examples for Alert, Animator, ComboBox, IconEntry and Notebook Signed-off-by: Simon Schampijer [squashed two patches into one] Signed-off-by: Sascha Silbe --- examples/alert.py | 25 ++++++++++++++++++++++++ examples/animator.py | 44 +++++++++++++++++++++++++++++++++++++++++++ examples/combobox.py | 27 ++++++++++++++++++++++++++ examples/iconentry.py | 30 +++++++++++++++++++++++++++++ examples/notebook.py | 32 +++++++++++++++++++++++++++++++ 5 files changed, 158 insertions(+) create mode 100644 examples/alert.py create mode 100644 examples/animator.py create mode 100644 examples/combobox.py create mode 100644 examples/iconentry.py create mode 100644 examples/notebook.py diff --git a/examples/alert.py b/examples/alert.py new file mode 100644 index 00000000..4eda9ce8 --- /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 00000000..cc68ad69 --- /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 00000000..a7128104 --- /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 00000000..1760043f --- /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 00000000..8cacd393 --- /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()