Update example to explain various response states
- As a part of #379, which fixed the Response sent on Timeout by TimeoutAlert and NotifyAlert modified: examples/alert.py
This commit is contained in:
parent
af31aa8059
commit
0bd9e8fabf
@ -1,25 +1,33 @@
|
|||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
from sugar3.graphics.alert import TimeoutAlert
|
from sugar3.graphics.alert import TimeoutAlert
|
||||||
from common import set_theme
|
from common import set_theme
|
||||||
|
|
||||||
|
|
||||||
set_theme()
|
set_theme()
|
||||||
|
|
||||||
|
|
||||||
def __start_response_cb(widget, data=None):
|
|
||||||
print 'Response: start download'
|
|
||||||
|
|
||||||
|
|
||||||
w = Gtk.Window()
|
w = Gtk.Window()
|
||||||
w.connect("delete-event", Gtk.main_quit)
|
w.connect("delete-event", Gtk.main_quit)
|
||||||
|
|
||||||
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||||
w.add(box)
|
w.add(box)
|
||||||
|
|
||||||
alert = TimeoutAlert(9)
|
# Create a TimeoutAlert Object
|
||||||
alert.props.title = 'Download started'
|
alert = TimeoutAlert(5)
|
||||||
alert.props.msg = 'Sugar'
|
alert.props.title = '<Alert Title>'
|
||||||
|
alert.props.msg = '<Alert Message>'
|
||||||
|
|
||||||
|
# Add Timeout Object to the box
|
||||||
box.pack_start(alert, False, False, 0)
|
box.pack_start(alert, False, False, 0)
|
||||||
alert.connect('response', __start_response_cb)
|
|
||||||
|
|
||||||
|
|
||||||
|
# Called when an alert object throws a response event.
|
||||||
|
def __alert_response_cb(alert, response_id):
|
||||||
|
if response_id is Gtk.ResponseType.OK:
|
||||||
|
print 'Continue Button was clicked.'
|
||||||
|
elif response_id is Gtk.ResponseType.CANCEL:
|
||||||
|
print 'Cancel Button was clicked.'
|
||||||
|
elif response_id == -1:
|
||||||
|
print 'Timeout occurred'
|
||||||
|
|
||||||
|
|
||||||
|
alert.connect('response', __alert_response_cb)
|
||||||
w.show_all()
|
w.show_all()
|
||||||
|
|
||||||
Gtk.main()
|
Gtk.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user