def load_game(self, b): dialog = Gtk.FileChooserDialog("Load..", None, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) dialog.set_default_response(Gtk.ResponseType.OK) dialog.set_current_folder(os.path.expanduser("~")) filter = Gtk.FileFilter() filter.set_name("pdn files") filter.add_pattern("*.pdn") dialog.add_filter(filter) filter = Gtk.FileFilter() filter.set_name("All files") filter.add_pattern("*") dialog.add_filter(filter) response = dialog.run() if response == Gtk.ResponseType.OK: self.board.board_position = engine.loadgame(dialog.get_filename()) self.board.display_board() self.set_panel_msg() dialog.destroy()
def load_game_gshog(self, fname): rc = engine.loadgame(fname) if (rc > 0): gv.gui.set_status_bar_msg( "Error 1 loading game - not a valid gshog file") return self.comments.clear_comments() # get movelist f = open(fname) startmoves = False movelist = [] redolist = [] startpos = "startpos" while 1: line = f.readline() if not line: break if line.startswith("startpos"): startpos = line[9:].strip() if gv.verbose: print "startpos set to", startpos continue if startmoves: l = line.strip() sl = l.split() m = sl[0] if m.startswith("+"): m = m[1:] if m.find("*") != -1: move = m else: move = m[1:] movelist.append(move) if line.startswith(" move score depth"): startmoves = True f.close() gv.usib.set_newgame() gv.usiw.set_newgame() gv.gui.set_status_bar_msg("game loaded") self.gameover = False gv.gshogi.set_movelist(movelist) gv.gshogi.set_redolist(redolist) gv.gshogi.set_startpos(startpos) gv.board.update() # update move list in move list window self.move_list.update() stm = gv.gshogi.get_side_to_move() gv.gshogi.set_side_to_move(stm) gv.gui.set_side_to_move(stm) gv.gui.unhilite_squares() utils.get_gamelist_ref().set_game_list([]) gv.tc.reset_clock()