Exemple #1
0
    def __init__(self, procesador, titulo, direct_option):

        QTVarios.WDialogo.__init__(self, procesador.main_window, titulo, Iconos.Libre(), "entMaquina")

        font = Controles.TipoLetra(puntos=procesador.configuration.x_menu_points)

        self.direct_option = direct_option

        self.setFont(font)

        self.configuration = procesador.configuration
        self.procesador = procesador

        self.personalidades = Personalities.Personalities(self, self.configuration)

        self.motores = SelectEngines.SelectEngines(self.configuration)

        fvar = self.configuration.file_books
        self.list_books = Books.ListBooks()
        self.list_books.restore_pickle(fvar)
        self.list_books.check()
        li_books = [(x.name, x) for x in self.list_books.lista]

        # Toolbar
        li_acciones = [
            (_("Accept"), Iconos.Aceptar(), self.aceptar),
            None,
            (_("Cancel"), Iconos.Cancelar(), self.cancelar),
            None,
            (_("Configurations"), Iconos.Configurar(), self.configurations),
            None,
        ]
        tb = QTVarios.LCTB(self, li_acciones)

        # Tab
        tab = Controles.Tab()
        tab.dispatchChange(self.cambiada_tab)

        self.tab_advanced = 4  # está en la posición 4
        self.tab_advanced_active = False  # Para no tener que leer las options uci to_sq que no sean necesarias, afecta a gridNumDatos

        def nueva_tab(layout, titulo):
            ly = Colocacion.V()
            ly.otro(layout)
            ly.relleno()
            w = QtWidgets.QWidget(self)
            w.setLayout(ly)
            w.setFont(font)
            tab.nuevaTab(w, titulo)

        def nuevoG():
            ly_g = Colocacion.G()
            ly_g.filaActual = 0
            ly_g.margen(10)
            return ly_g

        gb_style = Common.gb_style()

        def _label(ly_g, txt, xlayout, rutinaCHB=None, siCheck: object = False):
            groupbox = Controles.GB(self, txt, xlayout)
            if rutinaCHB:
                groupbox.to_connect(rutinaCHB)
            elif siCheck:
                groupbox.setCheckable(True)
                groupbox.setChecked(False)

            groupbox.setStyleSheet(gb_style)
            groupbox.setMinimumWidth(640)
            groupbox.setFont(font)
            ly_g.controlc(groupbox, ly_g.filaActual, 0)
            ly_g.filaActual += 1
            return groupbox

        # ##################################################################################################################################
        # TAB General
        # ##################################################################################################################################

        lyG = nuevoG()

        # # Motores

        # ## Rival
        self.rival = self.configuration.x_rival_inicial
        self.rivalTipo = SelectEngines.INTERNO
        self.btRival = Controles.PB(self, "", self.cambiaRival, plano=False).ponFuente(font).altoFijo(48)

        lbTiempoSegundosR = Controles.LB2P(self, _("Fixed time in seconds")).ponFuente(font)
        self.edRtiempo = Controles.ED(self).tipoFloat().anchoMaximo(50).ponFuente(font).capture_changes(self.change_time)
        bt_cancelar_tiempo = Controles.PB(self, "", rutina=self.cancelar_tiempo).ponIcono(Iconos.S_Cancelar())
        ly_tiempo = Colocacion.H().control(self.edRtiempo).control(bt_cancelar_tiempo).relleno(1)

        lb_depth = Controles.LB2P(self, _("Fixed depth")).ponFuente(font)
        self.edRdepth = Controles.ED(self).tipoInt().anchoMaximo(50).ponFuente(font).capture_changes(self.change_depth)
        bt_cancelar_depth = Controles.PB(self, "", rutina=self.cancelar_depth).ponIcono(Iconos.S_Cancelar())
        ly_depth = Colocacion.H().control(self.edRdepth).control(bt_cancelar_depth).relleno(1)

        ly = Colocacion.G()
        ly.controld(lbTiempoSegundosR, 0, 0).otro(ly_tiempo, 0, 1)
        ly.controld(lb_depth, 1, 0).otro(ly_depth, 1, 1)
        self.gb_thinks = Controles.GB(self, _("Limits of engine thinking"), ly)
        self.gb_thinks.setStyleSheet(
            """
            QGroupBox {
                font: bold %d;
                background-color: #F2F2EC;/*qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #E0E0E0, stop: 1 #FFFFFF);*/
                border: 1px solid gray;
                border-radius: 3px;
                padding: 18px;
                margin-top: 5ex; /* leave space at the top for the title */
            }
            QGroupBox::title {
                subcontrol-position: top center; /* position at the top center */
                padding: 8px;
                border: 1px solid gray;
             }
        """
            % procesador.configuration.x_menu_points
        )
        lyV = Colocacion.V().espacio(20).control(self.btRival).espacio(20).control(self.gb_thinks)

        _label(lyG, _("Opponent"), lyV)

        # # Side
        self.rb_white = Controles.RB(self, "").activa()
        self.rb_white.setIcon(Iconos.PeonBlanco())
        self.rb_white.setIconSize(QtCore.QSize(32, 32))
        self.rb_black = Controles.RB(self, "")
        self.rb_black.setIcon(Iconos.PeonNegro())
        self.rb_black.setIconSize(QtCore.QSize(32, 32))
        self.rbRandom = Controles.RB(self, _("Random"))
        self.rbRandom.setFont(Controles.TipoLetra(puntos=14))
        hbox = (
            Colocacion.H().relleno().control(self.rb_white).espacio(30).control(self.rb_black).espacio(30).control(self.rbRandom).relleno()
        )
        _label(lyG, _("Side you play with"), hbox)

        if self.configuration.x_digital_board:
            self.chb_dgt = Controles.CHB(self, "%s: %s" % (_("Activate board"), self.configuration.x_digital_board), DGT.siON()).ponFuente(
                Controles.TipoLetra(puntos=14)
            )
            lyH = Colocacion.H().control(self.chb_dgt)
            _label(lyG, "", lyH)

        nueva_tab(lyG, _("Basic configuration"))

        # ##################################################################################################################################
        # TAB Ayudas
        # ##################################################################################################################################
        self.chbSummary = Controles.CHB(self, _("Save a summary when the game is finished in the main comment"), False).ponFuente(font)

        self.chbTakeback = Controles.CHB(self, _("Option takeback activated"), True).ponFuente(font)

        # # Tutor
        lbAyudas = Controles.LB2P(self, _("Available hints")).ponFuente(font)
        liAyudas = [(_("Maximum"), 999)]
        for i in range(1, 21):
            liAyudas.append((str(i), i))
        for i in range(25, 51, 5):
            liAyudas.append((str(i), i))
        self.cbAyudas = Controles.CB(self, liAyudas, 999).ponFuente(font)
        self.chbChance = Controles.CHB(self, _("Second chance"), True).ponFuente(font)
        btTutorChange = (
            Controles.PB(self, _("Tutor change"), self.tutorChange, plano=False).ponIcono(Iconos.Tutor(), icon_size=16).ponFuente(font)
        )

        liThinks = [(_("Nothing"), -1), (_("Score"), 0)]
        for i in range(1, 5):
            liThinks.append(("%d %s" % (i, _("ply") if i == 1 else _("plies")), i))
        liThinks.append((_("All"), 9999))
        lbThoughtTt = Controles.LB(self, _("It is showed") + ":").ponFuente(font)
        self.cbThoughtTt = Controles.CB(self, liThinks, -1).ponFuente(font)

        lbArrows = Controles.LB2P(self, _("Arrows with the best moves")).ponFuente(font)
        self.sbArrowsTt = Controles.SB(self, 0, 0, 999).tamMaximo(50).ponFuente(font)

        lyT1 = Colocacion.H().control(lbAyudas).control(self.cbAyudas).relleno()
        lyT1.control(self.chbChance).relleno().control(btTutorChange)
        lyT3 = Colocacion.H().control(lbThoughtTt).control(self.cbThoughtTt).relleno()
        lyT3.control(lbArrows).control(self.sbArrowsTt)

        ly = Colocacion.V().otro(lyT1).espacio(16).otro(lyT3).relleno()

        self.gbTutor = Controles.GB(self, _("Activate the tutor's help"), ly)
        self.gbTutor.setCheckable(True)
        self.gbTutor.setStyleSheet(gb_style)

        lb = Controles.LB(self, _("It is showed") + ":").ponFuente(font)
        self.cbThoughtOp = Controles.CB(self, liThinks, -1).ponFuente(font)
        lbArrows = Controles.LB2P(self, _("Arrows to show")).ponFuente(font)
        self.sbArrows = Controles.SB(self, 0, 0, 999).tamMaximo(50).ponFuente(font)
        ly = Colocacion.H().control(lb).control(self.cbThoughtOp).relleno()
        ly.control(lbArrows).control(self.sbArrows)
        gbThoughtOp = Controles.GB(self, _("Opponent's thought information"), ly)
        gbThoughtOp.setStyleSheet(gb_style)

        self.lbBoxHeight = Controles.LB2P(self, '%s ("%s")' % (_("Box height"), _("It is showed"))).ponFuente(font)
        self.sbBoxHeight = Controles.SB(self, 0, 0, 999).tamMaximo(50).ponFuente(font)

        lyBox = Colocacion.H().control(self.lbBoxHeight).control(self.sbBoxHeight).relleno()

        ly = Colocacion.V().espacio(16).control(self.gbTutor).control(gbThoughtOp)
        ly.espacio(16).otro(lyBox).control(self.chbSummary).control(self.chbTakeback).margen(6)

        nueva_tab(ly, _("Help configuration"))

        # ##################################################################################################################################
        # TAB Tiempo
        # ##################################################################################################################################
        lyG = nuevoG()

        self.lbMinutos = Controles.LB(self, _("Total minutes") + ":").ponFuente(font)
        self.edMinutos = Controles.ED(self).tipoFloat(10.0).ponFuente(font).anchoFijo(50)
        self.edSegundos, self.lbSegundos = QTUtil2.spinBoxLB(
            self, 6, -999, 999, maxTam=54, etiqueta=_("Seconds added per move"), fuente=font
        )
        self.edMinExtra, self.lbMinExtra = QTUtil2.spinBoxLB(
            self, 0, -999, 999, maxTam=70, etiqueta=_("Extra minutes for the player"), fuente=font
        )
        self.edZeitnot, self.lbZeitnot = QTUtil2.spinBoxLB(
            self, 0, -999, 999, maxTam=54, etiqueta=_("Zeitnot: alarm sounds when remaining seconds"), fuente=font
        )
        lyH = Colocacion.H()
        lyH.control(self.lbMinutos).control(self.edMinutos).espacio(30)
        lyH.control(self.lbSegundos).control(self.edSegundos).relleno()
        lyH2 = Colocacion.H()
        lyH2.control(self.lbMinExtra).control(self.edMinExtra).relleno()
        lyH3 = Colocacion.H()
        lyH3.control(self.lbZeitnot).control(self.edZeitnot).relleno()
        ly = Colocacion.V().otro(lyH).otro(lyH2).otro(lyH3)
        self.chbTiempo = _label(lyG, _("Activate the time control"), ly, siCheck=True)

        nueva_tab(lyG, _("Time"))

        # ##################################################################################################################################
        # TAB Initial moves
        # ##################################################################################################################################
        lyG = nuevoG()

        # Posicion
        self.btPosicion = Controles.PB(self, " " * 5 + _("Change") + " " * 5, self.posicionEditar).ponPlano(False).ponFuente(font)
        self.fen = ""
        self.btPosicionQuitar = Controles.PB(self, "", self.posicionQuitar).ponIcono(Iconos.Motor_No()).ponFuente(font)
        self.btPosicionPegar = (
            Controles.PB(self, "", self.posicionPegar).ponIcono(Iconos.Pegar16()).ponToolTip(_("Paste FEN position"))
        ).ponFuente(font)
        hbox = Colocacion.H().relleno().control(self.btPosicionQuitar).control(self.btPosicion).control(self.btPosicionPegar).relleno()
        _label(lyG, _("Start position"), hbox)

        # Openings
        self.btOpening = Controles.PB(self, " " * 5 + _("Undetermined") + " " * 5, self.editOpening).ponPlano(False).ponFuente(font)
        self.opening_block = None
        self.btOpeningsFavoritas = Controles.PB(self, "", self.preferred_openings).ponIcono(Iconos.Favoritos())
        self.btOpeningsQuitar = Controles.PB(self, "", self.aperturasQuitar).ponIcono(Iconos.Motor_No())
        hbox = Colocacion.H().relleno().control(self.btOpeningsQuitar).control(self.btOpening).control(self.btOpeningsFavoritas).relleno()
        _label(lyG, _("Opening"), hbox)

        # Libros
        libInicial = li_books[0][1] if li_books else None

        li_resp_book = [
            (_("Selected by the player"), "su"),
            (_("Uniform random"), "au"),
            (_("Proportional random"), "ap"),
            (_("Always the highest percentage"), "mp"),
        ]

        ## Rival
        self.cbBooksR = QTUtil2.comboBoxLB(self, li_books, libInicial).ponFuente(font)
        self.btNuevoBookR = Controles.PB(self, "", self.nuevoBook, plano=True).ponIcono(Iconos.Mas(), icon_size=16)
        self.cbBooksRR = QTUtil2.comboBoxLB(self, li_resp_book, "mp").ponFuente(font)
        self.lbDepthBookR = Controles.LB2P(self, _("Max depth")).ponFuente(font)
        self.edDepthBookR = Controles.ED(self).ponFuente(font).tipoInt(0).anchoFijo(30)

        hbox = (
            Colocacion.H()
            .control(self.cbBooksR)
            .control(self.btNuevoBookR)
            .relleno()
            .control(self.cbBooksRR)
            .relleno()
            .control(self.lbDepthBookR)
            .control(self.edDepthBookR)
        )
        self.chbBookR = _label(lyG, "%s: %s" % (_("Activate book"), _("Opponent")), hbox, siCheck=True)

        ## Player
        self.cbBooksP = QTUtil2.comboBoxLB(self, li_books, libInicial).ponFuente(font)
        self.btNuevoBookP = Controles.PB(self, "", self.nuevoBook, plano=True).ponIcono(Iconos.Mas(), icon_size=16)
        self.lbDepthBookP = Controles.LB2P(self, _("Max depth")).ponFuente(font)
        self.edDepthBookP = Controles.ED(self).ponFuente(font).tipoInt(0).anchoFijo(30)
        hbox = (
            Colocacion.H().control(self.cbBooksP).control(self.btNuevoBookP).relleno().control(self.lbDepthBookP).control(self.edDepthBookP)
        )
        self.chbBookP = _label(lyG, "%s: %s" % (_("Activate book"), self.configuration.nom_player()), hbox, siCheck=True)

        nueva_tab(lyG, _("Initial moves"))

        # ##################################################################################################################################
        # TAB avanzada
        # ##################################################################################################################################
        lyG = nuevoG()

        liAjustes = self.personalidades.listaAjustes(True)
        self.cbAjustarRival = Controles.CB(self, liAjustes, ADJUST_BETTER).capture_changes(self.ajustesCambiado).ponFuente(font)
        lbAjustarRival = Controles.LB2P(self, _("Set strength")).ponFuente(font)
        self.btAjustarRival = (
            Controles.PB(self, _("Personality"), self.cambiaPersonalidades, plano=True).ponIcono(Iconos.Mas(), icon_size=16).ponFuente(font)
        )

        # ## Resign
        lbResign = Controles.LB2P(self, _("Resign/draw by engine")).ponFuente(font)
        liResign = (
            (_("Very early"), -100),
            (_("Early"), -300),
            (_("Average"), -500),
            (_("Late"), -800),
            (_("Very late"), -1000),
            (_("Never"), -9999999),
        )
        self.cbResign = Controles.CB(self, liResign, -800).ponFuente(font)

        self.lb_path_engine = Controles.LB(self, "").set_wrap()

        o_columns = Columnas.ListaColumnas()
        o_columns.nueva("OPTION", _("UCI option"), 240, centered=True)
        o_columns.nueva("VALUE", _("Value"), 200, centered=True, edicion=Delegados.MultiEditor(self))
        self.grid_uci = Grid.Grid(self, o_columns, siEditable=True)
        self.grid_uci.ponFuente(font)
        self.register_grid(self.grid_uci)

        lyH2 = Colocacion.H().control(lbAjustarRival).control(self.cbAjustarRival).control(self.btAjustarRival).relleno()
        lyH3 = Colocacion.H().control(lbResign).control(self.cbResign).relleno()
        ly = Colocacion.V().otro(lyH2).otro(lyH3).espacio(16).control(self.lb_path_engine).control(self.grid_uci)
        _label(lyG, _("Opponent"), ly)

        nueva_tab(lyG, _("Advanced"))

        layout = Colocacion.V().control(tb).control(tab).relleno().margen(3)

        self.setLayout(layout)

        self.li_preferred_openings = []
        self.btOpeningsFavoritas.hide()

        file = self.configuration.ficheroEntMaquina if self.direct_option else self.configuration.ficheroEntMaquinaPlay
        if not os.path.isfile(file):
            file = self.configuration.ficheroEntMaquina
        dic = Util.restore_pickle(file)
        if not dic:
            dic = {}
        self.restore_dic(dic)

        self.ajustesCambiado()
        # self.ayudasCambiado()
        self.ponRival()

        self.restore_video()