Exemplo n.º 1
0
    def importarSummary(self, ventana, gamebase, ficheroSummary, depth, siWhite, onlyone, minMoves):
        titulo = _("Importing the summary of a database")
        bp = QTUtil2.BarraProgreso1(ventana, titulo)
        bp.ponTotal(0)
        bp.ponRotulo(_X(_("Reading %1"), os.path.basename(ficheroSummary)))
        bp.mostrar()

        db_stat = DBgamesST.TreeSTAT(ficheroSummary)

        if depth == 0:
            depth = 99999

        pvBase = gamebase.pv()
        len_gamebase = len(gamebase)

        liPartidas = []

        def hazPV(lipv_ant):
            if bp.is_canceled():
                return
            n_ant = len(lipv_ant)
            siWhite1 = n_ant % 2 == 0

            pv_ant = " ".join(lipv_ant) if n_ant else ""
            liChildren = db_stat.children(pv_ant, False)

            if len(liChildren) == 0 or len(lipv_ant) > depth:
                p = Game.Game()
                p.leerLIPV(lipv_ant)
                if len(p) > len_gamebase:
                    liPartidas.append(p)
                    bp.ponTotal(len(liPartidas))
                    bp.pon(len(liPartidas))
                return

            if siWhite1 == siWhite:
                tt_max = 0
                limax = []
                for alm in liChildren:
                    tt = alm.W + alm.B + alm.O + alm.D
                    if tt > tt_max:
                        tt_max = tt
                        limax = [alm]
                    elif tt == tt_max and not onlyone:
                        limax.append(alm)
                liChildren = limax

            for alm in liChildren:
                li = lipv_ant[:]
                li.append(alm.move)
                hazPV(li)

        hazPV(pvBase.split(" ") if pvBase else [])

        bp.ponRotulo(_("Writing..."))
        self.guardaPartidas("%s,%s" % (_("Database summary"), os.path.basename(ficheroSummary)), liPartidas)
        bp.cerrar()

        return True
Exemplo n.º 2
0
    def __init__(self, nom_fichero):
        self.link_file = nom_fichero
        if nom_fichero.endswith(".lcdblink"):
            with open(nom_fichero, "rt", encoding="utf-8",
                      errors="ignore") as f:
                nom_fichero = f.read().strip()
            self.external_folder = os.path.dirname(nom_fichero)
        else:
            self.external_folder = ""
        self.nom_fichero = Util.relative_path(nom_fichero)

        self.conexion = sqlite3.connect(self.nom_fichero)
        self.conexion.row_factory = sqlite3.Row
        self.order = None
        self.filter = None

        self.cache = {}
        self.mincache = 2024
        self.maxcache = 4048

        self.li_fields = self.lista_campos()

        self.allows_duplicates = self.recuperaConfig("ALLOWS_DUPLICATES", True)
        self.allows_positions = self.recuperaConfig("ALLOWS_POSITIONS", True)
        self.allows_complete_game = self.recuperaConfig(
            "ALLOWS_COMPLETE_GAMES", True)
        self.allows_zero_moves = self.recuperaConfig("ALLOWS_ZERO_MOVES", True)

        self.li_order = []

        summary_depth = self.recuperaConfig("SUMMARY_DEPTH", 0)
        self.with_db_stat = summary_depth > 0

        self.db_stat = DBgamesST.TreeSTAT(self.nom_fichero + ".st1",
                                          summary_depth)

        self.li_row_ids = []

        self.rowidReader = UtilSQL.RowidReader(self.nom_fichero, "Games")

        self.with_plycount = "PLYCOUNT" in self.recuperaConfig("dcabs", {})
Exemplo n.º 3
0
    def creaTab(self):
        menu = QTVarios.LCMenu(self)
        menu.opcion("book", _("Polyglot book"), Iconos.Libros())
        menu.separador()
        menu.opcion("dbase", _("Database"), Iconos.Database())
        # menu.separador()
        # menu.opcion("tree", _("Tree"), Iconos.Arbol())
        resp = menu.lanza()
        pos = 0
        if resp == "book":
            book = self.seleccionaLibro()
            if book:
                tabbook = TabBook(self, book, self.configuration)
                self.li_tabs.append((resp, tabbook))
                pos = len(self.li_tabs) - 1
                self.tabs.nuevaTab(tabbook, book.name, pos)
                self.tabs.setTabIcon(pos, Iconos.Libros())
                self.setPosicion(self.game, self.njg, pos)

        # elif resp == "tree":
        #     tabtree = TabTree(self, self.configuration)
        #     self.li_tabs.append(("tree", tabtree))
        #     pos = len(self.li_tabs)-1
        #     self.tabs.nuevaTab(tabtree, _("Tree"), pos)
        #     self.tabs.setTabIcon(pos, Iconos.Arbol())
        #     tabtree.bt_update()

        elif resp == "dbase":
            nomfichgames = QTVarios.select_db(self, self.configuration, True,
                                              False)
            if nomfichgames:
                db_stat = DBgamesST.TreeSTAT(nomfichgames + ".st1")
                tabdb = TabDatabase(self, self.procesador, db_stat)
                self.li_tabs.append((resp, tabdb))
                pos = len(self.li_tabs) - 1
                self.setPosicion(self.game, self.njg, pos)
                name = os.path.basename(nomfichgames)[:-5]
                self.tabs.nuevaTab(tabdb, name, pos)
                self.tabs.setTabIcon(pos, Iconos.Database())
        self.tabs.activa(pos)
Exemplo n.º 4
0
    def __init__(self, nom_fichero):
        self.link_file = nom_fichero
        if nom_fichero.endswith(".lcdblink"):
            with open(nom_fichero, "rt", encoding="utf-8",
                      errors="ignore") as f:
                nom_fichero = f.read().strip()
            self.external_folder = os.path.dirname(nom_fichero)
        else:
            self.external_folder = ""
        self.nom_fichero = Util.relative_path(nom_fichero)

        self.conexion = sqlite3.connect(self.nom_fichero)
        self.conexion.row_factory = sqlite3.Row
        self.order = None
        self.filter = None

        self.cache = {}
        self.mincache = 2024
        self.maxcache = 4048

        self.li_fields = self.lista_campos()

        self.read_options()

        self.li_order = []

        summary_depth = self.read_config("SUMMARY_DEPTH", 0)
        self.with_db_stat = summary_depth > 0

        self.db_stat = DBgamesST.TreeSTAT(self.nom_fichero + ".st1",
                                          summary_depth)

        self.li_row_ids = []

        self.rowidReader = UtilSQL.RowidReader(self.nom_fichero, "Games")

        self.with_plycount = "PLYCOUNT" in self.read_config("dcabs", {})