diff options
author | Wade Brainerd <wadetb@gmail.com> | 2009-09-11 00:00:12 (GMT) |
---|---|---|
committer | Wade Brainerd <wadetb@gmail.com> | 2009-09-11 00:00:12 (GMT) |
commit | 05cb5364230d2d9ab65ac3a77a4a7dec29b8748b (patch) | |
tree | 157236d0157b34331de3a965f4304e230547abf8 | |
parent | 9ffd0d146b25b5430bdf18ac44c552d0d8a53454 (diff) |
Lesson editing bug fixes.
-rw-r--r-- | editlessonlistscreen.py | 23 | ||||
-rw-r--r-- | editlessonscreen.py | 35 |
2 files changed, 37 insertions, 21 deletions
diff --git a/editlessonlistscreen.py b/editlessonlistscreen.py index d1ed405..29d76d7 100644 --- a/editlessonlistscreen.py +++ b/editlessonlistscreen.py @@ -51,20 +51,13 @@ class EditLessonListScreen(gtk.VBox): titlebox.pack_start(stopbtn, False, False, 10) titlebox.pack_end(title, False, False, 10) - help = gtk.Label() - help.set_padding(10, 0) - help.set_alignment(1.0, 0.5) - help.set_markup( - _("Choose the lesson that you wish to modify. If you wish to add a new lesson, ") + - _("or delete an existing lesson, use the buttons at the bottom.") - ) - # Add the lesson list. self.treeview = gtk.TreeView() self.treeview.set_rules_hint(True) self.treeview.set_enable_search(False) self.treeview.connect('cursor-changed', self.lesson_selected_cb) + self.treeview.connect('row-activated', self.lesson_activated_cb) # Note that the only thing we store in our liststore is the lesson id. # All the actual data is in the lessons list. @@ -113,7 +106,6 @@ class EditLessonListScreen(gtk.VBox): buttonbox.pack_start(self.dellessonbtn, True, False, 10) self.pack_start(titlebox, False, False, 10) - self.pack_start(help, False, False, 10) self.pack_start(gtk.HSeparator(), False, False, 0) self.pack_start(scroll, True, True, 10) self.pack_start(buttonbox, False, False, 10) @@ -124,6 +116,7 @@ class EditLessonListScreen(gtk.VBox): def build(self): # Fill the lesson list. + self.liststore.clear() for t in range(0, len(self.lessons)-1): self.liststore.append((t,)) @@ -138,11 +131,16 @@ class EditLessonListScreen(gtk.VBox): cell_renderer.set_property('text', t['description']) def stop_clicked_cb(self, btn): + # Refresh the main screen given the new lesson data. + self.activity.mainscreen.show_lesson(self.activity.mainscreen.lesson_index) + self.activity.pop_screen() def add_lesson_clicked_cb(self, btn): - lesson = {} + lesson = { 'name':'', 'description':'', 'type':'normal', 'steps':[ { 'instructions':'', 'text':'' } ] } + self.lessons.append(lesson) self.activity.push_screen(editlessonscreen.EditLessonScreen(self.activity, lesson)) + self.build() def del_lesson_clicked_cb(self, btn): path = self.treeview.get_cursor()[0] @@ -150,8 +148,8 @@ class EditLessonListScreen(gtk.VBox): model = self.liststore iter = model.get_iter(path) id = model.get_value(iter, 0) - self.lessons = self.lessons[id:] + self.lessons[id:] - self.liststore.remove(iter) + self.lessons.pop(id) + self.build() def edit_lesson_clicked_cb(self, btn): path = self.treeview.get_cursor()[0] @@ -177,3 +175,4 @@ class EditLessonListScreen(gtk.VBox): lesson = self.lessons[id] self.activity.push_screen(editlessonscreen.EditLessonScreen(self.activity, lesson)) + diff --git a/editlessonscreen.py b/editlessonscreen.py index 26c74e2..3ddd8cf 100644 --- a/editlessonscreen.py +++ b/editlessonscreen.py @@ -36,6 +36,8 @@ class EditLessonScreen(gtk.VBox): self.activity = activity self.lesson = lesson + self.in_build = False + # Add the header. title = gtk.Label() title.set_markup("<span size='20000'><b>" + _("Edit a Lesson") + "</b></span>") @@ -50,14 +52,6 @@ class EditLessonScreen(gtk.VBox): titlebox.pack_start(stopbtn, False, False, 10) titlebox.pack_end(title, False, False, 10) - help = gtk.Label() - help.set_padding(10, 0) - help.set_alignment(1.0, 0.5) - help.set_markup( - _("Choose the lesson that you wish to modify. If you wish to add a new lesson, ") + - _("or delete an existing lesson, use the buttons at the bottom.") - ) - self.vp = gtk.Viewport() self.scroll = gtk.ScrolledWindow() @@ -65,7 +59,6 @@ class EditLessonScreen(gtk.VBox): self.scroll.add(self.vp) self.pack_start(titlebox, False, False, 10) - self.pack_start(help, False, False, 10) self.pack_start(gtk.HSeparator(), False, False, 0) self.pack_start(self.scroll, True, True, 0) @@ -151,6 +144,8 @@ class EditLessonScreen(gtk.VBox): return stepbox def build(self): + self.in_build = True + # Add the editing controls. detailslabel = gtk.Label() detailslabel.set_markup("<span size='x-large'><b>" + _('Lesson Details') + "</b></span>") @@ -175,7 +170,10 @@ class EditLessonScreen(gtk.VBox): typelabel.set_padding(20, 0) self.textradio = gtk.RadioButton(None, _('Normal Lesson')) + self.textradio.connect('toggled', self.type_toggled_cb) + self.balloonradio = gtk.RadioButton(self.textradio, _('Balloon Game')) + self.balloonradio.connect('toggled', self.type_toggled_cb) self.textradio.set_active(self.lesson['type'] == 'normal') self.balloonradio.set_active(self.lesson['type'] == 'balloon') @@ -216,6 +214,10 @@ class EditLessonScreen(gtk.VBox): self.vbox.pack_start(gtk.HSeparator(), False, False, 0) 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.stepboxes = [] for step in self.lesson['steps']: @@ -225,6 +227,9 @@ class EditLessonScreen(gtk.VBox): self.vbox.pack_start(stepbox, False, False, 0) if self.lesson['type'] == 'balloon': + if not self.lesson.has_key('words') or len(self.lesson['words']) == 0: + self.lesson['words'] = [] + textlabel = gtk.Label() textlabel.set_markup("<span size='large' weight='bold'>" + _('Words') + "</span>") textlabel.set_alignment(0.0, 0.5) @@ -246,6 +251,8 @@ class EditLessonScreen(gtk.VBox): self.vbox.show_all() + self.in_build = False + # Remove any existing controls. if self.vp.get_child(): self.vp.remove(self.vp.get_child()) @@ -308,3 +315,13 @@ class EditLessonScreen(gtk.VBox): self.lesson['steps'].insert(index+1, step) self.build() + def type_toggled_cb(self, btn): + # Prevent infinite recursion + if self.in_build: + return + + if self.textradio.get_active(): + self.lesson['type'] = 'normal' + if self.balloonradio.get_active(): + self.lesson['type'] = 'balloon' + self.build() |