/usr/share/sugar/activities/Connect.activity/buddiespanel.py is in sugar-connect-activity 22-1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | # Copyright 2007 One Laptop Per Child
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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 gtk
import hippo
import logging
from sugar.graphics.icon import CanvasIcon
from sugar.graphics.xocolor import XoColor
from sugar.graphics import style
logger = logging.getLogger('connect-activity.buddiespanel')
class BuddiesPanel(hippo.CanvasBox):
def __init__(self):
hippo.CanvasBox.__init__(self, spacing=4, padding=5,
orientation=hippo.ORIENTATION_VERTICAL)
self.players_box = hippo.CanvasBox(spacing=4, padding=5,
orientation=hippo.ORIENTATION_VERTICAL)
self.watchers_box = hippo.CanvasBox(spacing=4, padding=5,
orientation=hippo.ORIENTATION_VERTICAL)
self.append(self.players_box)
self.append(hippo.CanvasWidget(widget=gtk.HSeparator()))
self.append(self.watchers_box, hippo.PACK_EXPAND)
self.players = {}
self.watchers = {}
def _create_buddy_vbox (self, buddy):
buddy_color = buddy.props.color
if not buddy_color:
buddy_color = "#000000,#ffffff"
icon = CanvasIcon(
icon_name='computer-xo',
xo_color=XoColor(buddy_color))
nick = buddy.props.nick
if not nick:
nick = ""
name = hippo.CanvasText(text=nick, color=style.COLOR_WHITE.get_int())
vbox = hippo.CanvasBox(padding=5)
vbox.append(icon)
vbox.append(name)
return vbox
def add_watcher(self, buddy):
op = buddy.object_path()
if self.watchers.get(op) is not None:
return
# if the watcher is also a player, don't add them
if self.players.get(op) is not None:
return
vbox = self._create_buddy_vbox (buddy)
logger.debug("add watcher %s" % op)
self.watchers_box.append(vbox)
self.watchers[op] = vbox
def add_player(self, buddy):
op = buddy.object_path()
if self.players.get(op) is not None:
return
# if the player is also a watcher, drop them from the watchers
widget = self.watchers.pop(op, None)
if widget is not None:
self.watchers_box.remove(widget)
logger.debug("add player %s" % op)
assert len(self.players) < 2
hbox = hippo.CanvasBox(spacing=4, padding=5,
orientation=hippo.ORIENTATION_HORIZONTAL)
vbox = self._create_buddy_vbox(buddy)
hbox.append(vbox)
count_font = style.FONT_BOLD.get_pango_desc()
count_font.set_size(30000)
count = hippo.CanvasText(text="0", color=style.COLOR_WHITE.get_int(),
font_desc=count_font)
hbox.append(count)
self.players_box.append(hbox)
self.players[op] = hbox
def set_is_playing(self, buddy):
op = buddy.object_path()
for player, hbox in self.players.items():
vbox = hbox.get_children()[0]
icon, name = vbox.get_children()
if player == op:
name.props.font_desc = style.FONT_BOLD.get_pango_desc()
else:
name.props.font_desc = style.FONT_NORMAL.get_pango_desc()
def set_count(self, buddy, val):
hbox = self.players.get(buddy.object_path())
if hbox is None:
return
count = hbox.get_children()[1]
count.props.text = str(val)
def remove_watcher(self, buddy):
op = buddy.object_path()
widget = self.watchers.get(op)
if widget is None:
return
self.watchers_box.remove(widget)
del self.watchers[op]
# removing someone from the game entirely should also remove them
# from the players
self.remove_player(buddy)
def remove_player(self, buddy):
op = buddy.object_path()
widget = self.players.get(op)
if widget is None:
return
self.players_box.remove(widget)
del self.players[op]
self.add_watcher(buddy)
|