示例#1
0
 def pgn_paste(self):
     path = self.configuracion.ficheroTemporal("lcdb")
     texto = QTUtil.traePortapapeles()
     if texto:
         with open(path, "wb") as q:
             q.write(texto)
         self.read_pgn(path)
示例#2
0
 def control_teclado(self, nkey):
     if nkey == ord("V"):
         self.paste(QTUtil.traePortapapeles())
     elif nkey == ord("T"):
         li = [self.game.first_position.fen(), "", self.game.pgnBaseRAW()]
         self.saveSelectedPosition("|".join(li))
     elif nkey == ord("S"):
         self.startPosition()
示例#3
0
 def paste_pgn(self):
     texto = QTUtil.traePortapapeles()
     if texto:
         ok, game = Game.pgn_game(texto)
         if not ok:
             QTUtil2.message_error(self.main_window, _("The text from the clipboard does not contain a chess game in PGN format"))
             return
         self.replace_game(game)
示例#4
0
 def controlTeclado(self, nkey):
     if nkey == Qt.Key_V:
         self.paste(QTUtil.traePortapapeles())
     elif nkey == Qt.Key_T:
         li = [self.fen if self.fen else ControlPosicion.FEN_INICIAL,"",self.partida.pgnBaseRAW()]
         self.saveSelectedPosition("|".join(li))
     elif nkey == Qt.Key_S:
         self.startPosition()
 def pgn_paste(self):
     path = self.configuration.ficheroTemporal("pgn")
     texto = QTUtil.traePortapapeles()
     if texto:
         texto = texto.strip()
         if not texto.startswith("["):
             texto = '[Event "%s"]\n\n %s' % (_("Paste PGN"), texto)
         with open(path, "wt") as q:
             q.write(texto)
         self.read_pgn(path)
示例#6
0
 def posicionPegar(self):
     texto = QTUtil.traePortapapeles()
     if texto:
         cp = ControlPosicion.ControlPosicion()
         try:
             cp.leeFen(texto.strip())
             self.fen = cp.fen()
             if self.fen == ControlPosicion.FEN_INICIAL:
                 self.fen = ""
             self.muestraPosicion()
         except:
             pass
示例#7
0
 def posicionPegar(self):
     texto = QTUtil.traePortapapeles()
     if texto:
         cp = ControlPosicion.ControlPosicion()
         try:
             cp.leeFen(texto.strip())
             self.fen = cp.fen()
             if self.fen == ControlPosicion.FEN_INICIAL:
                 self.fen = ""
             self.muestraPosicion()
         except:
             pass
示例#8
0
 def posicionPegar(self):
     texto = QTUtil.traePortapapeles()
     if texto:
         cp = Position.Position()
         try:
             cp.read_fen(texto.strip())
             self.fen = cp.fen()
             if self.fen == FEN_INITIAL:
                 self.fen = ""
             self.muestraPosicion()
         except:
             pass
示例#9
0
 def paste(self):
     texto = QTUtil.traePortapapeles()
     if texto:
         pgn = PGN.UnPGN()
         try:
             pgn.leeTexto(str(texto))
         except:
             pgn.siError = True
         if pgn.siError:
             QTUtil2.mensError(self.pantalla,
                               _("The text from the clipboard does not contain a chess game in PGN format"))
             self.finPartida()
             return
         self.pgnPaste = texto
         self.mostrar(pgn, False)
示例#10
0
 def paste(self):
     texto = QTUtil.traePortapapeles()
     if texto:
         pgn = PGN.UnPGN()
         try:
             pgn.leeTexto(str(texto))
         except:
             pgn.siError = True
         if pgn.siError:
             QTUtil2.mensError(
                 self.pantalla,
                 _("The text from the clipboard does not contain a chess game in PGN format"
                   ))
             self.finPartida()
             return
         self.pgnPaste = texto
         self.mostrar(pgn, False)
示例#11
0
 def controlTeclado(self, nkey):
     if nkey == Qt.Key_V:  # V
         self.paste(QTUtil.traePortapapeles())
示例#12
0
    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)
示例#13
0
 def controlTeclado(self, nkey):
     if nkey in (86, 80):  # V,P
         self.paste(QTUtil.traePortapapeles())
示例#14
0
    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.is_complete:
            liMasOpciones.extend([
                ("position", _("Edit start position"), Iconos.Datos()),
                sep,
                ("pasteposicion", _("Paste FEN position"), Iconos.Pegar16()),
                sep,
                ("voyager", _("Voyager 2"), Iconos.Voyager()),
            ])

        resp = self.configurar(liMasOpciones,
                               siCambioTutor=True,
                               siSonidos=True)

        if resp == "rotacion":
            self.auto_rotate = not self.auto_rotate
            is_white = self.game.last_position.is_white
            if self.auto_rotate:
                if is_white != self.board.is_white_bottom:
                    self.board.rotaBoard()

        elif resp == "position":
            ini_position = self.game.first_position
            new_position = Voyager.voyager_position(self.main_window,
                                                    ini_position)
            if new_position and new_position != ini_position:
                self.game.set_position(new_position)
                self.start(self.game, self.is_complete, self.only_consult,
                           self.with_previous_next, self.save_routine)
                self.changed = True
                self.put_toolbar()

        elif resp == "pasteposicion":
            texto = QTUtil.traePortapapeles()
            if texto:
                new_position = Position.Position()
                try:
                    new_position.read_fen(str(texto))
                    ini_position = self.game.first_position
                    if new_position and new_position != ini_position:
                        self.game.set_position(new_position)
                        self.start(self.game, self.is_complete,
                                   self.only_consult, self.with_previous_next,
                                   self.save_routine)
                        self.changed = True
                        self.put_toolbar()

                except:
                    pass

        elif resp == "leerpgn":
            game = self.procesador.select_1_pgn(self.main_window)
            self.replace_game(game)

        elif resp == "pastepgn":
            self.paste_pgn()

        elif resp == "voyager":
            game = Voyager.voyagerPartida(self.main_window, self.game)
            self.replace_game(game)
示例#15
0
 def control_teclado(self, nkey):
     if nkey == ord("V"):  # V
         self.paste(QTUtil.traePortapapeles())
示例#16
0
    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([
                ("position", _("Edit 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.auto_rotate = not self.auto_rotate
            is_white = self.game.last_position.is_white
            if self.auto_rotate:
                if is_white != self.tablero.is_white_bottom:
                    self.tablero.rotaTablero()

        elif resp == "position":
            ini_position = self.game.first_position
            new_position = Voyager.voyager_position(self.main_window,
                                                    ini_position)
            if new_position and new_position != ini_position:
                self.game.set_position(new_position)
                self.inicio(self.game, self.siCompleta)

        elif resp == "pasteposicion":
            texto = QTUtil.traePortapapeles()
            if texto:
                cp = Position.Position()
                try:
                    cp.read_fen(str(texto))
                    self.fen = cp.fen()
                    self.posicApertura = None
                    self.reiniciar()
                except:
                    pass

        elif resp == "leerpgn":
            game = self.procesador.select_1_pgn(self.main_window)
            if game:
                if self.siCompleta and not game.siFenInicial():
                    return
                p = Game.Game()
                p.leeOtra(game)
                p.assign_opening()
                self.reinicio = p.save()
                self.reiniciar()

        elif resp == "pastepgn":
            texto = QTUtil.traePortapapeles()
            if texto:
                ok, game = Game.pgn_game(texto)
                if not ok:
                    QTUtil2.message_error(
                        self.main_window,
                        _("The text from the clipboard does not contain a chess game in PGN format"
                          ))
                    return
                if self.siCompleta and not game.siFenInicial():
                    return
                self.reinicio = game.save()
                self.reiniciar()

        elif resp == "voyager":
            ptxt = Voyager.voyagerPartida(self.main_window, self.game)
            if ptxt:
                dic = self.creaDic()
                dic["GAME"] = ptxt.save()
                dic["FEN"] = None if ptxt.siFenInicial(
                ) else ptxt.first_position.fen()
                dic["WHITEBOTTOM"] = self.tablero.is_white_bottom
                self.reiniciar(dic)
示例#17
0
    def configurarGS(self):
        sep = (None, None, None)

        liMasOpciones = [
            ("rotacion", _("Auto-rotate board"), Iconos.JS_Rotacion()), sep,
            ("apertura", _("Opening"), Iconos.Apertura()), sep,
            ("posicion", _("Start position"), Iconos.Datos()), sep,
            ("pasteposicion", _("Paste FEN position"), Iconos.Pegar16()), sep,
            ("leerpgn", _("Read PGN"), Iconos.PGN_Importar()), sep,
            ("pastepgn", _("Paste PGN"), 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 == "apertura":
            bl, ps = PantallaAperturas.dameApertura(self.pantalla, self.configuracion, self.bloqueApertura,
                                                    self.posicApertura)
            if bl:
                self.bloqueApertura = bl
                self.posicApertura = ps
                self.fen = None
                self.reiniciar()

        elif resp == "posicion":
            resp = XVoyager.xVoyagerFEN(self.pantalla, self.configuracion, self.fen)
            if resp is not None:
                self.fen = resp
                self.bloqueApertura = None
                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.bloqueApertura = None
                    self.posicApertura = None
                    self.reiniciar()
                except:
                    pass

        elif resp == "leerpgn":
            unpgn = PantallaPGN.eligePartida(self.pantalla)
            if unpgn:
                self.bloqueApertura = None
                self.posicApertura = None
                self.fen = unpgn.dic.get("FEN", None)
                dic = self.creaDic()
                dic["PARTIDA"] = unpgn.partida.guardaEnTexto()
                dic["liPGN"] = unpgn.listaCabeceras()
                dic["FEN"] = self.fen
                dic["SIBLANCASABAJO"] = unpgn.partida.ultPosicion.siBlancas
                self.reiniciar(dic)

        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
                self.bloqueApertura = None
                self.posicApertura = None
                self.fen = unpgn.dic.get("FEN", None)
                dic = self.creaDic()
                dic["PARTIDA"] = unpgn.partida.guardaEnTexto()
                dic["liPGN"] = unpgn.listaCabeceras()
                dic["FEN"] = self.fen
                dic["SIBLANCASABAJO"] = unpgn.partida.ultPosicion.siBlancas
                self.reiniciar(dic)

        elif resp == "voyager":
            ptxt = XVoyager.xVoyager(self.pantalla, self.configuracion, partida=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)
示例#18
0
    def execMenuSP(self, tipo, siInsertar):
        if siInsertar:
            fila = self.g_guion.recno()
            filaIni = fila
        else:
            fila = -1
            filaIni = len(self.guion)

        if tipo == "PI":
            fen = self.tablero.fenActual()
            fen = WinPosition.editarPosicion(self, VarGen.configuracion, fen)
            if fen is None:
                return None

            nombre = self.editaNombre(_("Start position"))
            if nombre is None:
                return

            tarea = TabVisual.GT_Posicion()
            if not fen:
                fen = ControlPosicion.FEN_INICIAL
            tarea.fen(fen)
            tarea.nombre(nombre)
            self.guion.nuevaTarea(tarea, fila)
            self.gridPonValor(None, filaIni, None, True)

        elif tipo == "PP":
            texto = QTUtil.traePortapapeles()
            if texto:
                cp = ControlPosicion.ControlPosicion()
                try:
                    nombre = self.editaNombre(_("Start position"))
                    if nombre is None:
                        return
                    cp.leeFen(str(texto))
                    tarea = TabVisual.GT_Posicion()
                    tarea.fen(cp.fen())
                    tarea.nombre(nombre)
                    self.guion.nuevaTarea(tarea, fila)
                    self.gridPonValor(None, filaIni, None, True)
                except:
                    return None
        elif tipo == "PA":
            nombre = self.editaNombre(_("Start position"))
            if nombre is None:
                return
            tarea = TabVisual.GT_Posicion()
            tarea.fen(self.tablero.fenActual())
            tarea.nombre(nombre)
            self.guion.nuevaTarea(tarea, fila)
        else:
            if tipo == "PGNF":
                unpgn = PantallaPGN.eligePartida(self)
                partida = unpgn.partida if unpgn else None
            else:
                pgn = QTUtil.traePortapapeles()
                partida = PantallaTabVPartidas.texto2partida(
                    self, pgn) if pgn else None
            if partida and partida.numJugadas():
                w = PantallaTabVPartidas.W_EligeMovimientos(self, partida)
                if w.exec_():
                    for jg in w.resultado:
                        tarea = TabVisual.GT_Jugada()
                        tarea.jugada(jg)
                        self.guion.nuevaTarea(tarea, fila)
                        if fila != -1:
                            fila += 1
                else:
                    return None
            else:
                return None

        self.g_guion.goto(filaIni, 0)
        self.g_guion.refresh()
示例#19
0
    def utilities_gs(self):
        mt = _("Engine").lower()
        mt = _X(_("Disable %1"), mt) if self.play_against_engine else _X(
            _("Enable %1"), mt)
        sep = (None, None, None)

        liMasOpciones = (
            (None, _("Change the initial position"), Iconos.PGN()),
            sep,
            ("position", _("Edit start position") + " [S]", Iconos.Datos()),
            sep,
            ("initial", _("Basic position") + " [B]", Iconos.Board()),
            sep,
            ("opening", _("Opening"), Iconos.Opening()),
            sep,
            ("pasteposicion", _("Paste FEN position") + " [V]",
             Iconos.Pegar16()),
            sep,
            ("leerpgn", _("Read PGN file"), Iconos.PGN_Importar()),
            sep,
            ("pastepgn", _("Paste PGN") + " [V]", Iconos.Pegar16()),
            sep,
            ("voyager", _("Voyager 2"), Iconos.Voyager()),
            (None, None, True),
            sep,
            ("books", _("Consult a book"), Iconos.Libros()),
            sep,
            ("engine", mt, Iconos.Motores()),
            sep,
        )

        resp = self.utilidades(liMasOpciones)
        if resp == "books":
            liMovs = self.librosConsulta(True)
            if liMovs:
                for x in range(len(liMovs) - 1, -1, -1):
                    from_sq, to_sq, promotion = liMovs[x]
                    self.player_has_moved(from_sq, to_sq, promotion)

        elif resp == "initial":
            self.basic_initial_position()

        elif resp == "opening":
            me = self.unMomento()
            w = WindowOpenings.WOpenings(self.main_window, self.configuration,
                                         self.opening_block)
            me.final()
            if w.exec_():
                self.opening_block = w.resultado()
                self.xfichero = None
                self.xpgn = None
                self.xjugadaInicial = None
                self.reiniciar()

        elif resp == "position":
            self.startPosition()

        elif resp == "pasteposicion":
            texto = QTUtil.traePortapapeles()
            if texto:
                cp = Position.Position()
                try:
                    cp.read_fen(str(texto))
                    self.xfichero = None
                    self.xpgn = None
                    self.xjugadaInicial = None
                    self.new_game()
                    self.game.set_position(first_position=cp)
                    self.opening_block = None
                    self.reiniciar()
                except:
                    pass

        elif resp == "leerpgn":
            self.leerpgn()

        elif resp == "pastepgn":
            texto = QTUtil.traePortapapeles()
            if texto:
                ok, game = Game.pgn_game(texto)
                if not ok:
                    QTUtil2.message_error(
                        self.main_window,
                        _("The text from the clipboard does not contain a chess game in PGN format"
                          ))
                    return
                self.xfichero = None
                self.xpgn = None
                self.xjugadaInicial = None
                self.opening_block = None
                dic = self.creaDic()
                dic["GAME"] = game.save()
                dic["WHITEBOTTOM"] = game.first_position.is_white
                self.reiniciar(dic)

        elif resp == "engine":
            self.set_label1("")
            if self.play_against_engine:
                if self.xrival:
                    self.xrival.terminar()
                    self.xrival = None
                self.play_against_engine = False
            else:
                self.cambioRival()

        elif resp == "voyager":
            ptxt = Voyager.voyagerPartida(self.main_window, self.game)
            if ptxt:
                self.xfichero = None
                self.xpgn = None
                self.xjugadaInicial = None
                dic = self.creaDic()
                dic["GAME"] = ptxt
                dic["WHITEBOTTOM"] = self.board.is_white_bottom
                self.reiniciar(dic)
示例#20
0
    def configurarGS(self):
        # self.test()
        # return

        mt = _("Engine").lower()
        mt = _X(_("Disable %1"), mt) if self.siJuegaMotor else _X(_("Enable %1"), mt)

        sep = ( None, None, None )

        liMasOpciones = [
            ( "rotacion", _("Auto-rotate board"), Iconos.JS_Rotacion() ), sep,
            ( "apertura", _("Opening"), Iconos.Apertura() ), sep,
            ( "posicion", _("Start position"), Iconos.Datos() ), sep,
            ( "pasteposicion", _("Paste FEN position"), Iconos.Pegar16() ), sep,
            ( "leerpgn", _("Read PGN"), Iconos.PGN_Importar() ), sep,
            ( "pastepgn", _("Paste PGN"), Iconos.Pegar16() ), sep,
            ( "motor", mt, Iconos.Motores() ), sep,
            ( "voyager", _("Voyager 2").replace("2", "1"), Iconos.Voyager1() ),
        ]
        if self.configuracion.voice:
            liMasOpciones.append(sep)
            if self.activeVoice:
                liMasOpciones.append(( "desvoice", _("Deactivate voice"), Iconos.X_Microfono() ))
            else:
                liMasOpciones.append(( "actvoice", _("Activate voice"), Iconos.S_Microfono() ))
        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 == "apertura":
            bl, ps = PantallaAperturas.dameApertura(self.pantalla, self.configuracion, self.bloqueApertura,
                                                    self.posicApertura)
            if bl:
                self.bloqueApertura = bl
                self.posicApertura = ps
                self.fen = None
                self.reiniciar()

        elif resp == "posicion":
            resp = WinPosition.editarPosicion(self.pantalla, self.configuracion, self.fen)
            if resp is not None:
                self.fen = resp
                self.bloqueApertura = None
                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.bloqueApertura = None
                    self.posicApertura = None
                    self.reiniciar()
                except:
                    pass

        elif resp == "leerpgn":
            unpgn = PantallaPGN.eligePartida(self.pantalla)
            if unpgn:
                self.bloqueApertura = None
                self.posicApertura = None
                self.fen = unpgn.dic.get("FEN", None)
                dic = self.creaDic()
                dic["PARTIDA"] = unpgn.partida.guardaEnTexto()
                dic["liPGN"] = unpgn.listaCabeceras()
                dic["FEN"] = self.fen
                dic["SIBLANCASABAJO"] = unpgn.partida.ultPosicion.siBlancas
                self.reiniciar(dic)

        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
                self.bloqueApertura = None
                self.posicApertura = None
                self.fen = unpgn.dic.get("FEN", None)
                dic = self.creaDic()
                dic["PARTIDA"] = unpgn.partida.guardaEnTexto()
                dic["liPGN"] = unpgn.listaCabeceras()
                dic["FEN"] = self.fen
                dic["SIBLANCASABAJO"] = unpgn.partida.ultPosicion.siBlancas
                self.reiniciar(dic)

        elif resp == "motor":
            self.ponRotulo1("")
            if self.siJuegaMotor:
                self.xrival.terminar()
                self.xrival = None
                self.siJuegaMotor = False
            else:
                self.cambioRival()

        elif resp == "voyager":
            ptxt = XVoyager.xVoyager(self.pantalla, self.configuracion, 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)

        elif resp == "actvoice":
            self.setVoice( True )

        elif resp == "desvoice":
            self.setVoice( False )
示例#21
0
    def execMenuSP(self, tipo, siInsertar):
        if siInsertar:
            fila = self.g_guion.recno()
            filaIni = fila
        else:
            fila = -1
            filaIni = len(self.guion)

        if tipo == "PI":
            fen = self.tablero.fenActual()
            fen = WinPosition.editarPosicion(self, VarGen.configuracion, fen)
            if fen is None:
                return None

            nombre = self.editaNombre(_("Start position"))
            if nombre is None:
                return

            tarea = TabVisual.GT_Posicion()
            if not fen:
                cp = ControlPosicion.FEN_INICIAL
            tarea.fen(fen)
            tarea.nombre(nombre)
            self.guion.nuevaTarea(tarea, fila)
            self.gridPonValor(None, filaIni, None, True)

        elif tipo == "PP":
            texto = QTUtil.traePortapapeles()
            if texto:
                cp = ControlPosicion.ControlPosicion()
                try:
                    nombre = self.editaNombre(_("Start position"))
                    if nombre is None:
                        return
                    cp.leeFen(str(texto))
                    tarea = TabVisual.GT_Posicion()
                    tarea.fen(cp.fen())
                    tarea.nombre(nombre)
                    self.guion.nuevaTarea(tarea, fila)
                    self.gridPonValor(None, filaIni, None, True)
                except:
                    return None
        elif tipo == "PA":
            nombre = self.editaNombre(_("Start position"))
            if nombre is None:
                return
            tarea = TabVisual.GT_Posicion()
            tarea.fen(self.tablero.fenActual())
            tarea.nombre(nombre)
            self.guion.nuevaTarea(tarea, fila)
        else:
            if tipo == "PGNF":
                unpgn = PantallaPGN.eligePartida(self)
                partida = unpgn.partida if unpgn else None
            else:
                pgn = QTUtil.traePortapapeles()
                partida = PantallaTabVPartidas.texto2partida(self, pgn) if pgn else None
            if partida and partida.numJugadas():
                w = PantallaTabVPartidas.W_EligeMovimientos(self, partida)
                if w.exec_():
                    for jg in w.resultado:
                        tarea = TabVisual.GT_Jugada()
                        tarea.jugada(jg)
                        self.guion.nuevaTarea(tarea, fila)
                        if fila != -1:
                            fila += 1
                else:
                    return None
            else:
                return None

        self.g_guion.goto(filaIni, 0)
        self.g_guion.refresh()
示例#22
0
    def utilities_gs(self):
        sep = (None, None, None)

        li_mas_opciones = [
            (None, _("Change the initial position"), Iconos.PGN()),
            sep,
            ("leerpgn", _("Read PGN file"), Iconos.PGN_Importar()),
            sep,
            ("pastepgn", _("Paste PGN"), Iconos.Pegar16()),
            sep,
        ]
        if not self.is_complete:
            li_mas_opciones.extend([
                ("position", _("Edit start position"), Iconos.Datos()),
                sep,
                ("pasteposicion", _("Paste FEN position"), Iconos.Pegar16()),
                sep,
                ("voyager", _("Voyager 2"), Iconos.Voyager()),
            ])

        li_mas_opciones.extend([(None, None, True), sep,
                                ("books", _("Consult a book"), Iconos.Libros())
                                ])

        resp = self.utilidades(li_mas_opciones)

        if resp == "books":
            liMovs = self.librosConsulta(True)
            if liMovs:
                for x in range(len(liMovs) - 1, -1, -1):
                    from_sq, to_sq, promotion = liMovs[x]
                    self.player_has_moved(from_sq, to_sq, promotion)

        elif resp == "position":
            ini_position = self.game.first_position
            new_position = Voyager.voyager_position(self.main_window,
                                                    ini_position)
            if new_position and new_position != ini_position:
                self.game.set_position(new_position)
                self.start(self.game, self.is_complete, self.only_consult,
                           self.with_previous_next, self.save_routine)
                self.changed = True
                self.put_toolbar()

        elif resp == "pasteposicion":
            texto = QTUtil.traePortapapeles()
            if texto:
                new_position = Position.Position()
                try:
                    new_position.read_fen(str(texto))
                    ini_position = self.game.first_position
                    if new_position and new_position != ini_position:
                        self.game.set_position(new_position)
                        self.start(self.game, self.is_complete,
                                   self.only_consult, self.with_previous_next,
                                   self.save_routine)
                        self.changed = True
                        self.put_toolbar()

                except:
                    pass

        elif resp == "leerpgn":
            game = self.procesador.select_1_pgn(self.main_window)
            self.replace_game(game)

        elif resp == "pastepgn":
            self.paste_pgn()

        elif resp == "voyager":
            game = Voyager.voyagerPartida(self.main_window, self.game)
            self.replace_game(game)
示例#23
0
    def configurarGS(self):
        mt = _("Engine").lower()
        mt = _X(_("Disable %1"), mt) if self.siJuegaMotor else _X(_("Enable %1"), mt)

        sep = (None, None, None)

        liMasOpciones = [
            ("rotacion", _("Auto-rotate board"), Iconos.JS_Rotacion()), sep,
            ("apertura", _("Opening"), Iconos.Apertura()), sep,
            ("posicion", _("Start position"), Iconos.Datos()), sep,
            ("pasteposicion", _("Paste FEN position"), Iconos.Pegar16()), sep,
            ("leerpgn", _("Read PGN"), Iconos.PGN_Importar()), sep,
            ("pastepgn", _("Paste PGN"), Iconos.Pegar16()), sep,
            ("motor", mt, Iconos.Motores()), 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 == "apertura":
            me = self.unMomento()
            w = PantallaAperturas.WAperturas(self.pantalla, self.configuracion, self.bloqueApertura)
            me.final()
            if w.exec_():
                self.bloqueApertura = w.resultado()
                # self.posicApertura = ps
                self.fen = None
                self.reiniciar()

        elif resp == "posicion":
            self.startPosition()

        elif resp == "pasteposicion":
            texto = QTUtil.traePortapapeles()
            if texto:
                cp = ControlPosicion.ControlPosicion()
                try:
                    cp.leeFen(str(texto))
                    self.fen = cp.fen()
                    self.bloqueApertura = None
                    self.posicApertura = None
                    self.reiniciar()
                except:
                    pass

        elif resp == "leerpgn":
            unpgn = PantallaPGN.eligePartida(self.pantalla)
            if unpgn:
                self.bloqueApertura = None
                self.posicApertura = None
                self.fen = unpgn.dic.get("FEN", None)
                dic = self.creaDic()
                dic["PARTIDA"] = unpgn.partida.guardaEnTexto()
                dic["liPGN"] = unpgn.listaCabeceras()
                dic["FEN"] = self.fen
                dic["SIBLANCASABAJO"] = unpgn.partida.ultPosicion.siBlancas
                self.reiniciar(dic)

        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
                self.bloqueApertura = None
                self.posicApertura = None
                self.fen = unpgn.dic.get("FEN", None)
                dic = self.creaDic()
                dic["PARTIDA"] = unpgn.partida.guardaEnTexto()
                dic["liPGN"] = unpgn.listaCabeceras()
                dic["FEN"] = self.fen
                dic["SIBLANCASABAJO"] = unpgn.partida.ultPosicion.siBlancas
                self.reiniciar(dic)

        elif resp == "motor":
            self.ponRotulo1("")
            if self.siJuegaMotor:
                if self.xrival:
                    self.xrival.terminar()
                    self.xrival = None
                self.siJuegaMotor = False
            else:
                self.cambioRival()

        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)
示例#24
0
    def configurarGS(self):
        mt = _("Engine").lower()
        mt = _X(_("Disable %1"), mt) if self.play_against_engine else _X(
            _("Enable %1"), mt)

        sep = (None, None, None)

        liMasOpciones = [
            ("rotacion", _("Auto-rotate board"), Iconos.JS_Rotacion()),
            sep,
            ("opening", _("Opening"), Iconos.Apertura()),
            sep,
            ("position", _("Edit start position"), Iconos.Datos()),
            sep,
            ("pasteposicion", _("Paste FEN position"), Iconos.Pegar16()),
            sep,
            ("leerpgn", _("Read PGN"), Iconos.PGN_Importar()),
            sep,
            ("pastepgn", _("Paste PGN"), Iconos.Pegar16()),
            sep,
            ("engine", mt, Iconos.Motores()),
            sep,
            ("voyager", _("Voyager 2"), Iconos.Voyager1()),
        ]
        resp = self.configurar(liMasOpciones,
                               siCambioTutor=True,
                               siSonidos=True)

        if resp == "rotacion":
            self.auto_rotate = not self.auto_rotate
            is_white = self.game.last_position.is_white
            if self.auto_rotate:
                if is_white != self.tablero.is_white_bottom:
                    self.tablero.rotaTablero()
        elif resp == "opening":
            me = self.unMomento()
            w = PantallaOpenings.WAperturas(self.main_window,
                                            self.configuracion,
                                            self.bloqueApertura)
            me.final()
            if w.exec_():
                self.bloqueApertura = w.resultado()
                self.xfichero = None
                self.xpgn = None
                self.xjugadaInicial = None
                self.reiniciar()

        elif resp == "position":
            self.startPosition()

        elif resp == "pasteposicion":
            texto = QTUtil.traePortapapeles()
            if texto:
                cp = Position.Position()
                try:
                    cp.read_fen(str(texto))
                    self.xfichero = None
                    self.xpgn = None
                    self.xjugadaInicial = None
                    self.new_game()
                    self.game.set_position(first_position=cp)
                    self.bloqueApertura = None
                    self.reiniciar()
                except:
                    pass

        elif resp == "leerpgn":
            self.leerpgn()

        elif resp == "pastepgn":
            texto = QTUtil.traePortapapeles()
            if texto:
                ok, game = Game.pgn_game(texto)
                if not ok:
                    QTUtil2.message_error(
                        self.main_window,
                        _("The text from the clipboard does not contain a chess game in PGN format"
                          ))
                    return
                self.xfichero = None
                self.xpgn = None
                self.xjugadaInicial = None
                self.bloqueApertura = None
                dic = self.creaDic()
                dic["GAME"] = game.save()
                dic["WHITEBOTTOM"] = game.last_position.is_white
                self.reiniciar(dic)

        elif resp == "engine":
            self.ponRotulo1("")
            if self.play_against_engine:
                if self.xrival:
                    self.xrival.terminar()
                    self.xrival = None
                self.play_against_engine = False
            else:
                self.cambioRival()

        elif resp == "voyager":
            ptxt = Voyager.voyagerPartida(self.main_window, self.game)
            if ptxt:
                self.xfichero = None
                self.xpgn = None
                self.xjugadaInicial = None
                dic = self.creaDic()
                dic["GAME"] = ptxt.save()
                dic["WHITEBOTTOM"] = self.tablero.is_white_bottom
                self.reiniciar(dic)
示例#25
0
 def controlTeclado(self, nkey):
     if nkey in (86, 80):  # V,P
         self.paste(QTUtil.traePortapapeles())