Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/lessonbuilder.py
diff options
context:
space:
mode:
authorWade Brainerd <wadetb@gmail.com>2008-12-16 03:30:44 (GMT)
committer Wade Brainerd <wadetb@gmail.com>2008-12-16 03:30:44 (GMT)
commit096a9758f7410a01d6fd8b76cc61f31d64a340df (patch)
treebf63c7b7186b0bc1730f6946f7ce34533fee3b17 /lessonbuilder.py
parentf9ff467b4000ce3e509e0a2824d522065ba2832f (diff)
parentd279c4680c0bdff198fdc7f880a105a882eed9ec (diff)
Merge branch 'master' of git+ssh://wadeb@dev.laptop.org/git/activities/typing-turtle
Diffstat (limited to 'lessonbuilder.py')
-rw-r--r--lessonbuilder.py172
1 files changed, 121 insertions, 51 deletions
diff --git a/lessonbuilder.py b/lessonbuilder.py
index 8931535..6480484 100644
--- a/lessonbuilder.py
+++ b/lessonbuilder.py
@@ -19,28 +19,53 @@
import os, sys, random, json
from gettext import gettext as _
-def make_triple(keys):
+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:
text += k + k + ' ' + k + ' '
return text
-def make_double(keys):
+def make_all_doubles(keys):
text = ''
for k in new_keys:
text += k + k + ' '
return text
-def make_random_triple(keys, count):
+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_random(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_pair(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):
@@ -72,25 +97,25 @@ def make_all_joined_pairs(keys1, keys2):
text += k2 + k1 + ' '
return text
-def make_words(wordlist, count):
+def make_random_words(words, count):
text = ''
for x in range(0, count):
- text += random.choice(wordlist) + ' '
+ text += random.choice(words) + ' '
return text
-def filter_wordlist(path, all_keys, req_keys, minlen, maxlen, badwordlist):
- wordlist = open(path, 'r').readlines()
- wordlist = [s.strip() for s in wordlist]
+def load_wordlist(path):
+ try:
+ words = open(path, 'r').readlines()
+ words = [s.strip() for s in words]
+ return words
+ except:
+ return []
- if badwordlist:
- bad_words = open(badwordlist, 'r').readlines()
- bad_words = [s.strip() for s in badwordlist]
- else:
- bad_words = []
+def filter_wordlist(words, all_keys, req_keys, minlen, maxlen, bad_words):
good_words = []
- for word in wordlist:
+ for word in words:
if len(word) < minlen or len(word) > maxlen:
continue
@@ -122,7 +147,7 @@ def filter_wordlist(path, all_keys, req_keys, minlen, maxlen, badwordlist):
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(
@@ -131,6 +156,12 @@ def build_lesson(
new_keys, base_keys,
wordlist=None, badwordlist=None):
+ 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 = {}
@@ -140,57 +171,96 @@ 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_triple(new_keys) * 4)
-
- add_step(lesson,
- _('Practice typing the keys you just learned.'),
- make_random_triple(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_pair(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_random(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_pair(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_random(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(path=wordlist,
+ good_words = filter_wordlist(words=words,
all_keys=all_keys, req_keys=new_keys,
minlen=2, maxlen=10,
- badwordlist=badwordlist)
+ bad_words=bad_words)
add_step(lesson,
- _('Practice typing these words.'),
- make_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@gmail.com>
@@ -219,7 +289,7 @@ if __name__ == "__main__":
usage()
sys.exit()
- name = 'Generated lesson'
+ name = 'Generated'
desc = 'Default description'
level = 0
required_level = 0
@@ -257,8 +327,8 @@ if __name__ == "__main__":
sys.exit()
lesson = build_lesson(
- name='Created Lesson', description='Lesson Description',
- level=0, required_level=0,
+ name=name, description=desc,
+ level=level, required_level=required_level,
new_keys=new_keys, base_keys=base_keys,
wordlist=wordlist, badwordlist=badwordlist)