Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Gueret <christophe.gueret@gmail.com>2013-01-13 00:11:15 (GMT)
committer Christophe Gueret <christophe.gueret@gmail.com>2013-01-13 00:11:15 (GMT)
commit38619bb43a9258c02dbdd0d134db3c12f43fbd7a (patch)
tree96e8affec3bd343e51a2d30a8c48e3fd716f962f
parent4cc34553d195922d2914f96cf9391b35786c849b (diff)
Added keeping the last scoreHEADmaster
-rw-r--r--activity_quiz/Activity.py34
-rw-r--r--activity_quiz/Application.py10
-rw-r--r--activity_quiz/GUI.glade4
3 files changed, 39 insertions, 9 deletions
diff --git a/activity_quiz/Activity.py b/activity_quiz/Activity.py
index b86059f..f0ba268 100644
--- a/activity_quiz/Activity.py
+++ b/activity_quiz/Activity.py
@@ -11,9 +11,8 @@ from sugar3.activity.widgets import ActivityButton
from sugar3.activity.widgets import TitleEntry
from sugar3.activity.widgets import StopButton
from sugar3.activity.widgets import DescriptionItem
-from sugar3.graphics.toolbutton import ToolButton
from Application import Main
-
+import simplejson
class QuizActivity(activity.Activity):
def __init__(self, handle):
@@ -23,7 +22,7 @@ class QuizActivity(activity.Activity):
activity.Activity.__init__(self, handle)
# Create the main part of the application
- main = Main()
+ self._application = Main()
# toolbar with the new toolbar redesign
toolbar_box = ToolbarBox()
@@ -54,6 +53,31 @@ class QuizActivity(activity.Activity):
toolbar_box.show()
# Set the canvas
- self.set_canvas(main.get_widget())
- main.get_widget().show()
+ self.set_canvas(self._application.get_widget())
+ self.canvas.show()
+
+ def write_file(self, file_path):
+ if not self.metadata['mime_type']:
+ self.metadata['mime_type'] = 'text/plain'
+
+ data = {}
+ data['last_score'] = self._application.get_score()
+
+ fd = open(file_path, 'w')
+ text = simplejson.dumps(data)
+ fd.write(text)
+ fd.close()
+
+ def read_file(self, file_path):
+ if self.metadata['mime_type'] != 'text/plain':
+ return
+
+ fd = open(file_path, 'r')
+ text = fd.read()
+ data = simplejson.loads(text)
+ fd.close()
+ if 'last_score' in data:
+ self._application.set_score(int(data['last_score']))
+ else:
+ self._application.set_score(0)
diff --git a/activity_quiz/Application.py b/activity_quiz/Application.py
index e8d2b82..3172741 100644
--- a/activity_quiz/Application.py
+++ b/activity_quiz/Application.py
@@ -61,6 +61,13 @@ class Main(object):
'''
return self._gui.get_object("main_box")
+ def get_score(self):
+ return self._points
+
+ def set_score(self, value):
+ self._points = value
+ self._gui.get_object("score_zone").set_label(str(self._points))
+
def make_new_question(self):
'''
Prepare a new question: pick a set of cities and update the buttons
@@ -79,8 +86,7 @@ class Main(object):
'''
# Check the answer picked
if number == self._good_answer:
- self._points = self._points + 1
- self._gui.get_object("score_zone").set_label(str(self._points))
+ self.set_score(self.get_score() + 1)
# Create a new question
self.make_new_question()
diff --git a/activity_quiz/GUI.glade b/activity_quiz/GUI.glade
index 5980607..1202abf 100644
--- a/activity_quiz/GUI.glade
+++ b/activity_quiz/GUI.glade
@@ -28,7 +28,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
- <property name="shadow_type">etched-out</property>
+ <property name="shadow_type">out</property>
<child>
<object class="GtkButtonBox" id="buttonbox1">
<property name="visible">True</property>
@@ -108,7 +108,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
- <property name="shadow_type">etched-out</property>
+ <property name="shadow_type">out</property>
<child>
<object class="GtkLabel" id="score_zone">
<property name="visible">True</property>