Add examples for Alert, Animator, ComboBox, IconEntry and Notebook
Signed-off-by: Simon Schampijer <simon@schampijer.de> [squashed two patches into one] Signed-off-by: Sascha Silbe <silbe@activitycentral.com>
This commit is contained in:
parent
82fcf0a0f0
commit
b9a19e952f
25
examples/alert.py
Normal file
25
examples/alert.py
Normal file
@ -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()
|
44
examples/animator.py
Normal file
44
examples/animator.py
Normal file
@ -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()
|
27
examples/combobox.py
Normal file
27
examples/combobox.py
Normal file
@ -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()
|
30
examples/iconentry.py
Normal file
30
examples/iconentry.py
Normal file
@ -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()
|
32
examples/notebook.py
Normal file
32
examples/notebook.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user