Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Schampijer <simon@schampijer.de>2011-10-31 18:56:13 (GMT)
committer Sascha Silbe <silbe@activitycentral.com>2011-11-22 12:28:58 (GMT)
commitc26176ad81838fff958ec7fc055f1b2dd9ab87e9 (patch)
treeb2770e5dc2db230b12d4dc2974e8991d3778af09
parenteedb5f2ca72db9bab49c3c3dd50823ec736fce35 (diff)
Add examples for Alert, Animator, ComboBox, IconEntry and Notebook
[squashed two patches into one] Signed-off-by: Sascha Silbe <silbe@activitycentral.com>
-rw-r--r--examples/alert.py25
-rw-r--r--examples/animator.py44
-rw-r--r--examples/combobox.py27
-rw-r--r--examples/iconentry.py30
-rw-r--r--examples/notebook.py32
5 files changed, 158 insertions, 0 deletions
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()