def leePGNRecno(self, recno): raw = self.leeAllRecno(recno) xpgn = raw["PGN"] result = raw["RESULT"] rtags = None if xpgn: xpgn = Util.blob2var(xpgn) if type(xpgn) in (str, unicode): return xpgn, result if "RTAGS" in xpgn: rtags = xpgn["RTAGS"] else: p = Partida.PartidaCompleta() p.restore(xpgn["FULLGAME"]) return p.pgn(), result pgn = xpv2pgn(raw["XPV"]) drots["PLIES"] = "PlyCount" litags = [] for field in self.liCamposBase: v = raw[field] if v: litags.append('[%s "%s"]' % (drots.get(field, field), str(v))) if rtags: for k, v in rtags: litags.append('[%s "%s"]' % (k, v)) tags = "\n".join(litags) return "%s\n\n%s\n" % (tags, pgn), result
def reiniciar(self): if self.siCambios and not QTUtil2.pregunta( self.pantalla, _("You will loose all changes, are you sure?")): return p = Partida.PartidaCompleta() p.restore(self.reinicio) self.inicio(p, self.siCompleta)
def leePartidaRecno(self, recno): raw = self.leeAllRecno(recno) p = Partida.PartidaCompleta(fen=raw["FEN"]) xpgn = raw["PGN"] rtags = None if xpgn: xpgn = Util.blob2var(xpgn) if type(xpgn) == str: # Version -9 p.readPGN(VarGen.configuracion, xpgn) return p p.restore(xpgn["FULLGAME"]) return p p.leerPV(xpv2pv(raw["XPV"])) rots = [ "Event", "Site", "Date", "Round", "White", "Black", "Result", "WhiteTitle", "BlackTitle", "WhiteElo", "BlackElo", "WhiteUSCF", "BlackUSCF", "WhiteNA", "BlackNA", "WhiteType", "BlackType", "EventDate", "EventSponsor", "ECO", "UTCTime", "UTCDate", "TimeControl", "SetUp", "FEN", "PlyCount" ] drots = {x.upper(): x for x in rots} drots["PLIES"] = "PlyCount" litags = [] for field in self.liCamposBase: v = raw[field] if v: litags.append((drots.get(field, field), str(v))) if rtags: litags.extend(rtags) p.setTags(litags) return p
def miniatura(self): self.pensando(True) fichero = "./IntFiles/miniaturas.gm" tam = Util.tamFichero(fichero) pos = random.randint(0, tam - 600) with open(fichero) as fm: fm.seek(pos) fm.readline() linea = fm.readline() lig = linea.split("|") liTags = [] pv = lig[-1] for n in range(len(lig) - 1): if "·" in lig[n]: k, v = lig[n].split("·") liTags.append((k, v)) p = Partida.PartidaCompleta(liTags=liTags) p.leerPV(pv) txt = p.pgn() pgn = PGN.UnPGN() pgn.leeTexto(txt) self.pensando(False) if pgn.siError: return self.pgnPaste = txt self.mostrar(pgn, False)
def updateStatus(self): if self.terminado: return if not self.summaryActivo: txt = "" else: partida = self.summaryActivo.get("partida", Partida.PartidaCompleta()) nj = partida.numJugadas() if nj > 1: p = partida.copia(nj - 2) txt = "%s | " % p.pgnBaseRAW() else: txt = "" siPte = self.dbGames.siFaltanRegistrosPorLeer() if not siPte: recs = self.dbGames.reccount() if recs: txt += "%s: %d" % (_("Games"), recs) if self.where: txt += " | %s: %s" % (_("Filter"), self.where) if siPte: QtCore.QTimer.singleShot(1000, self.updateStatus) self.status.showMessage(txt, 0)
def leePartidaRaw(self, raw): p = Partida.PartidaCompleta() xpgn = raw["PGN"] rtags = None if xpgn: xpgn = Util.blob2var(xpgn) if type(xpgn) in (str, unicode): # Version -9 p.readPGN(xpgn) return p if "RTAGS" in xpgn: rtags = xpgn["RTAGS"] else: p.restore(xpgn["FULLGAME"]) return p p.leerPV(xpv2pv(raw["XPV"])) rots = ["Event", "Site", "Date", "Round", "White", "Black", "Result", "WhiteTitle", "BlackTitle", "WhiteElo", "BlackElo", "WhiteUSCF", "BlackUSCF", "WhiteNA", "BlackNA", "WhiteType", "BlackType", "EventDate", "EventSponsor", "ECO", "UTCTime", "UTCDate", "TimeControl", "SetUp", "FEN", "PlyCount"] drots = {x.upper():x for x in rots} drots["PLIES"] = "PlyCount" litags = [] for field in self.liCamposBase: v = raw[field] if v: litags.append((drots.get(field, field), v if type(v) == unicode else str(v))) if rtags: litags.extend(rtags) p.setTags(litags) p.asignaApertura() return p
def leePGNRecno(self, recno): raw = self.leeAllRecno(recno) xpgn = raw["PGN"] result = raw["RESULT"] rtags = None if xpgn: xpgn = Util.blob2var(xpgn) if type(xpgn) in (str, unicode): return xpgn, result if "RTAGS" in xpgn: rtags = xpgn["RTAGS"] else: p = Partida.PartidaCompleta() p.restore(xpgn["FULLGAME"]) return p.pgn(), result pgn = xpv2pgn(raw["XPV"]) litags = [] st = set() for field in self.liCamposBase: v = raw[field] if v: if field not in st: litags.append('[%s "%s"]' % (drots.get( field, field), Util.primeraMayuscula(str(v)))) st.add(field) if rtags: for k, v in rtags: k = drots.get(k, Util.primeraMayuscula(k)) if k not in st: litags.append('[%s "%s"]' % (k, v)) st.add(k) tags = "\n".join(litags) return "%s\n\n%s\n" % (tags, pgn), result
def tw_nuevo(self): fen = Voyager.voyagerFEN(self, "", False) if fen is not None: if self.dbGamesFEN.si_existe_fen(fen): QTUtil2.mensError(self, _("This position already exists.")) return hoy = Util.hoy() liTags=[['Date', "%d.%02d.%02d" % (hoy.year, hoy.month, hoy.day)],['FEN', fen]] pc = Partida.PartidaCompleta(fen=fen, liTags=liTags) self.editar(None, pc)
def get_partida_random(): path = "./IntFiles/Everest" li = [fich for fich in os.listdir(path) if fich.endswith(".str")] fichero = random.choice(li) litourneys = str_file(os.path.join(path, fichero)) dictourney = random.choice(litourneys) games = dictourney["GAMES"] game = random.choice(games) labels = game["LABELS"] xpv = game["XPV"] pc = Partida.PartidaCompleta(liTags=labels) pv = LCEngine.xpv2pv(xpv) pc.leerPV(pv) return pc
def partidaCompleta(self): txt = self.pgnPaste.strip() liTags = [] for linea in txt.split("\n"): if linea.startswith("["): ti = linea.split('"') if len(ti) == 3: clave = ti[0][1:].strip() valor = ti[1].strip() liTags.append([clave, valor]) else: break pc = Partida.PartidaCompleta(liTags=liTags) pc.leeOtra(self.partida) return pc
def insert_pks(self, path_pks): f = open(path_pks, "rb") txt = f.read() f.close() dic = Util.txt2dic(txt) fen = dic.get("FEN") if fen: return _("This pks file is not a complete game") liTags = dic.get("liPGN", []) partidaCompleta = Partida.PartidaCompleta(liTags=liTags) partidaCompleta.recuperaDeTexto(dic["PARTIDA"]) if not self.inserta(partidaCompleta): return _("This game already exists.") return None
def genPGN(self, cursor): dicCampoPos = { campo: pos for pos, campo in enumerate(self.liCamposAll) } posPGN = dicCampoPos["PGN"] posRESULT = dicCampoPos["RESULT"] posXPV = dicCampoPos["XPV"] while True: raw = cursor.fetchone() if not raw: break xpgn = raw[posPGN] rtags = None result = raw[posRESULT] if xpgn: xpgn = Util.blob2var(xpgn) if type(xpgn) in (str, unicode): yield xpgn, result if "RTAGS" in xpgn: rtags = xpgn["RTAGS"] else: p = Partida.PartidaCompleta() p.restore(xpgn["FULLGAME"]) yield p.pgn(), result pgn = xpv2pgn(raw[posXPV]) drots["PLIES"] = "PlyCount" litags = [] for field in self.liCamposBase: v = raw[dicCampoPos[field]] if v: litags.append('[%s "%s"]' % (drots.get(field, field), str(v))) if rtags: for k, v in rtags: litags.append('[%s "%s"]' % (k, v)) tags = "\n".join(litags) tags += "\n\n" pgn = "%s\n\n%s" % (tags, pgn) yield pgn, result
def tw_nuevo(self): # Se genera un PGN fen = Voyager.voyagerFEN(self, "", False) if fen is not None: if self.dbGamesFEN.si_existe_fen(fen): QTUtil2.mensError(self, _("This position already exists.")) return hoy = Util.hoy() pgn = '[Date "%d.%02d.%02d"]\n[FEN "%s"]' % (hoy.year, hoy.month, hoy.day, fen) nuevoPGN, pv, dicPGN = self.procesador.gestorUnPGN(self, pgn) if dicPGN: liTags = [(clave, valor) for clave, valor in dicPGN.iteritems()] partida_completa = Partida.PartidaCompleta(fen=fen, liTags=liTags) if pv: partida_completa.leerPV(pv) if self.dbGamesFEN.inserta(partida_completa): self.actualiza() self.grid.refresh() self.grid.gobottom()
def crea_partida(self): li_tags = [] number = self.sb_number.valor() for key, value in self.li_labels: if key and value: if "#" in value: n = value.count("#") if n > 1: t = "#"*n if t in value: value = value.replace(t, "%0" + "%d"%n + "d") value = value % number else: value = value.replace("#", str(number), 1) else: value = value.replace("#", str(number)) li_tags.append((key, value)) li_tags.append(("FEN", self.posicion.fen())) li = ['[%s "%s"]\n'%(k,v) for k,v in li_tags] txt = "".join(li) pc = Partida.PartidaCompleta(self.posicion) txt += "\n%s" % self.em_solucion.texto() pc.readPGN(txt) return pc
def other_pc(): for engine in self.washing.liEngines: if engine.state == Washing.ENDED: game = self.dbwashing.restoreGame(engine) pc = Partida.PartidaCompleta() pc.leeOtra(game) dt = engine.date if engine.date else Util.hoy() if engine.color: white = self.configuracion.jugador black = engine.nombre result = "1-0" whiteelo = str(self.configuracion.elo) blackelo = engine.elo else: black = self.configuracion.jugador white = engine.nombre result = "0-1" blackelo = str(self.configuracion.elo) whiteelo = engine.elo tags = [ ["Site", "Lucas Chess"], ["Event", _("The Washing Machine")], ["Date", "%d-%d-%d" % (dt.year, dt.month, dt.day)], ["White", white], ["Black", black], ["WhiteElo", whiteelo], ["BlackElo", blackelo], ["Result", result], ] ap = game.apertura if ap: tags.append(["ECO", ap.eco]) tags.append(["Opening", ap.trNombre]) pc.setTags(tags) yield pc
def file(self): menu = QTVarios.LCMenu(self) menu.opcion("saveas", _("Save a copy"), Iconos.GrabarComo()) menu.separador() menu.opcion("restorefrom", _("Restore from"), Iconos.Recuperar()) menu.separador() submenu = menu.submenu(_("Create new"), Iconos.Nuevo()) submenu.opcion("new_UNED", _("UNED chess school"), Iconos.Uned()) submenu.separador() submenu.opcion("new_UWE", _("Uwe Auerswald"), Iconos.Uwe()) menu.separador() menu.opcion("savedb", _("Save as database"), Iconos.DatabaseC()) resp = menu.lanza() if resp is None: return if resp == "saveas": liGen = [(None, None)] config = FormLayout.Editbox(_("Name"), ancho=160) liGen.append((config, "")) resultado = FormLayout.fedit(liGen, title=_("Name"), parent=self, icon=Iconos.GrabarComo()) if resultado: accion, liResp = resultado fich = nombre = liResp[0] if nombre.lower()[-4:] != ".wsm": fich += ".wsm" path = os.path.join(self.configuracion.carpeta, fich) ok = True if Util.existeFichero(path): ok = QTUtil2.pregunta( self, _X( _("The file %1 already exists, what do you want to do?" ), fich), etiSi=_("Overwrite"), etiNo=_("Cancel")) if ok: shutil.copy(self.dbwashing.file, path) elif resp == "restorefrom": li = [] for fich in os.listdir(self.configuracion.carpeta): if fich.endswith(".wsm") and fich != self.dbwashing.filename: li.append(fich[:-4]) if not li: QTUtil2.mensaje(self, _("There is no file")) return menu = QTVarios.LCMenu(self) for fich in li: menu.opcion(fich, fich, Iconos.PuntoRojo()) resp = menu.lanza() if resp: if QTUtil2.pregunta( self, "%s\n%s" % (_("Current data will be removed and overwritten."), _("Are you sure?"))): shutil.copy( os.path.join(self.configuracion.carpeta, resp + ".wsm"), self.dbwashing.file) self.wreload = True self.guardarVideo() self.accept() elif resp.startswith("new_"): tactic = resp[4:] if QTUtil2.pregunta( self, "%s\n%s" % (_("Current data will be removed and overwritten."), _("Are you sure?"))): self.dbwashing.new(tactic) self.wreload = True self.guardarVideo() self.accept() elif resp == "savedb": ext = "lcg" path = QTUtil2.salvaFichero(self, _("Database of complete games"), self.configuracion.ficheroDBgames, _("File") + " %s (*.%s)" % (ext, ext), False) if path: if not path.lower().endswith(".lcg"): path += ".lcg" me = QTUtil2.mensEspera.inicio(self, _("Saving...")) dbn = DBgames.DBgames(path) for engine in self.washing.liEngines: if engine.state == Washing.ENDED: game = self.dbwashing.restoreGame(engine) pc = Partida.PartidaCompleta() pc.leeOtra(game) dt = engine.date if engine.color: white = self.configuracion.jugador black = engine.nombre result = "1-0" whiteelo = str(self.configuracion.elo) blackelo = engine.elo else: black = self.configuracion.jugador white = engine.nombre result = "0-1" blackelo = str(self.configuracion.elo) whiteelo = engine.elo tags = [ ["Site", "Lucas Chess"], ["Event", _("The Washing Machine")], ["Date", "%d-%d-%d" % (dt.year, dt.month, dt.day)], ["White", white], ["Black", black], ["WhiteElo", whiteelo], ["BlackElo", blackelo], ["Result", result], ] ap = game.apertura if ap: tags.append(["ECO", ap.eco]) tags.append(["Opening", ap.trNombre]) pc.setTags(tags) dbn.inserta(pc) me.final()
def configurarGS(self): sep = (None, None, None) liMasOpciones = [ ("rotacion", _("Auto-rotate board"), Iconos.JS_Rotacion()), sep, ("leerpgn", _("Read PGN"), Iconos.PGN_Importar()), sep, ("pastepgn", _("Paste PGN"), Iconos.Pegar16()), sep, ] if not self.siCompleta: liMasOpciones.extend([ ("posicion", _("Start position"), Iconos.Datos()), sep, ("pasteposicion", _("Paste FEN position"), Iconos.Pegar16()), sep, ("voyager", _("Voyager 2"), Iconos.Voyager1()) ]) resp = self.configurar(liMasOpciones, siCambioTutor=True, siSonidos=True) if resp == "rotacion": self.siVolteoAutomatico = not self.siVolteoAutomatico siBlancas = self.partida.ultPosicion.siBlancas if self.siVolteoAutomatico: if siBlancas != self.tablero.siBlancasAbajo: self.tablero.rotaTablero() elif resp == "posicion": ini_fen = self.partida.iniPosicion.fen() cur_fen = Voyager.voyagerFEN(self.pantalla, ini_fen) if cur_fen and cur_fen != ini_fen: self.partida.resetFEN(cur_fen) self.inicio(self.partida, self.siCompleta) elif resp == "pasteposicion": texto = QTUtil.traePortapapeles() if texto: cp = ControlPosicion.ControlPosicion() try: cp.leeFen(str(texto)) self.fen = cp.fen() self.posicApertura = None self.reiniciar() except: pass elif resp == "leerpgn": unpgn = PantallaPGN.eligePartida(self.pantalla) if unpgn: partida = unpgn.partida if self.siCompleta and not partida.siFenInicial(): return p = Partida.PartidaCompleta() p.leeOtra(partida) p.asignaApertura() p.setTags(unpgn.listaCabeceras()) self.reinicio = p.save() self.reiniciar() elif resp == "pastepgn": texto = QTUtil.traePortapapeles() if texto: unpgn = PGN.UnPGN() unpgn.leeTexto(texto) if unpgn.siError: QTUtil2.mensError( self.pantalla, _("The text from the clipboard does not contain a chess game in PGN format" )) return partida = unpgn.partida if self.siCompleta and not partida.siFenInicial(): return p = Partida.PartidaCompleta() p.leeOtra(partida) p.asignaApertura() p.setTags(unpgn.listaCabeceras()) self.reinicio = p.save() self.reiniciar() elif resp == "voyager": ptxt = Voyager.voyagerPartida(self.pantalla, self.partida) if ptxt: dic = self.creaDic() dic["PARTIDA"] = ptxt p = self.partida.copia() p.recuperaDeTexto(ptxt) dic["FEN"] = None if p.siFenInicial() else p.iniPosicion.fen() dic["SIBLANCASABAJO"] = self.tablero.siBlancasAbajo self.reiniciar(dic)
def blankPartida(self): hoy = Util.hoy() liTags = [ ["Date", "%d.%02d.%02d" % (hoy.year, hoy.month, hoy.day)], ] return Partida.PartidaCompleta(liTags=liTags)
def configurarGS(self): sep = (None, None, None) liMasOpciones = [ ("rotacion", _("Auto-rotate board"), Iconos.JS_Rotacion()), sep, ("leerpgn", _("Read PGN"), Iconos.PGN_Importar()), sep, ("pastepgn", _("Paste PGN"), Iconos.Pegar16()), sep, ] if not self.siCompleta: liMasOpciones.extend([ ("posicion", _("Start position"), Iconos.Datos()), sep, ("pasteposicion", _("Paste FEN position"), Iconos.Pegar16()), sep, ("voyager", _("Voyager 2"), Iconos.Voyager1()) ]) resp = self.configurar(liMasOpciones, siCambioTutor=True, siSonidos=True) if resp == "rotacion": self.siVolteoAutomatico = not self.siVolteoAutomatico siBlancas = self.partida.ultPosicion.siBlancas if self.siVolteoAutomatico: if siBlancas != self.tablero.siBlancasAbajo: self.tablero.rotaTablero() elif resp == "posicion": resp = Voyager.voyagerFEN(self.pantalla, self.fen) if resp is not None: self.fen = resp self.posicApertura = None if self.xpgn: siInicio = self.fen == ControlPosicion.FEN_INICIAL li = self.xpgn.split("\n") lin = [] siFen = False for linea in li: if linea.startswith("["): if "FEN " in linea: siFen = True if siInicio: continue linea = '[FEN "%s"]' % self.fen lin.append(linea) else: break if not siFen: linea = '[FEN "%s"]' % self.fen lin.append(linea) self.liPGN = lin self.xpgn = "\n".join(lin) + "\n\n*" self.reiniciar() elif resp == "pasteposicion": texto = QTUtil.traePortapapeles() if texto: cp = ControlPosicion.ControlPosicion() try: cp.leeFen(str(texto)) self.fen = cp.fen() self.posicApertura = None self.reiniciar() except: pass elif resp == "leerpgn": unpgn = PantallaPGN.eligePartida(self.pantalla) if unpgn: partida = unpgn.partida if self.siCompleta and not partida.siFenInicial(): return p = Partida.PartidaCompleta() p.leeOtra(partida) if self.siCompleta: p.asignaApertura(self.configuracion) p.setTags(unpgn.listaCabeceras()) self.reinicio = p.save() self.reiniciar() elif resp == "pastepgn": texto = QTUtil.traePortapapeles() if texto: unpgn = PGN.UnPGN() unpgn.leeTexto(texto) if unpgn.siError: QTUtil2.mensError( self.pantalla, _("The text from the clipboard does not contain a chess game in PGN format" )) return partida = unpgn.partida if self.siCompleta and not partida.siFenInicial(): return p = Partida.PartidaCompleta() p.leeOtra(partida) if self.siCompleta: p.asignaApertura(self.configuracion) p.setTags(unpgn.listaCabeceras()) self.reinicio = p.save() self.reiniciar() elif resp == "voyager": ptxt = Voyager.voyagerPartida(self.pantalla, self.partida) if ptxt: dic = self.creaDic() dic["PARTIDA"] = ptxt p = self.partida.copia() p.recuperaDeTexto(ptxt) dic["FEN"] = None if p.siFenInicial() else p.iniPosicion.fen() dic["SIBLANCASABAJO"] = self.tablero.siBlancasAbajo self.reiniciar(dic)