Implement friends removal, lots of cleanups

This commit is contained in:
Marco Pesenti Gritti
2006-09-15 15:28:18 +02:00
parent 16574cbfcc
commit f2f25f874d
9 changed files with 80 additions and 69 deletions
+4 -1
View File
@@ -88,7 +88,10 @@ class BuddyIcon(IconItem):
activity.invite(buddy)
elif action == BuddyPopup.ACTION_MAKE_FRIEND:
friends = model.get_friends()
friends.add_buddy(buddy)
friends.make_friend(buddy)
elif action == BuddyPopup.ACTION_REMOVE_FRIEND:
friends = model.get_friends()
friends.remove(buddy)
def _popdown_cb(self, friend):
if not self._hover_popup:
+15 -7
View File
@@ -9,16 +9,17 @@ from sugar.canvas.IconItem import IconItem
class BuddyPopup(gtk.Window):
ACTION_MAKE_FRIEND = 0
ACTION_INVITE = 1
ACTION_REMOVE_FRIEND = 2
__gsignals__ = {
'action': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ([int])),
}
def __init__(self, shell, friend):
def __init__(self, shell, buddy):
gtk.Window.__init__(self, gtk.WINDOW_POPUP)
self._friend = friend
self._buddy = buddy
self._hover = False
self._popdown_on_leave = False
self._width = 13
@@ -35,14 +36,14 @@ class BuddyPopup(gtk.Window):
model = goocanvas.CanvasModelSimple()
root = model.get_root_item()
color = friend.get_color()
color = buddy.get_color()
rect = goocanvas.Rect(fill_color=color.get_fill_color(),
stroke_color=color.get_stroke_color(),
line_width=3)
grid.set_constraints(rect, 0, 0, self._width, self._height)
root.add_child(rect)
text = goocanvas.Text(text=friend.get_name(), font="Sans bold 18",
text = goocanvas.Text(text=buddy.get_name(), font="Sans bold 18",
fill_color='black', anchor=gtk.ANCHOR_SW)
grid.set_constraints(text, 1, 3, self._width, self._height)
root.add_child(text)
@@ -55,9 +56,16 @@ class BuddyPopup(gtk.Window):
box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1)
grid.set_constraints(box, 0, 5)
icon = IconItem(icon_name='stock-make-friend')
icon.connect('clicked', self._action_clicked_cb,
BuddyPopup.ACTION_MAKE_FRIEND)
friends = shell.get_model().get_friends()
if friends.has_buddy(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)
box.set_constraints(icon, 3, 3)
box.add_child(icon)
+23
View File
@@ -4,7 +4,10 @@ import wnck
from sugar.canvas.Grid import Grid
from view.home.HomeWindow import HomeWindow
from sugar.presence import PresenceService
from view.ActivityHost import ActivityHost
from sugar.activity import ActivityFactory
from sugar.activity import Activity
from view.frame.Frame import Frame
from globalkeys import KeyGrabber
import sugar
@@ -71,6 +74,26 @@ class Shell(gobject.GObject):
def get_grid(self):
return self._grid
def join_activity(self, bundle_id, activity_id):
pservice = PresenceService.get_instance()
activity = self._model.get_activity(activity_id)
if activity:
activity.present()
else:
activity_ps = pservice.get_activity(activity_id)
if activity_ps:
activity = ActivityFactory.create(bundle_id)
activity.join(activity_ps.object_path())
else:
logging.error('Cannot start activity.')
def start_activity(self, activity_type):
activity = ActivityFactory.create(activity_type)
activity.execute('test', [])
return activity
def set_zoom_level(self, level):
if level == sugar.ZOOM_ACTIVITY:
self._screen.toggle_showing_desktop(False)
+2 -3
View File
@@ -5,7 +5,7 @@ from sugar.canvas.IconColor import IconColor
from sugar.canvas.CanvasBox import CanvasBox
from sugar.presence import PresenceService
from view.BuddyIcon import BuddyIcon
from model.Friends import Friend
from model.BuddyInfo import BuddyInfo
class RightPanel(CanvasBox):
def __init__(self, shell):
@@ -24,8 +24,7 @@ class RightPanel(CanvasBox):
self.__activity_changed_cb)
def add(self, buddy):
friend = Friend(buddy.get_name(), buddy.get_color())
icon = BuddyIcon(self._shell, friend)
icon = BuddyIcon(self._shell, BuddyInfo(buddy))
icon.set_popup_distance(1)
self.set_constraints(icon, 3, 3)
self.add_child(icon)
+12 -4
View File
@@ -12,6 +12,7 @@ class FriendsGroup(goocanvas.Group):
self._shell = shell
self._icon_layout = IconLayout(1200, 900)
self._friends = {}
me = MyIcon(100)
me.translate(600 - (me.get_property('size') / 2),
@@ -24,11 +25,18 @@ class FriendsGroup(goocanvas.Group):
self.add_friend(friend)
friends.connect('friend-added', self._friend_added_cb)
friends.connect('friend-removed', self._friend_removed_cb)
def add_friend(self, friend):
icon = BuddyIcon(self._shell, friend)
def add_friend(self, buddy_info):
icon = BuddyIcon(self._shell, buddy_info)
self.add_child(icon)
self._icon_layout.add_icon(icon)
def _friend_added_cb(self, data_model, friend):
self.add_friend(friend)
self._friends[buddy_info.get_name()] = icon
def _friend_added_cb(self, data_model, buddy_info):
self.add_friend(buddy_info)
def _friend_removed_cb(self, data_model, name):
self.remove_child(self._friends[name])
del self._friends[name]
+1 -1
View File
@@ -25,7 +25,7 @@ class HomeWindow(gtk.Window):
self._add_page(HomeGroup(shell))
self._add_page(FriendsGroup(shell))
self._add_page(MeshGroup())
self._add_page(MeshGroup(shell))
def _add_page(self, group):
view = CanvasView()
+4 -1
View File
@@ -32,8 +32,11 @@ class ActivityItem(IconItem):
return self._service
class MeshGroup(goocanvas.Group):
def __init__(self):
def __init__(self, shell):
goocanvas.Group.__init__(self)
self._shell = shell
self._icon_layout = IconLayout(1200, 900)
self._activities = {}