From 0bd9e8fabf740098159d94673d93cddbd3673718 Mon Sep 17 00:00:00 2001 From: Pro-Panda Date: Thu, 8 Feb 2018 17:45:15 +0530 Subject: [PATCH] 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 --- examples/alert.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/examples/alert.py b/examples/alert.py index ad11931a..f629a2ff 100644 --- a/examples/alert.py +++ b/examples/alert.py @@ -1,25 +1,33 @@ from gi.repository import Gtk from sugar3.graphics.alert import TimeoutAlert from common import set_theme + + set_theme() - - -def __start_response_cb(widget, data=None): - print 'Response: start download' - - w = Gtk.Window() w.connect("delete-event", Gtk.main_quit) - box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) w.add(box) -alert = TimeoutAlert(9) -alert.props.title = 'Download started' -alert.props.msg = 'Sugar' +# Create a TimeoutAlert Object +alert = TimeoutAlert(5) +alert.props.title = '' +alert.props.msg = '' + +# Add Timeout Object to the box 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() - Gtk.main()