示例#1
0
    def gm(self):

        liSelec = self.grid.recnosSeleccionados()

        # Datos
        liGen = [(None, None)]

        liGen.append((_("Name") + ":", ""))

        liGen.append(("<div align=\"right\">" + _(
            "Only player moves"
        ) + ":<br>%s</div>" % _(
            "(You can add multiple aliases separated by ; and wildcards with * )"
        ), ""))

        liGen.append((_("Only selected games") + ":", len(liSelec) > 1))

        li = [
            1, (0, _("Both sides")), (1, _("Only the winning side")),
            (2, _("The winning side and both if drawn"))
        ]

        liGen.append((_("Which side") + ":", li))

        eti = _("Play like a grandmaster")
        eti = _X(_('Create training to %1'), eti)
        resultado = FormLayout.fedit(liGen,
                                     title=eti,
                                     parent=self,
                                     anchoMinimo=460,
                                     icon=Iconos.GranMaestro())

        if not resultado:
            return
        accion, liGen = resultado
        nombre = liGen[0]
        jugador = liGen[1]
        siSelec = liGen[2]
        result = liGen[3]

        if not nombre:
            return

        liJugadores = jugador.upper().split(";") if jugador else None

        # Se crea el objeto de ejecucion
        fgm = GM.FabGM(self.gestor.configuracion, nombre, liJugadores)

        # Se pasan todas las partidas
        if not siSelec:
            liSelec = range(self.dbf.reccount())

        nregs = len(liSelec)
        mensaje = _("Game") + "  %d/" + str(nregs)
        tmpBP = QTUtil2.BarraProgreso(self, eti, "", nregs).mostrar()

        for n, recno in enumerate(liSelec):

            if tmpBP.siCancelado():
                break

            self.dbf.goto(recno)

            if n:
                tmpBP.pon(n)
            tmpBP.mensaje(mensaje % (n + 1, ))

            jugadas = self.dbf.leeOtroCampo(n, "PGN")

            pgn = PGN.UnPGN()
            pgn.leeTexto(jugadas)

            fgm.masMadera(pgn, pgn.partida, result)

        siCancelado = tmpBP.siCancelado()
        tmpBP.cerrar()

        if not siCancelado:
            # Se ejecuta
            siCreado = fgm.xprocesa()

            if siCreado:
                liCreados = [nombre]
                liNoCreados = None
            else:
                liNoCreados = [nombre]
                liCreados = None
            mensajeEntrenamientos(self, liCreados, liNoCreados)