diff options
author | Aleksey Lim <alsroot@member.fsf.org> | 2009-01-22 20:52:32 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@member.fsf.org> | 2009-01-22 20:52:32 (GMT) |
commit | 7a6ea32a02bec001495e6fc8f7ceb4265bb9d6e9 (patch) | |
tree | f6a9b2cef2f5e5b59c2844bbf181ed4275e26991 | |
parent | c59a060c9a804d33c98177321e27d082a06cbe05 (diff) |
make cardtable screen-resolution independent
-rw-r--r-- | activity.py | 8 | ||||
-rw-r--r-- | cardlist.py | 4 | ||||
-rw-r--r-- | cardtable.py | 35 | ||||
-rw-r--r-- | createcardpanel.py | 24 | ||||
-rw-r--r-- | scoreboard.py | 1 | ||||
-rw-r--r-- | svgcard.py | 2 | ||||
-rw-r--r-- | theme.py | 6 |
7 files changed, 53 insertions, 27 deletions
diff --git a/activity.py b/activity.py index 66f3bbe..ad357f5 100644 --- a/activity.py +++ b/activity.py @@ -114,8 +114,8 @@ class MemorizeActivity(Activity): self._memorizeToolbar.connect('game_changed', self.game.change_game) self.hbox = gtk.HBox(False) - self.hbox.pack_start(self.scoreboard, False, False) - self.hbox.pack_start(self.table) + self.hbox.pack_start(self.scoreboard) + self.hbox.pack_start(self.table, False) self.set_canvas(self.hbox) # connect to the in/out events of the memorize activity @@ -188,8 +188,8 @@ class MemorizeActivity(Activity): self.hbox.remove(self.createcardpanel) self.hbox.remove(self.cardlist) - self.hbox.pack_start(self.scoreboard, False, False) - self.hbox.pack_start(self.table) + self.hbox.pack_start(self.scoreboard) + self.hbox.pack_start(self.table, False) self.play_mode = True def restart(self, widget): diff --git a/cardlist.py b/cardlist.py index fef27e3..735af5c 100644 --- a/cardlist.py +++ b/cardlist.py @@ -259,14 +259,14 @@ class Pair(gtk.EventBox): 'front' : { 'fill_color' : '#4c4d4f', 'stroke_color' : '#ffffff', 'opacity' : '1' } }, - None, theme.CARD_SIZE, 1, self.bg_color) + None, theme.PAIR_SIZE, 1, self.bg_color) self.bcard2 = svgcard.SvgCard(-1, { 'front_text' : { 'card_text' : text2, 'text_color' : '#ffffff' }, 'front' : { 'fill_color' : '#4c4d4f', 'stroke_color' : '#ffffff', 'opacity' : '1' } }, - None, theme.CARD_SIZE, 1, self.bg_color) + None, theme.PAIR_SIZE, 1, self.bg_color) self.bcard1.flip() self.bcard2.flip() diff --git a/cardtable.py b/cardtable.py index 847a7bd..eeb4772 100644 --- a/cardtable.py +++ b/cardtable.py @@ -25,6 +25,8 @@ import math import gc from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT +import theme + class CardTable(gtk.EventBox): __gsignals__ = { @@ -34,6 +36,13 @@ class CardTable(gtk.EventBox): def __init__(self): gtk.EventBox.__init__(self) + self.data = None + self.cards_data = None + self._workspace_size = 0 + + # set request size to 100x100 to skip first time sizing in _allocate_cb + self.set_size_request(100, 100) + self.connect('size-allocate', self._allocate_cb) # Set table settings self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#000000')) @@ -41,9 +50,9 @@ class CardTable(gtk.EventBox): self.table.grab_focus() self.table.set_flags(gtk.CAN_FOCUS) self.table.set_flags(gtk.CAN_DEFAULT) - self.table.set_row_spacings(11) - self.table.set_col_spacings(11) - self.table.set_border_width(11) + self.table.set_row_spacings(theme.CARD_PAD) + self.table.set_col_spacings(theme.CARD_PAD) + self.table.set_border_width(theme.CARD_PAD) self.table.set_resize_mode(gtk.RESIZE_IMMEDIATE) self.set_property('child', self.table) self.load_message = gtk.Label('Loading Game') @@ -54,10 +63,26 @@ class CardTable(gtk.EventBox): self.load_mode = False self.dict = None self.show_all() + + def _allocate_cb(self, widget, allocation): + size = allocation.height + if size == 100: + # skip first time sizing + return + if self._workspace_size == 0: + # do it once + self.set_size_request(size, size) + self._workspace_size = size + self.load_game(None, self.data, self.cards_data) def load_game(self, widget, data, grid): self.data = data self.cards_data = grid + + if self._workspace_size == 0: + # widow is not allocated, thus postpone loading + return + self.size = int(math.ceil(math.sqrt(len(grid)))) if self.size < 4: self.size = 4 @@ -105,7 +130,7 @@ class CardTable(gtk.EventBox): self.id2cd[id] = card self.cards[(x, y)] = card self.dict[id] = (x, y) - self.table.attach(card, x, x+1, y, y+1, gtk.SHRINK, gtk.SHRINK) + self.table.attach(card, x, x+1, y, y+1) x += 1 if x == self.size: @@ -127,7 +152,7 @@ class CardTable(gtk.EventBox): self.load_game(None, data, grid) def get_card_size(self, size_table): - x = (780 - (11*size_table))/size_table + x = self._workspace_size/size_table - theme.CARD_PAD*2 return x def mouse_event(self, widget, event, coord): diff --git a/createcardpanel.py b/createcardpanel.py index a166252..3034586 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.CARD_SIZE + theme.CARD_PAD*4, -1) + theme.PAIR_SIZE + theme.PAIR_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.CARD_SIZE + theme.CARD_PAD*4, -1) + theme.PAIR_SIZE + theme.PAIR_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.CARD_PAD) - self.table.set_row_spacings(theme.CARD_PAD) - self.table.set_border_width(theme.CARD_PAD) + 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.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,21 +203,21 @@ class CardEditor(gtk.EventBox): self.textentry.connect('changed', self.update_text) table.set_homogeneous(False) - table.set_col_spacings(theme.CARD_PAD) - table.set_row_spacings(theme.CARD_PAD) - table.set_border_width(theme.CARD_PAD) + table.set_col_spacings(theme.PAIR_PAD) + table.set_row_spacings(theme.PAIR_PAD) + table.set_border_width(theme.PAIR_PAD) self.card = svgcard.SvgCard(-1, { 'front_text' : { 'card_text' : '', 'text_color' : '#ffffff' }, 'front_border': { 'fill_color' : '#4c4d4f', 'stroke_color' : '#ffffff', 'opacity' : '1' } }, - None, theme.CARD_SIZE, 1, '#c0c0c0') + None, theme.PAIR_SIZE, 1, '#c0c0c0') self.card.flip() table.attach(self.previewlabel, 0, 2, 0, 1, yoptions=gtk.SHRINK) table.attach(self.card, 0, 2, 1, 2, gtk.SHRINK, gtk.SHRINK, - theme.CARD_PAD) + theme.PAIR_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.CARD_SIZE - theme.CARD_PAD*2, - theme.CARD_SIZE - theme.CARD_PAD*2) + theme.PAIR_SIZE - theme.PAIR_PAD*2, + theme.PAIR_SIZE - theme.PAIR_PAD*2) self.card.set_pixbuf(pixbuf_t) _logger.error('Picture Loaded: '+index) self.emit('has-picture', True) diff --git a/scoreboard.py b/scoreboard.py index 95bb54b..7b20bd5 100644 --- a/scoreboard.py +++ b/scoreboard.py @@ -28,7 +28,6 @@ class Scoreboard(gtk.EventBox): self.players = {} self.current_buddy = None - self.set_size_request(400, 150) self.vbox = gtk.VBox(False) fill_box = gtk.EventBox() @@ -88,7 +88,7 @@ class SvgCard(gtk.DrawingArea): self.window.draw_pixbuf(None, pixbuf, 0, 0, 0, 0) if self.show_jpeg: self.window.draw_pixbuf(None, self.jpeg, 0, 0, - theme.CARD_PAD, theme.CARD_PAD) + theme.SVG_PAD, theme.SVG_PAD) if self.show_text: widget.window.draw_layout(gc, x=6, y=self.current_layout_position, layout=self.current_layout, foreground=gtk.gdk.color_parse(self.current_text_color)) return False @@ -17,5 +17,7 @@ import gtk -CARD_SIZE = gtk.gdk.screen_width() / 5 -CARD_PAD = 10 +PAIR_SIZE = gtk.gdk.screen_width() / 5 +PAIR_PAD = 10 +SVG_PAD = 10 +CARD_PAD = 2 |