Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWade Brainerd <wadetb@gmail.com>2009-10-22 12:22:11 (GMT)
committer Wade Brainerd <wadetb@gmail.com>2009-10-22 12:22:11 (GMT)
commitc58be83fd781cf6cf79c8def9866573ef69ed490 (patch)
tree381d3cdaa2f88c116f6202face4b418a85458da1
parent1f4b1d8a800a46328abd056c0ffa417c2fde735f (diff)
Checkboxes to allow/disallow mistakes and the backspace key. Lesson editor layout tweaks.
-rw-r--r--editlessonscreen.py43
-rw-r--r--lessonscreen.py72
2 files changed, 67 insertions, 48 deletions
diff --git a/editlessonscreen.py b/editlessonscreen.py
index b5133b8..daf0108 100644
--- a/editlessonscreen.py
+++ b/editlessonscreen.py
@@ -102,12 +102,12 @@ class EditLessonScreen(gtk.VBox):
okbtn.connect('clicked', self.generate_ok_clicked_cb, generatebox)
okbtn.set_alignment(0.5, 0.5)
- box.pack_end(okbtn)
+ box.pack_end(okbtn, expand=False)
generatebox.pack_start(box)
return generatebox
-
+
def build_step(self, step, idx):
stepbox = gtk.VBox()
stepbox.set_spacing(5)
@@ -295,17 +295,34 @@ class EditLessonScreen(gtk.VBox):
descbox = gtk.HBox()
descbox.pack_start(desclabel, expand=False)
descbox.pack_start(descscroll)
-
+
+ # Build the options.
+ optslabel = gtk.Label()
+ optslabel.set_markup("<span size='large' weight='bold'>" + _('Options') + "</span>")
+ optslabel.set_alignment(0.0, 0.5)
+ optslabel.set_padding(20, 0)
+
+ self.mistakescheck = gtk.CheckButton(_('Allow Mistakes'))
+ self.mistakescheck.set_active(self.lesson.get('options', {}).get('mistakes', True))
+ self.backspacecheck = gtk.CheckButton(_('Allow Backspace'))
+ self.backspacecheck.set_active(self.lesson.get('options', {}).get('backspace', True))
+
+ optsbox = gtk.HBox()
+ optsbox.pack_start(optslabel, expand=False)
+ optsbox.pack_start(self.backspacecheck, expand=False)
+ optsbox.pack_start(self.mistakescheck, expand=False)
+
self.labelsizegroup.add_widget(namelabel)
self.labelsizegroup.add_widget(typelabel)
self.labelsizegroup.add_widget(desclabel)
+ self.labelsizegroup.add_widget(optslabel)
self.vbox.pack_start(detailslabel, expand=False)
self.vbox.pack_start(namebox, expand=False)
self.vbox.pack_start(typebox, expand=False)
self.vbox.pack_start(descbox, expand=False)
- self.vbox.pack_start(gtk.HSeparator(), expand=False)
-
+ self.vbox.pack_start(optsbox, expand=False)
+
# Build the generator.
generatelabel = gtk.Label()
generatelabel.set_markup("<span size='x-large'><b>" + _('Automatic Lesson Generator') + "</b></span>")
@@ -313,7 +330,7 @@ class EditLessonScreen(gtk.VBox):
generatelabel.set_padding(10, 0)
generatebox = self.build_generate()
- self.vbox.pack_start(generatelabel, expand=False)
+ self.vbox.pack_start(generatelabel, expand=False, padding=10)
self.vbox.pack_start(generatebox, expand=False)
self.has_normal_widgets = False
@@ -326,9 +343,7 @@ class EditLessonScreen(gtk.VBox):
if not self.lesson.has_key('steps') or len(self.lesson['steps']) == 0:
step = { 'instructions': '', 'text': '' }
self.lesson['steps'] = [ step ]
-
- self.vbox.pack_start(gtk.HSeparator(), expand=False)
-
+
self.stepboxes = []
for step in self.lesson['steps']:
@@ -343,8 +358,6 @@ class EditLessonScreen(gtk.VBox):
if not self.lesson.has_key('words') or len(self.lesson['words']) == 0:
self.lesson['words'] = []
- self.vbox.pack_start(gtk.HSeparator(), expand=False)
-
textlabel = gtk.Label()
textlabel.set_markup("<span size='large' weight='bold'>" + _('Words') + "</span>")
textlabel.set_alignment(0.0, 0.5)
@@ -373,8 +386,7 @@ class EditLessonScreen(gtk.VBox):
medalslabel.set_alignment(0.0, 0.5)
medalslabel.set_padding(10, 0)
- self.vbox.pack_start(gtk.HSeparator(), expand=False)
- self.vbox.pack_start(medalslabel, expand=False)
+ self.vbox.pack_start(medalslabel, expand=False, padding=10)
self.medalboxes = []
self.medalboxes.append(self.build_medal(self.lesson['medals'][0], _('Bronze')))
@@ -406,6 +418,11 @@ class EditLessonScreen(gtk.VBox):
buf = self.desctext.get_buffer()
self.lesson['description'] = buf.get_text(buf.get_start_iter(), buf.get_end_iter())
+ if not self.lesson.has_key('options'):
+ self.lesson['options'] = {}
+ self.lesson['options']['mistakes'] = self.mistakescheck.get_active()
+ self.lesson['options']['backspace'] = self.backspacecheck.get_active()
+
if self.textradio.get_active():
self.lesson['type'] = 'normal'
diff --git a/lessonscreen.py b/lessonscreen.py
index 8a9e4cc..daed55b 100644
--- a/lessonscreen.py
+++ b/lessonscreen.py
@@ -392,7 +392,7 @@ class LessonScreen(gtk.VBox):
else:
# TODO - Play 'incorrect key' sound here.
-
+
self.incorrect_keys += 1
self.total_keys += 1
@@ -402,25 +402,26 @@ class LessonScreen(gtk.VBox):
self.start_timer()
# Handle backspace by deleting text and optionally moving up lines.
- if key_name == 'BackSpace':
- # Move to previous line if at the end of the current one.
- if self.char_idx == 0 and self.line_idx > 0:
- self.line_idx -= 1
- self.begin_line()
-
- self.char_idx = len(self.line)
-
- # Then delete the current character.
- if self.char_idx > 0:
- self.char_idx -= 1
-
- iter = self.lessonbuffer.get_iter_at_mark(self.line_mark)
- iter.forward_chars(self.char_idx)
-
- iter_end = iter.copy()
- iter_end.forward_char()
+ if key_name == 'BackSpace':
+ if self.lesson.get('options', {}).get('backspace', True):
+ # Move to previous line if at the end of the current one.
+ if self.char_idx == 0 and self.line_idx > 0:
+ self.line_idx -= 1
+ self.begin_line()
+
+ self.char_idx = len(self.line)
- self.lessonbuffer.delete(iter, iter_end)
+ # Then delete the current character.
+ if self.char_idx > 0:
+ self.char_idx -= 1
+
+ iter = self.lessonbuffer.get_iter_at_mark(self.line_mark)
+ iter.forward_chars(self.char_idx)
+
+ iter_end = iter.copy()
+ iter_end.forward_char()
+
+ self.lessonbuffer.delete(iter, iter_end)
self.hilite_next_key()
@@ -439,22 +440,23 @@ class LessonScreen(gtk.VBox):
tag_name = 'incorrect-copy'
self.incorrect_keys += 1
self.total_keys += 1
-
- # Insert the key into the bufffer.
- iter = self.lessonbuffer.get_iter_at_mark(self.line_mark)
- iter.forward_chars(self.char_idx)
-
- self.lessonbuffer.insert_with_tags_by_name(iter, key, tag_name)
-
- # Advance to the next character (or else).
- self.char_idx += 1
- if self.char_idx >= len(self.line):
- self.line_idx += 1
- if self.line_idx >= len(self.lines):
- self.advance_step()
- else:
- self.begin_line()
- return True
+
+ # Insert the key into the buffer if correct or if mistakes are allowed.
+ if tag_name == 'correct-copy' or self.lesson.get('options', {}).get('mistakes', True):
+ iter = self.lessonbuffer.get_iter_at_mark(self.line_mark)
+ iter.forward_chars(self.char_idx)
+
+ self.lessonbuffer.insert_with_tags_by_name(iter, key, tag_name)
+
+ # Advance to the next character (or else).
+ self.char_idx += 1
+ if self.char_idx >= len(self.line):
+ self.line_idx += 1
+ if self.line_idx >= len(self.lines):
+ self.advance_step()
+ else:
+ self.begin_line()
+ return True
self.update_stats()