From c58be83fd781cf6cf79c8def9866573ef69ed490 Mon Sep 17 00:00:00 2001 From: Wade Brainerd Date: Thu, 22 Oct 2009 12:22:11 +0000 Subject: Checkboxes to allow/disallow mistakes and the backspace key. Lesson editor layout tweaks. --- 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("" + _('Options') + "") + 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("" + _('Automatic Lesson Generator') + "") @@ -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("" + _('Words') + "") 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() -- cgit v0.9.1