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
|
# Copyright (C) 2006, 2007, 2008 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
import gtk
import logging
from playerscoreboard import PlayerScoreboard
_logger = logging.getLogger('memorize-activity')
class Scoreboard(gtk.EventBox):
def __init__(self):
gtk.EventBox.__init__(self)
self.players = {}
self.current_buddy = None
self.set_size_request(400, 150)
self.vbox = gtk.VBox(False)
fill_box = gtk.EventBox()
fill_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#4c4d4f'))
fill_box.show()
self.vbox.pack_end(fill_box, True, True)
scroll = gtk.ScrolledWindow()
scroll.props.shadow_type = gtk.SHADOW_NONE
scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scroll.add_with_viewport(self.vbox)
scroll.set_border_width(0)
scroll.get_child().set_property('shadow-type', gtk.SHADOW_NONE)
self.add(scroll)
self.show_all()
def add_buddy(self, widget, buddy, score):
### FIXME: this breaks when the body is empty
nick = buddy.props.nick
stroke_color, fill_color = buddy.props.color.split(',')
player = PlayerScoreboard(nick, fill_color, stroke_color, score)
player.show()
self.players[buddy]=player
self.vbox.pack_start(player, False, True)
if score == -1:
player.set_wait_mode(True)
self.show_all()
def rem_buddy(self, widget, buddy):
self.vbox.remove(self.players[buddy])
del self.players[buddy] ### fix for self.players[id]
def set_selected(self, widget, buddy):
if self.current_buddy <> None:
old = self.players[self.current_buddy]
old.set_selected(False)
self.current_buddy = buddy
player = self.players[buddy]
player.set_selected(True)
def set_buddy_message(self, widget, buddy, msg):
self.players[buddy].set_message(msg)
def increase_score(self, widget, buddy):
self.players[buddy].increase_score()
def reset(self, widget):
for buddy in self.players.keys():
self.players[buddy].reset()
def set_wait_mode(self, widget, buddy, status):
self.players[buddy].set_wait_mode(status)
|