From 9bad1637df73e51b658c1452b1bbca90a88c26a1 Mon Sep 17 00:00:00 2001 From: Pablo Moleri Date: Sat, 10 Apr 2010 23:33:30 +0000 Subject: Accesibility option in the game toolbar. --- diff --git a/activity.py b/activity.py index 81c36ae..af19665 100644 --- a/activity.py +++ b/activity.py @@ -111,6 +111,7 @@ class MemorizeActivity(Activity): self.game.connect('change_game', self._memorizeToolbar.update_toolbar) self._memorizeToolbar.connect('game_changed', self.game.change_game) + self._memorizeToolbar.connect('accesible_toggled', self.table.toggle_accesibility) self.hbox = gtk.HBox(False) self.set_canvas(self.hbox) @@ -317,10 +318,10 @@ class MemorizeActivity(Activity): _logger.debug("buddy left: %s", buddy.props.nick) self.game.rem_buddy(buddy) - def _focus_in(self, event, data=None): + def _focus_in(self, event, data=None): self.game.audio.play() - def _focus_out(self, event, data=None): + def _focus_out(self, event, data=None): self.game.audio.pause() def _cleanup_cb(self, data=None): diff --git a/activity/activity-memorize-accesible.svg b/activity/activity-memorize-accesible.svg new file mode 100644 index 0000000..a4ef3dd --- /dev/null +++ b/activity/activity-memorize-accesible.svg @@ -0,0 +1,95 @@ + + + +]> + + + + + + + + + + + + diff --git a/activity/activity.info b/activity/activity.info index 2fef1e1..72ea70c 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -1,9 +1,9 @@ [Activity] -name = Memorize -bundle_id = org.laptop.Memorize +name = MemorizeAccesible +bundle_id = org.ceibaljam.MemorizeAccesible exec = sugar-activity activity.MemorizeActivity -icon = activity-memorize -activity_version = 34 +icon = activity-memorize-accesible +activity_version = 1 show_launcher = yes mime_types = application/x-memorize-project; license = GPLv2+ diff --git a/cardtable.py b/cardtable.py index 1f251e2..4783ae5 100644 --- a/cardtable.py +++ b/cardtable.py @@ -22,6 +22,7 @@ import os import math import gc from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT +import gobject import logging _logger = logging.getLogger('memorize-activity') @@ -66,6 +67,10 @@ class CardTable(gtk.EventBox): self.load_mode = False self.dict = None self.show_all() + + # Sets the game to run in accesible mode: + self.accesible = False # This should be optional + self.scanning_id = 0 def _allocate_cb(self, widget, allocation): size = allocation.height @@ -154,7 +159,71 @@ class CardTable(gtk.EventBox): self._set_load_mode(False) self.show_all() #gc.collect() + + # If necessary starts scanning for accesibility + self.restart_scanning() + def restart_scanning(self): + # Increments scanning_id so new games will not be scanned by old timers + self.scanning_id += 1 + + # accesible game scanning info + if self.accesible: + self.scanning_status = { + "direction": "F", + "row": self.size - 1, # Initialized in last row, so the next is the first + "column": 0 + } + # Scanning will occur every two seconds <- this should be configurable + gobject.timeout_add(2000, self.scan_next, self.scanning_id) + + def scan_next(self, id): + if self.scanning_id != id: + if self.scanning_status["direction"] == 'F': + # Unhighlights last row + self.paint_cards(False, self.scanning_status["row"], None) + elif self.scanning_status["direction"] == 'C': + # Unhighlights last card + self.paint_cards(False, self.scanning_status["row"], self.scanning_status["column"]) + + # This event is from a previous game, disable the timer returning False + return False + + # self.scanning_status = { + # "direction": "F", + # "row":0, + # "column":0 + #} + + if self.scanning_status["direction"] == 'F': + # Unhighlights last row and hightlights next full row + self.paint_cards(False, self.scanning_status["row"], None) + self.scanning_status["row"] = (self.scanning_status["row"] + 1) % self.size + self.paint_cards(True, self.scanning_status["row"], None) + + elif self.scanning_status["direction"] == 'C': + # Unhighlights last card and highlights next card in the row + self.paint_cards(False, self.scanning_status["row"], self.scanning_status["column"]) + self.scanning_status["column"] = (self.scanning_status["column"] + 1) % self.size + self.paint_cards(True, self.scanning_status["row"], self.scanning_status["column"]) + + return True # So the timer continues calling this function + + def paint_cards(self, pintar, row, column=None): + first_card = row * self.size # Identifier of the first card in the row + if column is None: + for column in range(0, self.size): + if first_card + column < len(self.cards): + self.highlight_card(None, first_card + column, pintar) + else: + if first_card + column < len(self.cards): + self.highlight_card(None, first_card + column, pintar) + + def toggle_accesibility(self, widget, accesible): + print accesible + self.accesible = accesible + self.restart_scanning() + def change_game(self, widget, data, grid): if not self.first_load: for card in self.cards.values(): @@ -169,11 +238,13 @@ class CardTable(gtk.EventBox): return x def mouse_event(self, widget, event, coord): - #self.table.grab_focus() - card = self.cards[coord[0], coord[1]] - identifier = self.cd2id.get(card) - self.emit('card-highlighted', identifier, True) - self.selected_card = (coord[0], coord[1]) + # In accesible mode mouse event doesn't highlight cards, the highlighting occurs through the scanning + if not self.accesible: + #self.table.grab_focus() + card = self.cards[coord[0], coord[1]] + identifier = self.cd2id.get(card) + self.emit('card-highlighted', identifier, True) + self.selected_card = (coord[0], coord[1]) def key_press_event(self, widget, event): #self.table.grab_focus() @@ -209,9 +280,29 @@ class CardTable(gtk.EventBox): self.card_flipped(card) def flip_card_mouse(self, widget, event, identifier): - position = self.dict[identifier] - card = self.cards[position] - self.card_flipped(card) + if self.accesible: + if self.scanning_status["direction"] == 'F': + # Turn off row highlight + self.paint_cards(False, self.scanning_status["row"], None) + + # Change to column scanning + self.scanning_status["direction"] = 'C' + + # Sets the first column as highlighted + self.scanning_status["column"] = 0 + self.paint_cards(True, self.scanning_status["row"], 0) + + else: + # Flips the selected cards and go back to row scanning + identifier = self.scanning_status["row"] * self.size + self.scanning_status["column"] + position = self.dict[identifier] + card = self.cards[position] + self.card_flipped(card) + self.scanning_status["direction"] = 'F' + else: + position = self.dict[identifier] + card = self.cards[position] + self.card_flipped(card) def card_flipped(self, card): identifer = self.cd2id[card] diff --git a/memorizetoolbar.py b/memorizetoolbar.py index 782f818..c4fcfec 100644 --- a/memorizetoolbar.py +++ b/memorizetoolbar.py @@ -21,6 +21,7 @@ from os.path import join, dirname from gettext import gettext as _ from sugar.graphics.toolbutton import ToolButton from sugar.graphics.toolcombobox import ToolComboBox +from sugar.graphics.toggletoolbutton import ToggleToolButton from sugar.graphics.objectchooser import ObjectChooser from sugar import profile @@ -44,7 +45,8 @@ class MemorizeToolbar(gtk.Toolbar): ] __gsignals__ = { - 'game_changed': (SIGNAL_RUN_FIRST, None, 5 * [TYPE_PYOBJECT]) + 'game_changed': (SIGNAL_RUN_FIRST, None, 5 * [TYPE_PYOBJECT]), + 'accesible_toggled': (SIGNAL_RUN_FIRST, None, [TYPE_PYOBJECT]) } def __init__(self, activity): @@ -103,6 +105,11 @@ class MemorizeToolbar(gtk.Toolbar): self._game_combo.combo.connect('changed', self._game_changed_cb) self._add_widget(self._game_combo) + # Accesible mode checkbox + self._accesible = gtk.CheckButton(_('Accesible')) + self._accesible.connect('toggled', self._toggle_accesible) + self._add_widget(self._accesible) + def _add_widget(self, widget, expand=False): tool_item = gtk.ToolItem() tool_item.set_expand(expand) @@ -164,6 +171,9 @@ class MemorizeToolbar(gtk.Toolbar): self.emit('game_changed', game_file, game_size, 'demo', title, None) self._game_combo.combo.set_active(0) + def _toggle_accesible(self, checkbutton): + self.emit('accesible_toggled', checkbutton.get_active()) + def update_toolbar(self, widget, data, grid): size = data.get('size') self._size_combo.combo.handler_block(self.size_handle_id) diff --git a/svgcard.py b/svgcard.py index d408ca6..d16e4bc 100644 --- a/svgcard.py +++ b/svgcard.py @@ -42,7 +42,7 @@ class SvgCard(gtk.EventBox): default_props['back'] = {'fill_color':'#b2b3b7', 'stroke_color':'#b2b3b7', 'opacity':'1'} default_props['back_h'] = {'fill_color':'#b2b3b7', - 'stroke_color':'#ffffff', 'opacity':'1'} + 'stroke_color':'#C00000', 'opacity':'1'} default_props['back_text'] = {'text_color':'#c7c8cc'} default_props['front'] = {'fill_color':'#4c4d4f', 'stroke_color':'#ffffff', 'opacity':'1'} -- cgit v0.9.1