Move the menu to hippo canvas
This commit is contained in:
parent
9fd16ddd21
commit
0cd31b900a
@ -1,9 +1,11 @@
|
|||||||
from sugar.canvas.Menu import Menu
|
import gtk
|
||||||
from sugar.canvas.IconItem import IconItem
|
import gobject
|
||||||
from sugar.presence import PresenceService
|
|
||||||
import gtk, gobject
|
|
||||||
import goocanvas
|
import goocanvas
|
||||||
|
|
||||||
|
from sugar.graphics.menu import Menu
|
||||||
|
from sugar.graphics.canvasicon import CanvasIcon
|
||||||
|
from sugar.presence import PresenceService
|
||||||
|
|
||||||
_ICON_SIZE = 75
|
_ICON_SIZE = 75
|
||||||
|
|
||||||
class BuddyMenu(Menu):
|
class BuddyMenu(Menu):
|
||||||
@ -12,12 +14,21 @@ class BuddyMenu(Menu):
|
|||||||
ACTION_REMOVE_FRIEND = 2
|
ACTION_REMOVE_FRIEND = 2
|
||||||
|
|
||||||
def __init__(self, shell, buddy):
|
def __init__(self, shell, buddy):
|
||||||
Menu.__init__(self, shell.get_grid(), buddy.get_name())
|
|
||||||
|
|
||||||
self._buddy = buddy
|
self._buddy = buddy
|
||||||
self._buddy.connect('icon-changed', self.__buddy_icon_changed_cb)
|
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
|
|
||||||
|
icon_item = None
|
||||||
|
pixbuf = self._get_buddy_icon_pixbuf()
|
||||||
|
if pixbuf:
|
||||||
|
scaled_pixbuf = pixbuf.scale_simple(_ICON_SIZE, _ICON_SIZE,
|
||||||
|
gtk.gdk.INTERP_BILINEAR)
|
||||||
|
del pixbuf
|
||||||
|
icon_item = hippo.Image(pixbuf=scaled_pixbuf)
|
||||||
|
|
||||||
|
Menu.__init__(self, buddy.get_name(), icon_item)
|
||||||
|
|
||||||
|
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_actions()
|
||||||
@ -48,20 +59,12 @@ class BuddyMenu(Menu):
|
|||||||
shell_model = self._shell.get_model()
|
shell_model = self._shell.get_model()
|
||||||
pservice = PresenceService.get_instance()
|
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()
|
friends = shell_model.get_friends()
|
||||||
if friends.has_buddy(self._buddy):
|
if friends.has_buddy(self._buddy):
|
||||||
icon = IconItem(icon_name='stock-remove')
|
icon = CanvasIcon(icon_name='stock-remove')
|
||||||
self.add_action(icon, BuddyMenu.ACTION_REMOVE_FRIEND)
|
self.add_action(icon, BuddyMenu.ACTION_REMOVE_FRIEND)
|
||||||
else:
|
else:
|
||||||
icon = IconItem(icon_name='stock-add')
|
icon = CanvasIcon(icon_name='stock-add')
|
||||||
self.add_action(icon, BuddyMenu.ACTION_MAKE_FRIEND)
|
self.add_action(icon, BuddyMenu.ACTION_MAKE_FRIEND)
|
||||||
|
|
||||||
activity_id = shell_model.get_current_activity()
|
activity_id = shell_model.get_current_activity()
|
||||||
|
@ -1,95 +0,0 @@
|
|||||||
import gtk
|
|
||||||
import goocanvas
|
|
||||||
import gobject
|
|
||||||
|
|
||||||
from sugar.canvas.CanvasView import CanvasView
|
|
||||||
from sugar.canvas.CanvasBox import CanvasBox
|
|
||||||
from sugar.canvas.IconItem import IconItem
|
|
||||||
|
|
||||||
class Menu(gtk.Window):
|
|
||||||
__gsignals__ = {
|
|
||||||
'action': (gobject.SIGNAL_RUN_FIRST,
|
|
||||||
gobject.TYPE_NONE, ([int])),
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, grid, title):
|
|
||||||
gtk.Window.__init__(self, gtk.WINDOW_POPUP)
|
|
||||||
|
|
||||||
self._width = 15
|
|
||||||
self._height = 3
|
|
||||||
self._grid = grid
|
|
||||||
self._action_box = None
|
|
||||||
|
|
||||||
self._canvas = CanvasView()
|
|
||||||
self.add(self._canvas)
|
|
||||||
self._canvas.show()
|
|
||||||
|
|
||||||
model = goocanvas.CanvasModelSimple()
|
|
||||||
self._root = model.get_root_item()
|
|
||||||
|
|
||||||
self._rect = goocanvas.Rect(fill_color='black', line_width=0)
|
|
||||||
self._root.add_child(self._rect)
|
|
||||||
|
|
||||||
text = goocanvas.Text(text=title, font="Sans bold 18",
|
|
||||||
fill_color='white', anchor=gtk.ANCHOR_SW)
|
|
||||||
self._grid.set_constraints(text, 1, self._height, self._width, 2)
|
|
||||||
self._root.add_child(text)
|
|
||||||
self._height += 1
|
|
||||||
|
|
||||||
self._update_constraints()
|
|
||||||
|
|
||||||
self._canvas.set_model(model)
|
|
||||||
|
|
||||||
def _create_action_box(self):
|
|
||||||
separator = goocanvas.Path(data='M 15 0 L 215 0', line_width=3,
|
|
||||||
stroke_color='white')
|
|
||||||
self._grid.set_constraints(separator, 0, self._height)
|
|
||||||
self._root.add_child(separator)
|
|
||||||
self._height += 1
|
|
||||||
|
|
||||||
box = CanvasBox(self._grid, CanvasBox.HORIZONTAL)
|
|
||||||
self._grid.set_constraints(box, 0, self._height)
|
|
||||||
self._height += 5
|
|
||||||
|
|
||||||
return box
|
|
||||||
|
|
||||||
def get_grid(self):
|
|
||||||
return self._grid
|
|
||||||
|
|
||||||
def add_image(self, image_item, width, height):
|
|
||||||
"""width & height in grid units"""
|
|
||||||
separator = goocanvas.Path(data='M 15 0 L 215 0', line_width=3,
|
|
||||||
stroke_color='white')
|
|
||||||
self._grid.set_constraints(separator, 0, self._height)
|
|
||||||
self._root.add_child(separator)
|
|
||||||
self._height += 1
|
|
||||||
|
|
||||||
self._grid.set_constraints(image_item, x=5, y=self._height, width=width, height=height)
|
|
||||||
self._root.add_child(image_item)
|
|
||||||
self._height += height + 1
|
|
||||||
self._update_constraints()
|
|
||||||
|
|
||||||
def add_action(self, icon, action_id):
|
|
||||||
if self._action_box == None:
|
|
||||||
self._action_box = self._create_action_box()
|
|
||||||
self._root.add_child(self._action_box)
|
|
||||||
self._update_constraints()
|
|
||||||
|
|
||||||
icon.connect('clicked', self._action_clicked_cb, action_id)
|
|
||||||
self._action_box.set_constraints(icon, 5, 5)
|
|
||||||
self._action_box.add_child(icon)
|
|
||||||
|
|
||||||
def _action_clicked_cb(self, icon, action):
|
|
||||||
self.emit('action', action)
|
|
||||||
|
|
||||||
def _update_constraints(self):
|
|
||||||
self._grid.set_constraints(self._canvas, 0, 0,
|
|
||||||
self._width, self._height)
|
|
||||||
self._grid.set_constraints(self._rect, 0, 0,
|
|
||||||
self._width, self._height)
|
|
||||||
|
|
||||||
def get_width(self):
|
|
||||||
return self._width
|
|
||||||
|
|
||||||
def get_height(self):
|
|
||||||
return self._height
|
|
Loading…
Reference in New Issue
Block a user