1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
import gtk
class Alert:
def __init__(self, icontype, buttons, primary, secondary):
self.buttons = buttons
alert = gtk.Dialog()
for i in range(len(buttons)):
alert.add_button(buttons[i][0], i)
alert.set_default_response(len(buttons) - 1)
alert.connect("response", self.response)
icon = gtk.Image()
icon.set_from_stock(icontype, gtk.ICON_SIZE_DIALOG)
icon.show()
label = gtk.Label()
label.set_markup('<span weight="bold" size="larger">' +
primary +
'</span>\n\n' +
secondary)
label.show()
hbox = gtk.HBox()
hbox.pack_start(icon)
hbox.pack_start(label)
hbox.show()
alert.vbox.pack_start(hbox)
alert.set_property("title", u"")
alert.set_property("border-width", 6)
# alert.set_property("type", u"")
alert.set_property("resizable", gtk.FALSE)
alert.set_property("has-separator", gtk.FALSE)
alert.vbox.set_property("spacing", 12)
hbox.set_property("spacing", 12)
hbox.set_property("border-width", 6)
icon.set_property("yalign", 0.0)
label.set_property("selectable", gtk.TRUE)
label.set_property("use-markup", gtk.TRUE)
label.set_property("wrap", gtk.TRUE)
label.set_property("yalign", 0.0)
alert.show()
def response(self, dialog, response_id):
dialog.destroy()
tuple = self.buttons[response_id]
if len(tuple) == 2:
tuple[1]()
|