From 92cf55fcb7b956d6b7f049ae87d23f4671d08f09 Mon Sep 17 00:00:00 2001 From: Muriel de Souza Godoi Date: Tue, 11 Sep 2007 20:23:36 +0000 Subject: Basic interface (under development) for create game mode --- diff --git a/activity.py b/activity.py index eb92ccd..14c3ad7 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,27 @@ 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.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) @@ -130,7 +140,28 @@ 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) + + 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.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) + else: + self.hbox.remove(self.cardlist) + self.hbox.remove(self.createcardpanel) + self.hbox.pack_start(self.scoreboard, False, False) + self.hbox.pack_start(self.table) + def restart(self, widget): self.game.reset() diff --git a/cardlist.py b/cardlist.py new file mode 100644 index 0000000..cce0b04 --- /dev/null +++ b/cardlist.py @@ -0,0 +1,139 @@ +#! /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 + +_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.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 add_pair(self, widget, text): + pair = Pair(text, text) + 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) + self.show_all() + + def rem_pair(self, widget, event): + self.vbox.remove(widget) + del self.pairs[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, newtext): + self.current_pair.change_text(newtext) + +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_border':{'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_border':{'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..c1fb1be 100755 --- a/cardtable.py +++ b/cardtable.py @@ -69,8 +69,8 @@ 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) + buffer_card_1 = svgcard.SvgCard(-1, {'back_text':{'card_text':text1}}, {}, None, self.card_size,1) + buffer_card_2 = svgcard.SvgCard(-1, {'back_text':{'card_text':text2}}, {}, None, self.card_size,1) x = 0 y = 0 @@ -116,8 +116,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..fa8ecd6 --- /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]), + 'update-pair': (gobject.SIGNAL_RUN_FIRST, None, [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()) + + def emit_update_pair(self, widget, event): + self.emit('update-pair',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..f7981e4 --- /dev/null +++ b/createtoolbar.py @@ -0,0 +1,83 @@ +#! /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 + +from sugar.graphics.toolbutton import ToolButton +from sugar.graphics.combobox import ComboBox + +class CreateToolbar(gtk.Toolbar): + __gtype_name__ = 'CreateToolbar' + + def __init__(self, activity): + gtk.Toolbar.__init__(self) + self.activity = activity + self._lock = True + + # Reset Button + new_icon = os.path.join(os.path.dirname(__file__), "images/new.svg") + new_image = gtk.Image() + new_image.set_from_file(new_icon) + self._reset_button = gtk.ToolButton(new_image) + #self._reset_button.set_image(new_image) + #self._reset_button.connect('clicked', self._game_changed_cb) + self._add_widget(self._reset_button) + + # Separator + separator = gtk.SeparatorToolItem() + separator.set_draw(True) + self.insert(separator, -1) + + self._add_widget(gtk.Label('Game name: ')) + # Change game combobox + self.games = os.listdir(os.path.join(os.path.dirname(__file__), 'games')) + self.games.sort() + self._game_combo = gtk.ComboBoxEntry() + for i, f in enumerate(self.games): + self._game_combo.append_text(f) + if f == 'numbers': + self._game_combo.set_active(i) + #self._game_combo.connect('changed', self._game_changed_cb) + self._add_widget(self._game_combo) + + # Separator + separator2 = gtk.SeparatorToolItem() + separator2.set_draw(True) + self.insert(separator2, -1) + + self._add_widget(gtk.CheckButton('Equal pairs')) + + # Separator + separator2 = gtk.SeparatorToolItem() + separator2.set_draw(True) + self.insert(separator2, -1) + + 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() \ No newline at end of file diff --git a/images/new.svg b/images/new.svg new file mode 100755 index 0000000..4dc4b64 --- /dev/null +++ b/images/new.svg @@ -0,0 +1,128 @@ + + +image/svg+xml + + + + + + + + + + \ No newline at end of file diff --git a/locale/pt_BR/activity.linfo b/locale/pt_BR/activity.linfo index 51d5971..e3fbfbe 100755 --- a/locale/pt_BR/activity.linfo +++ b/locale/pt_BR/activity.linfo @@ -1,2 +1,2 @@ [Activity] -name = Jogo da Memória \ No newline at end of file +name = Memorize diff --git a/svgcard.py b/svgcard.py index 2958559..6ecfaa7 100755 --- a/svgcard.py +++ b/svgcard.py @@ -35,11 +35,11 @@ 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_border'] = {'fill_color':'#b2b3b7', 'stroke_color':'#b2b3b7', 'opacity':'1'} + default_props['back_h_border'] = {'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_border'] = {'fill_color':'#4c4d4f', 'stroke_color':'#ffffff', 'opacity':'0'} + default_props['front_h_border'] = {'fill_color':'#555555', 'stroke_color':'#888888', 'opacity':'0.5'} default_props['front_text'] = {'text_color':'#ffffff'} def __init__(self, id, pprops, pcache, jpeg, size, align, bg_color='#000000'): @@ -66,8 +66,8 @@ class SvgCard(gtk.DrawingArea): self.props[view].update(pprops.get(view, {})) # Cache - self.cache = {} - self.cache.update(pcache) + self.cache = pcache + #self.cache.update(pcache) build_all = (len(self.cache) == 0) @@ -103,7 +103,7 @@ class SvgCard(gtk.DrawingArea): return False def _read_icon_data(self, dict): - icon_file = open(dict.get('filename', 'card.svg'), 'r') + icon_file = open(self.border_svg, 'r') data = icon_file.read() icon_file.close() @@ -120,8 +120,6 @@ 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): -- cgit v0.9.1