From 84c94ecabeb21541d7ef888e1b480c3b6fa72130 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Sun, 01 Jul 2007 09:25:35 +0000 Subject: Restrict palette positioning to screen height/width - 1 grid cell. --- diff --git a/shell/model/BuddyModel.py b/shell/model/BuddyModel.py index ca58531..6c134e3 100644 --- a/shell/model/BuddyModel.py +++ b/shell/model/BuddyModel.py @@ -13,6 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +import logging from sugar.presence import presenceservice from sugar.graphics.xocolor import XoColor @@ -49,6 +50,7 @@ class BuddyModel(gobject.GObject): self._pservice = presenceservice.get_instance() self._buddy = None + self._nick = None # If given just a key, try to get the buddy from the PS first if not buddy: diff --git a/shell/view/BuddyIcon.py b/shell/view/BuddyIcon.py index 8b4e414..ebd12f0 100644 --- a/shell/view/BuddyIcon.py +++ b/shell/view/BuddyIcon.py @@ -15,10 +15,11 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA from sugar.graphics.canvasicon import CanvasIcon +from sugar.graphics.palette import Palette from view.BuddyMenu import BuddyMenu class BuddyIcon(CanvasIcon): - def __init__(self, shell, menu_shell, buddy): + def __init__(self, shell, buddy): CanvasIcon.__init__(self, icon_name='theme:stock-buddy', xo_color=buddy.get_color()) @@ -28,30 +29,10 @@ class BuddyIcon(CanvasIcon): self._buddy.connect('disappeared', self._buddy_presence_change_cb) self._buddy.connect('color-changed', self._buddy_presence_change_cb) + palette = BuddyMenu(shell, buddy) + self.set_palette(palette) + def _buddy_presence_change_cb(self, buddy, color=None): # Update the icon's color when the buddy comes and goes self.props.xo_color = buddy.get_color() - def set_popup_distance(self, distance): - self._popup_distance = distance - - def get_popup(self): - menu = BuddyMenu(self._shell, self._buddy) - menu.connect('action', self._popup_action_cb) - return menu - - def get_popup_context(self): - 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() - if action == BuddyMenu.ACTION_REMOVE_FRIEND: - friends.remove(self._buddy) - - if action == BuddyMenu.ACTION_INVITE: - activity = self._shell.get_current_activity() - activity.invite(self._buddy) - elif action == BuddyMenu.ACTION_MAKE_FRIEND: - friends.make_friend(self._buddy) diff --git a/shell/view/BuddyMenu.py b/shell/view/BuddyMenu.py index 28aa163..0024e07 100644 --- a/shell/view/BuddyMenu.py +++ b/shell/view/BuddyMenu.py @@ -14,38 +14,33 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA from gettext import gettext as _ +import logging import gtk import gobject import hippo -from sugar.graphics.menu import Menu, MenuItem -from sugar.graphics.canvasicon import CanvasIcon +from sugar.graphics.palette import Palette from sugar.graphics import units from sugar.presence import presenceservice -class BuddyMenu(Menu): - ACTION_MAKE_FRIEND = 0 - ACTION_INVITE = 1 - ACTION_REMOVE_FRIEND = 2 - +class BuddyMenu(Palette): def __init__(self, shell, buddy): self._buddy = buddy self._shell = shell - Menu.__init__(self, buddy.get_nick()) - self.props.border = 0 - self.props.padding = units.points_to_pixels(5) + Palette.__init__(self, buddy.get_nick()) + pixbuf = self._get_buddy_icon_pixbuf() if pixbuf: scaled_pixbuf = pixbuf.scale_simple(units.grid_to_pixels(1), units.grid_to_pixels(1), gtk.gdk.INTERP_BILINEAR) del pixbuf - image = hippo.cairo_surface_from_gdk_pixbuf(scaled_pixbuf) - icon_item = hippo.CanvasImage(image=image) - self.add_separator() - self.append(icon_item) + image = gtk.Image() + image.set_from_pixbuf(scaled_pixbuf) + self.set_content(image) + image.show() self._buddy.connect('icon-changed', self._buddy_icon_changed_cb) self._buddy.connect('nick-changed', self._buddy_nick_changed_cb) @@ -79,13 +74,13 @@ class BuddyMenu(Menu): friends = shell_model.get_friends() if friends.has_buddy(self._buddy): - self.add_item(MenuItem(BuddyMenu.ACTION_REMOVE_FRIEND, - _('Remove friend'), - 'theme:stock-remove')) + menu_item = gtk.MenuItem(_('Remove friend')) #, 'theme:stock-remove') + menu_item.connect('activate', self._remove_friend_cb) else: - self.add_item(MenuItem(BuddyMenu.ACTION_MAKE_FRIEND, - _('Make friend'), - 'theme:stock-add')) + menu_item = gtk.MenuItem(_('Make friend')) #, 'theme:stock-add') + menu_item.connect('activate', self._make_friend_cb) + self.append_menu_item(menu_item) + menu_item.show() activity = shell_model.get_home().get_current_activity() if activity != None: @@ -93,12 +88,26 @@ class BuddyMenu(Menu): # FIXME check that the buddy is not in the activity already - self.add_item(MenuItem(BuddyMenu.ACTION_INVITE, - _('Invite'), - 'theme:stock-invite')) + menu_item = gtk.MenuItem(_('Invite')) #, 'theme:stock-invite') + menu_item.connect('activate', self._invite_cb) + self.append_menu_item(menu_item) + menu_item.show() def _buddy_icon_changed_cb(self, buddy): pass def _buddy_nick_changed_cb(self, buddy, nick): - self.set_title(nick) + self.set_primary_text(nick) + + def _make_friend_cb(self, menuitem): + friends = self._shell.get_model().get_friends() + friends.make_friend(self._buddy) + + def _remove_friend_cb(self, menuitem): + friends = self._shell.get_model().get_friends() + friends.remove(self._buddy) + + def _invite_friend_cb(self, menuitem): + activity = self._shell.get_current_activity() + activity.invite(self._buddy) + diff --git a/sugar/graphics/palette.py b/sugar/graphics/palette.py index 00a45c9..72e8af9 100644 --- a/sugar/graphics/palette.py +++ b/sugar/graphics/palette.py @@ -23,6 +23,7 @@ import time import hippo from sugar.graphics import animator +from sugar.graphics import units from sugar import _sugarext _BOTTOM_LEFT = 0 @@ -158,9 +159,11 @@ class Palette(gobject.GObject): def _in_screen(self, x, y): [width, height] = self._menu.size_request() + screen_width = gtk.gdk.screen_width() - units.grid_to_pixels(1) + screen_height = gtk.gdk.screen_height() - units.grid_to_pixels(1) - return x + width < gtk.gdk.screen_width() and \ - y + height < gtk.gdk.screen_height() and \ + return x + width <= screen_width and \ + y + height <= screen_height and \ x >= 0 and y >= 0 def _get_automatic_position(self): -- cgit v0.9.1