Exemplo n.º 1
0
    def enNuevo(self):
        # Pedimos el ejecutable
        exeMotor = QTUtil2.leeFichero(self, self.torneo.ultCarpetaEngines(),
                                      "*", _("Engine"))
        if not exeMotor:
            return
        self.torneo.ultCarpetaEngines(os.path.dirname(exeMotor))

        # Leemos el UCI
        me = Engines.read_engine_uci(exeMotor)
        if not me:
            QTUtil2.message_bold(
                self,
                _X(_("The file %1 does not correspond to a UCI engine type."),
                   exeMotor))
            return
        eng = Tournament.EngineTournament()
        eng.restore(me.save())
        eng.pon_huella(self.torneo)
        self.torneo.save_engine(eng)
        self.gridEnginesAlias.refresh()
        self.gridEnginesAlias.gobottom(0)

        self.gridResults.refresh()

        self.rotulos_tabs()
Exemplo n.º 2
0
 def enImportarTodos(self):
     lista = self.configuration.comboMotores()
     for name, key in lista:
         for depth in range(1, 5):
             me = Tournament.EngineTournament()
             me.pon_huella(self.torneo)
             me.read_exist_engine(key)
             me.key = key + " - depth %d" % depth
             me.depth = depth
             me.elo = 1500
             self.torneo.save_engine(me)
     self.gridEnginesAlias.refresh()
     self.gridEnginesAlias.gobottom(0)
     self.gridResults.refresh()
     self.rotulos_tabs()
Exemplo n.º 3
0
    def enImportar(self):
        menu = QTVarios.LCMenu(self)
        lista = self.configuracion.comboMotores()
        nico = QTVarios.rondoPuntos()
        for name, clave in lista:
            menu.opcion(clave, name, nico.otro())

        resp = menu.lanza()
        if not resp:
            return

        me = Tournament.EngineTournament()
        me.pon_huella(self.torneo)
        me.read_exist_engine(resp)
        self.torneo.save_engine(me)
        self.gridEnginesAlias.refresh()
        self.gridEnginesAlias.gobottom(0)

        self.gridResults.refresh()

        self.rotulos_tabs()
Exemplo n.º 4
0
 def tournament(self):
     return Tournament.Tournament(self.file_tournament)
Exemplo n.º 5
0
    def __init__(self, wParent, nombre_torneo):

        torneo = self.torneo = Tournament.Tournament(nombre_torneo)

        titulo = nombre_torneo
        icono = Iconos.Torneos()
        extparam = "untorneo_v1"
        QTVarios.WDialogo.__init__(self, wParent, titulo, icono, extparam)

        self.configuracion = Code.configuracion

        # Datos

        self.liEnActual = []
        self.xjugar = None
        self.liResult = None
        self.last_change = Util.today()
        self.li_results = []

        # Toolbar
        tb = Controles.TBrutina(self, tamIcon=24)
        tb.new(_("Close"), Iconos.MainMenu(), self.terminar)
        tb.new(_("Launch a worker"), Iconos.Lanzamiento(), self.gm_launch)

        # Tabs
        self.tab = tab = Controles.Tab()

        # Tab-configuracion --------------------------------------------------
        w = QtWidgets.QWidget()

        # Adjudicator
        lb_resign = Controles.LB(
            self, "%s (%s): " %
            (_("Minimum centipawns to assign winner"), _("0=disable")))
        self.ed_resign = Controles.ED(self).tipoInt(
            torneo.resign()).anchoFijo(30)
        bt_resign = Controles.PB(self, "", rutina=self.borra_resign).ponIcono(
            Iconos.Reciclar())

        # Draw-plys
        lbDrawMinPly = Controles.LB(
            self,
            "%s (%s): " % (_("Minimum moves to assign draw"), _("0=disable")))
        self.sbDrawMinPly = Controles.SB(self, torneo.drawMinPly(), 20, 1000)
        # Draw-puntos
        lb_draw_range = Controles.LB(
            self,
            _("Maximum centipawns to assign draw") + ": ")
        self.ed_draw_range = Controles.ED(self).tipoInt(
            torneo.drawRange()).anchoFijo(30)
        bt_draw_range = Controles.PB(
            self, "", rutina=self.borra_draw_range).ponIcono(Iconos.Reciclar())

        # adjudicator
        self.liMotores = self.configuracion.comboMotoresMultiPV10()
        self.cbJmotor, self.lbJmotor = QTUtil2.comboBoxLB(
            self, self.liMotores, torneo.adjudicator(), _("Engine"))
        self.edJtiempo = Controles.ED(self).tipoFloat().ponFloat(
            1.0).anchoFijo(50).ponFloat(torneo.adjudicator_time())
        self.lbJtiempo = Controles.LB2P(self, _("Time in seconds"))
        layout = Colocacion.G()
        layout.controld(self.lbJmotor, 3, 0).control(self.cbJmotor, 3, 1)
        layout.controld(self.lbJtiempo, 4, 0).control(self.edJtiempo, 4, 1)
        self.gbJ = Controles.GB(self, _("Adjudicator"), layout)
        self.gbJ.setCheckable(True)
        self.gbJ.setChecked(torneo.adjudicator_active())

        lbBook = Controles.LB(self, _("Opening book") + ": ")
        fvar = self.configuracion.ficheroBooks
        self.listaLibros = Books.ListaLibros()
        self.listaLibros.restore_pickle(fvar)
        # Comprobamos que todos esten accesibles
        self.listaLibros.comprueba()
        li = [(x.name, x.path) for x in self.listaLibros.lista]
        li.insert(0, ("* " + _("None"), "-"))
        self.cbBooks = Controles.CB(self, li, torneo.book())
        btNuevoBook = Controles.PB(self, "", self.nuevoBook,
                                   plano=False).ponIcono(Iconos.Nuevo(),
                                                         tamIcon=16)
        lyBook = Colocacion.H().control(
            self.cbBooks).control(btNuevoBook).relleno()

        lbBookDepth = Controles.LB(self,
                                   _("Max depth of book (0=Maximum)") + ": ")
        self.sbBookDepth = Controles.SB(self, torneo.bookDepth(), 0, 200)

        # Posicion inicial
        lbFEN = Controles.LB(self, _("Initial position") + ": ")
        self.fen = torneo.fen()
        self.btPosicion = Controles.PB(self, " " * 5 + _("Change") + " " * 5,
                                       self.posicionEditar).ponPlano(False)
        self.btPosicionQuitar = Controles.PB(
            self, "", self.posicionQuitar).ponIcono(Iconos.Motor_No())
        self.btPosicionPegar = (Controles.PB(self, "",
                                             self.posicionPegar).ponIcono(
                                                 Iconos.Pegar16()).ponToolTip(
                                                     _("Paste FEN position")))
        lyFEN = (Colocacion.H().control(self.btPosicionQuitar).control(
            self.btPosicion).control(self.btPosicionPegar).relleno())

        # Norman Pollock
        lbNorman = Controles.LB(
            self,
            '%s(<a href="https://komodochess.com/pub/40H-pgn-utilities">?</a>): '
            % _("Initial position from Norman Pollock openings database"),
        )
        self.chbNorman = Controles.CHB(self, " ", self.torneo.norman())

        # Layout
        layout = Colocacion.G()
        ly_res = Colocacion.H().control(
            self.ed_resign).control(bt_resign).relleno()
        ly_dra = Colocacion.H().control(
            self.ed_draw_range).control(bt_draw_range).relleno()
        layout.controld(lb_resign, 0, 0).otro(ly_res, 0, 1)
        layout.controld(lbDrawMinPly, 1, 0).control(self.sbDrawMinPly, 1, 1)
        layout.controld(lb_draw_range, 2, 0).otro(ly_dra, 2, 1)
        layout.controld(lbBook, 3, 0).otro(lyBook, 3, 1)
        layout.controld(lbBookDepth, 4, 0).control(self.sbBookDepth, 4, 1)
        layout.controld(lbFEN, 5, 0).otro(lyFEN, 5, 1)
        layout.controld(lbNorman, 6, 0).control(self.chbNorman, 6, 1)
        layoutV = Colocacion.V().relleno().otro(layout).control(
            self.gbJ).relleno()
        layoutH = Colocacion.H().relleno().otro(layoutV).relleno()

        # Creamos
        w.setLayout(layoutH)
        tab.nuevaTab(w, _("Configuration"))

        # Tab-engines --------------------------------------------------
        self.splitterEngines = QtWidgets.QSplitter(self)
        self.register_splitter(self.splitterEngines, "engines")
        # TB
        li_acciones = [
            (_("New"), Iconos.TutorialesCrear(), self.enNuevo),
            None,
            (_("Modify"), Iconos.Modificar(), self.enModificar),
            None,
            (_("Remove"), Iconos.Borrar(), self.enBorrar),
            None,
            (_("Copy"), Iconos.Copiar(), self.enCopiar),
            None,
            (_("Import"), Iconos.MasDoc(), self.enImportar),
            None,
        ]
        tbEnA = Controles.TBrutina(self,
                                   li_acciones,
                                   tamIcon=16,
                                   style=QtCore.Qt.ToolButtonTextBesideIcon)

        # Grid engine
        o_columns = Columnas.ListaColumnas()
        o_columns.nueva("NUM", _("N."), 50, centered=True)
        o_columns.nueva("ALIAS", _("Alias"), 209)
        self.gridEnginesAlias = Grid.Grid(self,
                                          o_columns,
                                          siSelecFilas=True,
                                          siSeleccionMultiple=True,
                                          xid=GRID_ALIAS)
        self.register_grid(self.gridEnginesAlias)

        w = QtWidgets.QWidget()
        ly = Colocacion.V().control(self.gridEnginesAlias).margen(0)
        w.setLayout(ly)
        self.splitterEngines.addWidget(w)

        o_columns = Columnas.ListaColumnas()
        o_columns.nueva("CAMPO", _("Label"), 200, siDerecha=True)
        o_columns.nueva("VALOR", _("Value"), 286)
        self.gridEnginesValores = Grid.Grid(self,
                                            o_columns,
                                            siSelecFilas=False,
                                            xid=GRID_VALUES)
        self.register_grid(self.gridEnginesValores)

        w = QtWidgets.QWidget()
        ly = Colocacion.V().control(self.gridEnginesValores).margen(0)
        w.setLayout(ly)
        self.splitterEngines.addWidget(w)

        self.splitterEngines.setSizes([250, 520])  # por defecto

        w = QtWidgets.QWidget()
        ly = Colocacion.V().control(tbEnA).control(self.splitterEngines)
        w.setLayout(ly)
        tab.nuevaTab(w, _("Engines"))

        # Creamos

        # Tab-games queued--------------------------------------------------
        w = QtWidgets.QWidget()
        # TB
        li_acciones = [
            (_("New"), Iconos.TutorialesCrear(), self.gm_crear_queued),
            None,
            (_("Remove"), Iconos.Borrar(), self.gm_borrar_queued),
            None,
        ]
        tbEnG = Controles.TBrutina(self,
                                   li_acciones,
                                   tamIcon=16,
                                   style=QtCore.Qt.ToolButtonTextBesideIcon)

        o_columns = Columnas.ListaColumnas()
        o_columns.nueva("NUM", _("N."), 50, centered=True)
        o_columns.nueva("WHITE", _("White"), 190, centered=True)
        o_columns.nueva("BLACK", _("Black"), 190, centered=True)
        o_columns.nueva("TIME", _("Time"), 170, centered=True)
        # o_columns.nueva("STATE", _("State"), 190, centered=True)
        self.gridGamesQueued = Grid.Grid(self,
                                         o_columns,
                                         siSelecFilas=True,
                                         siSeleccionMultiple=True,
                                         xid=GRID_GAMES_QUEUED)
        self.register_grid(self.gridGamesQueued)
        # Layout
        layout = Colocacion.V().control(tbEnG).control(self.gridGamesQueued)

        # Creamos
        w.setLayout(layout)
        tab.nuevaTab(w, _("Games queued"))

        # Tab-games terminados--------------------------------------------------
        w = QtWidgets.QWidget()
        # TB
        li_acciones = [
            (_("Remove"), Iconos.Borrar(), self.gm_borrar_finished),
            None,
            (_("Show"), Iconos.PGN(), self.gm_show_finished),
            None,
            (_("Save") + "(%s)" % _("PGN"), Iconos.GrabarComo(),
             self.gm_save_pgn),
            None,
        ]
        tbEnGt = Controles.TBrutina(self,
                                    li_acciones,
                                    tamIcon=16,
                                    style=QtCore.Qt.ToolButtonTextBesideIcon)

        o_columns = Columnas.ListaColumnas()
        o_columns.nueva("NUM", _("N."), 50, centered=True)
        o_columns.nueva("WHITE", _("White"), 190, centered=True)
        o_columns.nueva("BLACK", _("Black"), 190, centered=True)
        o_columns.nueva("TIME", _("Time"), 170, centered=True)
        o_columns.nueva("RESULT", _("Result"), 190, centered=True)
        self.gridGamesFinished = Grid.Grid(self,
                                           o_columns,
                                           siSelecFilas=True,
                                           siSeleccionMultiple=True,
                                           xid=GRID_GAMES_FINISHED)
        self.register_grid(self.gridGamesFinished)
        # Layout
        layout = Colocacion.V().control(tbEnGt).control(self.gridGamesFinished)

        # Creamos
        w.setLayout(layout)
        tab.nuevaTab(w, _("Games finished"))

        # Tab-resultado --------------------------------------------------
        w = QtWidgets.QWidget()

        # Grid
        wh = _("W")
        bl = _("B")
        o_columns = Columnas.ListaColumnas()
        o_columns.nueva("NUM", _("N."), 35, centered=True)
        o_columns.nueva("ENGINE", _("Engine"), 120, centered=True)
        o_columns.nueva("SCORE", _("Score") + "%", 50, centered=True)
        o_columns.nueva("WIN", _("Wins"), 50, centered=True)
        o_columns.nueva("DRAW", _("Draws"), 50, centered=True)
        o_columns.nueva("LOST", _("Losses"), 50, centered=True)
        o_columns.nueva("WIN-WHITE",
                        "%s %s" % (wh, _("Wins")),
                        60,
                        centered=True)
        o_columns.nueva("DRAW-WHITE",
                        "%s %s" % (wh, _("Draws")),
                        60,
                        centered=True)
        o_columns.nueva("LOST-WHITE",
                        "%s %s" % (wh, _("Losses")),
                        60,
                        centered=True)
        o_columns.nueva("WIN-BLACK",
                        "%s %s" % (bl, _("Wins")),
                        60,
                        centered=True)
        o_columns.nueva("DRAW-BLACK",
                        "%s %s" % (bl, _("Draws")),
                        60,
                        centered=True)
        o_columns.nueva("LOST-BLACK",
                        "%s %s" % (bl, _("Losses")),
                        60,
                        centered=True)
        o_columns.nueva("GAMES", _("Games"), 50, centered=True)
        self.gridResults = Grid.Grid(self,
                                     o_columns,
                                     siSelecFilas=True,
                                     xid=GRID_RESULTS)
        self.register_grid(self.gridResults)

        self.qtColor = {
            "WHITE": QTUtil.qtColorRGB(255, 250, 227),
            "BLACK": QTUtil.qtColorRGB(221, 255, 221),
            "SCORE": QTUtil.qtColorRGB(170, 170, 170),
        }

        # Layout
        layout = Colocacion.V().control(self.gridResults)

        # Creamos
        w.setLayout(layout)
        tab.nuevaTab(w, _("Results"))

        # Layout
        # tab.setposition("W")
        layout = Colocacion.V().control(tb).espacio(-3).control(tab).margen(2)
        self.setLayout(layout)

        self.restore_video(siTam=True, anchoDefecto=800, altoDefecto=430)

        self.gridEnginesAlias.gotop()

        self.ed_resign.setFocus()

        self.muestraPosicion()

        QtCore.QTimer.singleShot(5000, self.comprueba_cambios)
        self.rotulos_tabs()