diff options
author | Pablo Moleri <pmoleri@PABLOMOLERI-PC.(none)> | 2010-04-10 23:33:30 (GMT) |
---|---|---|
committer | Pablo Moleri <pmoleri@PABLOMOLERI-PC.(none)> | 2010-04-10 23:33:30 (GMT) |
commit | 9bad1637df73e51b658c1452b1bbca90a88c26a1 (patch) | |
tree | 2e0c544ec489bb1c5f82c2e7bfed4c904416081f | |
parent | 61efd384fffb3c4ec9a3c694b1380ef2d3ecdff3 (diff) |
Accesibility option in the game toolbar.
-rw-r--r-- | activity.py | 5 | ||||
-rw-r--r-- | activity/activity-memorize-accesible.svg | 95 | ||||
-rw-r--r-- | activity/activity.info | 8 | ||||
-rw-r--r-- | cardtable.py | 107 | ||||
-rw-r--r-- | memorizetoolbar.py | 12 | ||||
-rw-r--r-- | svgcard.py | 2 |
6 files changed, 213 insertions, 16 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [ + <!ENTITY stroke_color "#666666"> + <!ENTITY fill_color "#FFFFFF"> +]> +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.0" + width="55" + height="55" + viewBox="0 0 55 55" + id="svg2" + xml:space="preserve"> +<g + transform="translate(-4.6761134,-5.2327935)" + id="activity-memorize" + style="display:block"> + <rect + width="10" + height="10" + x="7.2909999" + y="7.8330002" + id="rect5" + style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:3.5;display:inline" /> + <rect + width="10" + height="10" + x="22.625" + y="7.8330002" + id="rect7" + style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:3.5;display:inline" /> + <rect + width="10" + height="10" + x="37.375" + y="7.8330002" + id="rect9" + style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:3.5;display:inline" /> + <rect + width="10" + height="10" + x="7.2909999" + y="22.75" + id="rect11" + style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:3.5;display:inline" /> + <rect + width="10" + height="10" + x="22.625" + y="22.75" + id="rect13" + style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:3.5;display:inline" /> + <rect + width="10" + height="10" + x="37.375" + y="22.75" + id="rect15" + style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:3.5;display:inline" /> + <rect + width="10" + height="10" + x="7.2909999" + y="37.625" + id="rect17" + style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:3.5;display:inline" /> + <rect + width="10" + height="10" + x="22.625" + y="37.625" + id="rect19" + style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:3.5;display:inline" /> + <rect + width="10" + height="10" + x="37.375" + y="37.625" + id="rect21" + style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:3.5;display:inline" /> +</g><g + transform="matrix(0.4584559,0,0,0.4584559,36.055801,32.835149)" + id="terron"><path + d="M 38.822128,44.108722 C 38.822128,44.108722 38.445765,44.108722 38.092819,44.108722 C 38.092819,42.747378 38.097001,38.459638 38.097001,37.325183 C 38.097001,37.325183 38.097001,37.325183 38.097001,37.323527 L 38.097001,24.562988 L 38.089474,16.811436 C 38.086128,15.932855 37.361837,15.224857 36.48031,15.228997 C 36.052928,15.228997 35.648965,15.396267 35.347873,15.696856 C 35.045946,15.999101 34.882019,16.399058 34.883691,16.823857 C 34.883691,16.863604 34.885364,19.358576 34.887873,21.45773 L 22.071438,21.45773 C 20.330965,21.45773 18.920019,22.854682 18.920019,24.575409 L 18.920019,26.300276 L 13.265364,26.303588 C 12.377982,26.309384 11.663728,27.024008 11.667074,27.896793 C 11.668746,28.321592 11.837691,28.719892 12.141291,29.017998 C 12.446565,29.316931 12.850528,29.479232 13.277073,29.477576 C 13.326419,29.477576 16.696965,29.47592 18.919182,29.474263 L 18.919182,37.014658 C 18.919182,37.02625 18.915837,37.036187 18.915837,37.046952 C 18.915837,37.104917 18.919182,42.545329 18.919182,44.107894 C 18.567073,44.107894 18.189873,44.107894 18.189873,44.107894 C 17.285765,44.125284 16.584055,44.849844 16.59911,45.724285 C 16.61751,46.601209 17.351837,47.296787 18.234201,47.279397 L 20.537546,47.277741 C 21.439146,47.26118 22.145037,46.535792 22.126637,45.661352 L 22.123292,40.442034 L 34.887873,40.442034 L 34.882019,45.661352 C 34.865292,46.53662 35.571182,47.262009 36.472783,47.277741 L 38.774455,47.279397 C 39.661,47.296787 40.393656,46.601209 40.411219,45.724285 C 40.428782,44.849844 39.723728,44.126112 38.822128,44.108722 z M 30.604855,25.673428 C 31.197837,25.590621 31.748164,25.999687 31.832637,26.587615 C 31.917946,27.174716 31.50311,27.720413 30.910128,27.804876 C 30.3138,27.887683 29.76431,27.476962 29.680673,26.890689 C 29.595365,26.301932 30.010201,25.756235 30.604855,25.673428 z M 24.950201,26.467545 C 25.542346,26.384739 26.09351,26.793805 26.177147,27.381734 C 26.262455,27.97049 25.847619,28.513703 25.255473,28.598995 C 24.659146,28.683458 24.109656,28.272735 24.026019,27.684807 C 23.941546,27.096049 24.353874,26.552009 24.950201,26.467545 z M 26.384565,35.548148 C 25.364201,34.827728 23.744165,32.814693 24.326273,31.447552 C 24.532019,30.966443 24.984492,31.265376 25.47711,31.509657 C 26.653037,32.10421 28.05311,32.180392 29.308492,31.805277 C 29.946637,31.614821 30.491946,31.305951 31.012165,30.893574 C 31.328309,30.641012 32.191437,29.636565 32.666491,30.090346 C 33.037837,30.445588 33.101401,30.886121 33.101401,30.890261 C 33.634164,34.258844 29.418891,37.688706 26.384565,35.548148 z" + id="cuerpo" + style="fill:&fill_color;;stroke:&stroke_color;" /><path + d="M 17.233073,11.642631 C 18.971874,8.6971904 24.424965,8.6756607 25.411873,12.233044 C 25.743073,13.428775 25.717147,16.000757 24.39151,16.697991 C 23.925655,16.943099 23.764237,16.42804 23.540092,15.929543 C 23.003146,14.736296 21.969401,13.79975 20.755837,13.307049 C 20.139437,13.055317 19.519691,12.950152 18.853946,12.946839 C 18.446637,12.943527 17.137728,13.184495 17.060783,12.532805 C 17.000564,12.027683 17.233073,11.644287 17.233073,11.642631 z" + id="pelo_oscuro" + style="fill:&fill_color;;stroke:&stroke_color;" /><g + transform="matrix(0.8363636,0,0,0.8280687,4.3773279,7.643887)" + id="pelo_claro"><path + d="M 30.514,13.666 C 25.959,9.955 27.36,0.759 33.675,0.043 C 35.799,-0.198 40.171,0.537 41.006,2.954 C 41.299,3.802 40.382,3.936 39.473,4.18 C 37.299,4.765 35.434,6.261 34.273,8.172 C 33.681,9.144 33.342,10.161 33.16,11.281 C 33.047,11.964 33.108,14.236 31.982,14.194 C 31.107,14.162 30.516,13.668 30.514,13.666 z" + id="path2674" + style="fill:&fill_color;;stroke:&stroke_color;" /></g></g></svg> 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) @@ -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'} |