def onPublished(worker, vallist):
        for val in vallist:
            # The worker will start by publishing (gmwidg, game)
            if type(val) == tuple:
                gmwidg, game = val
                gamewidget.attachGameWidget(gmwidg)
                gamenanny.nurseGame(gmwidg, game)
                handler.emit("gmwidg_created", gmwidg, game)

            # Then the worker will publish functions setting up widget stuff
            elif callable(val):
                val()
Example #2
0
    def onPublished (worker, vallist):
        for val in vallist:
            # The worker will start by publishing (gmwidg, game)
            if type(val) == tuple:
                gmwidg, game = val
                gamewidget.attachGameWidget(gmwidg)
                gamenanny.nurseGame(gmwidg, game)
                handler.emit("gmwidg_created", gmwidg, game)

            # Then the worker will publish functions setting up widget stuff
            elif callable(val):
                val()
Example #3
0
    def onPublished (worker, vallist):
        for val in vallist:
            # The worker will start by publishing (gmwidg, game)
            if isinstance(val, tuple):
                gmwidg, game = val
                gamewidget.attachGameWidget(gmwidg)
                gamenanny.nurseGame(gmwidg, game)
                log.debug("onPublished: -> emit gmwidg_created: %s" % (gmwidg))
                handler.emit("gmwidg_created", gmwidg, game)
                log.debug("onPublished: <- emit gmwidg_created: %s" % (gmwidg))

            # Then the worker will publish functions setting up widget stuff
            elif callable(val):
                val()
Example #4
0
    def onPublished(worker, vallist):
        for val in vallist:
            # The worker will start by publishing (gmwidg, game)
            if isinstance(val, tuple):
                gmwidg, game = val
                gamewidget.attachGameWidget(gmwidg)
                gamenanny.nurseGame(gmwidg, game)
                log.debug("onPublished: -> emit gmwidg_created: %s" % (gmwidg))
                handler.emit("gmwidg_created", gmwidg, game)
                log.debug("onPublished: <- emit gmwidg_created: %s" % (gmwidg))

            # Then the worker will publish functions setting up widget stuff
            elif callable(val):
                val()
Example #5
0
def generalStart(gamemodel, player0tup, player1tup, loaddata=None):
    """ The player tuples are:
        (The type af player in a System.const value,
         A callable creating the player,
         A list of arguments for the callable,
         A preliminary name for the player)

        If loaddata is specified, it should be a tuple of:
        (A text uri or fileobj,
         A Savers.something module with a load function capable of loading it,
         An int of the game in file you want to load,
         The position from where to start the game) """
    log.debug("ionest.generalStart: %s\n %s\n %s" %
              (gamemodel, player0tup, player1tup))

    gmwidg = gamewidget.GameWidget(gamemodel)
    gmwidg.connect("close_clicked", closeGame, gamemodel)

    #worker.publish((gmwidg,gamemodel))
    gamewidget.attachGameWidget(gmwidg)
    gamenanny.nurseGame(gmwidg, gamemodel)
    log.debug("ionest.generalStart: -> emit gmwidg_created: %s" % (gmwidg))
    handler.emit("gmwidg_created", gmwidg, gamemodel)
    log.debug("ionest.generalStart: <- emit gmwidg_created: %s" % (gmwidg))

    # Initing players
    players = []
    for i, playertup in enumerate((player0tup, player1tup)):
        type, func, args, prename = playertup
        if type != LOCAL:
            players.append(func(*args))
            #if type == ARTIFICIAL:
            #    def readyformoves (player, color):
            #        gmwidg.setTabText(gmwidg.display_text))
            #    players[i].connect("readyForMoves", readyformoves, i)
        else:
            # Until PyChess has a proper profiles system, as discussed on the
            # issue tracker, we need to give human players special treatment
            player = func(gmwidg, *args)
            players.append(player)

            # Connect to conf
            if i == 0 or (i == 1 and player0tup[0] != LOCAL):
                key = "firstName"
                alt = _("You")
            else:
                key = "secondName"
                alt = _("Guest")
            if prename == conf.get(key, alt):
                conf.notify_add(key,
                                lambda *a: player.setName(conf.get(key, alt)))

    if player0tup[0] == ARTIFICIAL and player1tup[0] == ARTIFICIAL:

        def emit_action(action, param):
            if gmwidg.isInFront():
                gamemodel.curplayer.emit("offer", Offer(action, param=param))

        gmwidg.board.connect(
            "action", lambda b, action, param: emit_action(action, param))

    log.debug("ionest.generalStart: -> gamemodel.setPlayers(): %s" %
              (gamemodel))
    gamemodel.setPlayers(players)
    log.debug("ionest.generalStart: <- gamemodel.setPlayers(): %s" %
              (gamemodel))

    # Starting
    if loaddata:
        try:
            uri, loader, gameno, position = loaddata
            gamemodel.loadAndStart(uri, loader, gameno, position)
        except LoadingError as e:
            d = Gtk.MessageDialog(type=Gtk.MessageType.WARNING,
                                  buttons=Gtk.ButtonsType.OK)
            d.set_markup(_("<big><b>Error loading game</big></b>"))
            d.format_secondary_text(", ".join(str(a) for a in e.args))
            d.show()
            d.hide()

    else:
        if gamemodel.variant.need_initial_board:
            for player in gamemodel.players:
                player.setOptionInitialBoard(gamemodel)
        log.debug("ionest..generalStart: -> gamemodel.start(): %s" %
                  (gamemodel))
        gamemodel.start()
        log.debug("ionest.generalStart: <- gamemodel.start(): %s" %
                  (gamemodel))

    log.debug("ionest.generalStart: returning gmwidg=%s\n gamemodel=%s" % \
        (gmwidg, gamemodel))
    return gmwidg, gamemodel
Example #6
0
def generalStart (gamemodel, player0tup, player1tup, loaddata=None):
    """ The player tuples are:
    (The type af player in a System.const value,
    A callable creating the player,
    A list of arguments for the callable,
    A preliminary name for the player)

    If loaddata is specified, it should be a tuple of:
    (A text uri or fileobj,
    A Savers.something module with a load function capable of loading it,
    An int of the game in file you want to load,
    The position from where to start the game)
    """

    log.debug("ionest.generalStart: %s\n %s\n %s" % (gamemodel, player0tup, player1tup))

    gmwidg = gamewidget.GameWidget(gamemodel)
    gmwidg.connect("game_close_clicked", closeGame, gamemodel)

    #worker.publish((gmwidg,gamemodel))
    gamewidget.attachGameWidget(gmwidg)
    gamenanny.nurseGame(gmwidg, gamemodel)
    log.debug("ionest.generalStart: -> emit gmwidg_created: %s" % (gmwidg))
    handler.emit("gmwidg_created", gmwidg, gamemodel)
    log.debug("ionest.generalStart: <- emit gmwidg_created: %s" % (gmwidg))

    # Initing players
    players = []
    for i, playertup in enumerate((player0tup, player1tup)):
        type, func, args, prename = playertup
        if type != LOCAL:
            players.append(func(*args))
            #if type == ARTIFICIAL:
            #    def readyformoves (player, color):
            #        gmwidg.setTabText(gmwidg.display_text))
            #    players[i].connect("readyForMoves", readyformoves, i)
        else:
            # Until PyChess has a proper profiles system, as discussed on the
            # issue tracker, we need to give human players special treatment
            player = func(gmwidg, *args)
            players.append(player)

            # Connect to conf
            if i == 0 or (i == 1 and player0tup[0] != LOCAL):
                key = "firstName"
                alt = _("You")
            else:
                key = "secondName"
                alt = _("Guest")
            if prename == conf.get(key, alt):
                conf.notify_add(key, lambda *a:player.setName(conf.get(key,alt)))

    if player0tup[0] == ARTIFICIAL and player1tup[0] == ARTIFICIAL:
        def emit_action (action, param):
            if gmwidg.isInFront():
                gamemodel.curplayer.emit("offer", Offer(action, param=param))
        gmwidg.board.connect("action", lambda b,action,param: emit_action(action, param))

    log.debug("ionest.generalStart: -> gamemodel.setPlayers(): %s" % (gamemodel))
    gamemodel.setPlayers(players)
    log.debug("ionest.generalStart: <- gamemodel.setPlayers(): %s" % (gamemodel))

    # Starting
    if loaddata:
        try:
            uri, loader, gameno, position = loaddata
            gamemodel.loadAndStart (uri, loader, gameno, position)
            if position != gamemodel.ply:
                gmwidg.board.view.shown = position
        except LoadingError as e:
            d = Gtk.MessageDialog (type=Gtk.MessageType.WARNING, buttons=Gtk.ButtonsType.OK)
            d.set_markup(_("<big><b>Error loading game</big></b>"))
            d.format_secondary_text(", ".join(str(a) for a in e.args))
            d.show()
            d.hide()

    else:
        if gamemodel.variant.need_initial_board:
            for player in gamemodel.players:
                player.setOptionInitialBoard(gamemodel)
        log.debug("ionest..generalStart: -> gamemodel.start(): %s" % (gamemodel))
        gamemodel.start()
        log.debug("ionest.generalStart: <- gamemodel.start(): %s" % (gamemodel))

    log.debug("ionest.generalStart: returning gmwidg=%s\n gamemodel=%s" % \
        (gmwidg, gamemodel))
    return gmwidg, gamemodel