sugar-toolkit-gtk3/shell/view/BuddyPopup.py

114 lines
2.9 KiB
Python
Raw Normal View History

2006-09-13 16:26:54 +02:00
import gtk
2006-09-14 13:03:11 +02:00
import goocanvas
2006-09-15 02:54:25 +02:00
import gobject
2006-09-13 16:26:54 +02:00
2006-09-14 15:07:22 +02:00
from sugar.canvas.CanvasView import CanvasView
2006-09-13 16:26:54 +02:00
from sugar.canvas.CanvasBox import CanvasBox
2006-09-14 13:03:11 +02:00
from sugar.canvas.IconItem import IconItem
from sugar.presence import PresenceService
2006-09-13 16:26:54 +02:00
class BuddyPopup(gtk.Window):
2006-09-15 02:54:25 +02:00
ACTION_MAKE_FRIEND = 0
2006-09-15 03:33:09 +02:00
ACTION_INVITE = 1
ACTION_REMOVE_FRIEND = 2
2006-09-15 02:54:25 +02:00
__gsignals__ = {
'action': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ([int])),
}
def __init__(self, shell, buddy):
2006-09-13 16:26:54 +02:00
gtk.Window.__init__(self, gtk.WINDOW_POPUP)
self._buddy = buddy
2006-09-14 13:03:11 +02:00
self._hover = False
self._popdown_on_leave = False
2006-09-14 15:07:22 +02:00
self._width = 13
2006-09-16 10:46:10 +02:00
self._shell = shell
self._buddy = buddy
2006-09-14 13:03:11 +02:00
grid = shell.get_grid()
2006-09-14 15:07:22 +02:00
canvas = CanvasView()
2006-09-14 13:03:11 +02:00
self.add(canvas)
canvas.show()
model = goocanvas.CanvasModelSimple()
root = model.get_root_item()
2006-09-16 10:46:10 +02:00
color = self._buddy.get_color()
2006-09-14 13:03:11 +02:00
rect = goocanvas.Rect(fill_color=color.get_fill_color(),
stroke_color=color.get_stroke_color(),
line_width=3)
root.add_child(rect)
2006-09-16 10:46:10 +02:00
text = goocanvas.Text(text=self._buddy.get_name(), font="Sans bold 18",
2006-09-14 15:07:22 +02:00
fill_color='black', anchor=gtk.ANCHOR_SW)
2006-09-16 10:46:10 +02:00
grid.set_constraints(text, 1, 3, self._width, 2)
2006-09-14 13:03:11 +02:00
root.add_child(text)
2006-09-16 10:46:10 +02:00
self._height = 4
owner = shell.get_model().get_owner()
if buddy.get_name() != owner.get_name():
self._add_actions(grid, root)
grid.set_constraints(canvas, 0, 0, self._width, self._height)
grid.set_constraints(rect, 0, 0, self._width, self._height)
canvas.set_model(model)
def _add_actions(self, grid, root):
shell_model = self._shell.get_model()
pservice = PresenceService.get_instance()
2006-09-14 13:03:11 +02:00
separator = goocanvas.Path(data='M 15 0 L 185 0', line_width=3,
fill_color='black')
2006-09-14 15:07:22 +02:00
grid.set_constraints(separator, 0, 4)
2006-09-14 13:03:11 +02:00
root.add_child(separator)
box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1)
2006-09-14 15:07:22 +02:00
grid.set_constraints(box, 0, 5)
2006-09-14 13:03:11 +02:00
friends = shell_model.get_friends()
2006-09-16 10:46:10 +02:00
if friends.has_buddy(self._buddy):
icon = IconItem(icon_name='stock-remove-friend')
icon.connect('clicked', self._action_clicked_cb,
BuddyPopup.ACTION_REMOVE_FRIEND)
else:
icon = IconItem(icon_name='stock-make-friend')
icon.connect('clicked', self._action_clicked_cb,
BuddyPopup.ACTION_MAKE_FRIEND)
2006-09-14 13:03:11 +02:00
box.set_constraints(icon, 3, 3)
box.add_child(icon)
icon = IconItem(icon_name='stock-chat')
box.set_constraints(icon, 3, 3)
box.add_child(icon)
activity = shell_model.get_current_activity()
if activity != None:
activity_ps = pservice.get_activity(activity.get_id())
# FIXME check that the buddy is not in the activity already
icon = IconItem(icon_name='stock-invite')
icon.connect('clicked', self._action_clicked_cb,
BuddyPopup.ACTION_INVITE)
box.set_constraints(icon, 3, 3)
box.add_child(icon)
2006-09-14 13:03:11 +02:00
root.add_child(box)
2006-09-16 10:46:10 +02:00
self._height = 10
2006-09-14 13:03:11 +02:00
2006-09-15 02:54:25 +02:00
def _action_clicked_cb(self, icon, action):
self.emit('action', action)
2006-09-14 13:03:11 +02:00
def get_width(self):
return self._width
def get_height(self):
return self._height