Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--Activity.py83
-rw-r--r--Application.py93
-rw-r--r--GUI.glade157
-rw-r--r--activity/activity-icon.svg13
-rw-r--r--activity/activity.info9
-rw-r--r--main.py33
-rw-r--r--ranks.csv210
-rw-r--r--setup.py3
9 files changed, 605 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..555b0eb
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+dist
+*.pyc
+.project
+.pydevproject
diff --git a/Activity.py b/Activity.py
new file mode 100644
index 0000000..f0ba268
--- /dev/null
+++ b/Activity.py
@@ -0,0 +1,83 @@
+'''
+Created on 5 Nov 2012
+
+@author: cgueret
+'''
+from gi.repository import Gtk
+
+from sugar3.activity import activity
+from sugar3.graphics.toolbarbox import ToolbarBox
+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 Application import Main
+import simplejson
+
+class QuizActivity(activity.Activity):
+ def __init__(self, handle):
+ '''
+ Initialise the activity
+ '''
+ activity.Activity.__init__(self, handle)
+
+ # Create the main part of the application
+ self._application = Main()
+
+ # toolbar with the new toolbar redesign
+ toolbar_box = ToolbarBox()
+
+ activity_button = ActivityButton(self)
+ toolbar_box.toolbar.insert(activity_button, 0)
+ activity_button.show()
+
+ title_entry = TitleEntry(self)
+ toolbar_box.toolbar.insert(title_entry, -1)
+ title_entry.show()
+
+ description_item = DescriptionItem(self)
+ toolbar_box.toolbar.insert(description_item, -1)
+ description_item.show()
+
+ separator = Gtk.SeparatorToolItem()
+ separator.props.draw = False
+ separator.set_expand(True)
+ toolbar_box.toolbar.insert(separator, -1)
+ separator.show()
+
+ stop_button = StopButton(self)
+ toolbar_box.toolbar.insert(stop_button, -1)
+ stop_button.show()
+
+ self.set_toolbar_box(toolbar_box)
+ toolbar_box.show()
+
+ # Set the canvas
+ 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/Application.py b/Application.py
new file mode 100644
index 0000000..3172741
--- /dev/null
+++ b/Application.py
@@ -0,0 +1,93 @@
+'''
+Created on 11 Jan 2013
+
+@author: cgueret
+'''
+from gi.repository import Gtk
+import csv
+import random
+
+class Data(object):
+ '''
+ Class used to interface with the data
+ '''
+ def __init__(self):
+ '''
+ Constructor
+ '''
+ self._ranks = {}
+ with open('ranks.csv', 'rb') as csvfile:
+ reader = csv.reader(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
+ for row in reader:
+ self._ranks[row[0]] = int(row[1])
+
+ def get_random_subset(self, size):
+ '''
+ Generate a random subset of pairs (country, rank)
+ '''
+ subset = {}
+ while len(subset.keys()) != size:
+ key = self._ranks.keys()[random.randint(0, len(self._ranks.keys())-1)]
+ if key not in subset:
+ subset[key] = self._ranks[key]
+ return subset
+
+
+class Main(object):
+ def __init__(self):
+ '''
+ Constructor
+ '''
+ # Variable to count the number of points
+ self._points = 0
+ self._good_answer = -1
+ self._data = Data()
+
+ # Load the graphical user interface
+ self._gui = Gtk.Builder()
+ self._gui.add_from_file("GUI.glade")
+
+ # Connect the buttons
+ for number in range(1, 5):
+ button = self._gui.get_object("button%d" % number)
+ button.connect("clicked", self.on_button_clicked, number)
+
+ # Create a new question
+ self.make_new_question()
+
+ def get_widget(self):
+ '''
+ Return the main widget of the application
+ '''
+ 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
+ '''
+ subset = self._data.get_random_subset(4).items()
+ self._good_answer = 1
+ for i in range(1, 5):
+ (country, rank) = subset[i - 1]
+ if rank > subset[self._good_answer-1][1]:
+ self._good_answer = i
+ self._gui.get_object("button%d" % i).set_label(country)
+
+ def on_button_clicked(self, button, number):
+ '''
+ Function called when one of the buttons is clicked
+ '''
+ # Check the answer picked
+ if number == self._good_answer:
+ self.set_score(self.get_score() + 1)
+
+ # Create a new question
+ self.make_new_question()
+
diff --git a/GUI.glade b/GUI.glade
new file mode 100644
index 0000000..1202abf
--- /dev/null
+++ b/GUI.glade
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <object class="GtkBox" id="main_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkAlignment" id="alignment1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="box2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkFrame" id="frame1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label_xalign">0</property>
+ <property name="shadow_type">out</property>
+ <child>
+ <object class="GtkButtonBox" id="buttonbox1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">5</property>
+ <property name="homogeneous">True</property>
+ <property name="layout_style">start</property>
+ <child>
+ <object class="GtkButton" id="button1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button2">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button3">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button4">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child type="label">
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">&lt;b&gt;Who is the biggest ?&lt;/b&gt;</property>
+ <property name="use_markup">True</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="padding">5</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkFrame" id="frame2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label_xalign">0</property>
+ <property name="shadow_type">out</property>
+ <child>
+ <object class="GtkLabel" id="score_zone">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">0</property>
+ </object>
+ </child>
+ <child type="label">
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">&lt;b&gt;Score&lt;/b&gt;</property>
+ <property name="use_markup">True</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="padding">5</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkAlignment" id="alignment2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+</interface>
diff --git a/activity/activity-icon.svg b/activity/activity-icon.svg
new file mode 100644
index 0000000..21751ef
--- /dev/null
+++ b/activity/activity-icon.svg
@@ -0,0 +1,13 @@
+<?xml version="1.0" ?><!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 enable-background="new 0 0 55 55" height="55px" version="1.1" viewBox="0 0 55 55" width="55px" x="0px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" y="0px"><g display="block" id="emblem-question">
+ <g display="inline" id="_x3F__x3F__x3F__x3F__x3F__1_">
+ <rect fill="&fill_color;" height="40" stroke="&stroke_color;" stroke-width="3.5" width="40" x="7.5" y="7.5"/>
+ <g>
+ <g>
+ <path d="M24.825,26.918c0-1.271,1.413-1.483,2.862-1.87c1.412-0.39,2.824-0.954,2.824-3.003 c0-1.554-1.447-2.687-2.931-2.687c-2.969,0-3.428,3.497-5.688,3.497c-1.273,0-2.156-0.987-2.156-2.542 c0-3.709,4.664-5.829,7.843-5.829c4.556,0,8.441,2.827,8.441,7.559c0,3.922-2.471,6.217-6.109,7.135v1.273 c0,1.413-1.059,2.438-2.542,2.438c-1.591,0-2.545-1.024-2.545-2.438V26.918z M24.615,37.729c0-1.52,1.236-2.755,2.756-2.755 s2.754,1.235,2.754,2.755c0,1.518-1.234,2.755-2.754,2.755S24.615,39.247,24.615,37.729z" fill="&stroke_color;"/>
+ </g>
+ </g>
+ </g>
+</g></svg> \ No newline at end of file
diff --git a/activity/activity.info b/activity/activity.info
new file mode 100644
index 0000000..8f6cf78
--- /dev/null
+++ b/activity/activity.info
@@ -0,0 +1,9 @@
+[Activity]
+name = Quiz
+activity_version = 1
+license = GPLv3
+bundle_id = nl.vu.QuizActivity
+exec = sugar-activity Activity.QuizActivity
+icon = activity-icon
+show_launcher = yes
+summary = a simple quiz game \ No newline at end of file
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..2903809
--- /dev/null
+++ b/main.py
@@ -0,0 +1,33 @@
+'''
+Created on 11 Jan 2013
+
+@author: cgueret
+'''
+from gi.repository import Gtk, Gio
+from Application import Main
+
+class QuizApplication(Gtk.Application):
+ def __init__(self):
+ Gtk.Application.__init__(self, application_id="nl.vu.quiz", flags=Gio.ApplicationFlags.FLAGS_NONE)
+ self.connect("activate", self.on_activate)
+
+ def on_activate(self, data=None):
+ # Create the main part of the application
+ main = Main()
+ main_box = main.get_widget()
+
+ # Create the window
+ window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
+ window.set_default_size(600,450)
+ window.set_title("Quiz activity")
+ window.set_border_width(2)
+ window.set_position(Gtk.WindowPosition.CENTER)
+ window.add(main_box)
+
+ # Show the window and add it to the application
+ window.show_all()
+ self.add_window(window)
+
+if __name__ == "__main__":
+ app = QuizApplication()
+ app.run(None)
diff --git a/ranks.csv b/ranks.csv
new file mode 100644
index 0000000..5214268
--- /dev/null
+++ b/ranks.csv
@@ -0,0 +1,210 @@
+"Algeria",10
+"American Samoa",212
+"Anguilla",220
+"Antigua and Barbuda",195
+"Arab League",2
+"Argentina",8
+"Armenian Soviet Socialist Republic",15
+"Ascension Island",219
+"Australia",6
+"Austria",115
+"Avatele",8
+"Azerbaijan",114
+"Azerbaijan Soviet Socialist Republic",9
+"Bahrain",190
+"Bangladesh",94
+"Barbados",200
+"Belarus",85
+"Belgium",139
+"Belize",150
+"Bhutan",135
+"Bolivia",28
+"Bosnia and Herzegovina",127
+"Botswana",47
+"Brazil",5
+"British Virgin Islands",216
+"Brunei",172
+"Bulgaria",105
+"Burkina Faso",74
+"Burma",40
+"Burundi",145
+"Byelorussian Soviet Socialist Republic",6
+"Cambodia",88
+"Cameroon",54
+"Canada",2
+"Canton of Neuchâtel",15
+"Cape Verde",172
+"Cayman Islands",206
+"Chile",38
+"China",3
+"Colombia",26
+"Cook Islands",210
+"Costa Rica",128
+"Crimea",148
+"Croatia",126
+"Cuba",105
+"Cyprus",167
+"Czech Republic",116
+"Côte d'Ivoire",69
+"Democratic Republic of the Congo",11
+"Denmark",12
+"Djibouti",150
+"Dominica",184
+"Dominican Republic",130
+"E-Government in the United Arab Emirates",116
+"East Timor",159
+"Ecuador",75
+"Egypt",30
+"Equatorial Guinea",144
+"Eritrea",100
+"Estonia",132
+"Estonian Soviet Socialist Republic",13
+"Ethiopia",27
+"Falkland Islands",162
+"Faroe Islands",180
+"Federated States of Micronesia",188
+"Fiji",155
+"Finland",64
+"Gabon",76
+"Georgia (country)",120
+"Georgian Soviet Socialist Republic",10
+"Gibraltar",229
+"Greece",96
+"Greenland",12
+"Guam",190
+"Guatemala",107
+"Guinea",78
+"Guinea-Bissau",136
+"Guyana",84
+"Haiti",140
+"Hong Kong",179
+"Hungary",109
+"Iceland",108
+"India",7
+"Indonesia",15
+"Iran",18
+"Iraq",59
+"Israel",154
+"Jamaica",166
+"Japan",62
+"Jersey",227
+"Jordan",112
+"Karelo-Finnish Soviet Socialist Republic",7
+"Kazakh Soviet Socialist Republic",2
+"Kazakhstan",9
+"Kenya",47
+"Kingdom of the Netherlands",136
+"Kirghiz Soviet Socialist Republic",7
+"Kiribati",186
+"Korea",84
+"Kuwait",157
+"Kyrgyzstan",86
+"Laos",84
+"Latvia",124
+"Latvian Soviet Socialist Republic",12
+"Lebanon",166
+"Lesotho",140
+"Libya",17
+"Liechtenstein",215
+"Lithuanian Soviet Socialist Republic",11
+"Luxembourg",179
+"Macau",229
+"Madagascar",47
+"Malawi",99
+"Malaysia",67
+"Maldives",206
+"Mali",24
+"Malta",200
+"Marshall Islands",213
+"Mauritania",29
+"Mauritius",179
+"Mercosur",2
+"Mexico",14
+"Moldavian Soviet Socialist Republic",14
+"Moldova",138
+"Monaco",235
+"Mongolia",19
+"Montserrat",219
+"Morocco",58
+"Mozambique",35
+"Namibia",34
+"Nauru",239
+"Nepal",95
+"Netherlands",135
+"Nevis",207
+"New Caledonia",154
+"New Zealand",75
+"Nicaragua",97
+"Niger",22
+"Nigeria",32
+"Norfolk Island",227
+"North Korea",98
+"Northern Cyprus",174
+"Northern Mariana Islands",195
+"Oman",70
+"Pakistan",36
+"Palau",196
+"Panama",118
+"Papua New Guinea",54
+"Paraguay",60
+"Peru",20
+"Poland",69
+"Portugal",111
+"Puerto Rico",169
+"Qatar",164
+"Republic of Ireland",120
+"Republic of Macedonia",148
+"Republic of the Congo",64
+"Rwanda",149
+"Saint Kitts and Nevis",207
+"Saint Pierre and Miquelon",208
+"Saint Vincent and the Grenadines",198
+"Samoa",174
+"San Marino",219
+"Saudi Arabia",12
+"Senegal",87
+"Serbia",113
+"Seychelles",197
+"Sierra Leone",119
+"Singapore",189
+"Slovakia",129
+"Socialist Soviet Republic of Abkhazia",10
+"Solomon Islands",142
+"Somalia",44
+"South Africa",25
+"South Asian Association for Regional Cooperation",7
+"South Korea",109
+"South Sudan",42
+"Sri Lanka",122
+"Sudan",16
+"Swaziland",157
+"Sweden",57
+"Syria",89
+"Taiwan",136
+"Tajik Soviet Socialist Republic",8
+"Tajikistan",102
+"The Bahamas",160
+"The Gambia",164
+"Togo",125
+"Tonga",186
+"Tunisia",92
+"Turkey",37
+"Turkmen Soviet Socialist Republic",4
+"Turkmenistan",52
+"Turks and Caicos Islands",199
+"Tuvalu",226
+"Ukraine",46
+"United Arab Emirates",116
+"United Kingdom",80
+"United States",3
+"United States Minor Outlying Islands",190
+"United States Virgin Islands",202
+"Uzbek Soviet Socialist Republic",5
+"Uzbekistan",56
+"Vatican City",250
+"Vietnam",65
+"Wallis (island)",211
+"Western Sahara",76
+"Yemen",50
+"Zambia",39
+"Zimbabwe",60
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..f169461
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,3 @@
+from sugar3.activity import bundlebuilder
+if __name__ == "__main__":
+ bundlebuilder.start()