Example #1
0
 def importar(self):
     if importar_gm(self):
         liC = GM.lista_gm()
         self.cbGM.clear()
         for tp in liC:
             self.cbGM.addItem(tp[0], tp[1])
         self.cbGM.setCurrentIndex(0)
Example #2
0
    def __init__(self, procesador):
        self.configuracion = procesador.configuracion
        self.procesador = procesador

        self.dbHisto = UtilSQL.DictSQL(self.configuracion.ficheroGMhisto)
        self.bloqueApertura = None
        self.liAperturasFavoritas = []

        wParent = procesador.main_window
        titulo = _("Play like a Grandmaster")
        icono = Iconos.GranMaestro()

        extparam = "gm"
        QTVarios.WDialogo.__init__(self, wParent, titulo, icono, extparam)

        flb = Controles.TipoLetra(puntos=10)

        # Toolbar
        li_acciones = [
            (_("Accept"), Iconos.Aceptar(), self.aceptar),
            None,
            (_("Cancel"), Iconos.Cancelar(), self.cancelar),
            None,
            (_("One game"), Iconos.Uno(), self.unJuego),
            None,
            (_("Import"), Iconos.ImportarGM(), self.importar),
        ]
        tb = Controles.TBrutina(self, li_acciones)

        # Grandes maestros
        self.liGM = GM.lista_gm()
        li = [(x[0], x[1]) for x in self.liGM]
        li.insert(0, ("-", None))
        self.cbGM = QTUtil2.comboBoxLB(
            self, li, li[0][1] if len(self.liGM) == 0 else li[1][1])
        self.cbGM.capturaCambiado(self.compruebaGM)
        hbox = Colocacion.H().relleno().control(self.cbGM).relleno()
        gbGM = Controles.GB(self, _("Choose a Grandmaster"),
                            hbox).ponFuente(flb)

        # Personales
        self.liPersonal = GM.lista_gm_personal(
            self.procesador.configuracion.dirPersonalTraining)
        if self.liPersonal:
            li = [(x[0], x[1]) for x in self.liPersonal]
            li.insert(0, ("-", None))
            self.cbPersonal = QTUtil2.comboBoxLB(self, li, li[0][1])
            self.cbPersonal.capturaCambiado(self.compruebaP)
            btBorrar = Controles.PB(self, "", self.borrarPersonal,
                                    plano=False).ponIcono(Iconos.Borrar(),
                                                          tamIcon=16)
            hbox = Colocacion.H().relleno().control(
                self.cbPersonal).control(btBorrar).relleno()
            gbPersonal = Controles.GB(self, _("Personal games"),
                                      hbox).ponFuente(flb)

        # Color
        self.rbBlancas = Controles.RB(self,
                                      _("White"),
                                      rutina=self.check_color)
        self.rbBlancas.activa(True)
        self.rbNegras = Controles.RB(self, _("Black"), rutina=self.check_color)
        self.rbNegras.activa(False)

        # Contrario
        self.chContrario = Controles.CHB(
            self,
            _("Choose the opponent's move, when there are multiple possible answers"
              ), False)

        # Juez
        liDepths = [("--", 0)]
        for x in range(1, 31):
            liDepths.append((str(x), x))
        self.liMotores = self.configuracion.comboMotoresMultiPV10()
        self.cbJmotor, self.lbJmotor = QTUtil2.comboBoxLB(
            self, self.liMotores, self.configuracion.tutor_inicial,
            _("Engine"))
        self.edJtiempo = Controles.ED(self).tipoFloat().ponFloat(
            1.0).anchoFijo(50)
        self.lbJtiempo = Controles.LB2P(self, _("Time in seconds"))
        self.cbJdepth = Controles.CB(self, liDepths,
                                     0).capturaCambiado(self.cambiadoDepth)
        self.lbJdepth = Controles.LB2P(self, _("Depth"))
        self.lbJshow = Controles.LB2P(self, _("Show rating"))
        self.chbEvals = Controles.CHB(self, _("Show all evaluations"), False)
        liOptions = [(_("All moves"), None), (_("Moves are different"), True),
                     (_("Never"), False)]
        self.cbJshow = Controles.CB(self, liOptions, True)
        self.lbJmultiPV = Controles.LB2P(
            self, _("Number of moves evaluated by engine(MultiPV)"))
        li = [(_("Default"), "PD"), (_("Maximum"), "MX")]
        for x in (1, 3, 5, 10, 15, 20, 30, 40, 50, 75, 100, 150, 200):
            li.append((str(x), str(x)))
        self.cbJmultiPV = Controles.CB(self, li, "PD")

        # Inicial
        self.edJugInicial, lbInicial = QTUtil2.spinBoxLB(
            self, 1, 1, 99, etiqueta=_("Initial move"), maxTam=40)

        # Libros
        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) for x in self.listaLibros.lista]
        li.insert(0, ("--", None))
        self.cbBooks, lbBooks = QTUtil2.comboBoxLB(
            self, li, None, _("Bypass moves in the book"))

        # Aperturas

        self.btApertura = Controles.PB(self,
                                       " " * 5 + _("Undetermined") + " " * 5,
                                       self.aperturasEditar).ponPlano(False)
        self.btAperturasFavoritas = Controles.PB(
            self, "", self.aperturasFavoritas).ponIcono(Iconos.Favoritos())
        self.btAperturasQuitar = Controles.PB(
            self, "", self.aperturasQuitar).ponIcono(Iconos.Motor_No())
        hbox = (Colocacion.H().control(self.btAperturasQuitar).control(
            self.btApertura).control(self.btAperturasFavoritas).relleno())
        gbOpening = Controles.GB(self, _("Opening"), hbox)

        # gbBasic
        # # Color
        hbox = Colocacion.H().relleno().control(
            self.rbBlancas).espacio(10).control(self.rbNegras).relleno()
        gbColor = Controles.GB(self, _("Play with"), hbox).ponFuente(flb)

        # Tiempo
        ly1 = (Colocacion.H().control(self.lbJmotor).control(
            self.cbJmotor).control(self.lbJshow).control(
                self.cbJshow).relleno())
        ly2 = Colocacion.H().control(self.lbJtiempo).control(self.edJtiempo)
        ly2.control(self.lbJdepth).control(self.cbJdepth).espacio(15).control(
            self.chbEvals).relleno()
        ly3 = Colocacion.H().control(self.lbJmultiPV).control(
            self.cbJmultiPV).relleno()
        ly = Colocacion.V().otro(ly1).otro(ly2).otro(ly3)
        self.gbJ = Controles.GB(self, _("Adjudicator"),
                                ly).conectar(self.cambiaJuez)

        # Opciones
        vlayout = Colocacion.V().control(gbColor)
        vlayout.espacio(5).control(self.gbJ)
        vlayout.margen(20)
        gbBasic = Controles.GB(self, "", vlayout)
        gbBasic.setFlat(True)

        # Opciones avanzadas
        lyInicial = (Colocacion.H().control(lbInicial).control(
            self.edJugInicial).relleno().control(lbBooks).control(
                self.cbBooks).relleno())
        vlayout = Colocacion.V().relleno().otro(lyInicial).control(gbOpening)
        vlayout.espacio(5).control(self.chContrario).margen(20).relleno()
        gbAdvanced = Controles.GB(self, "", vlayout)
        gbAdvanced.setFlat(True)

        # Historico
        self.liHisto = []
        o_columns = Columnas.ListaColumnas()
        o_columns.nueva("FECHA", _("Date"), 80, centered=True)
        o_columns.nueva("PACIERTOS", _("Hints"), 90, centered=True)
        o_columns.nueva("PUNTOS", _("Points accumulated"), 120, centered=True)
        o_columns.nueva("ENGINE", _("Adjudicator"), 100, centered=True)
        o_columns.nueva("RESUMEN", _("Game played"), 150)

        self.grid = grid = Grid.Grid(self,
                                     o_columns,
                                     siSelecFilas=True,
                                     background=None)
        self.grid.coloresAlternados()
        self.register_grid(grid)

        # Tabs
        self.tab = Controles.Tab().setposition("S")
        self.tab.nuevaTab(gbBasic, _("Basic"))
        self.tab.nuevaTab(gbAdvanced, _("Advanced"))
        self.tab.nuevaTab(self.grid, _("Track record"))

        # Cabecera
        lyCab = Colocacion.H().control(gbGM)
        if self.liPersonal:
            lyCab.control(gbPersonal)

        layout = Colocacion.V().control(tb).otro(lyCab).control(
            self.tab).margen(6)

        self.setLayout(layout)

        self.recuperaDic()
        self.cambiaJuez()
        self.compruebaGM()
        self.compruebaP()
        self.compruebaHisto()
        self.aperturaMuestra()
        self.btAperturasFavoritas.hide()

        self.restore_video(anchoDefecto=450)