diff options
author | Wade Brainerd <wadetb@gmail.com> | 2009-09-16 01:20:01 (GMT) |
---|---|---|
committer | Wade Brainerd <wadetb@gmail.com> | 2009-09-16 01:20:01 (GMT) |
commit | 7b9cc164d04f9c7c6d657c502a03f7e74e200660 (patch) | |
tree | 177f779b0193ec52f9277c1f6a25e7258c39d696 | |
parent | 145397211135ca75ee39fa87071c059d3a654bcb (diff) |
Lesson editor fixes.
-rw-r--r-- | editlessonlistscreen.py | 11 | ||||
-rw-r--r-- | editlessonscreen.py | 101 | ||||
-rw-r--r-- | lessonscreen.py | 7 |
3 files changed, 106 insertions, 13 deletions
diff --git a/editlessonlistscreen.py b/editlessonlistscreen.py index e7a6238..7c1ab4b 100644 --- a/editlessonlistscreen.py +++ b/editlessonlistscreen.py @@ -156,7 +156,16 @@ class EditLessonListScreen(gtk.VBox): self.activity.pop_screen() def add_lesson_clicked_cb(self, btn): - lesson = { 'name':'', 'description':'', 'type':'normal', 'steps':[ { 'instructions':'', 'text':'' } ] } + lesson = {} + lesson['name'] = '' + lesson['description'] = '' + lesson['type'] = 'normal' + lesson['steps'] = [ { 'instructions':'', 'text':'' } ] + lesson['medals'] = [ + { 'name': 'bronze', 'wpm': 15, 'accuracy': 70, 'score': 3000 }, + { 'name': 'silver', 'wpm': 20, 'accuracy': 80, 'score': 4500 }, + { 'name': 'gold', 'wpm': 25, 'accuracy': 90, 'score': 6000 }, + ] self.lessons.append(lesson) self.activity.push_screen(editlessonscreen.EditLessonScreen(self.activity, lesson)) self.liststore.append() diff --git a/editlessonscreen.py b/editlessonscreen.py index 46bfd4c..bf9677a 100644 --- a/editlessonscreen.py +++ b/editlessonscreen.py @@ -91,6 +91,11 @@ class EditLessonScreen(gtk.VBox): movedownbtn.add(sugar.graphics.icon.Icon(icon_name='go-down')) movedownbtn.connect('clicked', self.move_step_down_clicked_cb, idx) + if idx == 0: + moveupbtn.set_sensitive(False) + if idx == len(self.lesson['steps']) - 1: + movedownbtn.set_sensitive(False) + btnbox = gtk.HBox() btnbox.pack_start(steplabel, False, False) btnbox.pack_end(addstepbtn, False, False) @@ -104,6 +109,8 @@ class EditLessonScreen(gtk.VBox): instlabel.set_alignment(0.0, 0.5) instlabel.set_padding(20, 0) + self.labelsizegroup.add_widget(instlabel) + stepbox.insttext = gtk.TextView(gtk.TextBuffer()) stepbox.insttext.props.wrap_mode = gtk.WRAP_WORD instscroll = gtk.ScrolledWindow() @@ -121,6 +128,8 @@ class EditLessonScreen(gtk.VBox): textlabel.set_alignment(0.0, 0.5) textlabel.set_padding(20, 0) + self.labelsizegroup.add_widget(textlabel) + stepbox.texttext = gtk.TextView(gtk.TextBuffer()) stepbox.texttext.props.wrap_mode = gtk.WRAP_WORD textscroll = gtk.ScrolledWindow() @@ -143,10 +152,53 @@ class EditLessonScreen(gtk.VBox): return stepbox + def build_medal(self, medal, name): + box = gtk.HBox() + + label = gtk.Label() + label.set_markup("<span size='large' weight='bold'>" + name + "</span>") + label.set_alignment(0.0, 0.5) + label.set_padding(20, 0) + + self.labelsizegroup.add_widget(label) + + box.pack_start(label, False, False) + + if self.lesson['type'] == 'normal': + acclabel = gtk.Label(_('Accuracy')) + wpmlabel = gtk.Label(_('WPM')) + + box.accent = gtk.Entry() + box.wpment = gtk.Entry() + + box.accent.set_text(str(medal['accuracy'])) + box.wpment.set_text(str(medal['wpm'])) + + box.pack_start(acclabel, False, False, 10) + box.pack_start(box.accent, False, False) + box.pack_start(wpmlabel, False, False, 10) + box.pack_start(box.wpment, False, False) + + elif self.lesson['type'] == 'balloon': + scorelabel = gtk.Label(_('Score')) + + box.scoreent = gtk.Entry() + box.scoreent.set_text(str(medal['score'])) + + box.pack_start(scorelabel, False, False, 10) + box.pack_start(box.scoreent, False, False) + + return box + def build(self): self.in_build = True - # Add the editing controls. + self.vbox = gtk.VBox() + self.vbox.set_border_width(20) + + self.labelsizegroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) + + # Lesson details widgets. detailslabel = gtk.Label() detailslabel.set_markup("<span size='x-large'><b>" + _('Lesson Details') + "</b></span>") detailslabel.set_alignment(0.0, 0.5) @@ -199,25 +251,25 @@ class EditLessonScreen(gtk.VBox): descbox = gtk.HBox() descbox.pack_start(desclabel, False, False) descbox.pack_start(descscroll, True, True) - - sizegroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) - sizegroup.add_widget(namelabel) - sizegroup.add_widget(typelabel) - sizegroup.add_widget(desclabel) - - self.vbox = gtk.VBox() - self.vbox.set_border_width(20) + + self.labelsizegroup.add_widget(namelabel) + self.labelsizegroup.add_widget(typelabel) + self.labelsizegroup.add_widget(desclabel) + self.vbox.pack_start(detailslabel, False, False, 10) self.vbox.pack_start(namebox, False, False, 10) self.vbox.pack_start(typebox, False, False, 10) self.vbox.pack_start(descbox, False, False, 10) self.vbox.pack_start(gtk.HSeparator(), False, False, 0) + # Steps or words widgets. if self.lesson['type'] == 'normal': if not self.lesson.has_key('steps') or len(self.lesson['steps']) == 0: step = { 'instructions': '', 'text': '' } - self.lesson['steps'] = [ step ] + self.lesson['steps'] = [ step ] + self.vbox.pack_start(gtk.HSeparator(), False, False, 0) + self.stepboxes = [] for step in self.lesson['steps']: @@ -230,11 +282,15 @@ 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(), False, False, 0) + textlabel = gtk.Label() textlabel.set_markup("<span size='large' weight='bold'>" + _('Words') + "</span>") textlabel.set_alignment(0.0, 0.5) textlabel.set_padding(20, 0) + self.labelsizegroup.add_widget(textlabel) + self.wordstext = gtk.TextView(gtk.TextBuffer()) self.wordstext.props.wrap_mode = gtk.WRAP_WORD textscroll = gtk.ScrolledWindow() @@ -249,6 +305,24 @@ class EditLessonScreen(gtk.VBox): self.vbox.pack_start(textbox, False, False, 10) + # Medal requirements widgets. + medalslabel = gtk.Label() + medalslabel.set_markup("<span size='x-large'><b>" + _('Medal Requirements') + "</b></span>") + medalslabel.set_alignment(0.0, 0.5) + medalslabel.set_padding(10, 0) + + self.vbox.pack_start(gtk.HSeparator(), False, False, 0) + self.vbox.pack_start(medalslabel, False, False, 10) + + self.medalboxes = [] + self.medalboxes.append(self.build_medal(self.lesson['medals'][0], _('Bronze'))) + self.medalboxes.append(self.build_medal(self.lesson['medals'][1], _('Silver'))) + self.medalboxes.append(self.build_medal(self.lesson['medals'][2], _('Gold'))) + + self.vbox.pack_start(self.medalboxes[0], False, False, 10) + self.vbox.pack_start(self.medalboxes[1], False, False, 10) + self.vbox.pack_start(self.medalboxes[2], False, False, 10) + self.vbox.show_all() self.in_build = False @@ -287,12 +361,19 @@ class EditLessonScreen(gtk.VBox): self.lesson['steps'] = steps + for i in range(0, 3): + self.lesson['medals'][i]['accuracy'] = int(self.medalboxes[i].accent.get_text()) + self.lesson['medals'][i]['wpm'] = int(self.medalboxes[i].wpment.get_text()) + if self.balloonradio.get_active(): self.lesson['type'] = 'balloon' buf = self.wordstext.get_buffer() text = buf.get_text(buf.get_start_iter(), buf.get_end_iter()) self.lesson['words'] = text.split(' ') + + for i in range(0, 3): + self.lesson['medals'][i]['score'] = int(self.medalboxes[i].scoreent.get_text()) def add_step_clicked_cb(self, btn, index): step = { 'instructions': '', 'text': '' } diff --git a/lessonscreen.py b/lessonscreen.py index 884ad3c..68efc4f 100644 --- a/lessonscreen.py +++ b/lessonscreen.py @@ -254,7 +254,10 @@ class LessonScreen(gtk.VBox): self.next_step_idx = self.next_step_idx + 1 # Single character steps are handled differently from multi-character steps. - self.mode = self.step['mode'] + if len(self.step['text']) == 1: + self.mode = 'key' + else: + self.mode = 'text' # Clear the buffer *before* key steps. self.lessonbuffer.set_text('') @@ -360,7 +363,7 @@ class LessonScreen(gtk.VBox): if not event.string: return True - print 'key_cb: ' + event.string + #print 'key_cb: ' + event.string # Ignore either press or release events, depending on mode. if self.mode == 'key' and event.type == gtk.gdk.KEY_PRESS: |