Пример #1
0
    def fichero(self, siNuestro=False, siBuscar=False, path=""):
        if path:
            if not os.path.isfile(path):
                return
        self.siFicheroNuestro = siNuestro
        if siNuestro:
            path = self.nuestroFichero
        elif siBuscar:
            # Elegimos el fichero
            files = QTVarios.select_pgns(self.pantalla)
            if not files:
                if self.muestraInicial:
                    self.finPartida()
                return
            if len(files) == 1:
                path = files[0]
            else:
                path = self.configuracion.ficheroTemporal("pgn")
                with open(path, "wb") as q:
                    for fich in files:
                        with open(fich, "rb") as f:
                            q.write(f.read())

        # ~ else ya esta el nombre

        fpgn = PGN.PGN()

        dicDB = fpgn.leeFichero(self.pantalla, path)
        if dicDB is None:
            return None

        self.ficheroMostrar(dicDB, False)
Пример #2
0
    def fichero(self, siNuestro=False, siBuscar=False, path=""):
        if path:
            if not os.path.isfile(path):
                return
        self.siFicheroNuestro = siNuestro
        if siNuestro:
            path = self.nuestroFichero
        elif siBuscar:
            # Elegimos el fichero
            path = QTUtil2.leeFichero(self.pantalla, self.configuracion.dirPGN,
                                      "pgn")
            if not path:
                if self.muestraInicial:
                    self.finPartida()
                return
            carpeta, fichero = os.path.split(path)
            if self.configuracion.dirPGN != carpeta:
                self.configuracion.dirPGN = carpeta
                self.configuracion.graba()
        # ~ else ya esta el nombre

        fpgn = PGN.PGN()

        dicDB = fpgn.leeFichero(self.pantalla, path)
        if dicDB is None:
            return None

        self.ficheroMostrar(dicDB, False)
Пример #3
0
def eligePartida(ventana, path=None):
    configuracion = VarGen.configuracion
    # Elegimos el fichero PGN
    if path is None:
        path = QTUtil2.leeFichero(ventana, configuracion.dirPGN, "pgn")
        if not path:
            return None
    carpeta, fichero = os.path.split(path)
    if configuracion.dirPGN != carpeta:
        configuracion.dirPGN = carpeta
        configuracion.graba()

    # Lo importamos
    fpgn = PGN.PGN(configuracion)

    dicDB = fpgn.leeFichero(ventana, path)
    if dicDB is None:
        return None

    # Los datos los tenemos en una BD.sql
    dClaves = dicDB["DCLAVES"]

    bd = SQL.Base.DBBase(dicDB["PATHDB"])

    dbf = bd.dbf("GAMES", ",".join(dClaves.keys()) + ",PGN")

    siSeguir, estadoWpgn, siSeHaBorradoAlgo = elegirPGN(ventana,
                                                        dbf,
                                                        dClaves,
                                                        None,
                                                        None,
                                                        siElegir=True)
    if siSeguir:
        reg = dbf.dicValores()

    dbf.cerrar()

    bd.cerrar()

    if not siSeguir:
        return None

    unpgn = PGN.UnPGN()
    unpgn.leeTexto(reg["PGN"])

    return unpgn
Пример #4
0
    def fichero(self, siNuestro=False, siBuscar=False, path=""):
        if path:
            if not os.path.isfile(path):
                return
        self.siFicheroNuestro = siNuestro
        if siNuestro:
            path = self.nuestroFichero
        elif siBuscar:
            # Elegimos el fichero
            path = QTVarios.select_pgn(self.pantalla)
            if not path:
                if self.muestraInicial:
                    self.finPartida()
                return
        # ~ else ya esta el nombre

        fpgn = PGN.PGN()

        dicDB = fpgn.leeFichero(self.pantalla, path)
        if dicDB is None:
            return None

        self.ficheroMostrar(dicDB, False)
Пример #5
0
    def ficheroMostrar(self,
                       dicDB,
                       siRepite,
                       siAnterior=False,
                       siSiguiente=False):

        bd = SQLBase.DBBase(dicDB["PATHDB"])

        if (not siRepite) and self.siFicheroNuestro:
            orden = "ROWID DESC"
        else:
            orden = ""

        dClavesTam = dicDB["DCLAVES"]
        dbf = bd.dbf(
            "GAMES", ",".join(dClavesTam.keys()), orden=orden
        )  # La lectura se hace en la pantalla, para que la haga en el mismo sitio tanto siRepite como si no

        estadoWpgn = dicDB["ESTADOWPGN"] if siRepite else None

        if siAnterior or siSiguiente:
            siSeguir = True
            siSeHaBorradoAlgo = False
            dbf.leer()
            recno = estadoWpgn.recno
            if siAnterior:
                if recno > 0:
                    recno -= 1
            elif siSiguiente:
                if recno < dbf.reccount() - 1:
                    recno += 1
            dbf.goto(recno)
            estadoWpgn.recno = recno
        else:
            siSeguir, estadoWpgn, siSeHaBorradoAlgo = PantallaPGN.elegirPGN(
                self.pantalla, dbf, dClavesTam, self, estadoWpgn)

        if siSeguir:
            self.pensando(True)
            rid = dbf.rowid(dbf.recno)
            self.dicDB = dicDB
            dicDB["ESTADOWPGN"] = estadoWpgn
            dbf.cerrar()
            dbf = bd.dbfT("GAMES",
                          ",".join(dClavesTam.keys()) + ",PGN",
                          condicion="ROWID=%d" % rid)
            dbf.leer()
            dbf.gotop()
            dicDatos = dbf.dicValores()
            self.pgnPaste = dicDatos["PGN"]

            dbf.cerrar()
            pgn = PGN.UnPGN()
            pgn.leeTexto(self.pgnPaste)
            siMostrar = not pgn.siError
            self.pensando(False)
            if not siMostrar:
                QTUtil2.mensError(self.pantalla,
                                  _("This is not a valid PGN file"))

        else:
            siMostrar = False

        bd.cerrar()

        if siSeHaBorradoAlgo:
            fpgn = PGN.PGN()
            fpgn.borraReferenciaA(dicDB["FICHERO"])

        if siMostrar:
            self.mostrar(pgn, True)
        elif self.muestraInicial or self.finExit:
            self.finPartida()
Пример #6
0
    def mas(self):
        path = QTVarios.select_pgn(self)
        if not path:
            return

        fpgn = PGN.PGN()

        dicDB = fpgn.leeFichero(self, path)
        if dicDB is None:
            return

        bd = SQLBase.DBBase(dicDB["PATHDB"])

        dClavesTam = dicDB["DCLAVES"]
        dbf = bd.dbf("GAMES", ",".join(dClavesTam.keys()))
        dbf.leer()

        nreccount = dbf.reccount()

        plant = ""
        shuffle = False
        reverse = False
        todos = range(1, nreccount + 1)
        li_regs = None
        while True:
            sep = FormLayout.separador
            liGen = []
            liGen.append((None, "%s: %d" % (_("Total games"), nreccount)))
            liGen.append(sep)
            config = FormLayout.Editbox(_("Select games") + "<br>" +
                                        _("By example:") + " -5,7-9,14,19-" +
                                        "<br>" + _("Empty means all games"),
                                        rx="[0-9,\-,\,]*")
            liGen.append((config, plant))

            liGen.append(sep)

            liGen.append((_("Shuffle") + ":", shuffle))

            liGen.append(sep)

            liGen.append((_("Reverse") + ":", reverse))

            liGen.append(sep)

            config = FormLayout.Spinbox(_("Max moves"), 0, 999, 50)
            liGen.append((config, 0))

            resultado = FormLayout.fedit(liGen,
                                         title=_("Select games"),
                                         parent=self,
                                         anchoMinimo=200,
                                         icon=Iconos.Opciones())
            if resultado:
                accion, liResp = resultado
                plant, shuffle, reverse, max_moves = liResp
                if plant:
                    ln = Util.ListaNumerosImpresion(plant)
                    li_regs = ln.selected(todos)
                else:
                    li_regs = todos
                nregs = len(li_regs)
                if 12 <= nregs <= 500:
                    break
                else:
                    QTUtil2.mensError(
                        self, "%s (%d)" %
                        (_("Number of games must be in range 12-500"), nregs))
                    li_regs = None
            else:
                break

        if li_regs:
            if shuffle:
                random.shuffle(li_regs)
            if reverse:
                li_regs.sort(reverse=True)
            li_regs = [x - 1 for x in li_regs]  # 0 init

            dic = {}
            dic["TOURNEY"] = os.path.basename(path)[:-4]
            games = dic["GAMES"] = []

            for recno in li_regs:
                pgn = dbf.leeOtroCampo(recno, "PGN")
                g = PGNReader.read1Game(pgn)
                pv = g.pv()
                if max_moves:
                    lipv = pv.strip().split(" ")
                    if len(lipv) > max_moves:
                        pv = " ".join(lipv[:max_moves])
                dt = {
                    "LABELS": [(k, v) for k, v in g.labels.items()],
                    "XPV": LCEngine.pv2xpv(pv)
                }
                games.append(dt)

            self.litourneys.append(dic)

            li = [("%s (%d)" % (tourney["TOURNEY"], len(tourney["GAMES"])),
                   tourney) for tourney in self.litourneys]
            self.cbtourney.rehacer(li, dic)

        dbf.cerrar()
        bd.cerrar()