#
#   Python GUI - Alert base class - Gtk
#

import gtk
from GBaseAlerts import BaseAlert as GBaseAlert

_kind_to_gtk_stock_id = {
    'stop':    gtk.STOCK_DIALOG_ERROR,
    'caution': gtk.STOCK_DIALOG_WARNING,
    'note':    gtk.STOCK_DIALOG_INFO,
    'query':   gtk.STOCK_DIALOG_QUESTION,
}

class BaseAlert(GBaseAlert):

    _left_margin = 24
    _right_margin = 24
    _top_margin = 14
    _bottom_margin = 20
    _icon_spacing = 16
    _label_button_spacing = 20
    _default_width = 380
    _default_lines = 3

    def layout(self, kind):
        gtk_stock_id = _kind_to_gtk_stock_id[kind]
        gtk_icon = gtk.image_new_from_stock(gtk_stock_id, gtk.ICON_SIZE_DIALOG)
        gtk_icon.show()
        icon_width, icon_height = gtk_icon.size_request()
        self._gtk_inner_widget.put(gtk_icon, self._left_margin, self._top_margin)
        label_left = self._left_margin + icon_width + self._icon_spacing
        if self.label.height < icon_height:
            self.label.height = icon_height
        self.place(self.label,
            left = label_left,
            top = self._top_margin)# + icon_height/4)
        #_wrap_text(self.label, self._default_width - label_left - self._right_margin)
        self.layout_buttons()
        self.shrink_wrap(padding = (self._right_margin, self._bottom_margin))


#def _wrap_text(label, label_width):
#	hard_lines = [text.split()
#		for text in label.text.split("\n")]
#	words = hard_lines[0]
#	for hard_line in hard_lines[1:]:
#		words.append("\n")
#		words.extend(hard_line)
#	font = label.font
#	space_width = font.width(" ")
#	lines = []
#	line = []
#	line_width = 0
#	for word in words:
#		word_width = font.width(word)
#		if word == "\n" or (line_width > 0
#				and line_width + space_width + word_width > label_width):
#			lines.append(line)
#			line = []
#			line_width = 0
#		if word <> "\n":
#			line.append(word)
#			if line_width > 0:
#				line_width += space_width
#			line_width += word_width
#	if line:
#		lines.append(line)
#	label.text = "\n".join([" ".join(line) for line in lines])
