Make BuddyIcon and BuddyMenu use the new Menu.

This commit is contained in:
Tomeu Vizoso 2007-02-21 17:55:44 +01:00
parent 3fbc00f74a
commit 7be3333671
3 changed files with 35 additions and 26 deletions

View File

@ -14,12 +14,12 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from sugar.graphics.menuicon import MenuIcon from sugar.graphics.canvasicon import CanvasIcon
from view.BuddyMenu import BuddyMenu from view.BuddyMenu import BuddyMenu
class BuddyIcon(MenuIcon): class BuddyIcon(CanvasIcon):
def __init__(self, shell, menu_shell, buddy): def __init__(self, shell, menu_shell, buddy):
MenuIcon.__init__(self, menu_shell, icon_name='theme:stock-buddy', CanvasIcon.__init__(self, icon_name='theme:stock-buddy',
color=buddy.get_color()) color=buddy.get_color())
self._shell = shell self._shell = shell
@ -35,13 +35,16 @@ class BuddyIcon(MenuIcon):
def set_popup_distance(self, distance): def set_popup_distance(self, distance):
self._popup_distance = distance self._popup_distance = distance
def create_menu(self): def get_popup(self):
menu = BuddyMenu(self._shell, self._buddy) menu = BuddyMenu(self._shell, self._buddy)
menu.connect('action', self._popup_action_cb) menu.connect('action', self._popup_action_cb)
return menu return menu
def _popup_action_cb(self, popup, action): def get_popup_context(self):
self.popdown() return self._shell.get_popup_context()
def _popup_action_cb(self, popup, menu_item):
action = menu_item.props.action_id
friends = self._shell.get_model().get_friends() friends = self._shell.get_model().get_friends()
if action == BuddyMenu.ACTION_REMOVE_FRIEND: if action == BuddyMenu.ACTION_REMOVE_FRIEND:

View File

@ -13,18 +13,18 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from gettext import gettext as _
import gtk import gtk
import gobject import gobject
import hippo import hippo
from sugar.graphics.menu import Menu from sugar.graphics.menu import Menu, MenuItem
from sugar.graphics.canvasicon import CanvasIcon from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics import units
from sugar.presence import PresenceService from sugar.presence import PresenceService
import _sugar import _sugar
_ICON_SIZE = 75
class BuddyMenu(Menu): class BuddyMenu(Menu):
ACTION_MAKE_FRIEND = 0 ACTION_MAKE_FRIEND = 0
ACTION_INVITE = 1 ACTION_INVITE = 1
@ -34,25 +34,26 @@ class BuddyMenu(Menu):
self._buddy = buddy self._buddy = buddy
self._shell = shell self._shell = shell
Menu.__init__(self, buddy.get_name())
pixbuf = self._get_buddy_icon_pixbuf() pixbuf = self._get_buddy_icon_pixbuf()
if pixbuf: if pixbuf:
icon_item = hippo.CanvasImage() icon_item = hippo.CanvasImage()
scaled_pixbuf = pixbuf.scale_simple(_ICON_SIZE, _ICON_SIZE, scaled_pixbuf = pixbuf.scale_simple(units.grid_to_pixels(1),
units.grid_to_pixels(1),
gtk.gdk.INTERP_BILINEAR) gtk.gdk.INTERP_BILINEAR)
del pixbuf del pixbuf
Menu.__init__(self, buddy.get_name(), icon_item) self.add_separator()
self.append(icon_item)
# FIXME: have to set the image _after_ adding the HippoCanvasImage # FIXME: have to set the image _after_ adding the HippoCanvasImage
# to it's parent item, because that sets the HippoCanvasImage's context, # to it's parent item, because that sets the HippoCanvasImage's context,
# which resets the object's 'image' property. Grr. # which resets the object's 'image' property. Grr.
_sugar.hippo_canvas_image_set_image_from_gdk_pixbuf(icon_item, scaled_pixbuf) _sugar.hippo_canvas_image_set_image_from_gdk_pixbuf(icon_item, scaled_pixbuf)
else:
Menu.__init__(self, buddy.get_name(), None)
self._buddy.connect('icon-changed', self.__buddy_icon_changed_cb) self._buddy.connect('icon-changed', self.__buddy_icon_changed_cb)
owner = shell.get_model().get_owner() owner = shell.get_model().get_owner()
if buddy.get_name() != owner.get_name(): if buddy.get_name() != owner.get_name():
self._add_actions() self._add_items()
def _get_buddy_icon_pixbuf(self): def _get_buddy_icon_pixbuf(self):
buddy_object = self._buddy.get_buddy() buddy_object = self._buddy.get_buddy()
@ -76,17 +77,19 @@ class BuddyMenu(Menu):
del pbl del pbl
return pixbuf return pixbuf
def _add_actions(self): def _add_items(self):
shell_model = self._shell.get_model() shell_model = self._shell.get_model()
pservice = PresenceService.get_instance() pservice = PresenceService.get_instance()
friends = shell_model.get_friends() friends = shell_model.get_friends()
if friends.has_buddy(self._buddy): if friends.has_buddy(self._buddy):
icon = CanvasIcon(icon_name='theme:stock-remove') self.add_item(MenuItem(BuddyMenu.ACTION_REMOVE_FRIEND,
self.add_action(icon, BuddyMenu.ACTION_REMOVE_FRIEND) _('Remove friend'),
'theme:stock-remove'))
else: else:
icon = CanvasIcon(icon_name='theme:stock-add') self.add_item(MenuItem(BuddyMenu.ACTION_MAKE_FRIEND,
self.add_action(icon, BuddyMenu.ACTION_MAKE_FRIEND) _('Make friend'),
'theme:stock-add'))
activity = shell_model.get_home().get_current_activity() activity = shell_model.get_home().get_current_activity()
if activity != None: if activity != None:
@ -94,9 +97,9 @@ class BuddyMenu(Menu):
# FIXME check that the buddy is not in the activity already # FIXME check that the buddy is not in the activity already
icon = CanvasIcon(icon_name='theme:stock-invite') self.add_item(MenuItem(BuddyMenu.ACTION_INVITE,
self.add_action(icon, BuddyMenu.ACTION_INVITE) _('Invite'),
'theme:stock-invite'))
def __buddy_icon_changed_cb(self, buddy): def __buddy_icon_changed_cb(self, buddy):
pass pass

View File

@ -52,8 +52,7 @@ class MenuItem(hippo.CanvasBox):
icon.props.color = icon_color icon.props.color = icon_color
self.append(icon) self.append(icon)
self._canvas_text = hippo.CanvasText() self._canvas_text = hippo.CanvasText(text=label)
self._canvas_text.props.text = label
self._canvas_text.props.color = color.LABEL_TEXT.get_int() self._canvas_text.props.color = color.LABEL_TEXT.get_int()
self._canvas_text.props.font_desc = font.DEFAULT.get_pango_desc() self._canvas_text.props.font_desc = font.DEFAULT.get_pango_desc()
self.append(self._canvas_text) self.append(self._canvas_text)
@ -89,7 +88,11 @@ class Menu(Popup):
self.props.border = units.points_to_pixels(1) self.props.border = units.points_to_pixels(1)
if title: if title:
pass title_item = hippo.CanvasText(text=title)
title_item.props.color = color.LABEL_TEXT.get_int()
title_item.props.font_desc = font.DEFAULT.get_pango_desc()
self.append(title_item)
self.add_separator()
def add_item(self, item): def add_item(self, item):
item.connect('button-press-event', self._item_button_press_event_cb) item.connect('button-press-event', self._item_button_press_event_cb)