def start_lesson_from(filename, index=None): chessfile = PGNFile(protoopen(addDataPrefix("learn/lessons/%s" % filename))) chessfile.limit = 1000 chessfile.init_tag_database() records, plys = chessfile.get_records() progress = lessons_solving_progress.get(filename, [0] * chessfile.count) if index is None: index = progress.index(0) rec = records[index] timemodel = TimeModel(0, 0) gamemodel = LearnModel(timemodel) chessfile.loadToModel(rec, -1, gamemodel) if len(gamemodel.moves) > 0: start_lesson_game(gamemodel, filename, chessfile, records, index, rec) else: start_puzzle_game(gamemodel, filename, records, index, rec, from_lesson=True)
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 coro(): 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 ])
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
def start_lesson_from(filename, index=None): if filename.startswith("lichess_study"): chessfile = PGNFile( protoopen(addDataPrefix("learn/lessons/%s" % filename), encoding="utf-8")) else: chessfile = PGNFile( protoopen(addDataPrefix("learn/lessons/%s" % filename))) chessfile.limit = 1000 chessfile.init_tag_database() records, plys = chessfile.get_records() progress = lessons_solving_progress.get(filename, [0] * chessfile.count) if index is None: index = progress.index(0) rec = records[index] timemodel = TimeModel(0, 0) gamemodel = LearnModel(timemodel) gamemodel.set_learn_data(LESSON, filename, index, len(records)) chessfile.loadToModel(rec, -1, gamemodel) color = gamemodel.boards[0].color player_name = conf.get("firstName", _("You")) w_name = player_name if color == WHITE else "PyChess" b_name = "PyChess" if color == WHITE else player_name p0 = (LOCAL, Human, (WHITE, w_name), w_name) p1 = (LOCAL, Human, (BLACK, b_name), b_name) def learn_success(gamemodel): chessfile.loadToModel(rec, -1, gamemodel) progress = lessons_solving_progress[gamemodel.source] progress[gamemodel.current_index] = 1 lessons_solving_progress[gamemodel.source] = progress asyncio. async (gamemodel.restart_analyzer(HINT)) gamemodel.connect("learn_success", learn_success) def on_game_started(gamemodel): perspective.activate_panel("annotationPanel") asyncio. async (gamemodel.start_analyzer( HINT, force_engine=discoverer.getEngineLearn())) gamemodel.connect("game_started", on_game_started) gamemodel.status = WAITING_TO_START perspective = perspective_manager.get_perspective("games") asyncio. async (perspective.generalStart(gamemodel, p0, p1))
def start_lesson_from(filename, index=None): chessfile = PGNFile(protoopen(addDataPrefix("learn/lessons/%s" % filename))) chessfile.limit = 1000 chessfile.init_tag_database() records, plys = chessfile.get_records() progress = lessons_solving_progress.get(filename, [0] * chessfile.count) if index is None: index = progress.index(0) rec = records[index] timemodel = TimeModel(0, 0) gamemodel = LearnModel(timemodel) gamemodel.set_learn_data(LESSON, filename, index, len(records)) chessfile.loadToModel(rec, -1, gamemodel) color = gamemodel.boards[0].color player_name = conf.get("firstName", _("You")) w_name = player_name if color == WHITE else "PyChess" b_name = "PyChess" if color == WHITE else player_name p0 = (LOCAL, Human, (WHITE, w_name), w_name) p1 = (LOCAL, Human, (BLACK, b_name), b_name) def learn_success(gamemodel): progress = lessons_solving_progress[gamemodel.source] progress[gamemodel.current_index] = 1 lessons_solving_progress[gamemodel.source] = progress asyncio.async(gamemodel.restart_analyzer(HINT)) gamemodel.connect("learn_success", learn_success) def start_analyzer(gamemodel): asyncio.async(gamemodel.start_analyzer(HINT, force_engine=discoverer.getEngineLearn())) gamemodel.connect("game_started", start_analyzer) gamemodel.status = WAITING_TO_START perspective = perspective_manager.get_perspective("games") asyncio.async(perspective.generalStart(gamemodel, p0, p1))
def start_lesson_from(filename, index=None): chessfile = PGNFile(protoopen(addDataPrefix("learn/lessons/%s" % filename))) chessfile.limit = 1000 chessfile.init_tag_database() records, plys = chessfile.get_records() progress = lessons_solving_progress.get(filename, [0] * chessfile.count) if index is None: index = progress.index(0) rec = records[index] timemodel = TimeModel(0, 0) gamemodel = LearnModel(timemodel) chessfile.loadToModel(rec, -1, gamemodel) if len(gamemodel.moves) > 0: start_lesson_game(gamemodel, filename, chessfile, records, index, rec) else: start_puzzle_game(gamemodel, filename, records, index, rec, from_lesson=True)
def coro(): 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])