def __init__(self, buddies): hippo.CanvasBox.__init__(self, xalign=hippo.ALIGNMENT_START, orientation=hippo.ORIENTATION_HORIZONTAL) for buddy in buddies: nick_, color = buddy hbox = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL) icon = CanvasIcon(icon_name='computer-xo', xo_color=XoColor(color), size=style.STANDARD_ICON_SIZE) icon.set_palette(BuddyPalette(buddy)) hbox.append(icon) self.append(hbox)
def _create_icon(self): icon = CanvasIcon(file_name=misc.get_icon_name(self._metadata)) icon.connect_after('button-release-event', self._icon_button_release_event_cb) if misc.is_activity_bundle(self._metadata): xo_color = XoColor('%s,%s' % (style.COLOR_BUTTON_GREY.get_svg(), style.COLOR_TRANSPARENT.get_svg())) else: xo_color = misc.get_icon_color(self._metadata) icon.props.xo_color = xo_color icon.set_palette(ObjectPalette(self._metadata)) return icon
class GroupBox(hippo.Canvas): __gtype_name__ = 'SugarGroupBox' def __init__(self): logging.debug('STARTUP: Loading the group view') gobject.GObject.__init__(self) self._box = hippo.CanvasBox() self._box.props.background_color = style.COLOR_WHITE.get_int() self.set_root(self._box) self._friends = {} self._layout = SpreadLayout() self._box.set_layout(self._layout) client = gconf.client_get_default() color = XoColor(client.get_string('/desktop/sugar/user/color')) self._owner_icon = CanvasIcon(icon_name='computer-xo', cache=True, xo_color=color) self._owner_icon.props.size = style.LARGE_ICON_SIZE self._owner_icon.set_palette(BuddyMenu(get_owner_instance())) self._layout.add(self._owner_icon) friends_model = friends.get_model() for friend in friends_model: self.add_friend(friend) friends_model.connect('friend-added', self._friend_added_cb) friends_model.connect('friend-removed', self._friend_removed_cb) def add_friend(self, buddy_info): icon = FriendView(buddy_info) self._layout.add(icon) self._friends[buddy_info.get_key()] = icon def _friend_added_cb(self, data_model, buddy_info): self.add_friend(buddy_info) def _friend_removed_cb(self, data_model, key): icon = self._friends[key] self._layout.remove(icon) del self._friends[key] icon.destroy() def do_size_allocate(self, allocation): width = allocation.width height = allocation.height min_w_, icon_width = self._owner_icon.get_width_request() min_h_, icon_height = self._owner_icon.get_height_request(icon_width) x = (width - icon_width) / 2 y = (height - icon_height) / 2 self._layout.move(self._owner_icon, x, y) hippo.Canvas.do_size_allocate(self, allocation)