diff options
author | Simon Schampijer <simon@schampijer.de> | 2007-09-24 13:19:31 (GMT) |
---|---|---|
committer | Simon Schampijer <simon@schampijer.de> | 2007-09-24 13:19:31 (GMT) |
commit | d85f9a04075107e799d7a748bbbc96f7f43ae73e (patch) | |
tree | 6bf68d80ccb80dc4d3e89d78160c51dd4675bb44 | |
parent | 7b8800191ad29440393ce1649a7d82419ef6fa5f (diff) | |
parent | e3af6ee47390ac2bde75a6c31f85c091fdc3bce2 (diff) |
Merge branch 'develop'
-rwxr-xr-x | activity.py | 50 | ||||
-rw-r--r-- | cardlist.py | 164 | ||||
-rwxr-xr-x | cardtable.py | 11 | ||||
-rw-r--r-- | createcardpanel.py | 117 | ||||
-rwxr-xr-x | createtoolbar.py | 116 | ||||
-rw-r--r-- | images/game-load.svg | 166 | ||||
-rwxr-xr-x | images/game-new.svg | 128 | ||||
-rw-r--r-- | images/game-save.svg | 166 | ||||
-rwxr-xr-x | memorizetoolbar.py | 23 | ||||
-rwxr-xr-x | playerscoreboard.py | 21 | ||||
-rwxr-xr-x | svgcard.py | 170 |
11 files changed, 1002 insertions, 130 deletions
diff --git a/activity.py b/activity.py index eb92ccd..2eefa76 100755 --- a/activity.py +++ b/activity.py @@ -38,6 +38,9 @@ import scoreboard import game import messenger import memorizetoolbar +import createtoolbar +import cardlist +import createcardpanel from sugar.presence.tubeconn import TubeConnection @@ -57,20 +60,28 @@ class MemorizeActivity(Activity): self.scoreboard = scoreboard.Scoreboard() self.game = game.MemorizeGame() - hbox = gtk.HBox(False) - hbox.pack_start(self.scoreboard, False, False) - hbox.pack_start(self.table) + self.create_load = False + self.create_mode = False + + self.hbox = gtk.HBox(False) + self.hbox.pack_start(self.scoreboard, False, False) + self.hbox.pack_start(self.table) toolbox = ActivityToolbox(self) + toolbox.connect('current-toolbar-changed', self.change_mode) activity_toolbar = toolbox.get_activity_toolbar() self._memorizeToolbar = memorizetoolbar.MemorizeToolbar(self) toolbox.add_toolbar(_('Games'), self._memorizeToolbar) self._memorizeToolbar.show() + self._createToolbar = createtoolbar.CreateToolbar(self) + toolbox.add_toolbar('Create', self._createToolbar) + self._createToolbar.show() + self.set_toolbox(toolbox) toolbox.show() - self.set_canvas(hbox) + self.set_canvas(self.hbox) self.table.connect('key-press-event', self.table.key_press_event) self.connect('shared', self._shared_cb) @@ -94,8 +105,6 @@ class MemorizeActivity(Activity): self.game.connect('wait_mode_buddy', self.scoreboard.set_wait_mode) self.game.connect('change-turn', self.scoreboard.set_selected) - self.show_all() - # connect to the in/out events of the memorize activity self.connect('focus_in_event', self._focus_in) self.connect('focus_out_event', self._focus_out) @@ -130,7 +139,34 @@ class MemorizeActivity(Activity): _logger.debug("buddy joined - __init__: %s", self.owner.props.nick) self.game.load_game('addition', 4) self.game.add_buddy(self.owner) - + self.show_all() + + def change_mode(self, notebook, index): + if index == 2: + if not self.create_load: + # Create mode components + self.cardlist = cardlist.CardList() + self.createcardpanel = createcardpanel.CreateCardPanel() + self.createcardpanel.connect('add-pair', self.cardlist.add_pair) + self.createcardpanel.connect('update-pair', self.cardlist.update_selected) + self.cardlist.connect('pair-selected', self.createcardpanel.load_pair) + self._createToolbar.connect('create_new_game', self.cardlist.clean_list) + self._createToolbar.connect('create_load_game', self.cardlist.load_game) + self._createToolbar.connect('create_save_game', self.cardlist.save_game) + self.create_load = True + self.hbox.remove(self.scoreboard) + self.hbox.remove(self.table) + self.hbox.pack_start(self.createcardpanel) + self.hbox.pack_start(self.cardlist, False, False) + self.create_mode = True + else: + if self.create_mode: + self.hbox.remove(self.cardlist) + self.hbox.remove(self.createcardpanel) + self.hbox.pack_start(self.scoreboard, False, False) + self.hbox.pack_start(self.table) + self.create_mode = False + def restart(self, widget): self.game.reset() diff --git a/cardlist.py b/cardlist.py new file mode 100644 index 0000000..b84e2fe --- /dev/null +++ b/cardlist.py @@ -0,0 +1,164 @@ +#! /usr/bin/env python +# +# Copyright (C) 2006, 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +import gtk +import svgcard +import gobject +import logging +import os +import model + +_logger = logging.getLogger('memorize-activity') + +class CardList(gtk.EventBox): + + __gsignals__ = { + 'pair-selected': (gobject.SIGNAL_RUN_FIRST, None, [gobject.TYPE_PYOBJECT]), + } + + def __init__(self): + gtk.EventBox.__init__(self) + self.model = model.Model(os.path.dirname(__file__)) + self.pairs = [] + self.current_pair = None + + self.set_size_request(450, 150) + self.vbox = gtk.VBox(False) + + fill_box = gtk.EventBox() + fill_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#000000')) + 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_ALWAYS) + scroll.add_with_viewport(self.vbox) + scroll.set_border_width(0) + #scroll.get_child().set_property('shadow-type', gtk.SHADOW_NONE) + scroll.get_child().modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#000000')) + self.add(scroll) + self.add_pair(self, '', '') + self.pairs[0].set_selected(True) + self.current_pair = self.pairs[0] + self.show() + + def load_game(self, widget, game_name): + self.model.read(game_name) + game_pairs = self.model.pairs + self.clean_list() + map(lambda key: self.add_pair(None, game_pairs[key].props.achar, game_pairs[key].props.bchar, False) , game_pairs) + + def save_game(self, widget, game_name): + game_model = model.Model(os.path.dirname(__file__)) + game_model.data['name'] = 'game_name' + for pair in range(len(self.pairs)): + pair_card = model.Pair() + pair_card.set_property('achar', self.pairs[pair].get_text()) + pair_card.set_property('bchar', self.pairs[pair].get_text()) + game_model.pairs[pair] = pair_card + game_model.write() + + def clean_list(self, button = None): + map(lambda x: self.vbox.remove(x), self.pairs) + del self.pairs + self.pairs = [] + + def add_pair(self, widget, achar, bchar, show = True): + pair = Pair(achar, bchar) + self.vbox.pack_end(pair, False, True) + self.pairs.append(pair) + pair.connect('pair-selected', self.set_selected) + pair.connect('pair-closed', self.rem_pair) + if show: + self.show_all() + + def rem_pair(self, widget, event): + self.vbox.remove(widget) + self.pairs.remove(widget) + del widget + + def set_selected(self, widget, event): + if self.current_pair <> None: + self.old = self.current_pair + self.old.set_selected(False) + self.current_pair = widget + widget.set_selected(True) + self.emit('pair-selected', self.current_pair.get_text()) + + def update_selected(self, widget, newtext1, newtext2): + self.current_pair.change_text(newtext1) + +class Pair(gtk.EventBox): + + __gsignals__ = { + 'pair-selected': (gobject.SIGNAL_RUN_FIRST, None, [gobject.TYPE_PYOBJECT]), + 'pair-closed': (gobject.SIGNAL_RUN_FIRST, None, [gobject.TYPE_PYOBJECT]), + } + + def __init__(self, text1, text2 = None): + gtk.EventBox.__init__(self) + self.bg_color = '#000000' + if text2 == None: + self.text2 = text1 + else: + self.text2 = text2 + self.text1 = text1 + + close_button = gtk.Button('X') + close_button.connect('button-press-event', self.emit_close) + table = gtk.Table() + table.connect('button-press-event', self.emit_selected) + table.set_col_spacings(5) + table.set_border_width(10) + self.bcard1 = svgcard.SvgCard(-1, {'front_text':{'card_text':text1, 'text_color':'#ffffff'}, 'front':{'fill_color':'#4c4d4f', 'stroke_color':'#ffffff', 'opacity':'1'}}, None, 184, 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, 184, 1, self.bg_color) + self.bcard1.flip() + self.bcard2.flip() + + table.attach(self.bcard1, 0, 1, 0, 8) + table.attach(self.bcard2, 1, 2, 0, 8) + table.attach(close_button, 2, 3, 0, 1, gtk.FILL, gtk.FILL) + + self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.bg_color)) + self.add(table) + self.show_all() + + def emit_selected(self, widget, event): + self.emit('pair-selected', self) + + def emit_close(self, widget, event): + self.emit('pair-closed', self) + + def set_selected(self, status): + if not status: + self.bg_color = '#000000' + else: + self.bg_color = '#b2b3b7' + + self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.bg_color)) + self.bcard1.set_background(self.bg_color) + self.bcard2.set_background(self.bg_color) + + def change_text(self, newtext): + self.bcard1.change_text(newtext) + self.bcard2.change_text(newtext) + + def get_text(self): + return self.bcard1.get_text()
\ No newline at end of file diff --git a/cardtable.py b/cardtable.py index 70f70b1..f1a992c 100755 --- a/cardtable.py +++ b/cardtable.py @@ -69,8 +69,6 @@ class CardTable(gtk.EventBox): else: text1 = str(self.data.get('face','')) text2 = str(self.data.get('face','')) - buffer_card_1 = svgcard.SvgCard(-1, {'front_border':{'opacity':'0'}, 'front_h_border':{'opacity':'0.5'}, 'back_text':{'card_text':text1}}, {}, None, self.card_size,1) - buffer_card_2 = svgcard.SvgCard(-1, {'front_border':{'opacity':'0'}, 'front_h_border':{'opacity':'0.5'}, 'back_text':{'card_text':text2}}, {}, None, self.card_size,1) x = 0 y = 0 @@ -82,18 +80,14 @@ class CardTable(gtk.EventBox): else: jpg = None props = {} - props['front_border'] = {'opacity':'1'} - props['front_h_border'] ={'opacity':'1'} props['front_text']= {'card_text':card.get('char', '')} if card['ab']== 'a': - buffer_card = buffer_card_1 props['back_text']= {'card_text':text1} elif card['ab']== 'b': - buffer_card = buffer_card_2 props['back_text']= {'card_text':text2} - card = svgcard.SvgCard(id, props, buffer_card.get_cache(), jpg, self.card_size,self.data.get('align','1')) + card = svgcard.SvgCard(id, props, jpg, self.card_size,self.data.get('align','1')) card.connect('enter-notify-event', self.mouse_event, [x, y]) card.connect("button-press-event", self.flip_card_mouse, id) self.table_positions[(x, y)]=1 @@ -116,8 +110,9 @@ class CardTable(gtk.EventBox): for card in self.cards.values(): self.table.remove(card) del card - self.load_game(None, data, grid) gc.collect() + self.load_game(None, data, grid) + def get_card_size(self, size_table): x = (780 - (11*size_table))/size_table diff --git a/createcardpanel.py b/createcardpanel.py new file mode 100644 index 0000000..e2de4bc --- /dev/null +++ b/createcardpanel.py @@ -0,0 +1,117 @@ +#! /usr/bin/env python +# +# Copyright (C) 2006, 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +import gtk +import svgcard +import logging +import gobject + +_logger = logging.getLogger('memorize-activity') + +class CreateCardPanel(gtk.EventBox): + + __gsignals__ = { + 'add-pair': (gobject.SIGNAL_RUN_FIRST, None, [gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT]), + 'update-pair': (gobject.SIGNAL_RUN_FIRST, None, [gobject.TYPE_PYOBJECT,gobject.TYPE_PYOBJECT]), + } + + def __init__(self): + gtk.EventBox.__init__(self) + + table = gtk.Table() + table.set_col_spacings(10) + table.set_row_spacings(10) + table.set_border_width(200) + + addbutton = gtk.Button('Add as new pair') + addbutton.connect('button-press-event',self.emit_add_pair) + + updatebutton = gtk.Button('Update selected pair') + updatebutton.connect('button-press-event',self.emit_update_pair) + + self.cardeditor = CardEditor() + table.attach(self.cardeditor, 0, 2, 0, 1) + table.attach(addbutton, 0, 1, 1, 2) + table.attach(updatebutton, 1, 2, 1, 2) + + self.add(table) + self.show_all() + + def emit_add_pair(self, widget, event): + self.emit('add-pair',self.cardeditor.get_text(),self.cardeditor.get_text()) + + def emit_update_pair(self, widget, event): + self.emit('update-pair',self.cardeditor.get_text(),self.cardeditor.get_text()) + + def load_pair(self, widget, newtext): + self.cardeditor.set_text(newtext) + +class CardEditor(gtk.EventBox): + + def __init__(self): + gtk.EventBox.__init__(self) + self.set_size_request(400, 400) + + table = gtk.Table() + self.previewlabel = gtk.Label('Preview:') + self.previewlabel.set_alignment(1, 0.5) + self.textlabel = gtk.Label('Text:') + self.textlabel.set_alignment(1, 0.5) + self.picturelabel = gtk.Label('Picture:') + self.picturelabel.set_alignment(1, 0.5) + self.soundlabel = gtk.Label('Sound:') + self.soundlabel.set_alignment(1, 0.5) + + self.browsepicture = gtk.Button('Browse') + self.capturepicture = gtk.Button('Capture') + self.browsesound = gtk.Button('Browse') + self.recordsound = gtk.Button('Record') + self.textentry = gtk.Entry() + self.textentry.connect('changed', self.update_text) + + table.set_col_spacings(10) + table.set_row_spacings(10) + table.set_border_width(20) + self.card = svgcard.SvgCard(-1, {'front_text':{'card_text':'', 'text_color':'#ffffff'}, 'front_border':{'fill_color':'#4c4d4f', 'stroke_color':'#ffffff', 'opacity':'1'}}, None, 184, 1, '#c0c0c0') + self.card.flip() + + table.attach(self.previewlabel, 0, 1, 1, 2) + table.attach(self.card, 1, 3, 1, 2) + #Text label and entry + table.attach(self.textlabel, 0, 1, 2, 3) + table.attach(self.textentry, 1, 3, 2, 3) + #Picture label and entry + table.attach(self.picturelabel, 0, 1, 3, 4) + table.attach(self.browsepicture, 1, 2, 3, 4) + table.attach(self.capturepicture, 2, 3, 3, 4) + #Sound label and entry + table.attach(self.soundlabel, 0, 1, 4, 5) + table.attach(self.browsesound, 1, 2, 4, 5) + table.attach(self.recordsound, 2, 3, 4, 5) + + self.add(table) + + def update_text(self, entry): + self.card.change_text(entry.get_text()) + + def get_text(self): + return self.textentry.get_text() + + def set_text(self, newtext): + self.textentry.set_text(newtext) diff --git a/createtoolbar.py b/createtoolbar.py new file mode 100755 index 0000000..af6a2dc --- /dev/null +++ b/createtoolbar.py @@ -0,0 +1,116 @@ +#! /usr/bin/env python +# +# Copyright (C) 2006, 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +import logging +from gettext import gettext as _ + +import gtk +import os +import gobject + +from sugar.graphics.toolbutton import ToolButton +from sugar.graphics.toolcombobox import ToolComboBox + +class CreateToolbar(gtk.Toolbar): + __gtype_name__ = 'CreateToolbar' + + __gsignals__ = { + 'create_new_game': (gobject.SIGNAL_RUN_FIRST, None, []), + 'create_load_game': (gobject.SIGNAL_RUN_FIRST, None, [gobject.TYPE_PYOBJECT]), + 'create_save_game': (gobject.SIGNAL_RUN_FIRST, None, [gobject.TYPE_PYOBJECT]), + } + + def __init__(self, activity): + gtk.Toolbar.__init__(self) + self.activity = activity + self._lock = True + + # New Button + new_icon = os.path.join(os.path.dirname(__file__), "images/game-new.svg") + new_image = gtk.Image() + new_image.set_from_file(new_icon) + self._new_button = ToolButton() + self._new_button.set_icon_widget(new_image) + self._new_button.set_tooltip(_('New game set')) + self._new_button.connect('clicked', self._new_game_bt) + self._add_widget(self._new_button) + + # Load Button + load_icon = os.path.join(os.path.dirname(__file__), "images/game-load.svg") + load_image = gtk.Image() + load_image.set_from_file(load_icon) + self._load_button = ToolButton() + self._load_button.set_icon_widget(load_image) + self._load_button.set_tooltip(_('Load game set')) + self._load_button.connect('enter-notify-event', self._drop_palette) + self._add_widget(self._load_button) + self.games = os.listdir(os.path.join(os.path.dirname(__file__), 'games')) + self.games.sort() + palette = self._load_button.get_palette() + for game in self.games: + menu_item = gtk.MenuItem(game) + menu_item.connect('activate', self._game_changed_cb, game) + palette.menu.prepend(menu_item) + menu_item.show() + + # Save Button + save_icon = os.path.join(os.path.dirname(__file__), "images/game-save.svg") + save_image = gtk.Image() + save_image.set_from_file(save_icon) + self._save_button = ToolButton() + self._save_button.set_icon_widget(save_image) + self._save_button.set_tooltip(_('Save game set')) + self._save_button.connect('clicked', self._save_game_bt) + self._add_widget(self._save_button) + + # Separator + separator2 = gtk.SeparatorToolItem() + separator2.set_draw(True) + self.insert(separator2, -1) + + self._add_widget(gtk.Label(_('Game name: '))) + self.game_name_entry = gtk.Entry() + self._add_widget(self.game_name_entry) + + self._add_widget(gtk.CheckButton('Equal pairs')) + + self._add_widget(gtk.CheckButton('Grouped')) + + + def _add_widget(self, widget, expand=False): + tool_item = gtk.ToolItem() + tool_item.set_expand(expand) + tool_item.add(widget) + widget.show() + self.insert(tool_item, -1) + tool_item.show() + + def _game_changed_cb(self, combobox, game_name): + self.game_name_entry.set_text(game_name) + self.emit('create_load_game',game_name) + + def _drop_palette(self, button): + button.get_palette().popdown(False) + + def _new_game_bt(self, button): + self.game_name_entry.set_text('') + self.emit('create_new_game') + + def _save_game_bt(self, button): + self.emit('create_save_game',self.game_name_entry.get_text())
\ No newline at end of file diff --git a/images/game-load.svg b/images/game-load.svg new file mode 100644 index 0000000..deaaa2a --- /dev/null +++ b/images/game-load.svg @@ -0,0 +1,166 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://web.resource.org/cc/" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + 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" + enable-background="new 0 0 55 55" + height="55px" + version="1.1" + viewBox="0 0 55 55" + width="55px" + x="0px" + xml:space="preserve" + y="0px" + id="svg5142" + sodipodi:version="0.32" + inkscape:version="0.45.1" + sodipodi:docname="game-load.svg" + sodipodi:docbase="/home/msgodoi/olpc/workspace/Memorize.activity/images" + inkscape:output_extension="org.inkscape.output.svg.inkscape"><metadata + id="metadata5176"><rdf:RDF><cc:Work + rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs + id="defs5174"> + + + + + + + + + + + + + + + </defs><sodipodi:namedview + inkscape:window-height="871" + inkscape:window-width="1432" + inkscape:pageshadow="2" + inkscape:pageopacity="0.0" + guidetolerance="10.0" + gridtolerance="10.0" + objecttolerance="10.0" + borderopacity="1.0" + bordercolor="#666666" + pagecolor="#ffffff" + id="base" + inkscape:zoom="12.145455" + inkscape:cx="27.5" + inkscape:cy="30.793413" + inkscape:window-x="4" + inkscape:window-y="25" + inkscape:current-layer="svg5142" /><g + id="g5125" + transform="translate(-2,2)"><g + id="g5147"> + <g + id="g5149"> + <path + style="fill:#ffffff;stroke:#8c8c8c;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round" + id="path5151" + d="M 6.736,49.002 L 31.256,49.002 C 33.481,49.002 34.695,47.555 34.695,45.561 L 34.695,18.281 C 34.695,16.551 32.963,14.84 31.256,14.84 L 26.867,14.84" /> + </g> + </g><g + id="g5153"> + <g + id="g5155"> + <path + style="fill:#ffffff;stroke:#8c8c8c;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round" + id="path5157" + d="M 26.867,38.592 C 26.867,40.428 25.522,41.793 23.426,42.639 L 6.736,49.002 L 6.736,14.84 L 23.426,6.241 C 25.654,5.847 26.867,7.081 26.867,9.075 L 26.867,38.592 z " /> + </g> + </g><path + style="fill:none;stroke:#8c8c8c;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round" + id="path5159" + d="M 9.424,42.607 C 9.424,42.607 8.073,42.064 6.722,42.064 C 5.371,42.064 4.019,42.607 4.019,42.607" /><path + style="fill:none;stroke:#8c8c8c;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round" + id="path5161" + d="M 9.424,32.006 C 9.424,32.006 8.185,31.463 6.609,31.463 C 5.032,31.463 4.019,32.006 4.019,32.006" /><path + style="fill:none;stroke:#8c8c8c;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round" + id="path5163" + d="M 9.424,21.678 C 9.424,21.678 8.299,21.134 6.497,21.134 C 4.695,21.134 4.019,21.678 4.019,21.678" /><line + style="fill:none;stroke:#8c8c8c;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round" + id="line5165" + y2="11.505" + y1="46.533001" + x2="13.209" + x1="13.209" /></g><g + id="g4140" + transform="matrix(0.8372116,0,0,0.8372116,8.751416,-7.2720533e-2)"><rect + style="fill:#ffffff;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2221" + height="5.0509453" + width="5.0529833" + y="2.5764074" + x="32.505089" /><rect + style="fill:#aaaaaa;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2223" + height="5.0509453" + width="5.0529833" + y="2.5764074" + x="40.25333" /><rect + style="fill:#aaaaaa;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2225" + height="5.0509453" + width="5.0529833" + y="2.5764074" + x="47.70649" /><rect + style="fill:#aaaaaa;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2227" + height="5.0509453" + width="5.0529833" + y="10.110903" + x="32.505089" /><rect + style="fill:#aaaaaa;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2229" + height="5.0509453" + width="5.0529833" + y="10.110903" + x="40.25333" /><rect + style="fill:#aaaaaa;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2231" + height="5.0509453" + width="5.0529833" + y="10.110903" + x="47.70649" /><rect + style="fill:#aaaaaa;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2233" + height="5.0509453" + width="5.0529833" + y="17.624184" + x="32.505089" /><rect + style="fill:#ffffff;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2235" + height="5.0509453" + width="5.0529833" + y="17.624184" + x="40.25333" /><rect + style="fill:#aaaaaa;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2237" + height="5.0509453" + width="5.0529833" + y="17.624184" + x="47.70649" /></g><line + style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" + id="line5169" + y2="36.425068" + y1="22.462688" + x2="44.528595" + x1="44.72258" /><polyline + style="fill:none;stroke:#ffffff;stroke-width:5.1055975;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" + id="polyline5171" + points=" 51.562,15.306 41.17,16.188 42.053,5.794 " + transform="matrix(-0.5053552,0.4648229,-0.493202,-0.4762768,73.4836,10.383118)" /><line + style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" + id="line4138" + y2="36.52364" + y1="36.329655" + x2="44.443764" + x1="36.409523" /></svg>
\ No newline at end of file diff --git a/images/game-new.svg b/images/game-new.svg new file mode 100755 index 0000000..4dc4b64 --- /dev/null +++ b/images/game-new.svg @@ -0,0 +1,128 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Generator: Adobe Illustrator 12.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 51448) --> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://web.resource.org/cc/" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + 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" + version="1.1" + id="Icon" + width="43.584" + height="43.292" + viewBox="0 0 43.584 43.292" + overflow="visible" + enable-background="new 0 0 43.584 43.292" + xml:space="preserve" + sodipodi:version="0.32" + inkscape:version="0.45" + sodipodi:docname="new.svg" + sodipodi:docbase="/home/msgodoi/olpc/jhbuild/sugar-jhbuild/build/share/activities/Memorize.activity/images" + inkscape:output_extension="org.inkscape.output.svg.inkscape" + sodipodi:modified="true"><metadata + id="metadata2242"><rdf:RDF><cc:Work + rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs + id="defs2240" /><sodipodi:namedview + inkscape:window-height="847" + inkscape:window-width="1432" + inkscape:pageshadow="2" + inkscape:pageopacity="0.0" + guidetolerance="10.0" + gridtolerance="10.0" + objecttolerance="10.0" + borderopacity="1.0" + bordercolor="#666666" + pagecolor="#ffffff" + id="base" + inkscape:zoom="15.407004" + inkscape:cx="21.792" + inkscape:cy="43.004242" + inkscape:window-x="0" + inkscape:window-y="0" + inkscape:current-layer="Icon" /> +<rect + x="1.5007635" + y="1.5007635" + width="8.5757914" + height="8.5757914" + id="rect2221" + style="fill:#ffffff;stroke:#000000;stroke-width:3.00152707" /> +<rect + x="14.650882" + y="1.5007635" + width="8.5757914" + height="8.5757914" + id="rect2223" + style="fill:#aaaaaa;stroke:#000000;stroke-width:3.00152707" /> +<rect + x="27.300175" + y="1.5007635" + width="8.5757914" + height="8.5757914" + id="rect2225" + style="fill:#aaaaaa;stroke:#000000;stroke-width:3.00152707" /> +<rect + x="1.5007635" + y="14.293271" + width="8.5757914" + height="8.5757914" + id="rect2227" + style="fill:#aaaaaa;stroke:#000000;stroke-width:3.00152707" /> +<rect + x="14.650882" + y="14.293271" + width="8.5757914" + height="8.5757914" + id="rect2229" + style="fill:#aaaaaa;stroke:#000000;stroke-width:3.00152707" /> +<rect + x="27.300175" + y="14.293271" + width="8.5757914" + height="8.5757914" + id="rect2231" + style="fill:#aaaaaa;stroke:#000000;stroke-width:3.00152707" /> +<rect + x="1.5007635" + y="27.049763" + width="8.5757914" + height="8.5757914" + id="rect2233" + style="fill:#aaaaaa;stroke:#000000;stroke-width:3.00152707" /> +<rect + x="14.650882" + y="27.049763" + width="8.5757914" + height="8.5757914" + id="rect2235" + style="fill:#ffffff;stroke:#000000;stroke-width:3.00152707" /> +<rect + x="27.300175" + y="27.049763" + width="8.5757914" + height="8.5757914" + id="rect2237" + style="fill:#aaaaaa;stroke:#000000;stroke-width:3.00152707" /> +<g + id="g8128" + transform="matrix(1.1533304,0,0,1.1849266,74.491613,11.842114)" + style="stroke:#ffffff;stroke-opacity:1"><path + sodipodi:nodetypes="cccccc" + id="path6167" + d="M -27.423669,19.213102 L -34.384959,18.667751 L -41.332006,19.051133 L -34.303975,19.649604 L -27.488656,19.213102 L -34.44067,18.736178" + style="fill:#ffffff;fill-rule:evenodd;stroke:#ffffff;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:round;marker-start:none;stroke-opacity:1" /><path + sodipodi:nodetypes="cccccc" + id="path6165" + d="M -34.432262,26.112846 L -33.886911,19.151556 L -34.270293,12.204509 L -34.868764,19.23254 L -34.432262,26.047859 L -33.955338,19.095845" + style="fill:#ffffff;fill-rule:evenodd;stroke:#ffffff;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:round;marker-start:none;stroke-opacity:1" /><path + sodipodi:nodetypes="cccccc" + id="path6169" + d="M -29.517762,24.133282 L -34.054516,18.825285 L -39.237912,14.184073 L -34.691527,19.576825 L -29.563716,24.087329 L -34.142295,18.834277" + style="fill:#ffffff;fill-rule:evenodd;stroke:#ffffff;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:round;marker-start:none;stroke-opacity:1" /><path + sodipodi:nodetypes="cccccc" + id="path6171" + d="M -29.403233,14.298603 L -34.71123,18.835357 L -39.352442,24.018753 L -33.959691,19.472367 L -29.449186,14.344555 L -34.702238,18.923135" + style="fill:#ffffff;fill-rule:evenodd;stroke:#ffffff;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:round;marker-start:none;stroke-opacity:1" /></g></svg>
\ No newline at end of file diff --git a/images/game-save.svg b/images/game-save.svg new file mode 100644 index 0000000..8d43d4b --- /dev/null +++ b/images/game-save.svg @@ -0,0 +1,166 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://web.resource.org/cc/" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + 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" + enable-background="new 0 0 55 55" + height="55px" + version="1.1" + viewBox="0 0 55 55" + width="55px" + x="0px" + xml:space="preserve" + y="0px" + id="svg5142" + sodipodi:version="0.32" + inkscape:version="0.45.1" + sodipodi:docname="game-save.svg" + sodipodi:docbase="/home/msgodoi/olpc/workspace/Memorize.activity/images" + inkscape:output_extension="org.inkscape.output.svg.inkscape"><metadata + id="metadata5176"><rdf:RDF><cc:Work + rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs + id="defs5174"> + + + + + + + + + + + + + + + </defs><sodipodi:namedview + inkscape:window-height="871" + inkscape:window-width="1432" + inkscape:pageshadow="2" + inkscape:pageopacity="0.0" + guidetolerance="10.0" + gridtolerance="10.0" + objecttolerance="10.0" + borderopacity="1.0" + bordercolor="#666666" + pagecolor="#ffffff" + id="base" + inkscape:zoom="12.145455" + inkscape:cx="27.5" + inkscape:cy="30.793413" + inkscape:window-x="4" + inkscape:window-y="25" + inkscape:current-layer="svg5142" /><g + id="g5125" + transform="translate(-2,2)"><g + id="g5147"> + <g + id="g5149"> + <path + style="fill:#ffffff;stroke:#8c8c8c;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round" + id="path5151" + d="M 6.736,49.002 L 31.256,49.002 C 33.481,49.002 34.695,47.555 34.695,45.561 L 34.695,18.281 C 34.695,16.551 32.963,14.84 31.256,14.84 L 26.867,14.84" /> + </g> + </g><g + id="g5153"> + <g + id="g5155"> + <path + style="fill:#ffffff;stroke:#8c8c8c;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round" + id="path5157" + d="M 26.867,38.592 C 26.867,40.428 25.522,41.793 23.426,42.639 L 6.736,49.002 L 6.736,14.84 L 23.426,6.241 C 25.654,5.847 26.867,7.081 26.867,9.075 L 26.867,38.592 z " /> + </g> + </g><path + style="fill:none;stroke:#8c8c8c;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round" + id="path5159" + d="M 9.424,42.607 C 9.424,42.607 8.073,42.064 6.722,42.064 C 5.371,42.064 4.019,42.607 4.019,42.607" /><path + style="fill:none;stroke:#8c8c8c;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round" + id="path5161" + d="M 9.424,32.006 C 9.424,32.006 8.185,31.463 6.609,31.463 C 5.032,31.463 4.019,32.006 4.019,32.006" /><path + style="fill:none;stroke:#8c8c8c;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round" + id="path5163" + d="M 9.424,21.678 C 9.424,21.678 8.299,21.134 6.497,21.134 C 4.695,21.134 4.019,21.678 4.019,21.678" /><line + style="fill:none;stroke:#8c8c8c;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round" + id="line5165" + y2="11.505" + y1="46.533001" + x2="13.209" + x1="13.209" /></g><g + id="g4140" + transform="matrix(0.8372116,0,0,0.8372116,8.751416,-7.2720533e-2)"><rect + style="fill:#ffffff;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2221" + height="5.0509453" + width="5.0529833" + y="2.5764074" + x="32.505089" /><rect + style="fill:#aaaaaa;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2223" + height="5.0509453" + width="5.0529833" + y="2.5764074" + x="40.25333" /><rect + style="fill:#aaaaaa;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2225" + height="5.0509453" + width="5.0529833" + y="2.5764074" + x="47.70649" /><rect + style="fill:#aaaaaa;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2227" + height="5.0509453" + width="5.0529833" + y="10.110903" + x="32.505089" /><rect + style="fill:#aaaaaa;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2229" + height="5.0509453" + width="5.0529833" + y="10.110903" + x="40.25333" /><rect + style="fill:#aaaaaa;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2231" + height="5.0509453" + width="5.0529833" + y="10.110903" + x="47.70649" /><rect + style="fill:#aaaaaa;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2233" + height="5.0509453" + width="5.0529833" + y="17.624184" + x="32.505089" /><rect + style="fill:#ffffff;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2235" + height="5.0509453" + width="5.0529833" + y="17.624184" + x="40.25333" /><rect + style="fill:#aaaaaa;stroke:#000000;stroke-width:2.38888216;stroke-miterlimit:4;stroke-dasharray:none" + id="rect2237" + height="5.0509453" + width="5.0529833" + y="17.624184" + x="47.70649" /></g><line + style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" + id="line5169" + y2="36.425068" + y1="22.462688" + x2="45.845959" + x1="46.039944" /><polyline + style="fill:none;stroke:#ffffff;stroke-width:5.1055975;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" + id="polyline5171" + points=" 51.562,15.306 41.17,16.188 42.053,5.794 " + transform="matrix(0.4648229,0.5053552,-0.4762768,0.493202,24.919883,7.4889306)" /><line + style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" + id="line4138" + y2="36.52364" + y1="36.329655" + x2="45.78508" + x1="37.750839" /></svg>
\ No newline at end of file diff --git a/memorizetoolbar.py b/memorizetoolbar.py index bf9f84d..bb17ba2 100755 --- a/memorizetoolbar.py +++ b/memorizetoolbar.py @@ -24,7 +24,7 @@ import os from gettext import gettext as _ from sugar.graphics.toolbutton import ToolButton -from sugar.graphics.combobox import ComboBox +from sugar.graphics.toolcombobox import ToolComboBox class MemorizeToolbar(gtk.Toolbar): @@ -42,6 +42,7 @@ class MemorizeToolbar(gtk.Toolbar): # Reset Button self._reset_button = ToolButton('insert-image') self._reset_button.connect('clicked', self._game_changed_cb) + self._reset_button.set_tooltip(_('Restart Game')) self.insert(self._reset_button, -1) self._reset_button.show() @@ -53,12 +54,12 @@ class MemorizeToolbar(gtk.Toolbar): # Change game combobox self.games = os.listdir(os.path.join(os.path.dirname(__file__), 'games')) self.games.sort() - self._game_combo = ComboBox() + self._game_combo = ToolComboBox() for i, f in enumerate(self.games): if f in self.standard_game_names: f = _(f) - self._game_combo.append_item(i, f) - self._game_combo.connect('changed', self._game_changed_cb) + self._game_combo.combo.append_item(i, f) + self._game_combo.combo.connect('changed', self._game_changed_cb) self._add_widget(self._game_combo) separator = gtk.SeparatorToolItem() @@ -67,11 +68,11 @@ class MemorizeToolbar(gtk.Toolbar): self._lock = False # Change size combobox - self._size_combo = ComboBox() + self._size_combo = ToolComboBox() self._sizes = ['4 X 4', '5 X 5', '6 X 6'] for i, f in enumerate(self._sizes): - self._size_combo.append_item(i, f) - self._size_combo.connect('changed', self._game_changed_cb) + self._size_combo.combo.append_item(i, f) + self._size_combo.combo.connect('changed', self._game_changed_cb) self._add_widget(self._size_combo) def _add_widget(self, widget, expand=False): @@ -84,8 +85,8 @@ class MemorizeToolbar(gtk.Toolbar): def _game_changed_cb(self, combobox): if not self._lock: - game_name = self.games[self._game_combo.get_active()] - game_size = int(self._sizes[self._size_combo.get_active()][0]) + game_name = self.games[self._game_combo.combo.get_active()] + game_size = int(self._sizes[self._size_combo.combo.get_active()][0]) if game_name in self.translated_game_names: index = self.translated_game_names.index(game_name) game_name = self.standard_game_names[index] @@ -96,7 +97,7 @@ class MemorizeToolbar(gtk.Toolbar): size = data.get('size') self._lock = True game_index = self.games.index(game) - self._game_combo.set_active(game_index) + self._game_combo.combo.set_active(game_index) size_index = self._sizes.index(size+' X '+size) - self._size_combo.set_active(int(size_index)) + self._size_combo.combo.set_active(int(size_index)) self._lock = False diff --git a/playerscoreboard.py b/playerscoreboard.py index 2526917..32bf551 100755 --- a/playerscoreboard.py +++ b/playerscoreboard.py @@ -54,12 +54,7 @@ class PlayerScoreboard(gtk.EventBox): self.icon = svglabel.SvgLabel(self.xo_buddy, fill_color, stroke_color, False, self.current_color, 45, 55) # Set waiting buddy icon - self.waiting_icon = svglabel.SvgLabel(self.xo_buddy, self.default_color, '#ffffff', False, self.current_color, 45, 55) - - # Cache the score icon - score_label = Score(fill_color, stroke_color) - self.score_pixbuf_unsel = score_label.get_pixbuf() - self.score_pixbuf_sel = score_label.get_pixbuf_sel() + #self.waiting_icon = svglabel.SvgLabel(self.xo_buddy, self.default_color, '#ffffff', False, self.current_color, 45, 55) # Set nick label self.nick = gtk.Label(nick) @@ -68,10 +63,10 @@ class PlayerScoreboard(gtk.EventBox): 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.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) @@ -82,6 +77,12 @@ class PlayerScoreboard(gtk.EventBox): self.increase_score() def increase_score(self): + if len(self.scores) == 0: + # Cache the score icon + score_label = Score(self.fill_color, self.stroke_color) + 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) self.scores.append(new_score) new_score.show() @@ -35,75 +35,70 @@ class SvgCard(gtk.DrawingArea): # Default properties default_props = {} - default_props['back_border'] = {'filename':border_svg, 'fill_color':'#b2b3b7', 'stroke_color':'#b2b3b7', 'opacity':'1'} - default_props['back_h_border'] = {'filename':border_svg, 'fill_color':'#b2b3b7', 'stroke_color':'#ffffff', 'opacity':'1'} + default_props['back'] = {'fill_color':'#b2b3b7', 'stroke_color':'#b2b3b7', 'opacity':'1'} + default_props['back_h'] = {'fill_color':'#b2b3b7', 'stroke_color':'#ffffff', 'opacity':'1'} default_props['back_text'] = {'text_color':'#c7c8cc'} - default_props['front_border'] = {'filename':border_svg, 'fill_color':'#4c4d4f', 'stroke_color':'#ffffff', 'opacity':'0'} - default_props['front_h_border'] = {'filename':border_svg, 'fill_color':'#555555', 'stroke_color':'#888888', 'opacity':'0.5'} + default_props['front'] = {'fill_color':'#4c4d4f', 'stroke_color':'#ffffff', 'opacity':'1'} + default_props['front_h'] = {'fill_color':'#555555', 'stroke_color':'#888888', 'opacity':'1'} default_props['front_text'] = {'text_color':'#ffffff'} - def __init__(self, id, pprops, pcache, jpeg, size, align, bg_color='#000000'): + cache = {} + + def __init__(self, id, pprops, jpeg, size, align, bg_color='#000000'): gtk.DrawingArea.__init__(self) self.set_size_request(size, size) self.bg_color = bg_color - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.bg_color)) - self.connect('expose-event', self._expose_cb) + self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.bg_color)) self.flipped = False self.flipped_once = False self.id = id self.jpeg = jpeg + self.show_jpeg = False + self.show_text = False self.size = size self.align = align - self.set_flags(gtk.CAN_FOCUS) # Views properties - views = ['back_border', 'back_h_border', 'back_text', 'front_border', 'front_h_border', 'front_text'] + views = ['back', 'back_h', 'back_text', 'front', 'front_h', 'front_text'] self.pprops = pprops self.props = {} for view in views: self.props[view] = {} self.props[view].update(self.default_props[view]) self.props[view].update(pprops.get(view, {})) - - # Cache - self.cache = {} - self.cache.update(pcache) - - build_all = (len(self.cache) == 0) - - self.build_all = build_all - - if build_all or pprops.has_key('back_border'): - self.cache['back_border']= self._read_icon_data(self.props['back_border']) - if build_all or pprops.has_key('back_h_border'): - self.cache['back_h_border']= self._read_icon_data(self.props['back_h_border']) - - self.back_layout = self.get_text_layout(self.props['back_text'].get('card_text', ''), self.size-12) - self.back_layout_position = (self.size -(self.back_layout.get_size()[1]/1000))/2 - - if build_all or self.pprops.has_key('back_border') or self.pprops.has_key('back_text'): - self.cache['back'] = self.build_face('back') - if build_all or self.pprops.has_key('back_h_border') or self.pprops.has_key('back_text'): - self.cache['back_h'] = self.build_face('back_h') - - self.current_pixbuf = self.cache['back'] - self.current_layout = self.back_layout - self.current_layout_position = self.back_layout_position - self.current_text_color = self.props['back_text'].get('text_color', '#c7c8cc') + + if len(self.props['back_text'].get('card_text','')) > 0: + self.back_layout = self.get_text_layout(self.props['back_text']['card_text'], self.size-12) + self.back_layout_position = (self.size -(self.back_layout.get_size()[1]/1000))/2 + self.current_layout = self.back_layout + self.current_layout_position = self.back_layout_position + self.current_text_color = self.props['back_text']['text_color'] + self.show_text = True + self.current_face = 'back' # Set events and listeners + self.connect('expose-event', self._expose_cb) self.set_events(gtk.gdk.ALL_EVENTS_MASK) gc.collect() self.show() def _expose_cb(self, widget, event): - self.window.draw_pixbuf(None, self.current_pixbuf, 0, 0, 0, 0) gc = self.window.new_gc() - 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)) + pixbuf = self._read_icon_data(self.current_face) + self.window.draw_pixbuf(None, pixbuf, 0, 0, 0, 0) + if self.show_jpeg: + self.window.draw_pixbuf(None, self.jpeg, 0, 0, 11, 11) + 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 - def _read_icon_data(self, dict): - icon_file = open(dict.get('filename', 'card.svg'), 'r') + def _read_icon_data(self, view): + dict = self.props[view] + set = str(self.size)+dict.get('fill_color')+dict.get('stroke_color') + if self.cache.has_key(set): + return self.cache[set] + + icon_file = open(self.border_svg, 'r') data = icon_file.read() icon_file.close() @@ -120,85 +115,73 @@ class SvgCard(gtk.DrawingArea): data = re.sub('size_card1', str(self.size), data) data = re.sub('size_card2', str(self.size-6), data) data = re.sub('size_card3', str(self.size-17), data) - - self.data_size = len(data) - return rsvg.Handle(data=data).get_pixbuf() - - def build_face(self, face): - if face.endswith('_h'): - text = face[:-2] - else: - text = face - pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, self.size, self.size) - pixbuf.fill(0x00000000) - self.cache[face + '_border'].composite(pixbuf, 0, 0, self.size, self.size, 0, 0, 1, 1, gtk.gdk.INTERP_NEAREST, 255) - if face.startswith('front') and self.jpeg <> None: - self.cache['jpeg'].composite(pixbuf, 11, 11, self.size-22, self.size-22, 11, 11, 1, 1, gtk.gdk.INTERP_NEAREST, 255) + pixbuf = rsvg.Handle(data=data).get_pixbuf() + self.cache[set] = pixbuf return pixbuf def set_border(self, stroke_color, fill_color): - self.props['front_border'].update({'fill_color':fill_color, 'stroke_color':stroke_color}) - self.cache['front_border'] = self._read_icon_data(self.props['front_border']) - self.cache['front'] = self.build_face('front') - self.current_pixbuf = self.cache['front'] - self.queue_draw() + self.props['front'].update({'fill_color':fill_color, 'stroke_color':stroke_color}) + self.queue_draw() + while gtk.events_pending(): + gtk.main_iteration() def set_highlight(self, status, mouse = False): if self.flipped: if mouse: return if status: - self.current_pixbuf = self.cache['front_h'] + self.current_face = 'front_h' else: - self.current_pixbuf = self.cache['front'] + self.current_face = 'front' else: if status: - self.current_pixbuf = self.cache['back_h'] + self.current_face = 'back_h' else: - self.current_pixbuf = self.cache['back'] + self.current_face = 'back' self.queue_draw() def flip(self): if not self.flipped: if not self.flipped_once: - if self.build_all or self.pprops.has_key('front_border'): - self.cache['front_border']= self._read_icon_data(self.props['front_border']) - if self.build_all or self.pprops.has_key('front_h_border'): - self.cache['front_h_border']= self._read_icon_data(self.props['front_h_border']) - self.front_layout = self.get_text_layout(self.props['front_text'].get('card_text', ''), self.size-11) - if self.align == '2': # top - self.front_layout_position = 6 - elif self.align == '3': # bottom - self.front_layout_position = self.size -(self.front_layout.get_size()[1]/1000) - else: # center and none - self.front_layout_position = (self.size -(self.front_layout.get_size()[1]/1000))/2 if self.jpeg <> None: pixbuf_t = gtk.gdk.pixbuf_new_from_file(self.jpeg) - self.cache['jpeg']= pixbuf_t.scale_simple(self.size-22, self.size-22, gtk.gdk.INTERP_BILINEAR) - del pixbuf_t - - if self.cache.has_key('front_border') or self.cache.has_key('front_text'): - self.cache['front'] = self.build_face('front') - if self.cache.has_key('front_h_border') or self.cache.has_key('front_text'): - self.cache['front_h'] = self.build_face('front_h') + self.jpeg = pixbuf_t.scale_simple(self.size-22, self.size-22, gtk.gdk.INTERP_BILINEAR) + del pixbuf_t + if len(self.props.get('front_text',[]).get('card_text','')) > 0: + self.front_layout = self.get_text_layout(self.props['front_text']['card_text'], self.size-12) + self.front_layout_position = (self.size -(self.front_layout.get_size()[1]/1000))/2 self.flipped_once = True - self.current_layout = self.front_layout - self.current_layout_position = self.front_layout_position - self.current_text_color = self.props['front_text'].get('text_color', '#c7c8cc') - self.current_pixbuf = self.build_face('front') + if self.jpeg <> None: + self.show_jpeg = True + if len(self.props['front_text'].get('card_text','')) > 0: + self.current_layout = self.front_layout + self.current_layout_position = self.front_layout_position + self.current_text_color = self.props['front_text']['text_color'] + self.show_text = True + else: + self.show_text = False + + self.current_face = 'front' + self.flipped = True self.queue_draw() + while gtk.events_pending(): gtk.main_iteration() gc.collect() def flop(self): - self.current_pixbuf = self.build_face('back') - self.current_layout = self.back_layout - self.current_layout_position = self.back_layout_position - self.current_text_color = self.props['back_text'].get('text_color', '#c7c8cc') + self.current_face = 'back' + if len(self.props['back_text'].get('card_text','')) > 0: + self.current_layout = self.back_layout + self.current_layout_position = self.back_layout_position + self.current_text_color = self.props['back_text']['text_color'] + self.show_text = True + else: + self.show_text = False self.flipped = False + self.show_jpeg = False self.queue_draw() def is_flipped(self): @@ -207,13 +190,10 @@ class SvgCard(gtk.DrawingArea): def get_id(self): return self.id - def get_cache(self): - return self.cache - def reset(self): if self.flipped: fill_color = self.default_props.get('front_border').get('fill_color') - stroke_color = self.default_props.get('front_border').get('stroke_color') + stroke_color = self.default_propsfront_text.get('front_border').get('stroke_color') self.set_border(fill_color, stroke_color) self.flop() @@ -256,7 +236,9 @@ class SvgCard(gtk.DrawingArea): self.current_layout = self.front_layout self.current_layout_position = self.front_layout_position - self.queue_draw() - + self.current_text_color = self.props['front_text']['text_color'] + if len(newtext) > 0: + self.show_text = True + self.queue_draw() def get_text(self): return self.props['front_text']['card_text']
\ No newline at end of file |