Restrict palette positioning to screen height/width - 1 grid cell.
This commit is contained in:
parent
3ca87cd46d
commit
84c94ecabe
@ -13,6 +13,7 @@
|
|||||||
# 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
|
||||||
|
import logging
|
||||||
|
|
||||||
from sugar.presence import presenceservice
|
from sugar.presence import presenceservice
|
||||||
from sugar.graphics.xocolor import XoColor
|
from sugar.graphics.xocolor import XoColor
|
||||||
@ -49,6 +50,7 @@ class BuddyModel(gobject.GObject):
|
|||||||
self._pservice = presenceservice.get_instance()
|
self._pservice = presenceservice.get_instance()
|
||||||
|
|
||||||
self._buddy = None
|
self._buddy = None
|
||||||
|
self._nick = None
|
||||||
|
|
||||||
# If given just a key, try to get the buddy from the PS first
|
# If given just a key, try to get the buddy from the PS first
|
||||||
if not buddy:
|
if not buddy:
|
||||||
|
@ -15,10 +15,11 @@
|
|||||||
# 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.canvasicon import CanvasIcon
|
from sugar.graphics.canvasicon import CanvasIcon
|
||||||
|
from sugar.graphics.palette import Palette
|
||||||
from view.BuddyMenu import BuddyMenu
|
from view.BuddyMenu import BuddyMenu
|
||||||
|
|
||||||
class BuddyIcon(CanvasIcon):
|
class BuddyIcon(CanvasIcon):
|
||||||
def __init__(self, shell, menu_shell, buddy):
|
def __init__(self, shell, buddy):
|
||||||
CanvasIcon.__init__(self, icon_name='theme:stock-buddy',
|
CanvasIcon.__init__(self, icon_name='theme:stock-buddy',
|
||||||
xo_color=buddy.get_color())
|
xo_color=buddy.get_color())
|
||||||
|
|
||||||
@ -28,30 +29,10 @@ class BuddyIcon(CanvasIcon):
|
|||||||
self._buddy.connect('disappeared', self._buddy_presence_change_cb)
|
self._buddy.connect('disappeared', self._buddy_presence_change_cb)
|
||||||
self._buddy.connect('color-changed', 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):
|
def _buddy_presence_change_cb(self, buddy, color=None):
|
||||||
# Update the icon's color when the buddy comes and goes
|
# Update the icon's color when the buddy comes and goes
|
||||||
self.props.xo_color = buddy.get_color()
|
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)
|
|
||||||
|
@ -14,38 +14,33 @@
|
|||||||
# 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 _
|
from gettext import gettext as _
|
||||||
|
import logging
|
||||||
|
|
||||||
import gtk
|
import gtk
|
||||||
import gobject
|
import gobject
|
||||||
import hippo
|
import hippo
|
||||||
|
|
||||||
from sugar.graphics.menu import Menu, MenuItem
|
from sugar.graphics.palette import Palette
|
||||||
from sugar.graphics.canvasicon import CanvasIcon
|
|
||||||
from sugar.graphics import units
|
from sugar.graphics import units
|
||||||
from sugar.presence import presenceservice
|
from sugar.presence import presenceservice
|
||||||
|
|
||||||
class BuddyMenu(Menu):
|
class BuddyMenu(Palette):
|
||||||
ACTION_MAKE_FRIEND = 0
|
|
||||||
ACTION_INVITE = 1
|
|
||||||
ACTION_REMOVE_FRIEND = 2
|
|
||||||
|
|
||||||
def __init__(self, shell, buddy):
|
def __init__(self, shell, buddy):
|
||||||
self._buddy = buddy
|
self._buddy = buddy
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
|
|
||||||
Menu.__init__(self, buddy.get_nick())
|
Palette.__init__(self, buddy.get_nick())
|
||||||
self.props.border = 0
|
|
||||||
self.props.padding = units.points_to_pixels(5)
|
|
||||||
pixbuf = self._get_buddy_icon_pixbuf()
|
pixbuf = self._get_buddy_icon_pixbuf()
|
||||||
if pixbuf:
|
if pixbuf:
|
||||||
scaled_pixbuf = pixbuf.scale_simple(units.grid_to_pixels(1),
|
scaled_pixbuf = pixbuf.scale_simple(units.grid_to_pixels(1),
|
||||||
units.grid_to_pixels(1),
|
units.grid_to_pixels(1),
|
||||||
gtk.gdk.INTERP_BILINEAR)
|
gtk.gdk.INTERP_BILINEAR)
|
||||||
del pixbuf
|
del pixbuf
|
||||||
image = hippo.cairo_surface_from_gdk_pixbuf(scaled_pixbuf)
|
image = gtk.Image()
|
||||||
icon_item = hippo.CanvasImage(image=image)
|
image.set_from_pixbuf(scaled_pixbuf)
|
||||||
self.add_separator()
|
self.set_content(image)
|
||||||
self.append(icon_item)
|
image.show()
|
||||||
|
|
||||||
self._buddy.connect('icon-changed', self._buddy_icon_changed_cb)
|
self._buddy.connect('icon-changed', self._buddy_icon_changed_cb)
|
||||||
self._buddy.connect('nick-changed', self._buddy_nick_changed_cb)
|
self._buddy.connect('nick-changed', self._buddy_nick_changed_cb)
|
||||||
@ -79,13 +74,13 @@ class BuddyMenu(Menu):
|
|||||||
|
|
||||||
friends = shell_model.get_friends()
|
friends = shell_model.get_friends()
|
||||||
if friends.has_buddy(self._buddy):
|
if friends.has_buddy(self._buddy):
|
||||||
self.add_item(MenuItem(BuddyMenu.ACTION_REMOVE_FRIEND,
|
menu_item = gtk.MenuItem(_('Remove friend')) #, 'theme:stock-remove')
|
||||||
_('Remove friend'),
|
menu_item.connect('activate', self._remove_friend_cb)
|
||||||
'theme:stock-remove'))
|
|
||||||
else:
|
else:
|
||||||
self.add_item(MenuItem(BuddyMenu.ACTION_MAKE_FRIEND,
|
menu_item = gtk.MenuItem(_('Make friend')) #, 'theme:stock-add')
|
||||||
_('Make friend'),
|
menu_item.connect('activate', self._make_friend_cb)
|
||||||
'theme:stock-add'))
|
self.append_menu_item(menu_item)
|
||||||
|
menu_item.show()
|
||||||
|
|
||||||
activity = shell_model.get_home().get_current_activity()
|
activity = shell_model.get_home().get_current_activity()
|
||||||
if activity != None:
|
if activity != None:
|
||||||
@ -93,12 +88,26 @@ 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
|
||||||
|
|
||||||
self.add_item(MenuItem(BuddyMenu.ACTION_INVITE,
|
menu_item = gtk.MenuItem(_('Invite')) #, 'theme:stock-invite')
|
||||||
_('Invite'),
|
menu_item.connect('activate', self._invite_cb)
|
||||||
'theme:stock-invite'))
|
self.append_menu_item(menu_item)
|
||||||
|
menu_item.show()
|
||||||
|
|
||||||
def _buddy_icon_changed_cb(self, buddy):
|
def _buddy_icon_changed_cb(self, buddy):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _buddy_nick_changed_cb(self, buddy, nick):
|
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)
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import time
|
|||||||
import hippo
|
import hippo
|
||||||
|
|
||||||
from sugar.graphics import animator
|
from sugar.graphics import animator
|
||||||
|
from sugar.graphics import units
|
||||||
from sugar import _sugarext
|
from sugar import _sugarext
|
||||||
|
|
||||||
_BOTTOM_LEFT = 0
|
_BOTTOM_LEFT = 0
|
||||||
@ -158,9 +159,11 @@ class Palette(gobject.GObject):
|
|||||||
|
|
||||||
def _in_screen(self, x, y):
|
def _in_screen(self, x, y):
|
||||||
[width, height] = self._menu.size_request()
|
[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 \
|
return x + width <= screen_width and \
|
||||||
y + height < gtk.gdk.screen_height() and \
|
y + height <= screen_height and \
|
||||||
x >= 0 and y >= 0
|
x >= 0 and y >= 0
|
||||||
|
|
||||||
def _get_automatic_position(self):
|
def _get_automatic_position(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user