Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to Python 3 #10

Merged
merged 17 commits into from
May 15, 2020
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pyc
*~
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Recall Activity
===============

The Recall Activity is a series of three memory games, each of increasing difficulty.

How to use?
===============
Recall is not a part of Sugar Desktop but can be added. Refer to the following links-

* [How to Get Sugar on sugarlabs.org](https://sugarlabs.org/),
* [How to use Sugar](https://help.sugarlabs.org/), and;
* [How to use Recall](https://wiki.sugarlabs.org/go/Activities/Recall)

<img src="screenshots/en/2.png" width="75%" title="Recall Activity">
<img src="screenshots/en/3.png" width="75%" title="Recall Activity">
The first game prompts the learner to observe which images are repeated in the grid. It starts easy, with just three images, but as more images are added, it becomes more challenging.
The second game prompts the user to identify the image which had not appeared in the grid. Again, it starts easy, with just three images to remember, but gets very challenging as the number of images increases.
The third game (an "n-back"-style game) shows images in sequence and prompts the learner to recall which image came earlier. First is asked for the image that was present just previously; then two-previously,... up to six previously.
<img src="screenshots/en/4.png" width="75%" title="Recall Activity">
<img src="screenshots/en/5.png" width="75%" title="Recall Activity">

How to upgrade?
===============
On Sugar Desktop systems;

* [Use My Settings,](https://help.sugarlabs.org/my_settings.html) [Software Update](https://help.sugarlabs.org/my_settings.html#software-update)
* [Use Browse to open ](https://activities.sugarlabs.org/)activities.sugarlabs.org Search for Recall, then download
66 changes: 4 additions & 62 deletions RecallActivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,20 @@
# along with this library; if not, write to the Free Software
# Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA

import gi
gi.require_version('Gtk','3.0')
from gi.repository import Gtk
from gi.repository import Gdk

import dbus
import telepathy
import logging
from gettext import gettext as _
from dbus.service import signal
from dbus.gobject_service import ExportedGObject

from toolbar_utils import button_factory, radio_factory, label_factory, \
separator_factory
from utils import json_load, json_dump

from sugar3 import profile
from sugar3.activity import activity
from sugar3.presence import presenceservice
from sugar3.presence.tubeconn import TubeConnection

try:
from sugar3.presence.wrapper import CollabWrapper
logging.error('USING SUGAR COLLAB WRAPPER!')
except ImportError:
from collabwrapper.collabwrapper import CollabWrapper

from sugar3.graphics.toolbarbox import ToolbarBox
from sugar3.activity.widgets import ActivityToolbarButton
Expand All @@ -54,6 +44,7 @@ class RecallActivity(activity.Activity):
def __init__(self, handle):
""" Initialize the toolbars and the game board """
super(RecallActivity, self).__init__(handle)
self.max_participants = 1
Copy link
Member

@srevinsaju srevinsaju May 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuiP, I guess; we could remove this instance of self.max_participants if its possible to. then this PR would be perfect!


self.path = activity.get_bundle_path()

Expand All @@ -76,7 +67,6 @@ def __init__(self, handle):

self._game = Game(canvas, parent=self, path=self.path,
colors=self.colors)
self._setup_collab()
if 'dotlist' in self.metadata:
self._restore()
else:
Expand All @@ -85,7 +75,7 @@ def __init__(self, handle):
def _setup_toolbars(self, have_toolbox):
""" Setup the toolbars. """

self.max_participants = 4
self.max_participants = 1
toolbox = ToolbarBox()

# Activity toolbar
Expand Down Expand Up @@ -166,51 +156,3 @@ def _restore(self):
game = 0
self._game.restore_game(dot_list, correct, level, game)
self._restoring = False

# Collaboration-related methods

def _setup_collab(self):
""" Setup the Collab Wrapper. """
self.initiating = None # sharing (True) or joining (False)
self._collab = CollabWrapper(self)
self._collab.connect('message', self.__message_cb)

owner = self._collab._leader
self.owner = owner

self._game.set_sharing(True)

def __message_cb(self, collab, buddy, message):
action = message.get('action')
payload = message.get('payload')
if action == 'n':
'''Get a new game grid'''
self._receive_new_game(payload)
elif action == 'p':
'''Get a dot click'''
self._receive_dot_click(payload)

def send_new_game(self):
''' Send a new grid to all players '''
self._collab.post(dict(
action = 'n',
payload = json_dump(self._game.save_game())
))

def _receive_new_game(self, payload):
''' Sharer can start a new game. '''
dot_list, correct, level, game = json_load(payload)
self._game.restore_game(dot_list, correct, level, game)

def send_dot_click(self, dot, color):
''' Send a dot click to all the players '''
self._collab.post(dict(
action = 'p',
payload = json_dump([dot, color])
))

def _receive_dot_click(self, payload):
''' When a dot is clicked, everyone should change its color. '''
(dot, color) = json_load(payload)
self._game.remote_button_press(dot, color)

2 changes: 1 addition & 1 deletion activity/activity.info
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = Recall
activity_version = 6
license = GPLv3
bundle_id = org.sugarlabs.RecallActivity
exec = sugar-activity RecallActivity.RecallActivity
exec = sugar-activity3 RecallActivity.RecallActivity
icon = activity-recall
show_launcher = yes
summary = memory exercise game
Expand Down
Loading