<commit_before>from sugar.canvas.Menu import Menu
from sugar.canvas.IconItem import IconItem
from sugar.presence import PresenceService
import gtk
import goocanvas

_ICON_SIZE = 75

class BuddyMenu(Menu):
	ACTION_MAKE_FRIEND = 0
	ACTION_INVITE = 1
	ACTION_REMOVE_FRIEND = 2

	def __init__(self, shell, buddy):
		Menu.__init__(self, shell.get_grid(), buddy.get_name())

		self._buddy = buddy
		self._buddy.connect('icon-changed', self.__buddy_icon_changed_cb)
		self._shell = shell

		owner = shell.get_model().get_owner()
		if buddy.get_name() != owner.get_name():
			self._add_actions()

	def _get_buddy_icon_pixbuf(self):
		buddy_object = self._buddy.get_buddy()
		if not buddy_object:
			return None
		icon_data = buddy_object.get_icon()
		icon_data_string = ""
		for item in icon_data:
			if item < 0:
				item = item + 128
			icon_data_string = icon_data_string + chr(item)
		pbl = gtk.gdk.PixbufLoader()
		pbl.write(icon_data_string)
		pbl.close()
		pixbuf = pbl.get_pixbuf()
		del pbl
		return pixbuf

	def _add_actions(self):
		shell_model = self._shell.get_model()
		pservice = PresenceService.get_instance()

		pixbuf = self._get_buddy_icon_pixbuf()
		if pixbuf:
			scaled_pixbuf = pixbuf.scale_simple(_ICON_SIZE, _ICON_SIZE, gtk.gdk.INTERP_BILINEAR)
			del pixbuf
			self._buddy_icon_item = goocanvas.Image()
			self._buddy_icon_item.set_property('pixbuf', scaled_pixbuf)
			self.add_image(self._buddy_icon_item, 5, 5)

		friends = shell_model.get_friends()
		if friends.has_buddy(self._buddy):
			icon = IconItem(icon_name='stock-remove')
			self.add_action(icon, BuddyMenu.ACTION_REMOVE_FRIEND) 
		else:
			icon = IconItem(icon_name='stock-add')<commit_msg>Don't traceback on unknown image formats<commit_after>from sugar.canvas.Menu import Menu
from sugar.canvas.IconItem import IconItem
from sugar.presence import PresenceService
import gtk
import goocanvas

_ICON_SIZE = 75

class BuddyMenu(Menu):
	ACTION_MAKE_FRIEND = 0
	ACTION_INVITE = 1
	ACTION_REMOVE_FRIEND = 2

	def __init__(self, shell, buddy):
		Menu.__init__(self, shell.get_grid(), buddy.get_name())

		self._buddy = buddy
		self._buddy.connect('icon-changed', self.__buddy_icon_changed_cb)
		self._shell = shell

		owner = shell.get_model().get_owner()
		if buddy.get_name() != owner.get_name():
			self._add_actions()

	def _get_buddy_icon_pixbuf(self):
		buddy_object = self._buddy.get_buddy()
		if not buddy_object:
			return None

		pixbuf = None
		icon_data = buddy_object.get_icon()
		icon_data_string = ""
		for item in icon_data:
			if item < 0:
				item = item + 128
			icon_data_string += chr(item)
		pbl = gtk.gdk.PixbufLoader()
		pbl.write(icon_data_string)
		try:
			pbl.close()
			pixbuf = pbl.get_pixbuf()
		except gobject.GError:
			pass
		del pbl
		return pixbuf

	def _add_actions(self):
		shell_model = self._shell.get_model()
		pservice = PresenceService.get_instance()

		pixbuf = self._get_buddy_icon_pixbuf()
		if pixbuf:
			scaled_pixbuf = pixbuf.scale_simple(_ICON_SIZE, _ICON_SIZE, gtk.gdk.INTERP_BILINEAR)
			del pixbuf
			self._buddy_icon_item = goocanvas.Image()
			self._buddy_icon_item.set_property('pixbuf', scaled_pixbuf)
			self.add_image(self._buddy_icon_item, 5, 5)

		friends = shell_model.get_friends()
		if friends.has_buddy(self._buddy):
			icon = IconItem(icon_name='stock-remove')
			self.add_action(icon, BuddyMenu.ACTION_REMOVE_FRIEND) 
		else:
			icon = IconItem(icon_name='stock-add')
{'fraction_non_alphanumeric': 0.10416666666666667, 'fraction_numerical': 0.006455399061032864, 'mean_word_length': 4.625412541254126, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4191836', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1271, 'n_words': 237}