Replace the hippo-based TimeoutIcon with one based on a gtk.Label and gtk.Alignment

This patch depends on the addition of the SugarTimeoutIcon
to the artwork where we set the font and background color.

Signed-off-by: Simon Schampijer <simon@laptop.org>
Reviewed-by: Benjamin Berg <benzea@sugarlabs.org>
This commit is contained in:
Simon Schampijer 2011-08-11 17:57:40 +02:00
parent 4018265f6c
commit 17ec110798

View File

@ -49,7 +49,7 @@ import gettext
import gtk import gtk
import gobject import gobject
import hippo import pango
import math import math
from sugar.graphics import style from sugar.graphics import style
@ -338,27 +338,43 @@ class ErrorAlert(Alert):
icon.show() icon.show()
class _TimeoutIcon(hippo.CanvasText, hippo.CanvasItem): class _TimeoutIcon(gtk.Alignment):
"""An icon with a round border""" __gtype_name__ = 'SugarTimeoutIcon'
__gtype_name__ = 'AlertTimeoutIcon'
def __init__(self, **kwargs): def __init__(self):
hippo.CanvasText.__init__(self, **kwargs) gtk.Alignment.__init__(self, 0, 0, 1, 1)
self.set_app_paintable(True)
self._text = gtk.Label()
self._text.set_alignment(0.5, 0.5)
attrlist = pango.AttrList()
attrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD))
self._text.set_attributes(attrlist)
self.add(self._text)
self._text.show()
self.connect("expose_event", self.__expose_cb)
self.props.orientation = hippo.ORIENTATION_HORIZONTAL def __expose_cb(self, widget, event):
self.props.border_left = style.DEFAULT_SPACING context = widget.window.cairo_create()
self.props.border_right = style.DEFAULT_SPACING self._draw(context)
return False
def do_paint_background(self, cr, damaged_box): def do_size_request(self, requisition):
[width, height] = self.get_allocation() requisition.height, requisition.width = \
gtk.icon_size_lookup(gtk.ICON_SIZE_BUTTON)
self._text.size_request()
xval = width * 0.5 def _draw(self, context):
yval = height * 0.5 rect = self.get_allocation()
radius = min(width * 0.5, height * 0.5) x = rect.x + rect.width * 0.5
y = rect.y + rect.height * 0.5
radius = rect.width / 2
context.arc(x, y, radius, 0, 2 * math.pi)
widget_style = self.get_style()
context.set_source_color(widget_style.bg[self.get_state()])
context.fill_preserve()
hippo.cairo_set_source_rgba32(cr, self.props.background_color) def set_text(self, text):
cr.arc(xval, yval, radius, 0, 2 * math.pi) self._text.set_text(str(text))
cr.fill_preserve()
class TimeoutAlert(Alert): class TimeoutAlert(Alert):
@ -412,20 +428,16 @@ class TimeoutAlert(Alert):
self.add_button(gtk.RESPONSE_CANCEL, _('Cancel'), icon) self.add_button(gtk.RESPONSE_CANCEL, _('Cancel'), icon)
icon.show() icon.show()
self._timeout_text = _TimeoutIcon( self._timeout_text = _TimeoutIcon()
text=self._timeout, self._timeout_text.set_text(self._timeout)
color=style.COLOR_BUTTON_GREY.get_int(), self.add_button(gtk.RESPONSE_OK, _('Continue'), self._timeout_text)
background_color=style.COLOR_WHITE.get_int()) self._timeout_text.show()
canvas = hippo.Canvas()
canvas.set_root(self._timeout_text)
canvas.show()
self.add_button(gtk.RESPONSE_OK, _('Continue'), canvas)
gobject.timeout_add_seconds(1, self.__timeout) gobject.timeout_add_seconds(1, self.__timeout)
def __timeout(self): def __timeout(self):
self._timeout -= 1 self._timeout -= 1
self._timeout_text.props.text = self._timeout self._timeout_text.set_text(self._timeout)
if self._timeout == 0: if self._timeout == 0:
self._response(gtk.RESPONSE_OK) self._response(gtk.RESPONSE_OK)
return False return False
@ -461,20 +473,16 @@ class NotifyAlert(Alert):
self._timeout = timeout self._timeout = timeout
self._timeout_text = _TimeoutIcon( self._timeout_text = _TimeoutIcon()
text=self._timeout, self._timeout_text.set_text(self._timeout)
color=style.COLOR_BUTTON_GREY.get_int(), self.add_button(gtk.RESPONSE_OK, _('Ok'), self._timeout_text)
background_color=style.COLOR_WHITE.get_int()) self._timeout_text.show()
canvas = hippo.Canvas()
canvas.set_root(self._timeout_text)
canvas.show()
self.add_button(gtk.RESPONSE_OK, _('Ok'), canvas)
gobject.timeout_add(1000, self.__timeout) gobject.timeout_add(1000, self.__timeout)
def __timeout(self): def __timeout(self):
self._timeout -= 1 self._timeout -= 1
self._timeout_text.props.text = self._timeout self._timeout_text.set_text(self._timeout)
if self._timeout == 0: if self._timeout == 0:
self._response(gtk.RESPONSE_OK) self._response(gtk.RESPONSE_OK)
return False return False