[Commits] typing-turtle branch master updated.

olpc olpc at xo-05-26-CC.localdomain
Mon Dec 15 22:20:50 EST 2008


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "/home/olpc-code/git/activities/typing-turtle".

The branch, master has been updated
       via  d279c4680c0bdff198fdc7f880a105a882eed9ec (commit)
      from  241d9d4a9fa1c6d6ef8cb783acff296a1c27ae4d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

 images/main-background.png         |  Bin 0 -> 76342 bytes
 keyboard.py                        |   86 ++++++++-------
 lessonbuilder.py                   |  133 ++++++++++++++++------
 lessons/en_US/homerow_intro.lesson |   92 ---------------
 mainscreen.py                      |  218 +++++++++++++++++++++++-------------
 5 files changed, 285 insertions(+), 244 deletions(-)
 create mode 100755 images/main-background.png
 delete mode 100644 lessons/en_US/homerow_intro.lesson

- Log -----------------------------------------------------------------
commit d279c4680c0bdff198fdc7f880a105a882eed9ec
Author: olpc <olpc at xo-05-26-CC.localdomain>
Date:   Tue Dec 16 03:20:30 2008 +0000

    Add dummy background to main screen.

diff --git a/images/main-background.png b/images/main-background.png
new file mode 100755
index 0000000..dceafa8
Binary files /dev/null and b/images/main-background.png differ
diff --git a/keyboard.py b/keyboard.py
index 1eb340f..c22ef36 100644
--- a/keyboard.py
+++ b/keyboard.py
@@ -67,6 +67,10 @@ KEY_PROPS = [
 
     # Text label to be displayed on keys which do not generate keys.
     { 'name': 'key-label', 'default': '' },
+
+    # Which finger should be used to press the key.  
+    # Options are [LR][TIMRP], so LM would mean the left middle finger.
+    { 'name': 'key-finger', 'default': '' },
 ]
 
 # This is an example keyboard layout.
@@ -137,20 +141,20 @@ DEFAULT_LAYOUT = {
                 'group-y': 100,
         
             'keys': [
-                {'key-scan':0x17,'key-label':"tab"},
-                {'key-scan':0x18}, 
-                {'key-scan':0x19}, 
-                {'key-scan':0x1a}, 
-                {'key-scan':0x1b}, 
-                {'key-scan':0x1c}, 
-                {'key-scan':0x1d}, 
-                {'key-scan':0x1e}, 
-                {'key-scan':0x1f}, 
-                {'key-scan':0x20}, 
-                {'key-scan':0x21}, 
-                {'key-scan':0x22}, 
-                {'key-scan':0x23,'key-width':55},
-                {'key-scan':0x24,'key-label':"enter",'key-width':95,'key-height':95}
+                {'key-scan':0x17,'key-finger':'LP','key-label':"tab"},
+                {'key-scan':0x18,'key-finger':'LP'}, 
+                {'key-scan':0x19,'key-finger':'LR'}, 
+                {'key-scan':0x1a,'key-finger':'LM'}, 
+                {'key-scan':0x1b,'key-finger':'LI'}, 
+                {'key-scan':0x1c,'key-finger':'LI'}, 
+                {'key-scan':0x1d,'key-finger':'RI'}, 
+                {'key-scan':0x1e,'key-finger':'RI'}, 
+                {'key-scan':0x1f,'key-finger':'RM'}, 
+                {'key-scan':0x20,'key-finger':'RR'}, 
+                {'key-scan':0x21,'key-finger':'RP'}, 
+                {'key-scan':0x22,'key-finger':'RP'}, 
+                {'key-scan':0x23,'key-finger':'RP','key-width':55},
+                {'key-scan':0x24,'key-finger':'RP','key-label':"enter",'key-width':95,'key-height':95}
             ]
         },
         {
@@ -159,19 +163,19 @@ DEFAULT_LAYOUT = {
             'group-y': 150,
         
             'keys': [
-                {'key-scan':0x25,'key-label':"ctrl",'key-width':55},
-                {'key-scan':0x26}, 
-                {'key-scan':0x27}, 
-                {'key-scan':0x28}, 
-                {'key-scan':0x29}, 
-                {'key-scan':0x2a}, 
-                {'key-scan':0x2b},
-                {'key-scan':0x2c}, 
-                {'key-scan':0x2d}, 
-                {'key-scan':0x2e}, 
-                {'key-scan':0x2f}, 
-                {'key-scan':0x30}, 
-                {'key-scan':0x33}
+                {'key-scan':0x25,'key-finger':'LP','key-label':"ctrl",'key-width':55},
+                {'key-scan':0x26,'key-finger':'LP'}, 
+                {'key-scan':0x27,'key-finger':'LR'}, 
+                {'key-scan':0x28,'key-finger':'LM'}, 
+                {'key-scan':0x29,'key-finger':'LI'}, 
+                {'key-scan':0x2a,'key-finger':'LI'}, 
+                {'key-scan':0x2b,'key-finger':'RI'},
+                {'key-scan':0x2c,'key-finger':'RI'}, 
+                {'key-scan':0x2d,'key-finger':'RM'}, 
+                {'key-scan':0x2e,'key-finger':'RR'}, 
+                {'key-scan':0x2f,'key-finger':'RP'}, 
+                {'key-scan':0x30,'key-finger':'RP'}, 
+                {'key-scan':0x33,'key-finger':'RP'}
             ]
         },
         {
@@ -180,19 +184,19 @@ DEFAULT_LAYOUT = {
             'group-y': 200,
         
             'keys': [
-                {'key-scan':0x32,'key-label':"shift",'key-width':75},
-                {'key-scan':0x34}, 
-                {'key-scan':0x35}, 
-                {'key-scan':0x36}, 
-                {'key-scan':0x37}, 
-                {'key-scan':0x38}, 
-                {'key-scan':0x39},
-                {'key-scan':0x3a}, 
-                {'key-scan':0x3b}, 
-                {'key-scan':0x3c}, 
-                {'key-scan':0x3d},
-                {'key-scan':0x3e,'key-label':"shift",'key-width':75},
-                {'key-scan':0x6f,'key-label':""}, # Up
+                {'key-scan':0x32,'key-finger':'LP','key-label':"shift",'key-width':75},
+                {'key-scan':0x34,'key-finger':'LP'}, 
+                {'key-scan':0x35,'key-finger':'LR'}, 
+                {'key-scan':0x36,'key-finger':'LM'}, 
+                {'key-scan':0x37,'key-finger':'LI'}, 
+                {'key-scan':0x38,'key-finger':'LI'}, 
+                {'key-scan':0x39,'key-finger':'RI'},
+                {'key-scan':0x3a,'key-finger':'RI'}, 
+                {'key-scan':0x3b,'key-finger':'RM'}, 
+                {'key-scan':0x3c,'key-finger':'RR'}, 
+                {'key-scan':0x3d,'key-finger':'RP'},
+                {'key-scan':0x3e,'key-finger':'RP','key-label':"shift",'key-width':75},
+                {'key-scan':0x6f,'key-finger':'RP','key-label':""}, # Up
                 {'key-label':""}, # Language key
             ]
         },
@@ -205,7 +209,7 @@ DEFAULT_LAYOUT = {
                 {'key-label':"fn",'key-width':35},
                 {'key-label':"",'key-width':55}, # LHand
                 {'key-scan':0x40,'key-label':"alt",'key-width':55}, # LAlt
-                {'key-scan':0x41,'key-width':325}, # Spacebar
+                {'key-scan':0x41,'key-finger':'RT','key-width':325}, # Spacebar
                 {'key-scan':0x6c,'key-label':"alt",'key-width':55}, # RAlt
                 {'key-label':"",'key-width':55}, # RHand
                 {'key-scan':0x71,'key-label':""}, # Left 
diff --git a/lessonbuilder.py b/lessonbuilder.py
index 82d2493..6480484 100644
--- a/lessonbuilder.py
+++ b/lessonbuilder.py
@@ -19,6 +19,31 @@
 import os, sys, random, json
 from gettext import gettext as _
 
+import keyboard
+
+CONGRATS = [
+    _('Well done!'),
+    _('Good job.'),
+    _('Awesome!'),
+    _('Way to go!'),
+    _('Wonderful!'),
+    _('Nice work.'),
+    _('You did it!'),
+]
+
+FINGERS = {
+    'LP': _('left pinky'),
+    'LR': _('left ring'),
+    'LM': _('left middle'),
+    'LI': _('left index'),
+    'LT': _('left thumb'),
+    'RP': _('right pinky'),
+    'RR': _('right ring'),
+    'RM': _('right middle'),
+    'RI': _('right index'),
+    'RT': _('right thumb'),
+}
+
 def make_all_triples(keys):
     text = ''
     for k in new_keys:
@@ -33,14 +58,14 @@ def make_all_doubles(keys):
 
 def make_random_triples(keys, count):
     text = ''
-    for y in xrange(0, count * len(keys)):
+    for y in xrange(0, count):
         k = random.choice(keys)
         text += k + k + ' ' + k + ' '
     return text
 
-def make_jumble(keys, count, gap):
+def make_jumbles(keys, count, gap):
     text = ''
-    for y in range(0, count * len(keys)):
+    for y in range(0, count):
         text += random.choice(keys)
         if y % gap == gap-1:
             text += ' '
@@ -55,12 +80,12 @@ def make_all_pairs(keys):
             text += k2 + k1 + ' '
     return text
 
-def make_random_pairs(keys, count):
+def make_random_pairs(required_keys, keys, count):
     text = ''
-    for y in xrange(0, count * len(keys)):
-        k1 = random.choice(keys)
+    for y in xrange(0, count):
+        k1 = random.choice(required_keys)
         k2 = random.choice(keys)
-        text += k1 + k2 + ' '
+        text += random.choice([k1 + k2, k2 + k1]) + ' '
     return text
 
 def make_all_joined_pairs(keys1, keys2):
@@ -122,7 +147,7 @@ def filter_wordlist(words, all_keys, req_keys, minlen, maxlen, bad_words):
 def add_step(lesson, instructions, text):
     step = {}
     step['instructions'] = instructions
-    step['text'] = text
+    step['text'] = text.strip() + '\n'
     lesson['steps'].append(step)
 
 def build_lesson(
@@ -134,6 +159,9 @@ def build_lesson(
     words = load_wordlist(wordlist)
     bad_words = load_wordlist(badwordlist)
 
+    kb = keyboard.Keyboard(None)
+    kb.set_layout(keyboard.DEFAULT_LAYOUT)
+
     all_keys = new_keys + base_keys
 
     lesson = {}
@@ -143,44 +171,58 @@ def build_lesson(
     lesson['requiredlevel'] = required_level
     lesson['steps'] = []
 
+    keynames = ''
+    for k in new_keys[:-2]:
+        keynames += k + ', '
+    keynames += new_keys[-2] + ' and ' + new_keys[-1]
+
+    add_step(lesson,
+        _('Welcome to the %(name)s lesson!\n\nIn this lesson, you will learn the %(keynames)s keys.  Press the Enter key when you are ready to begin!') \
+            % { 'name': name, 'keynames': keynames },
+        '\n')
+
     for key in new_keys:
+        k = kb.find_key_by_letter(key)
         add_step(lesson,
-            _('Press the %(name)s key with your %(finger)s.') \
-                % { 'name': key, 'finger': 'finger' },
+            _('Press the %(name)s key using your %(finger)s finger.') \
+                % { 'name': key, 'finger': FINGERS[k.props['key-finger']]},
             key)
+
+    # Key patterns - useful or not?
+    #add_step(lesson,
+    #    _('Time to practice some simple key patterns.'),
+    #    make_all_triples(new_keys) * 4)
     
     add_step(lesson,
-        _('Practice typing the keys you just learned.'),
-        make_all_triples(new_keys) * 4)
-    
-    add_step(lesson,
-        _('Practice typing the keys you just learned.'),
-        make_random_triples(new_keys, count=5))
+        _('Good job!  Now, practice typing the keys you just learned.'),
+        make_random_triples(new_keys, count=20))
     
-    add_step(lesson,
-        _('Practice typing the keys you just learned.'),
-        make_all_pairs(new_keys))
+    # Key patterns - useful or not?
+    #add_step(lesson,
+    #    _('Practice typing the keys you just learned.'),
+    #    make_all_pairs(new_keys))
     
     add_step(lesson,
-        _('Practice typing the keys you just learned.'),
-        make_random_pairs(new_keys, count=10))
+        _('Well done! Now let\'s put the keys together in pairs.\n\nBe careful to use the correct finger to press each key.  Look at the keyboard below if you need help remembering.'),
+        make_random_pairs(new_keys, new_keys, count=50))
     
     add_step(lesson,
-        _('Practice typing the keys you just learned.'),
-        make_jumble(new_keys, count=40, gap=5))
+        _('You made it!  Now we are going to practice word jumbles.  You can speed up a little, but be careful to get all the keys right!'),
+        make_jumbles(new_keys, count=100, gap=5))
     
     if base_keys != '':
-        add_step(lesson,
-            _('Practice typing the keys you just learned.'),
-            make_all_joined_pairs(new_keys, all_keys))
+        # Key patterns - useful or not?
+        #add_step(lesson,
+        #    _('Wonderful!  Now we are going to bring in the keys you already know. We\'ll start with pairs.\n\nPay attention to your posture, and always be sure to use the correct finger!'),
+        #    make_all_joined_pairs(new_keys, all_keys))
     
         add_step(lesson,
-            _('Practice typing the keys you just learned.'),
-            make_random_pairs(all_keys, count=20))
+            _('Wonderful!  Now we will add the keys you already know.  Let\'s start with pairs.\n\nPay attention to your posture, and always be sure to use the correct finger.'),
+            make_random_pairs(new_keys, all_keys, count=200))
     
         add_step(lesson,
-            _('Practice typing the keys you just learned.'),
-            make_jumble(all_keys, count=50, gap=5))
+            _('Great job.  Now practice these jumbles, using all the keys you know.'),
+            make_jumbles(all_keys, count=300, gap=5))
 
     if wordlist:
         good_words = filter_wordlist(words=words, 
@@ -189,11 +231,36 @@ def build_lesson(
             bad_words=bad_words)
 
         add_step(lesson,
-            _('Practice typing these words.'),
-            make_random_words(good_words, count=500))
+            _('You\'re almost finished!  It\'s time to learn to type real words, using the keys you have just learned.'),
+            make_random_words(good_words, count=300))
     
     return lesson
 
+def build_intro_lesson():
+    lesson = {}
+    lesson['name'] = _('Welcome to Typing Turtle!') 
+    lesson['description'] = _('Click here to begin.') 
+    lesson['level'] = 0
+    lesson['requiredlevel'] = 0
+    lesson['steps'] = []
+
+    text = ''
+    text += _('Hi there, welcome to Typing Turtle!  My name is Max the Turtle, ')
+    text += _('and I\'m going to teach you how to type.\n\n')
+    text += _('First, I will tell you the secret of fast typing.  Are you ready?\n\n')
+    text += _('The secret is: Always use the correct finger to press each key!\n\n')
+    text += _('Simple, right?  Now all you need to do is practice.')
+    #show you how to use the activity.  The box you are ')
+    text += _('reading right now is where the instructions will appear.  The ')
+    text += _('picture of the keyboard below shows what your hands should be ')
+    text += _('doing.  And the dials to the right, they show how quickly and ')
+    text += _('accurately you are typing!\n\n')
+    text += _('When you see a big picture of a key like the one below, that ')
+    text += _('means you are supposed to press that key on the keyboard! ')
+    text += _('Make sure you use the correct finger to type each key!')
+
+    return lesson
+
 def usage():
     print """
 lessonbuilder.py v1.0 by Wade Brainerd <wadetb at gmail.com>
@@ -222,7 +289,7 @@ if __name__ == "__main__":
         usage()
         sys.exit()
 
-    name = 'Generated lesson'
+    name = 'Generated'
     desc = 'Default description'
     level = 0
     required_level = 0
diff --git a/lessons/en_US/homerow_intro.lesson b/lessons/en_US/homerow_intro.lesson
deleted file mode 100644
index 8f674d8..0000000
--- a/lessons/en_US/homerow_intro.lesson
+++ /dev/null
@@ -1,92 +0,0 @@
-{
-  "name": "Home Row",
-  "description": "Teaches the middle row of keys on the keyboard.",
-  "level": 1,
-  "requiredlevel": 0,
-  "steps": [
-    {
-      "instructions": "Welcome to the first Typing Turtle lesson!  Place your fingers on the keyboard as shown below.\n\nWhen you are ready to begin, press the f key with your left index finger.",
-      "text": "f"
-    },
-    {
-      "instructions": "Good job!  Now press the d key with your left middle finger.",
-      "text": "d"
-    },
-    {
-      "instructions": "Now the s key with your left ring finger.",
-      "text": "s"
-    },
-    {
-      "instructions": "And the a key with your left pinky finger.",
-      "text": "a"
-    },
-    {
-      "instructions": "Great work!  We will now move on to the right hand.  As shown in the picture below, press the j key with your right index finger.",
-      "text": "j"
-    },
-    {
-      "instructions": "The k key with your right middle finger.",
-      "text": "k"
-    },
-    {
-      "instructions": "The l key with your right ring finger.",
-      "text": "l"
-    },
-    {
-      "instructions": "The ; (semicolon) key with your right pinky finger.",
-      "text": ";"
-    },
-    {
-      "instructions": "Excellent!  These keys are known as the home row.  Your fingers should always return to rest lightly on them.\n\nType all of the letters below.  Press down quickly and lightly with your fingertips, but do not move your hands.",
-      "text": "fdsajkl;"
-    },
-    {
-      "instructions": "Again, from left to right!",
-      "text": "asdfjkl;"
-    },
-    {
-      "instructions": "Keep it up, you are doing great!  Now, from right to left!",
-      "text": ";lkjfdsa"
-    },
-    {
-      "instructions": "Okay, now to learn the Enter reach.  Without moving your hands, move your right pinky over and press the Enter key.",
-      "text": "\n"
-    },
-    {
-      "instructions": "Good.  Now type the next two lines, using the Enter key to move from one line to the next.",
-      "text": "asdf\njkl;"
-    },
-    {
-      "instructions": "Time to practice Enter and ;!",
-      "text": ";\n;\n;\n"
-    },
-    {
-      "instructions": "Time to practice letters.  Now type in the following lines.",
-      "text": "asdf\njkl;\nasdfjkl;\njkl;asdf"
-    },
-    {
-      "instructions": "Now we will learn the Space bar.  The space bar is used to leave a space between words.  Use your right thumb to press it.",
-      "text": " "
-    },
-    {
-      "instructions": "Press it again!",
-      "text": " "
-    },
-    {
-      "instructions": "One more time!",
-      "text": " "
-    },
-    {
-      "instructions": "Good job.  Let's put it all together now with some practice lines.",
-      "text": "ff f jj j dd d kk k ss s ll l aa a ;; ;\nfdsa jkl;\nff f jj j dd d kk k ss s ll l aa a ;; ;\nfdsa jkl;\n; ;; a aa l ll s ss k kk d dd j jj f ff\nasdf jkl;\n; ;; a aa l ll s ss k kk d dd j jj f ff\nasdf jkl;\n"
-    },
-    {
-      "instructions": "It's very important to master the home row before learning to reach for the other keys.  Stick with it and you will be touch typing in no time at all!",
-      "text": "a; a; sl sl dk dk fj fj jf jf kd kd ls ls ;a ;a\na; a; sl sl dk dk fj fj jf jf kd kd ls ls ;a ;a\n;ajf ;ajf ;alskdjf ;alskdjf ;alskdjf ;alskdjf ;alskdjf\n\n;ajf ;ajf ;alskdjf ;alskdjf ;alskdjf ;alskdjf ;alskdjf\nfja; fjsd j;kl lk;j sldk kdls ajf;dkls ajf;dkls jdfksl;a\n"
-    },
-    {
-      "instructions": "Try and speed up your typing a little.\n\nWhen your fingers are on the home row, they should be curved so that your thumbs rest on the space bar.",
-      "text": "a;sldkfj a;sldkfj a;sldkfj a;sldkfj\njj ff kk dd ll ss ;; aa\na; sl dk fj a; sl dk fj asdf ;lkj\njf kd ls ;a fj dk sl a; fdsa jkl; jfkdls;a\n;; ll kk kj lk ;l aa ss dd df sd as jd fl jd fl jj dd ff ll\na a as as sad sad lad lad fad fad ask ask\nadd add ask ask lass lass as as falls falls jaff\nask lass fall as daff lass ads ask add ask\na lass; all lads; a fall; fall a lad; a dall a lad; fall dad fad; a jad falls a fad;\nsalad lad; lass sad; a fad a dall; salad dad; salad fad;"
-    }
-  ]
-}
diff --git a/mainscreen.py b/mainscreen.py
index 8aea101..ce7c33a 100644
--- a/mainscreen.py
+++ b/mainscreen.py
@@ -28,6 +28,62 @@ from sugar.graphics import *
 # Import activity modules.
 import lessonscreen, medalscreen
 
+class TitleScene(gtk.DrawingArea):
+    def __init__(self):
+        gtk.DrawingArea.__init__(self)
+
+        bundle = sugar.activity.activity.get_bundle_path()
+        self.backgroundpixbuf = gtk.gdk.pixbuf_new_from_file(bundle + '/images/main-background.png')
+        
+        self.set_size_request(self.backgroundpixbuf.get_width(), self.backgroundpixbuf.get_height())
+        
+        self.connect("expose-event", self.expose_cb)
+        
+        self.title_original = _('Typing Turtle')
+        self.title_src = self.title_original
+        self.title_text = ''
+        self.title_counter = 50
+        
+        gobject.timeout_add(10, self.timer_cb)
+
+    def expose_cb(self, area, event):
+        bounds = self.get_allocation()
+        
+        gc = self.get_style().fg_gc[gtk.STATE_NORMAL]
+        
+        self.window.draw_pixbuf(
+            gc, self.backgroundpixbuf, 
+            event.area.x, event.area.y, 
+            event.area.x, event.area.y, event.area.width, event.area.height)
+        
+        # Animated Typing Turtle title.
+        pc = self.create_pango_context()
+        
+        layout = self.create_pango_layout('')
+        layout.set_font_description(pango.FontDescription('Times 60'))
+        
+        layout.set_text(self.title_original)
+        original_size = layout.get_size()
+        
+        x = (bounds.width-original_size[0]/pango.SCALE)/2
+        y = 10
+
+        layout.set_text(self.title_text)        
+        self.window.draw_layout(gc, x, y, layout)
+
+    def timer_cb(self):
+        self.title_counter -= 1
+        if self.title_counter == 0:
+            if len(self.title_src) > 0:
+                self.title_text += self.title_src[0]
+                self.title_src = self.title_src[1:]
+                self.queue_draw()
+                print "queue draw "+self.title_text
+            
+            self.title_counter = random.randint(1, 5)
+            
+        return True
+    
 class MainScreen(gtk.VBox):
     def __init__(self, activity):
         gtk.VBox.__init__(self)
@@ -35,107 +91,113 @@ class MainScreen(gtk.VBox):
         self.activity = activity
         
         # Build background.
-        title = gtk.Label()
-        title.set_markup("<span size='40000'><b>" + _('Typing Turtle') + "</b></span>")
+        self.titlescene = TitleScene()
         
-        subtitle = gtk.Label()
-        subtitle.set_markup(_('Welcome to Typing Turtle! To begin, select a lesson from the list below.'))
+        #title = gtk.Label()
+        #title.set_markup("<span size='40000'><b>" + _('Typing Turtle') + "</b></span>")
         
-        spacer = gtk.HBox()
-        
-        # Lessons header.
-        headerbox = gtk.VBox()
-        label = gtk.Label()
-        label.set_alignment(0.0, 0.5)
-        label.set_markup("<span size='large'><b>"+_('Available Lessons')+"</b></span>")
-        headerbox.pack_start(label, False)
-        headerbox.pack_start(gtk.HSeparator(), False)
+        #subtitle = gtk.Label()
+        #subtitle.set_markup(_('Welcome to Typing Turtle! To begin, select a lesson from the list below.'))
         
         # Build lessons list.
-        self.lessonbox = gtk.VBox()
-        self.lessonbox.set_spacing(10)
+        self.lessonbox = gtk.HBox()
+        
+        self.nextlessonbtn = gtk.Button()
+        self.nextlessonbtn.add(gtk.Label('Next'))
+        #self.nextlessonbtn.add(nextimage)
+        self.nextlessonbtn.connect('clicked', self.next_lesson_clicked_cb)
+        
+        self.prevlessonbtn = gtk.Button()
+        self.prevlessonbtn.add(gtk.Label('Prev'))
+        #self.prevlessonbtn.add(previmage)
+        self.prevlessonbtn.connect('clicked', self.prev_lesson_clicked_cb)
         
         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.
-        lessons = []
+        self.lessons = []
         for f in os.listdir(path):
             fd = open(path + f, 'r')
             try:
                 lesson = json.read(fd.read())
-                lessons.append(lesson)
+                self.lessons.append(lesson)
             finally:
                 fd.close()
         
-        lessons.sort(lambda x, y: x['level'] - y['level'])
+        self.lessons.sort(lambda x, y: x['level'] - y['level'])
         
-        for l in lessons:
-            label = gtk.Label()
-            label.set_alignment(0.0, 0.5)
-            label.set_markup("<span size='large'>" + l['name'] + "</span>\n" + l['description'])
-            
-            btn = gtk.Button()
-            btn.lesson = l
-            btn.add(label)
-            btn.connect('clicked', self.lesson_clicked_cb)
-            
-            medalimage = gtk.Image()
-            
-            medalbtn = gtk.Button()
-            medalbtn.lesson = l
-            medalbtn.add(medalimage)
-            medalbtn.connect('clicked', self.medal_clicked_cb)
-            
-            hbox = gtk.HBox()
-            hbox.pack_start(btn, True, True, 10)
-            hbox.pack_end(medalbtn, False, False)            
-            
-            hbox.button = btn
-            hbox.medalbutton = medalbtn
-            hbox.lesson = l
-            hbox.medalimage = medalimage
-            
-            self.lessonbox.pack_start(hbox, False)
+        lessonscrollbox = gtk.HBox()
+        lessonscrollbox.set_spacing(10)
+        lessonscrollbox.pack_start(self.prevlessonbtn, False)
+        lessonscrollbox.pack_start(self.lessonbox)
+        lessonscrollbox.pack_start(self.nextlessonbtn, False)
         
-        self.lessonscroll = gtk.ScrolledWindow()
-        self.lessonscroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
-        self.lessonscroll.add_with_viewport(self.lessonbox)
+        self.pack_start(self.titlescene, False, True, 10)
+        self.pack_start(lessonscrollbox, True)
         
-        self.pack_start(title, False, True, 10)
-        self.pack_start(subtitle, False)
-        self.pack_start(spacer, False, False, 50)
-        self.pack_start(headerbox, False)
-        self.pack_start(self.lessonscroll, True)
+        self.show_lesson(0)
         
-        self.update_medals()
-
-    def update_medals(self):
-        for l in self.lessonbox:
-            # Disable the lesson button unless available.
-            lesson_available = self.activity.data['level'] >= l.lesson['requiredlevel']
-            l.button.set_sensitive(lesson_available)
-            l.medalbutton.set_sensitive(lesson_available)
-            
-            # Update the medal image.
-            medal_type = 'none'
-            if self.activity.data['medals'].has_key(l.lesson['name']):
-                medal_type = self.activity.data['medals'][l.lesson['name']]['type']
-
-            bundle = sugar.activity.activity.get_bundle_path()
-            images = {
-                'none':   bundle+'/images/no-medal.jpg',
-                'bronze': bundle+'/images/bronze-medal.jpg',
-                'silver': bundle+'/images/silver-medal.jpg',
-                'gold':   bundle+'/images/gold-medal.jpg'
-            }
-            l.medalimage.set_from_file(images[medal_type])
+    def show_lesson(self, index):
+        # Clear all widgets in the lesson box.
+        for w in self.lessonbox:
+            self.lessonbox.remove(w)
+        
+        self.prevlessonbtn.set_sensitive(index > 0)
+        self.nextlessonbtn.set_sensitive(index < len(self.lessons)-1)
+        
+        lesson = self.lessons[index]
+        
+        self.visible_lesson = lesson
+        
+        # Create the lesson button.
+        label = gtk.Label()
+        label.set_alignment(0.0, 0.5)
+        label.set_markup("<span size='large'>" + lesson['name'] + "</span>\n" + lesson['description'])
+        
+        lessonbtn = gtk.Button()
+        lessonbtn.add(label)
+        lessonbtn.connect('clicked', self.lesson_clicked_cb)
+        
+        # Create the medal image.
+        medalimage = gtk.Image()
+        
+        medal_type = 'none'
+        if self.activity.data['medals'].has_key(lesson['name']):
+            medal_type = self.activity.data['medals'][lesson['name']]['type']
+        
+        bundle = sugar.activity.activity.get_bundle_path()
+        images = {
+            'none':   bundle+'/images/no-medal.jpg',
+            'bronze': bundle+'/images/bronze-medal.jpg',
+            'silver': bundle+'/images/silver-medal.jpg',
+            'gold':   bundle+'/images/gold-medal.jpg'
+        }
+        medalimage.set_from_file(images[medal_type])
+        
+        medalbtn = gtk.Button()
+        medalbtn.add(medalimage)
+        medalbtn.connect('clicked', self.medal_clicked_cb)
+        
+        # Disable the buttons unless available.
+        lesson_available = self.activity.data['level'] >= lesson['requiredlevel']
+        lessonbtn.set_sensitive(lesson_available)
+        medalbtn.set_sensitive(lesson_available)
+        
+        self.lessonbox.pack_start(lessonbtn, True)
+        self.lessonbox.pack_start(medalbtn, False)
+    
+    def next_lesson_clicked_cb(self, widget):
+        pass
+    
+    def prev_lesson_clicked_cb(self, widget):
+        pass
     
     def lesson_clicked_cb(self, widget):
-        self.activity.push_screen(lessonscreen.LessonScreen(widget.lesson, self.activity))
+        self.activity.push_screen(lessonscreen.LessonScreen(self.visible_lesson, self.activity))
     
     def medal_clicked_cb(self, widget):
-        if self.activity.data['medals'].has_key(widget.lesson['name']):
-            medal = self.activity.data['medals'][widget.lesson['name']]
+        if self.activity.data['medals'].has_key(self.visible_lesson['name']):
+            medal = self.activity.data['medals'][self.visible_lesson['name']]
             self.activity.push_screen(medalscreen.MedalScreen(medal, self.activity))
-----------------------------------------------------------------------


--
/home/olpc-code/git/activities/typing-turtle


More information about the Commits mailing list