From f070c15fa1e17b3e27586d68d1814f67f27f9e6f Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Fri, 10 Aug 2012 20:53:13 +0000 Subject: Edit lessons section After the port to Gtk3 the Edit Lessons section didn't work anymore. This commits solves this and make this section available again. Signed-off-by: Manuel Kaufmann Reviewed-by: Gonzalo Odiard --- diff --git a/editlessonlistscreen.py b/editlessonlistscreen.py index 6ac2c34..984f3b7 100644 --- a/editlessonlistscreen.py +++ b/editlessonlistscreen.py @@ -61,9 +61,6 @@ class EditLessonListScreen(Gtk.VBox): 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. self.liststore = Gtk.ListStore(GObject.TYPE_INT) @@ -136,6 +133,11 @@ class EditLessonListScreen(Gtk.VBox): self.pack_start(scroll, True, True, 10) self.pack_start(btnbox, False, False, 10) + # README: I had to move these two lines here because the + # signal was emitted before all the widget are created + self.treeview.connect('cursor-changed', self.lesson_selected_cb) + self.treeview.connect('row-activated', self.lesson_activated_cb) + self.build() self.show_all() @@ -146,18 +148,18 @@ class EditLessonListScreen(Gtk.VBox): for t in range(0, len(self.lessons)): self.liststore.append((0,)) - def name_render_cb(self, column, cell_renderer, model, iter): - id = model.get_path(iter)[0] + def name_render_cb(self, column, cell_renderer, model, iter, data): + id = model.get_path(iter).get_indices()[0] t = self.lessons[id] cell_renderer.set_property('text', t['name']) - def description_render_cb(self, column, cell_renderer, model, iter): - id = model.get_path(iter)[0] + def description_render_cb(self, column, cell_renderer, model, iter, data): + id = model.get_path(iter).get_indices()[0] t = self.lessons[id] cell_renderer.set_property('text', t['description']) - def type_render_cb(self, column, cell_renderer, model, iter): - id = model.get_path(iter)[0] + def type_render_cb(self, column, cell_renderer, model, iter, data): + id = model.get_path(iter).get_indices()[0] t = self.lessons[id] if t['type'] == 'normal': cell_renderer.set_property('text', _('Text')) @@ -195,31 +197,32 @@ class EditLessonListScreen(Gtk.VBox): def del_lesson_clicked_cb(self, btn): if len(self.lessons) > 1: - path = self.treeview.get_cursor()[0] + path, focus_column = self.treeview.get_cursor() + if path: msg = sugar3.graphics.alert.ConfirmationAlert() msg.props.title = _('Delete Lesson?') msg.props.msg = _('Deleting the lesson will erase the lesson content.') - def alert_response_cb(alert, response_id, self, id): + def alert_response_cb(alert, response_id, self, path): self.activity.remove_alert(alert) if response_id is Gtk.ResponseType.OK: + id = path.get_indices()[0] self.lessons.pop(id) - del self.liststore[id] + del self.liststore[path] self.treeview.get_selection().select_path(id) self.treeview.grab_focus() self.update_sensitivity() - - id = path[0] - msg.connect('response', alert_response_cb, self, id) + + msg.connect('response', alert_response_cb, self, path) self.activity.add_alert(msg) msg.show_all() def move_lesson_up_clicked_cb(self, btn): - path = self.treeview.get_cursor()[0] + path, focus_column = self.treeview.get_cursor() if path: - id = path[0] + id = path.get_indices()[0] if id > 0: lesson = self.lessons.pop(id) self.lessons.insert(id - 1, lesson) @@ -229,9 +232,9 @@ class EditLessonListScreen(Gtk.VBox): self.update_sensitivity() def move_lesson_down_clicked_cb(self, btn): - path = self.treeview.get_cursor()[0] + path, focus_column = self.treeview.get_cursor() if path: - id = path[0] + id = path.get_indices()[0] if id < len(self.lessons) - 1: lesson = self.lessons.pop(id) self.lessons.insert(id + 1, lesson) @@ -244,7 +247,8 @@ class EditLessonListScreen(Gtk.VBox): self.update_sensitivity() def lesson_activated_cb(self, treeview, path, column): - id = path[0] + path, focus_column = self.treeview.get_cursor() + id = path.get_indices()[0] lesson = self.lessons[id] self.activity.push_screen(editlessonscreen.EditLessonScreen(self.activity, lesson)) @@ -252,21 +256,20 @@ class EditLessonListScreen(Gtk.VBox): self.update_sensitivity() def update_sensitivity(self): - path = self.treeview.get_cursor()[0] - + path, focus_column = self.treeview.get_cursor() if path: self.delbtn.set_sensitive(True) - - if path[0] > 0: + + id = path.get_indices()[0] + if id > 0: self.moveupbtn.set_sensitive(True) else: self.moveupbtn.set_sensitive(False) - - if path[0] < len(self.lessons) - 1: + + if id < len(self.lessons) - 1: self.movedownbtn.set_sensitive(True) else: self.movedownbtn.set_sensitive(False) - else: self.delbtn.set_sensitive(False) self.moveupbtn.set_sensitive(False) diff --git a/editlessonscreen.py b/editlessonscreen.py index e5ce0b4..d81d250 100644 --- a/editlessonscreen.py +++ b/editlessonscreen.py @@ -157,7 +157,8 @@ class EditLessonScreen(Gtk.VBox): btnbox = Gtk.HBox() btnbox.pack_start(steplabel, False, False, 0) - btnbox.pack_start(stepbox.typecombo, expand=False, padding=10) + btnbox.pack_start(stepbox.typecombo, expand=False, + fill=False, padding=10) btnbox.pack_end(addstepbtn, False, False, 0) btnbox.pack_end(delstepbtn, False, False, 0) btnbox.pack_end(moveupbtn, False, False, 0) @@ -171,7 +172,8 @@ class EditLessonScreen(Gtk.VBox): self.labelsizegroup.add_widget(instlabel) - stepbox.insttext = Gtk.TextView(Gtk.TextBuffer()) + stepbox.insttext = Gtk.TextView() + stepbox.insttext.set_buffer(Gtk.TextBuffer()) stepbox.insttext.props.wrap_mode = Gtk.WrapMode.WORD stepbox.insttext.modify_font(Pango.FontDescription('Monospace')) instscroll = Gtk.ScrolledWindow() @@ -192,7 +194,8 @@ class EditLessonScreen(Gtk.VBox): self.labelsizegroup.add_widget(textlabel) - stepbox.texttext = Gtk.TextView(Gtk.TextBuffer()) + stepbox.texttext = Gtk.TextView() + stepbox.texttext.set_buffer(Gtk.TextBuffer()) stepbox.texttext.props.wrap_mode = Gtk.WrapMode.WORD stepbox.texttext.modify_font(Pango.FontDescription('monospace')) textscroll = Gtk.ScrolledWindow() @@ -304,7 +307,8 @@ class EditLessonScreen(Gtk.VBox): desclabel.set_alignment(0.0, 0.5) desclabel.set_padding(20, 0) - self.desctext = Gtk.TextView(Gtk.TextBuffer()) + self.desctext = Gtk.TextView() + self.desctext.set_buffer(Gtk.TextBuffer()) self.desctext.props.wrap_mode = Gtk.WrapMode.WORD descscroll = Gtk.ScrolledWindow() descscroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) @@ -350,7 +354,8 @@ class EditLessonScreen(Gtk.VBox): generatelabel.set_padding(10, 0) generatebox = self.build_generate() - self.vbox.pack_start(generatelabel, expand=False, padding=10) + self.vbox.pack_start(generatelabel, expand=False, + fill=False, padding=10) self.vbox.pack_start(generatebox, False, True, 0) self.has_normal_widgets = False @@ -385,7 +390,8 @@ class EditLessonScreen(Gtk.VBox): self.labelsizegroup.add_widget(textlabel) - self.wordstext = Gtk.TextView(Gtk.TextBuffer()) + self.wordstext = Gtk.TextView() + self.wordstext.set_buffer(Gtk.TextBuffer()) self.wordstext.props.wrap_mode = Gtk.WrapMode.WORD self.wordstext.modify_font(Pango.FontDescription('Monospace')) textscroll = Gtk.ScrolledWindow() @@ -406,7 +412,8 @@ class EditLessonScreen(Gtk.VBox): medalslabel.set_alignment(0.0, 0.5) medalslabel.set_padding(10, 0) - self.vbox.pack_start(medalslabel, expand=False, padding=10) + self.vbox.pack_start(medalslabel, expand=False, + fill=False, padding=10) self.medalboxes = [] self.medalboxes.append(self.build_medal(self.lesson['medals'][0], _('Bronze'))) @@ -436,7 +443,8 @@ class EditLessonScreen(Gtk.VBox): self.lesson['name'] = self.nameent.get_text() buf = self.desctext.get_buffer() - self.lesson['description'] = buf.get_text(buf.get_start_iter(), buf.get_end_iter()) + self.lesson['description'] = buf.get_text(buf.get_start_iter(), + buf.get_end_iter(), False) if not self.lesson.has_key('options'): self.lesson['options'] = {} @@ -453,10 +461,13 @@ class EditLessonScreen(Gtk.VBox): step = {} buf = sb.insttext.get_buffer() - step['instructions'] = buf.get_text(buf.get_start_iter(), buf.get_end_iter()) + step['instructions'] = buf.get_text(buf.get_start_iter(), + buf.get_end_iter(), + False) buf = sb.texttext.get_buffer() - step['text'] = buf.get_text(buf.get_start_iter(), buf.get_end_iter()) + step['text'] = buf.get_text(buf.get_start_iter(), + buf.get_end_iter(), False) if sb.typecombo.get_active() == 0: step['mode'] = 'key' @@ -476,7 +487,8 @@ class EditLessonScreen(Gtk.VBox): if self.has_balloon_widgets: buf = self.wordstext.get_buffer() - text = buf.get_text(buf.get_start_iter(), buf.get_end_iter()) + text = buf.get_text(buf.get_start_iter(), + buf.get_end_iter(), False) self.lesson['words'] = text.split(' ') for i in range(0, 3): @@ -581,7 +593,8 @@ class WordListScreen(Gtk.VBox): subtitle.set_markup("" + _("Type or paste words here, for the Automatic Lesson Generator. If empty, the dictionary will be used.") + "") subtitle.set_alignment(1.0, 0.0) - self.wordlisttext = Gtk.TextView(Gtk.TextBuffer()) + self.wordlisttext = Gtk.TextView() + self.wordlisttext.set_buffer(Gtk.TextBuffer()) self.wordlisttext.props.wrap_mode = Gtk.WrapMode.WORD wordlistscroll = Gtk.ScrolledWindow() wordlistscroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) @@ -591,14 +604,16 @@ class WordListScreen(Gtk.VBox): self.pack_start(titlebox, False, True, 0) self.pack_start(subtitle, False, True, 0) - self.pack_start(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL), expand=False, padding=0) + separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL) + self.pack_start(separator, expand=False, fill=False, padding=0) self.pack_start(wordlistscroll, True, True, 0) self.show_all() def stop_clicked_cb(self, btn): buf = self.wordlisttext.get_buffer() - wordstext = buf.get_text(buf.get_start_iter(), buf.get_end_iter()) + wordstext = buf.get_text(buf.get_start_iter(), + buf.get_end_iter(), False) self.activity.wordlist = wordstext.split() self.activity.pop_screen() -- cgit v0.9.1