def load(self, persp): self.persp = persp self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.tv = Gtk.TreeView() renderer = Gtk.CellRendererText() column = Gtk.TreeViewColumn(_("Title"), renderer, text=1) self.tv.append_column(column) renderer = Gtk.CellRendererText() column = Gtk.TreeViewColumn(_("Source"), renderer, text=2) self.tv.append_column(column) renderer = Gtk.CellRendererProgress() column = Gtk.TreeViewColumn(_("Progress"), renderer, text=3, value=4) self.tv.append_column(column) self.tv.connect("row-activated", self.row_activated) def on_progress_updated(solving_progress, key, progress): for i, row in enumerate(self.store): if row[0] == key: solved = progress.count(1) percent = 0 if not solved else round( (solved * 100.) / len(progress)) treeiter = self.store.get_iter(Gtk.TreePath(i)) self.store[treeiter][3] = "%s / %s" % (solved, len(progress)) self.store[treeiter][4] = percent lessons_solving_progress.connect("progress_updated", on_progress_updated) self.store = Gtk.ListStore(str, str, str, str, int) for file_name, title, author in LESSONS: progress = lessons_solving_progress.get(file_name) solved = progress.count(1) percent = 0 if not solved else round( (solved * 100.) / len(progress)) self.store.append([ file_name, title, author, "%s / %s" % (solved, len(progress)), percent ]) self.tv.set_model(self.store) self.tv.get_selection().set_mode(Gtk.SelectionMode.BROWSE) self.tv.set_cursor(0) scrollwin = Gtk.ScrolledWindow() scrollwin.add(self.tv) scrollwin.show_all() self.box.pack_start(scrollwin, True, True, 0) self.box.show_all() return self.box
def load(self, persp): self.persp = persp self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.tv = Gtk.TreeView() renderer = Gtk.CellRendererText() column = Gtk.TreeViewColumn(_("Id"), renderer, text=0) self.tv.append_column(column) renderer = Gtk.CellRendererText() column = Gtk.TreeViewColumn(_("Title"), renderer, text=2) self.tv.append_column(column) renderer = Gtk.CellRendererText() column = Gtk.TreeViewColumn(_("Author"), renderer, text=3) self.tv.append_column(column) renderer = Gtk.CellRendererProgress() column = Gtk.TreeViewColumn(_("Progress"), renderer, text=4, value=5) self.tv.append_column(column) self.tv.connect("row-activated", self.row_activated) def on_progress_updated(solving_progress, key, progress): for i, row in enumerate(self.store): if row[1] == key: solved = progress.count(1) percent = 0 if not solved else round((solved * 100.) / len(progress)) treeiter = self.store.get_iter(Gtk.TreePath(i)) self.store[treeiter][4] = "%s / %s" % (solved, len(progress)) self.store[treeiter][5] = percent lessons_solving_progress.connect("progress_updated", on_progress_updated) self.store = Gtk.ListStore(int, str, str, str, str, int) for num, file_name, title, author, count in LESSONS: progress = lessons_solving_progress.get(file_name, [0] * count) solved = progress.count(1) progress = 0 if not solved else round((solved * 100.) / len(progress)) self.store.append([num, file_name, title, author, "%s / %s" % (solved, count), progress]) self.tv.set_model(self.store) self.tv.get_selection().set_mode(Gtk.SelectionMode.BROWSE) self.tv.set_cursor(0) scrollwin = Gtk.ScrolledWindow() scrollwin.add(self.tv) scrollwin.show_all() self.box.pack_start(scrollwin, True, True, 0) self.box.show_all() return self.box