diff options
author | Wade Brainerd <wadetb@gmail.com> | 2009-01-29 05:01:04 (GMT) |
---|---|---|
committer | Wade Brainerd <wadetb@gmail.com> | 2009-01-29 05:01:04 (GMT) |
commit | 27fbcc80d5435f943dcd63bbf375529fe39af3b3 (patch) | |
tree | 1138071edb3c0f598129b191838d906d2d475984 /mainscreen.py | |
parent | 6fb4ec696e195691cc6611b981fc50fbfb5a4f76 (diff) |
Optimize lesson builder, add colors to balloongame (busts performance atm), fallback to en_US when no lessons found, remove req_keys pairs from lessons - seemed dumb and pointless.
Diffstat (limited to 'mainscreen.py')
-rw-r--r-- | mainscreen.py | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/mainscreen.py b/mainscreen.py index 49641bc..fef569e 100644 --- a/mainscreen.py +++ b/mainscreen.py @@ -111,20 +111,20 @@ class MainScreen(gtk.VBox): self.prevlessonbtn.add(previcon) self.prevlessonbtn.connect('clicked', self.prev_lesson_clicked_cb) + # Load lessons for this language. bundle_path = sugar.activity.activity.get_bundle_path() code = locale.getlocale(locale.LC_ALL)[0] path = bundle_path + '/lessons/' + code - - # Find all .lesson files in ./lessons/en_US/ for example. - self.lessons = [] - for f in glob.iglob(path + '/*.lesson'): - fd = open(f, 'r') - try: - lesson = json.read(fd.read()) - self.lessons.append(lesson) - finally: - fd.close() - + self.load_lessons(path) + + # Fallback to en_US lessons if none found. + if not len(self.lessons): + self.load_lessons(bundle_path + '/lessons/en_US') + + # We cannot run without lessons/ + if not len(self.lessons): + sys.exit(1) + # Sort by the 'order' field. self.lessons.sort(lambda x, y: x.get('order', 0) - y.get('order', 0)) @@ -139,6 +139,18 @@ class MainScreen(gtk.VBox): self.show_next_lesson() + def load_lessons(self, path): + # Find all .lesson files in ./lessons/en_US/ for example. + self.lessons = [] + for f in glob.iglob(path + '/*.lesson'): + fd = open(f, 'r') + try: + lesson = json.read(fd.read()) + self.lessons.append(lesson) + finally: + fd.close() + + def get_next_lesson(self): """Returns the index of the first lesson without a medal.""" index = len(self.lessons)-1 |