Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2009-01-23 21:20:48 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2009-01-23 21:20:48 (GMT)
commitcc06afa04cd0f729fcaddf82a18bb0e67de75847 (patch)
tree4f599a1756914a1801944a5d1b4667195b24c2ce
parenta436ef6447bbe650e8ed4ef6ba35b6c3b9ca8eac (diff)
make scoreboard screen-resolution independent
-rw-r--r--activity.py1
-rw-r--r--createcardpanel.py22
-rw-r--r--images/score.svg28
-rw-r--r--playerscoreboard.py82
-rw-r--r--score.py6
-rw-r--r--scoreboard.py14
-rw-r--r--theme.py6
7 files changed, 98 insertions, 61 deletions
diff --git a/activity.py b/activity.py
index ad357f5..55a8294 100644
--- a/activity.py
+++ b/activity.py
@@ -102,6 +102,7 @@ class MemorizeActivity(Activity):
self.game.connect('increase-score', self.scoreboard.increase_score)
self.game.connect('wait_mode_buddy', self.scoreboard.set_wait_mode)
self.game.connect('change-turn', self.scoreboard.set_selected)
+ self.game.connect('change_game', self.scoreboard.change_game)
self.game.connect('reset_scoreboard', self.scoreboard.reset)
self.game.connect('reset_table', self.table.reset)
diff --git a/createcardpanel.py b/createcardpanel.py
index 3034586..88929d5 100644
--- a/createcardpanel.py
+++ b/createcardpanel.py
@@ -52,7 +52,7 @@ class CreateCardPanel(gtk.EventBox):
self._addbutton.set_image(add_image)
self._addbutton.connect('pressed', self.emit_add_pair)
self._addbutton.set_size_request(
- theme.PAIR_SIZE + theme.PAIR_PAD*4, -1)
+ theme.PAIR_SIZE + theme.PAD*4, -1)
# Set update selected pair buttom
update_icon = join(dirname(__file__), 'images', 'pair-update.svg')
@@ -62,7 +62,7 @@ class CreateCardPanel(gtk.EventBox):
self._updatebutton.set_image(update_image)
self._updatebutton.connect('pressed', self.emit_update_pair)
self._updatebutton.set_size_request(
- theme.PAIR_SIZE + theme.PAIR_PAD*4, -1)
+ theme.PAIR_SIZE + theme.PAD*4, -1)
# Set card editors
self.cardeditor1 = CardEditor()
@@ -76,9 +76,9 @@ class CreateCardPanel(gtk.EventBox):
# Create table and add components to the table
self.table = gtk.Table()
self.table.set_homogeneous(False)
- self.table.set_col_spacings(theme.PAIR_PAD)
- self.table.set_row_spacings(theme.PAIR_PAD)
- self.table.set_border_width(theme.PAIR_PAD)
+ self.table.set_col_spacings(theme.PAD)
+ self.table.set_row_spacings(theme.PAD)
+ self.table.set_border_width(theme.PAD)
self.table.attach(self.cardeditor1, 0, 1, 0, 1, yoptions=gtk.SHRINK)
self.table.attach(self.cardeditor2, 1, 2, 0, 1, yoptions=gtk.SHRINK)
self.table.attach(self._addbutton, 0, 1, 1, 2, yoptions=gtk.SHRINK)
@@ -203,9 +203,9 @@ class CardEditor(gtk.EventBox):
self.textentry.connect('changed', self.update_text)
table.set_homogeneous(False)
- table.set_col_spacings(theme.PAIR_PAD)
- table.set_row_spacings(theme.PAIR_PAD)
- table.set_border_width(theme.PAIR_PAD)
+ table.set_col_spacings(theme.PAD)
+ table.set_row_spacings(theme.PAD)
+ table.set_border_width(theme.PAD)
self.card = svgcard.SvgCard(-1,
{ 'front_text' : { 'card_text' : '',
'text_color' : '#ffffff' },
@@ -217,7 +217,7 @@ class CardEditor(gtk.EventBox):
table.attach(self.previewlabel, 0, 2, 0, 1, yoptions=gtk.SHRINK)
table.attach(self.card, 0, 2, 1, 2, gtk.SHRINK, gtk.SHRINK,
- theme.PAIR_PAD)
+ theme.PAD)
#Text label and entry
table.attach(self.textlabel, 0, 1, 2, 3, yoptions=gtk.SHRINK)
table.attach(self.textentry, 0, 2, 3, 4, yoptions=gtk.SHRINK)
@@ -265,8 +265,8 @@ class CardEditor(gtk.EventBox):
def _load_image(self, index):
pixbuf_t = gtk.gdk.pixbuf_new_from_file_at_size(index,
- theme.PAIR_SIZE - theme.PAIR_PAD*2,
- theme.PAIR_SIZE - theme.PAIR_PAD*2)
+ theme.PAIR_SIZE - theme.PAD*2,
+ theme.PAIR_SIZE - theme.PAD*2)
self.card.set_pixbuf(pixbuf_t)
_logger.error('Picture Loaded: '+index)
self.emit('has-picture', True)
diff --git a/images/score.svg b/images/score.svg
index 00a996a..5b779fc 100644
--- a/images/score.svg
+++ b/images/score.svg
@@ -13,8 +13,8 @@
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
- width="42"
- height="42"
+ width="30"
+ height="30"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.45"
@@ -62,20 +62,20 @@
inkscape:groupmode="layer"
id="layer1">
<rect
- style="fill:&fill_color;;fill-opacity:1;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:3.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ style="fill:&fill_color;;fill-opacity:1;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:2.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect7017"
- width="30.046175"
- height="30.046175"
- x="1.9769126"
- y="1.9769124"
- ry="4.5299301" />
+ width="22.5"
+ height="22.5"
+ x="1.25"
+ y="1.25"
+ ry="2.5299301" />
<rect
- style="fill:&fill_color;;fill-opacity:1;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:3.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ style="fill:&fill_color;;fill-opacity:1;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:2.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect3133"
- width="30.046175"
- height="30.046175"
- x="9.9769125"
- y="9.9769125"
- ry="4.5299301" />
+ width="22.5"
+ height="22.5"
+ x="6.0769125"
+ y="6.0769125"
+ ry="2.5299301" />
</g>
</svg>
diff --git a/playerscoreboard.py b/playerscoreboard.py
index d95a639..9668dfa 100644
--- a/playerscoreboard.py
+++ b/playerscoreboard.py
@@ -22,6 +22,9 @@ import svglabel
import logging
from os.path import join, dirname
from score import Score
+import math
+
+import theme
_logger = logging.getLogger('memorize-activity')
@@ -34,49 +37,74 @@ class PlayerScoreboard(gtk.EventBox):
self.selected_color = '#818286'
self.current_color = '#4c4d4f'
self.status = False
-
+ self._score_width = 0
+ self._score_cols = 0
+ self._game_size = 16
self.fill_color = fill_color
self.stroke_color = stroke_color
+
+ self.connect('size-allocate', self._allocate_cb)
# Set table
- self.table = gtk.Table(2, 3, True)
+ self.table = gtk.Table(2, 2, False)
self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.current_color))
- self.table.set_row_spacings(0)
- self.table.set_col_spacings(5)
- self.table.set_border_width(10)
+ self.table.set_row_spacings(theme.PAD/2)
+ self.table.set_col_spacings(theme.PAD/2)
+ self.table.set_border_width(theme.PAD)
+ # Score table
+ self.score_table = gtk.Table()
+ self.score_table.set_row_spacings(theme.PAD/2)
+ self.score_table.set_col_spacings(theme.PAD/2)
+
self.scores = []
- self.current_x = 1
- self.current_y = 1
+ self.current_x = 0
+ self.current_y = 0
status = False
# Set buddy icon
self.xo_buddy = join(dirname(__file__), 'images', 'stock-buddy.svg')
- self.icon = svglabel.SvgLabel(self.xo_buddy, fill_color, stroke_color, False, self.current_color, 45, 55)
+ self.icon = svglabel.SvgLabel(self.xo_buddy, fill_color, stroke_color,
+ False, self.current_color, theme.BODY_WIDTH, theme.BODY_HEIGHT)
# Set waiting buddy icon
- #self.waiting_icon = svglabel.SvgLabel(self.xo_buddy, self.default_color, '#ffffff', False, self.current_color, 45, 55)
+ self.waiting_icon = svglabel.SvgLabel(self.xo_buddy, self.default_color,
+ '#ffffff', False, self.current_color,
+ theme.BODY_WIDTH, theme.BODY_HEIGHT)
# Set nick label
self.nick = gtk.Label(nick)
- self.nick.modify_font(pango.FontDescription('12'))
self.nick.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#ffffff'))
self.nick.set_alignment(0, 0.5)
# Set message label
self.msg = gtk.Label('Waiting for next game...')
- self.msg.modify_font(pango.FontDescription('12'))
self.msg.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#ffffff'))
self.msg.set_alignment(0, 0.5)
-
+
self.add(self.table)
- self.table.attach(self.icon, 0, 1, 0, 1)
- self.table.attach(self.nick, 1, 7, 0, 1)
-
+ self.table.attach(self.icon, 0, 1, 0, 3)
+ self.table.attach(self.nick, 1, 2, 0, 1, yoptions=gtk.SHRINK)
+ self.table.attach(self.score_table, 1, 2, 1, 2, gtk.SHRINK, gtk.SHRINK)
+
if score <> 0:
for i in range(score):
self.increase_score()
-
+
+ def _allocate_cb(self, widget, allocation):
+ self._score_width = allocation.width - theme.BODY_WIDTH - theme.PAD*2 - theme.PAD/2
+ self._score_cols = self._score_width / (theme.SCORE_SIZE+theme.PAD/2)
+ self.change_game(self._game_size)
+
+ def change_game(self, size):
+ self._game_size = size
+ if self._score_cols == 0: return
+
+ rows = int(math.ceil(float(size/2) / self._score_cols))
+ self.score_table.resize(rows, self._score_cols)
+ self.score_table.set_size_request(self._score_width,
+ (theme.SCORE_SIZE+theme.PAD/2) * (rows) - theme.PAD/2)
+
def increase_score(self):
if len(self.scores) == 0:
# Cache the score icon
@@ -84,13 +112,15 @@ class PlayerScoreboard(gtk.EventBox):
self.score_pixbuf_unsel = score_label.get_pixbuf()
self.score_pixbuf_sel = score_label.get_pixbuf_sel()
- new_score = Score(self.fill_color, self.stroke_color, self.score_pixbuf_sel, self.score_pixbuf_unsel, self.status)
+ new_score = Score(self.fill_color, self.stroke_color,
+ self.score_pixbuf_sel, self.score_pixbuf_unsel, self.status)
self.scores.append(new_score)
new_score.show()
- self.table.attach(new_score, self.current_x , self.current_x+1, self.current_y, self.current_y+1)
+ self.score_table.attach(new_score, self.current_x , self.current_x+1,
+ self.current_y, self.current_y+1, gtk.SHRINK, gtk.SHRINK)
self.current_x += 1
- if self.current_x == 7:
- self.current_x = 1
+ if self.current_x == self._score_cols:
+ self.current_x = 0
self.current_y += 1
self.queue_draw()
@@ -108,9 +138,9 @@ class PlayerScoreboard(gtk.EventBox):
def reset(self):
for score in self.scores:
- self.table.remove(score)
- self.current_x = 1
- self.current_y = 1
+ self.score_table.remove(score)
+ self.current_x = 0
+ self.current_y = 0
del self.scores
self.scores = []
self.queue_draw()
@@ -118,12 +148,12 @@ class PlayerScoreboard(gtk.EventBox):
def set_wait_mode(self, status):
if status:
self.table.remove(self.icon)
- self.table.attach(self.waiting_icon, 0, 1, 0, 1)
+ self.table.attach(self.waiting_icon, 0, 1, 0, 2)
if len(self.scores) == 0:
- self.table.attach(self.msg, 1, 7, 1, 2)
+ self.table.attach(self.msg, 1, 2, 1, 2)
else:
self.table.remove(self.waiting_icon)
- self.table.attach(self.icon, 0, 1, 0, 1)
+ self.table.attach(self.icon, 0, 1, 0, 2)
self.table.remove(self.msg)
if len(self.scores) == 0:
self.table.remove(self.msg)
diff --git a/score.py b/score.py
index acc5e82..81b015e 100644
--- a/score.py
+++ b/score.py
@@ -22,6 +22,8 @@ import gtk
import gobject
import os
+import theme
+
class Score(svglabel.SvgLabel):
selected_color = "#818286"
@@ -42,7 +44,9 @@ class Score(svglabel.SvgLabel):
else:
self.pixbuf = self.pixbuf_un
- svglabel.SvgLabel.__init__(self, filename, fill_color, stroke_color, self.pixbuf, self.default_color, 35, 35)
+ svglabel.SvgLabel.__init__(self, filename, fill_color, stroke_color,
+ self.pixbuf, self.default_color, theme.SCORE_SIZE,
+ theme.SCORE_SIZE)
self.set_selected(status)
def set_selected(self, status):
diff --git a/scoreboard.py b/scoreboard.py
index 7b20bd5..e57cfae 100644
--- a/scoreboard.py
+++ b/scoreboard.py
@@ -35,14 +35,12 @@ class Scoreboard(gtk.EventBox):
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.add(self.vbox)
self.show_all()
+
+ def change_game(self, widget, data, grid):
+ for buddy in self.players.keys():
+ self.players[buddy].change_game(len(grid))
def add_buddy(self, widget, buddy, score):
### FIXME: this breaks when the body is empty
@@ -51,7 +49,7 @@ class Scoreboard(gtk.EventBox):
player = PlayerScoreboard(nick, fill_color, stroke_color, score)
player.show()
self.players[buddy]=player
- self.vbox.pack_start(player, False, True)
+ self.vbox.pack_start(player, False, False)
if score == -1:
player.set_wait_mode(True)
self.show_all()
diff --git a/theme.py b/theme.py
index 5a2a0be..eae4a53 100644
--- a/theme.py
+++ b/theme.py
@@ -18,6 +18,10 @@
import gtk
PAIR_SIZE = gtk.gdk.screen_width() / 5
-PAIR_PAD = 10
+PAD = 10
SVG_PAD = 10
CARD_PAD = 2
+BODY_WIDTH = 45
+BODY_HEIGHT = 55
+STARS_COLS = 6
+SCORE_SIZE = 30