Example #1
0
    def tg_exportar_PGN(self):
        li = self.grid.recnosSeleccionados()
        if li:
            if len(li) > 1:
                menu = QTVarios.LCMenu(self)
                menu.opcion(True, _("All read"), Iconos.PuntoVerde())
                menu.separador()
                menu.opcion(False, _("Only selected"), Iconos.PuntoAzul())
                resp = menu.lanza()
                if resp is None:
                    return
                siTodos = resp
            else:
                siTodos = True

            if siTodos:
                li = range(self.dbGames.reccount())

            w = PantallaSavePGN.WSaveVarios(self, self.configuracion)
            if w.exec_():
                ws = PantallaSavePGN.FileSavePGN(self, w.dic_result)
                if ws.open():
                    ws.um()
                    for n, recno in enumerate(li):
                        pgn = self.dbGames.leePGNRecno(recno)
                        if n > 0 or not ws.is_new:
                            ws.write("\n\n")
                        ws.write(pgn)

                    ws.close()
                    ws.um_final()
Example #2
0
    def tg_exportar_PGN(self):
        li = self.listaSelected()
        if li:
            w = PantallaSavePGN.WSaveVarios(self, self.configuracion)
            if w.exec_():
                ws = PantallaSavePGN.FileSavePGN(self, w.dic_result)
                if ws.open():
                    pb = QTUtil2.BarraProgreso1(self, _("Saving..."), formato1="%p%")
                    pb.mostrar()
                    pb.ponTotal(len(li))
                    for n, recno in enumerate(li):
                        pb.pon(n)
                        pgn, result = self.dbGames.leePGNRecno(recno)
                        if pb.siCancelado():
                            break
                        if n > 0 or not ws.is_new:
                            ws.write("\n\n")
                        pgn = pgn.strip().replace("e.p.", "").replace("#+", "#")
                        if result in ( "*", "1-0", "0-1", "1/2-1/2"):
                            if not pgn.endswith(result):
                                pgn += " " + result
                        ws.write(pgn + "\n\n")

                    pb.close()
                    ws.close()
Example #3
0
    def tw_exportar_pgn(self, only_selected):
        w = PantallaSavePGN.WSaveVarios(self, self.configuracion)
        if w.exec_():
            ws = PantallaSavePGN.FileSavePGN(self, w.dic_result)
            if ws.open():
                sp = "\r\n" if ws.crlf else "\n"
                pb = QTUtil2.BarraProgreso1(self, _("Saving..."), formato1="%p%")
                pb.mostrar()
                if only_selected:
                    li_sel = self.grid.recnosSeleccionados()
                else:
                    li_sel = list(range(self.dbGames.reccount()))
                pb.ponTotal(len(li_sel))
                for n, recno in enumerate(li_sel):
                    pb.pon(n)
                    pgn, result = self.dbGames.leePGNRecno(recno, sp)
                    if pb.is_canceled():
                        break
                    if n > 0 or not ws.is_new:
                        ws.write(sp + sp)
                    if result in ("*", "1-0", "0-1", "1/2-1/2"):
                        if not pgn.endswith(result):
                            pgn += " " + result
                    ws.write(pgn + sp)

                pb.close()
                ws.close()
Example #4
0
 def gm_save_pgn(self):
     if self.torneo.num_games_finished() > 0:
         w = PantallaSavePGN.WSaveVarios(self, self.configuracion)
         if w.exec_():
             ws = PantallaSavePGN.FileSavePGN(self, w.dic_result)
             if ws.open():
                 ws.um()
                 if not ws.is_new:
                     ws.write("\n\n")
                 for gm in self.torneo.db_games_finished:
                     game = Game.Game()
                     game.restore(gm.game_save)
                     ws.write(game.pgn())
                     ws.write("\n\n\n")
                 ws.close()
                 ws.um_final()
 def exportar(self):
     menu = QTVarios.LCMenu(self)
     submenu = menu.submenu(_("PGN Format"), Iconos.PGN())
     r = "%s %%s" % _("Result")
     submenu.opcion("1-0", r % "1-0", Iconos.Blancas8())
     submenu.opcion("0-1", r % "0-1", Iconos.Negras8())
     submenu.opcion("1/2-1/2", r % "1/2-1/2", Iconos.Tablas8())
     submenu.opcion("", _("Without Result"), Iconos.Gris())
     resp = menu.lanza()
     if resp is not None:
         w = PantallaSavePGN.WSaveVarios(self, self.configuracion)
         if w.exec_():
             ws = PantallaSavePGN.FileSavePGN(self, w.dic_result)
             if ws.open():
                 self.dbop.exportarPGN(ws, resp)
                 ws.close()
                 ws.um_final()
Example #6
0
    def gmGuardar(self):
        nrec = self.gridGames.reccount()
        if not nrec:
            return None
        li = self.gridGames.recnosSeleccionados()
        if not li:
            li = range(nrec)

        pgn = self.torneo.grabaPGNgames(li)

        if pgn:
            w = PantallaSavePGN.WSaveVarios(self, self.configuracion)
            if w.exec_():
                ws = PantallaSavePGN.FileSavePGN(self, w.dic_result)
                if ws.open():
                    ws.write(pgn)
                    ws.close()
                    ws.um_final()
Example #7
0
    def guardar(self):
        nrecs = self.dbf.reccount()
        if nrecs == 0:
            return
        elif nrecs > 1:
            menu = QTVarios.LCMenu(self)
            menu.opcion("all", _("All games"), Iconos.PuntoNaranja())
            menu.separador()
            menu.opcion("selected", _("Selected games"), Iconos.PuntoAzul())
            resp = menu.lanza()
            if resp is None:
                return
            elif resp == "all":
                liSelected = range(nrecs)
            else:
                liSelected = self.grid.recnosSeleccionados()
        else:
            liSelected = [0]

        w = PantallaSavePGN.WSaveVarios(self, self.gestor.configuracion)
        if w.exec_():
            ws = PantallaSavePGN.FileSavePGN(self, w.dic_result)
            if ws.open():
                ws.um()

                antSelect = self.dbf.select
                nueSelect = antSelect + ",PGN"
                self.dbf.ponSelect(nueSelect)
                self.dbf.leer()
                self.dbf.gotop()

                for i in liSelected:
                    self.dbf.goto(i)
                    dic = self.dbf.dicValores()
                    pgn = dic["PGN"]
                    if i > 0 or not ws.is_new:
                        ws.write("\n\n")
                    ws.write(pgn)

                ws.close()
                self.dbf.ponSelect(antSelect)
                ws.um_final()
Example #8
0
    def tg_exportar_PGN(self):
        li = self.grid.recnosSeleccionados()
        if li:
            if len(li) > 1:
                menu = QTVarios.LCMenu(self)
                menu.opcion(True, _("All read"), Iconos.PuntoVerde())
                menu.separador()
                menu.opcion(False, _("Only selected"), Iconos.PuntoAzul())
                resp = menu.lanza()
                if resp is None:
                    return
                siTodos = resp
            else:
                siTodos = True

            if siTodos:
                li = range(self.dbGames.reccount())

            w = PantallaSavePGN.WSaveVarios(self, self.configuracion)
            if w.exec_():
                ws = PantallaSavePGN.FileSavePGN(self, w.dic_result)
                if ws.open():
                    pb = QTUtil2.BarraProgreso1(self,
                                                _("Saving..."),
                                                formato1="%p%")
                    pb.mostrar()
                    pb.ponTotal(len(li))
                    for n, recno in enumerate(li):
                        pb.pon(n)
                        pgn, result = self.dbGames.leePGNRecno(recno)
                        if pb.siCancelado():
                            break
                        if n > 0 or not ws.is_new:
                            ws.write("\n\n")
                        ws.write(pgn)

                    pb.close()
                    ws.close()
Example #9
0
 def gmGuardar(self):
     pgn = self.pgnActual()
     if pgn:
         w = PantallaSavePGN.WSave(self, pgn, self.configuracion)
         w.exec_()
Example #10
0
    def file(self):
        menu = QTVarios.LCMenu(self)
        menu.opcion("saveas", _("Save a copy"), Iconos.GrabarComo())
        menu.separador()
        menu.opcion("restorefrom", _("Restore from"), Iconos.Recuperar())
        menu.separador()
        submenu = menu.submenu(_("Create new"), Iconos.Nuevo())
        submenu.opcion("new_UNED", _("UNED chess school"), Iconos.Uned())
        submenu.separador()
        submenu.opcion("new_UWE", _("Uwe Auerswald"), Iconos.Uwe())
        submenu.separador()
        submenu.opcion("new_SM", _("Singular moves"), Iconos.Singular())
        menu.separador()
        submenu = menu.submenu(_("Export to"), Iconos.DatabaseMas())
        submenu.opcion("save_pgn", _("A PGN file"), Iconos.FichPGN())
        submenu.separador()
        submenu.opcion("save_db", _("Database"), Iconos.DatabaseC())

        resp = menu.lanza()
        if resp is None:
            return
        if resp == "saveas":
            liGen = [(None, None)]
            config = FormLayout.Editbox(_("Name"), ancho=160)
            liGen.append((config, ""))

            resultado = FormLayout.fedit(liGen,
                                         title=_("Name"),
                                         parent=self,
                                         icon=Iconos.GrabarComo())
            if resultado:
                accion, liResp = resultado
                fich = nombre = liResp[0]
                if nombre.lower()[-4:] != ".wsm":
                    fich += ".wsm"
                path = os.path.join(self.configuracion.carpeta, fich)
                ok = True
                if Util.existeFichero(path):
                    ok = QTUtil2.pregunta(
                        self,
                        _X(
                            _("The file %1 already exists, what do you want to do?"
                              ), fich),
                        etiSi=_("Overwrite"),
                        etiNo=_("Cancel"))
                if ok:
                    shutil.copy(self.dbwashing.file, path)
        elif resp == "restorefrom":
            li = []
            for fich in os.listdir(self.configuracion.carpeta):
                if fich.endswith(".wsm") and fich != self.dbwashing.filename:
                    li.append(fich[:-4])
            if not li:
                QTUtil2.mensaje(self, _("There is no file"))
                return
            menu = QTVarios.LCMenu(self)
            for fich in li:
                menu.opcion(fich, fich, Iconos.PuntoRojo())
            resp = menu.lanza()
            if resp:
                if QTUtil2.pregunta(
                        self, "%s\n%s" %
                    (_("Current data will be removed and overwritten."),
                     _("Are you sure?"))):
                    shutil.copy(
                        os.path.join(self.configuracion.carpeta,
                                     resp + ".wsm"), self.dbwashing.file)
                    self.wreload = True
                    self.guardarVideo()
                    self.accept()
        elif resp.startswith("new_"):
            tactic = resp[4:]
            if QTUtil2.pregunta(
                    self, "%s\n%s" %
                (_("Current data will be removed and overwritten."),
                 _("Are you sure?"))):
                self.dbwashing.new(tactic)
                self.wreload = True
                self.guardarVideo()
                self.accept()

        elif resp.startswith("save_"):

            def other_pc():
                for engine in self.washing.liEngines:
                    if engine.state == Washing.ENDED:
                        game = self.dbwashing.restoreGame(engine)
                        pc = Partida.PartidaCompleta()
                        pc.leeOtra(game)
                        dt = engine.date if engine.date else Util.hoy()
                        if engine.color:
                            white = self.configuracion.jugador
                            black = engine.nombre
                            result = "1-0"
                            whiteelo = str(self.configuracion.elo)
                            blackelo = engine.elo
                        else:
                            black = self.configuracion.jugador
                            white = engine.nombre
                            result = "0-1"
                            blackelo = str(self.configuracion.elo)
                            whiteelo = engine.elo
                        tags = [
                            ["Site", "Lucas Chess"],
                            ["Event", _("The Washing Machine")],
                            ["Date",
                             "%d-%d-%d" % (dt.year, dt.month, dt.day)],
                            ["White", white],
                            ["Black", black],
                            ["WhiteElo", whiteelo],
                            ["BlackElo", blackelo],
                            ["Result", result],
                        ]
                        ap = game.apertura
                        if ap:
                            tags.append(["ECO", ap.eco])
                            tags.append(["Opening", ap.trNombre])
                        pc.setTags(tags)
                        yield pc

            if resp == "save_db":
                ext = "lcg"
                path = QTUtil2.salvaFichero(
                    self, _("Database of complete games"),
                    self.configuracion.ficheroDBgames,
                    _("File") + " %s (*.%s)" % (ext, ext), False)
                if path:
                    if not path.lower().endswith(".lcg"):
                        path += ".lcg"
                    me = QTUtil2.mensEspera.inicio(self, _("Saving..."))
                    dbn = DBgames.DBgames(path)
                    for pc in other_pc():
                        dbn.inserta(pc)
                    me.final()
                    QTUtil2.mensaje(self, _X(_("Saved to %1"), path))
            else:
                w = PantallaSavePGN.WSaveVarios(self, self.configuracion)
                if w.exec_():
                    ws = PantallaSavePGN.FileSavePGN(self, w.dic_result)
                    if ws.open():
                        ws.um()
                        for n, pc in enumerate(other_pc()):
                            if n or not ws.is_new:
                                ws.write("\n\n")
                        ws.write(pc.pgn())
                    ws.close()
                    ws.um_final()