Beispiel #1
0
    def __init__(self, game_engine):

        super(ChessScene, self).__init__()

        #board
        self.board = BoardWidget()
        self.addItem(self.board)

        #moves
        self.moves = MovesWidget(self.board, game_engine)
        self.board.boardChanged.connect(self.moves.resetEngine)
        self.addItem(self.moves)

        #fen
        self.addItem(self.board.fen)

        self.moves.setPos(0, 0)
        size = self.moves.preferredSize()
        self.board.setPos(0, size.height())

        #opening_table
        #self.opening_table = OpeningTable()
        #self.move_table.moveMade.connect(self.opening_table.onMoveMade)

        #game engine
        self.setEngine(game_engine)
        self.newGame()

        #actions
        actions = [
            Action(self, "Play", settings.keys['mode_play'], tr("play game"), self.onShowMoves, 'media-playback-start'),
            Action(self, "Edit", settings.keys['mode_edit'], tr("set board position"), self.onShowPallete, 'document-open')
        ]
        #FIXME
        #self.addActions(actions)

        play, edit = [a.graphics_button for a in actions]
        self.addItem(play)
        self.addItem(edit)
        rect = self.board.squares.boundingRect()
        play.setPos(rect.width(), 0)
        edit.setPos(rect.width() + play.size().width(), 0)
        self.onShowMoves()
Beispiel #2
0
class ChessScene(QtGui.QGraphicsScene):

    def __init__(self, game_engine):

        super(ChessScene, self).__init__()

        #board
        self.board = BoardWidget()
        self.addItem(self.board)

        #moves
        self.moves = MovesWidget(self.board, game_engine)
        self.board.boardChanged.connect(self.moves.resetEngine)
        self.addItem(self.moves)

        #fen
        self.addItem(self.board.fen)

        self.moves.setPos(0, 0)
        size = self.moves.preferredSize()
        self.board.setPos(0, size.height())

        #opening_table
        #self.opening_table = OpeningTable()
        #self.move_table.moveMade.connect(self.opening_table.onMoveMade)

        #game engine
        self.setEngine(game_engine)
        self.newGame()

        #actions
        actions = [
            Action(self, "Play", settings.keys['mode_play'], tr("play game"), self.onShowMoves, 'media-playback-start'),
            Action(self, "Edit", settings.keys['mode_edit'], tr("set board position"), self.onShowPallete, 'document-open')
        ]
        #FIXME
        #self.addActions(actions)

        play, edit = [a.graphics_button for a in actions]
        self.addItem(play)
        self.addItem(edit)
        rect = self.board.squares.boundingRect()
        play.setPos(rect.width(), 0)
        edit.setPos(rect.width() + play.size().width(), 0)
        self.onShowMoves()

    def onShowMoves(self):
        self.board.setEditable(False)
        self.moves.setEnabled(True)

    def onShowPallete(self):
        self.board.setEditable(True)
        self.moves.setEnabled(False)

    def moveCursor(self, direction):
        self.board.moveCursor(direction)

    def cursorSelect(self):
        self.board.cursorSelect()

    def loadGame(self, moves):
        position = self.moves.loadGame(moves)
        self.moves.first()

    def newGame(self):
        self.moves.newGame()

    def setEngine(self, game_engine):
        self.moves.setEngine(game_engine)
    

    def onVariationSelected(self, from_square, to_square, subject, target):
        
        # go back on move
        last_move = self.moves_table.previousMove()
        self.setMove(last_move)
        self.moves_table.onMoveMade(last_move)

        # set the new move
        self.onNewMove(from_square, to_square, subject, target)