コード例 #1
0
ファイル: PolyglotImports.py プロジェクト: xaizek/lucaschessR
    def import_pgn(self):
        path_pgn = QTVarios.select_pgn(self.wpolyglot)
        if not path_pgn:
            return

        resp = self.import_config(os.path.basename(path_pgn))
        if resp is None:
            return
        plies, st_side, st_results, ru, min_games, min_score, calc_weight, save_score = resp

        db = UtilSQL.DictBig()

        def fsum(keymove, pt):
            num, pts = db.get(keymove, (0, 0))
            num += 1
            pts += pt
            db[keymove] = num, pts

        dltmp = ImportarPGNDB(self.wpolyglot, os.path.basename(path_pgn))
        dltmp.show()
        ok = add_pgn(path_pgn, plies, st_results, st_side, ru.encode(), time.time, 1.2, dltmp.dispatch, fsum)
        dltmp.close()
        if not ok:
            db.close()
            return

        self.merge(db, min_games, min_score, calc_weight, save_score)
コード例 #2
0
    def tg_importar_PGN(self):
        path = QTVarios.select_pgn(self)
        if not path:
            return None

        dlTmp = QTVarios.ImportarFicheroPGN(self)
        dlTmp.show()
        self.dbGamesFEN.leerPGN(path, dlTmp)

        self.actualiza(True)
コード例 #3
0
    def select_1_pgn(self, wparent=None):
        wparent = self.main_window if wparent is None else wparent
        path = QTVarios.select_pgn(wparent)
        if path:
            fichero_pgn = os.path.abspath(path)
            cfecha_pgn = str(os.path.getmtime(fichero_pgn))
            cdir = self.configuration.folder_databases_pgn()

            file_db = os.path.join(
                cdir,
                os.path.basename(fichero_pgn)[:-4] + ".lcdb")

            if Util.exist_file(file_db):
                create = False
                db = DBgames.DBgames(file_db)
                cfecha_pgn_ant = db.recuperaConfig("PGN_DATE")
                fichero_pgn_ant = db.recuperaConfig("PGN_FILE")
                db.close()
                if cfecha_pgn != cfecha_pgn_ant or fichero_pgn_ant != fichero_pgn:
                    create = True
                    Util.remove_file(file_db)
            else:
                create = True

            if create:
                db = DBgames.DBgames(file_db)
                dlTmp = QTVarios.ImportarFicheroPGN(wparent)
                dlTmp.show()
                db.import_pgns([fichero_pgn], dlTmp=dlTmp)
                db.save_config("PGN_DATE", cfecha_pgn)
                db.save_config("PGN_FILE", fichero_pgn)
                db.close()
                dlTmp.close()

            w = WindowDatabase.WBDatabase(self.main_window, self, file_db,
                                          True, True)
            if w.exec_():
                return w.game

        return None
コード例 #4
0
ファイル: GestorPGN.py プロジェクト: MarCialR/lucaschess
    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 visorPGN(self):
     path = QTVarios.select_pgn(self.main_window)
     if path:
         self.read_pgn(path)
コード例 #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()
コード例 #7
0
    def mas(self):
        path_pgn = QTVarios.select_pgn(self)
        if not path_pgn:
            return

        path_db = self.configuration.ficheroTemporal("lcdb")
        db = DBgames.DBgames(path_db)
        dlTmp = QTVarios.ImportarFicheroPGN(self)
        dlTmp.show()
        db.import_pgns([path_pgn], dlTmp=dlTmp)
        db.close()
        dlTmp.close()

        db = DBgames.DBgames(path_db)
        nreccount = db.all_reccount()
        if nreccount == 0:
            return

        plant = ""
        shuffle = False
        reverse = False
        todos = range(1, nreccount + 1)
        li_regs = []
        max_moves = 0
        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.message_error(
                        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_pgn)[:-4]
            games = dic["GAMES"] = []

            for recno in li_regs:
                g = db.read_game_recno(recno)
                pv = g.pv()
                if max_moves:
                    lipv = pv.strip().split(" ")
                    if len(lipv) > max_moves:
                        pv = " ".join(lipv[:max_moves])
                dt = {"LABELS": g.li_tags, "XPV": FasterCode.pv_xpv(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)

        db.close()