diff --git a/shell/home/FriendsModel.py b/shell/home/FriendsModel.py index 0df084c5..791aa815 100644 --- a/shell/home/FriendsModel.py +++ b/shell/home/FriendsModel.py @@ -2,6 +2,7 @@ import gobject from sugar.presence import PresenceService from sugar.canvas.IconColor import IconColor +import logging class Friend: def __init__(self, buddy): @@ -11,8 +12,13 @@ class Friend: return self._buddy.get_name() def get_color(self): - color = self._buddy.get_color() - return IconColor(color) + color = self._buddy.get_color() + try: + icolor = IconColor(color) + except RuntimeError: + icolor = IconColor() + logging.info("Buddy %s doesn't have an allowed color; using a random color instead." % self.get_name()) + return icolor class FriendsModel(gobject.GObject): __gsignals__ = { diff --git a/sugar/canvas/IconColor.py b/sugar/canvas/IconColor.py index 6329c8ff..48522e65 100644 --- a/sugar/canvas/IconColor.py +++ b/sugar/canvas/IconColor.py @@ -109,7 +109,13 @@ class IconColor: if fill_color == None: n = int(random.random() * (len(self.__colors_dict) - 1)) fill_color = self.__colors_dict.keys()[n] - + else: + if fill_color[0] == '#': + fill_color = fill_color.upper() + else: + fill_color = fill_color.lower() + if not self.__colors_dict.has_key(fill_color): + raise RuntimeError("Specified fill color %s is not allowed." % fill_color) self._fill_color = fill_color def get_stroke_color(self):