Exemplo n.º 1
0
def gestorWashing(procesador):
    dbwashing = Washing.DBWashing(procesador.configuracion)
    washing = dbwashing.washing
    engine = washing.lastEngine(procesador.configuracion)
    if engine.state == Washing.CREATING:
        procesador.gestor = GestorWashingCreate(procesador)
        procesador.gestor.inicio(dbwashing, washing, engine)

    elif engine.state == Washing.TACTICS:
        procesador.gestor = GestorWashingTactics(procesador)
        procesador.gestor.inicio(dbwashing, washing, engine)

    elif engine.state == Washing.REPLAY:
        procesador.gestor = GestorWashingReplay(procesador)
        procesador.gestor.inicio(dbwashing, washing, engine)
def managerWashing(procesador):
    dbwashing = Washing.DBWashing(procesador.configuration)
    washing = dbwashing.washing
    engine = washing.last_engine(procesador.configuration)
    if engine.state == Washing.CREATING:
        procesador.manager = ManagerWashingCreate(procesador)
        procesador.manager.start(dbwashing, washing, engine)

    elif engine.state == Washing.TACTICS:
        procesador.manager = ManagerWashingTactics(procesador)
        procesador.manager.start(dbwashing, washing, engine)

    elif engine.state == Washing.REPLAY:
        procesador.manager = ManagerWashingReplay(procesador)
        procesador.manager.start(dbwashing, washing, engine)
Exemplo n.º 3
0
    def __init__(self, procesador):

        self.procesador = procesador
        self.configuracion = procesador.configuracion

        self.siPlay = False
        self.wreload = False

        self.dbwashing = Washing.DBWashing(procesador.configuracion)
        self.washing = self.dbwashing.washing
        eng = self.washing.lastEngine(procesador.configuracion)
        siTerminado = eng is None

        owner = procesador.pantalla
        titulo = _("The Washing Machine")
        extparam = "washing"
        icono = Iconos.WashingMachine()
        QTVarios.WDialogo.__init__(self, owner, titulo, icono, extparam)

        # Toolbar
        tb = QTVarios.LCTB(self)
        tb.new(_("Close"), Iconos.MainMenu(), self.terminar)
        tb.new(_("File"), Iconos.Recuperar(), self.file)
        if not siTerminado:
            tb.new(_("Play"), Iconos.Play(), self.play)

        # Tab current
        ia = self.washing.index_average()

        c_create = "#f9e7e7"
        c_tactics = "#df8f87"
        c_reinit = "#8aa678"
        c_des = "#e4e4e4"
        c_hab = "#9dde67"
        c_act = "#dd2a2b"
        c_ia = "#cccdea"

        li_ia = ("#ffed00", "#ff8e00", "#29b41b", "#1174ff", "#bc01d9",
                 "#eb0000")
        d_ia = li_ia[int(eng.index() / (100.0 / 6.0)) % 6]
        state = eng.state
        wsvg = QtSvg.QSvgWidget()
        with open("IntFiles/washing-machine.svg") as f:
            svg = f.read()
            d_create = c_des
            d_tactics = c_des
            d_reinit = c_des
            ctac = ""
            if state == Washing.CREATING:
                d_create = c_act
            elif state == Washing.REPLAY:
                d_create = c_hab
                d_tactics = c_hab
                d_reinit = c_act
            elif state == Washing.TACTICS:
                d_create = c_hab
                d_tactics = c_act
                ctac = str(eng.numTactics())
            svg = svg.replace(c_create, d_create)
            svg = svg.replace(c_tactics, d_tactics)
            svg = svg.replace(c_reinit, d_reinit)
            svg = svg.replace("TAC", ctac)
            svg = svg.replace(c_ia, d_ia)
            wsvg.load(QtCore.QByteArray(svg))
        p = 1.0
        wsvg.setFixedSize(287.79 * p, 398.83 * p)

        if siTerminado:
            plant = "<tr><td align=\"right\">%s:</td><td><b>%s</b></td></tr>"
            hints, times, games = self.washing.totals()
            nEngines = self.washing.numEngines()
            html = '<h2><center>%s: %d %s</center></h2><br><table cellpadding="4">' % (
                _("Finished"), nEngines, _("engines"))
            for x in range(3):
                html += plant
            html += "</table>"

            html = html % (
                _("Hints"),
                "%d (%0.02f)" % (hints, hints * 1.0 / nEngines),
                _("Games"),
                "%d (%0.02f)" % (games, games * 1.0 / nEngines),
                _("Time"),
                "%s (%s)" %
                (Util.secs2str(times), Util.secs2str(int(times / nEngines))),
            )

        else:
            plant = "<tr><td align=\"right\">%s:</td><td><b>%s</b></td></tr>"
            plantverde = "<tr><td align=\"right\">%s:</td><td style=\"color:green;\"><b>%s</b></td></tr>"
            html = "<h2><center>%s %d/%d</center></h2><br><table cellpadding=\"4\">"
            for x in range(8):
                html += plantverde if x == 2 else plant
            html += "</table>"
            html = html % (
                _("Washing"),
                self.washing.numEngines(),
                self.washing.totalEngines(procesador.configuracion),
                _("Engine"),
                eng.nombre,
                _("Elo"),
                eng.elo,
                "<b>%s</b>" % _("Task"),
                eng.lbState(),
                _("Color"),
                _("White") if eng.color else _("Black"),
                _("Hints"),
                "%d/%d" % (eng.hints_current, eng.hints),
                _("Games"),
                eng.games,
                _("Time"),
                eng.lbTime(),
                _("Index"),
                eng.cindex(),
            )

        lbTxt = Controles.LB(self, html).ponTipoLetra(puntos=12)
        lbIdx = Controles.LB(self, "%0.2f%%" % ia).alinCentrado().ponTipoLetra(
            puntos=36, peso=700)

        ly0 = Colocacion.V().control(wsvg).relleno(1)
        ly1 = Colocacion.V().espacio(20).control(lbTxt).espacio(20).control(
            lbIdx).relleno(1)
        ly2 = Colocacion.H().otro(ly0).otro(ly1)
        gbCurrent = Controles.GB(self, "", ly2)

        # Lista
        oColumnas = Columnas.ListaColumnas()
        oColumnas.nueva("STEP", _("Washing"), 50, siCentrado=True)
        oColumnas.nueva("ENGINE", _("Engine"), 170, siCentrado=True)
        oColumnas.nueva("ELO", _("Elo"), 50, siCentrado=True)
        oColumnas.nueva("COLOR", _("Color"), 70, siCentrado=True)
        oColumnas.nueva("STATE", _("State"), 90, siCentrado=True)
        oColumnas.nueva("HINTS", _("Hints"), 60, siCentrado=True)
        oColumnas.nueva("GAMES", _("Games"), 60, siCentrado=True)
        oColumnas.nueva("TIME", _("Time"), 60, siCentrado=True)
        oColumnas.nueva("DATE", _("Date"), 120, siCentrado=True)
        oColumnas.nueva("INDEX", _("Index"), 60, siCentrado=True)

        self.grid = grid = Grid.Grid(self, oColumnas, siSelecFilas=True)
        nAnchoPgn = self.grid.anchoColumnas() + 20
        self.grid.setMinimumWidth(nAnchoPgn)
        self.registrarGrid(grid)

        ly0 = Colocacion.V().control(self.grid)
        gbDatos = Controles.GB(self, "", ly0)

        self.tab = Controles.Tab()
        self.tab.nuevaTab(gbCurrent, _("Current"))
        self.tab.nuevaTab(gbDatos, _("Data"))

        # Colocamos ---------------------------------------------------------------
        ly = Colocacion.V().control(tb).control(self.tab)
        self.setLayout(ly)

        self.recuperarVideo(siTam=True, anchoDefecto=nAnchoPgn)