コード例 #1
0
ファイル: main.py プロジェクト: mbuechmann/kivy-gol
class GameOfLifeApp(App):

    _board = None
    _population = None


    def build(self):
        self._population = Population(cols=256, rows=256)
        self._board = BoardWidget(width=256, height=256, population = self._population)
        Clock.schedule_interval(self.callback, 0.1)
        return self._board

    def callback(self, dt):
        self._population.evolve() 
        self._board.update_graphics()
コード例 #2
0
    def __init__(self):

        super(ChessGameWidget, self).__init__()

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

        # moves
        game_engine = ChessLibGameEngine()
        self.moves = MovesWidget(self.board, game_engine)
        self.moves.newGame()

        self.fen = self.board.fen.text
        self.fen.setParentItem(self.board)
        self.fen.setPos(0, -40)

        # 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-edit"
            ),
            Action(
                self,
                "Analyze",
                settings.keys["mode_analyze"],
                tr("analyze position"),
                self.onShowAnalyze,
                "games-solve",
            ),
        ]
        self._buttons = [b.graphics_button for b in actions]
        for button in self._buttons:
            button._checkable = True
            button._radio = True
        self.addActions(actions)

        size = self.moves.preferredSize()
        x, y = self.board.squares.size().width() + self.board.spacing, size.height()
        self._pack_actions(self.moves.actions(), x + 10, y + 10, False)

        self.onShowMoves()

        layout = QtGui.QGraphicsLinearLayout()
        buttons = self.getGraphicsButtonLayout()
        layout.addItem(buttons)
        layout.setAlignment(buttons, QtCore.Qt.AlignRight)
        layout.addItem(self.moves)
        layout.addItem(self.board)
        layout.setOrientation(QtCore.Qt.Vertical)
        self.setLayout(layout)
コード例 #3
0
    def __init__(self, parent=None):
        super(Center, self).__init__(parent)
        layout = QVBoxLayout()

        p = self.palette()
        p.setColor(QPalette.Background, QColor(192, 192, 192))
        self.setPalette(p)
        self.setAutoFillBackground(True)

        self.board = BoardWidget(16, 30, 99, parent=self)
        self.top = TopWidget(99, parent=self)

        layout.addWidget(self.top)
        layout.addWidget(self.board)

        self.setLayout(layout)
コード例 #4
0
ファイル: main_window.py プロジェクト: suryansh2020/arimaa
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.setWindowModality(QtCore.Qt.WindowModal)
        MainWindow.resize(894, 592)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
                                       QtGui.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            MainWindow.sizePolicy().hasHeightForWidth())
        MainWindow.setSizePolicy(sizePolicy)
        MainWindow.setMaximumSize(QtCore.QSize(900, 600))
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout_2 = QtGui.QVBoxLayout(self.centralwidget)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.widget_2 = QtGui.QWidget(self.centralwidget)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                                       QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.widget_2.sizePolicy().hasHeightForWidth())
        self.widget_2.setSizePolicy(sizePolicy)
        self.widget_2.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.widget_2.setObjectName("widget_2")
        self.hboxlayout = QtGui.QHBoxLayout(self.widget_2)
        self.hboxlayout.setObjectName("hboxlayout")
        self.board = BoardWidget(self.widget_2)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                                       QtGui.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.board.sizePolicy().hasHeightForWidth())
        self.board.setSizePolicy(sizePolicy)
        self.board.setMaximumSize(QtCore.QSize(700, 700))
        self.board.setObjectName("board")
        self.horizontalLayout = QtGui.QHBoxLayout(self.board)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.hboxlayout.addWidget(self.board)
        self.widget_3 = QtGui.QWidget(self.widget_2)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed,
                                       QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(200)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.widget_3.sizePolicy().hasHeightForWidth())
        self.widget_3.setSizePolicy(sizePolicy)
        self.widget_3.setMaximumSize(QtCore.QSize(300, 16777215))
        self.widget_3.setObjectName("widget_3")
        self.verticalLayout = QtGui.QVBoxLayout(self.widget_3)
        self.verticalLayout.setObjectName("verticalLayout")
        self.record = QtGui.QListWidget(self.widget_3)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
                                       QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(200)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.record.sizePolicy().hasHeightForWidth())
        self.record.setSizePolicy(sizePolicy)
        self.record.setMinimumSize(QtCore.QSize(0, 130))
        self.record.setObjectName("record")
        self.verticalLayout.addWidget(self.record)
        self.widget_4 = QtGui.QWidget(self.widget_3)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
                                       QtGui.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.widget_4.sizePolicy().hasHeightForWidth())
        self.widget_4.setSizePolicy(sizePolicy)
        self.widget_4.setObjectName("widget_4")
        self.horizontalLayout_2 = QtGui.QHBoxLayout(self.widget_4)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.button_back = QtGui.QPushButton(self.widget_4)
        self.button_back.setObjectName("button_back")
        self.horizontalLayout_2.addWidget(self.button_back)
        self.button_forward = QtGui.QPushButton(self.widget_4)
        self.button_forward.setObjectName("button_forward")
        self.horizontalLayout_2.addWidget(self.button_forward)
        self.verticalLayout.addWidget(self.widget_4)
        self.hboxlayout.addWidget(self.widget_3)
        self.verticalLayout_2.addWidget(self.widget_2)
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 894, 27))
        self.menubar.setObjectName("menubar")
        self.menuGame = QtGui.QMenu(self.menubar)
        self.menuGame.setObjectName("menuGame")
        MainWindow.setMenuBar(self.menubar)
        self.actionLoadGame = QtGui.QAction(MainWindow)
        self.actionLoadGame.setObjectName("actionLoadGame")
        self.actionNewGame = QtGui.QAction(MainWindow)
        self.actionNewGame.setObjectName("actionNewGame")
        self.actionExit = QtGui.QAction(MainWindow)
        self.actionExit.setObjectName("actionExit")
        self.actionPlayer_x_player = QtGui.QAction(MainWindow)
        self.actionPlayer_x_player.setObjectName("actionPlayer_x_player")
        self.actionComputer_color = QtGui.QAction(MainWindow)
        self.actionComputer_color.setObjectName("actionComputer_color")
        self.actionNew_bot = QtGui.QAction(MainWindow)
        self.actionNew_bot.setObjectName("actionNew_bot")
        self.actionLoadPosition = QtGui.QAction(MainWindow)
        self.actionLoadPosition.setObjectName("actionLoadPosition")
        self.actionSavePosition = QtGui.QAction(MainWindow)
        self.actionSavePosition.setObjectName("actionSavePosition")
        self.menuGame.addAction(self.actionLoadPosition)
        self.menuGame.addAction(self.actionSavePosition)
        self.menuGame.addAction(self.actionLoadGame)
        self.menuGame.addSeparator()
        self.menuGame.addAction(self.actionExit)
        self.menubar.addAction(self.menuGame.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
コード例 #5
0
ファイル: main_window.py プロジェクト: bakshinder/akimot
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.setWindowModality(QtCore.Qt.WindowModal)
        MainWindow.resize(894, 592)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
        MainWindow.setSizePolicy(sizePolicy)
        MainWindow.setMaximumSize(QtCore.QSize(900, 600))
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout_2 = QtGui.QVBoxLayout(self.centralwidget)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.widget_2 = QtGui.QWidget(self.centralwidget)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.widget_2.sizePolicy().hasHeightForWidth())
        self.widget_2.setSizePolicy(sizePolicy)
        self.widget_2.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.widget_2.setObjectName("widget_2")
        self.hboxlayout = QtGui.QHBoxLayout(self.widget_2)
        self.hboxlayout.setObjectName("hboxlayout")
        self.board = BoardWidget(self.widget_2)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.board.sizePolicy().hasHeightForWidth())
        self.board.setSizePolicy(sizePolicy)
        self.board.setMaximumSize(QtCore.QSize(700, 700))
        self.board.setObjectName("board")
        self.horizontalLayout = QtGui.QHBoxLayout(self.board)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.hboxlayout.addWidget(self.board)
        self.widget_3 = QtGui.QWidget(self.widget_2)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(200)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.widget_3.sizePolicy().hasHeightForWidth())
        self.widget_3.setSizePolicy(sizePolicy)
        self.widget_3.setMaximumSize(QtCore.QSize(300, 16777215))
        self.widget_3.setObjectName("widget_3")
        self.verticalLayout = QtGui.QVBoxLayout(self.widget_3)
        self.verticalLayout.setObjectName("verticalLayout")
        self.record = QtGui.QListWidget(self.widget_3)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(200)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.record.sizePolicy().hasHeightForWidth())
        self.record.setSizePolicy(sizePolicy)
        self.record.setMinimumSize(QtCore.QSize(0, 130))
        self.record.setObjectName("record")
        self.verticalLayout.addWidget(self.record)
        self.widget_4 = QtGui.QWidget(self.widget_3)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.widget_4.sizePolicy().hasHeightForWidth())
        self.widget_4.setSizePolicy(sizePolicy)
        self.widget_4.setObjectName("widget_4")
        self.horizontalLayout_2 = QtGui.QHBoxLayout(self.widget_4)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.button_back = QtGui.QPushButton(self.widget_4)
        self.button_back.setObjectName("button_back")
        self.horizontalLayout_2.addWidget(self.button_back)
        self.button_forward = QtGui.QPushButton(self.widget_4)
        self.button_forward.setObjectName("button_forward")
        self.horizontalLayout_2.addWidget(self.button_forward)
        self.verticalLayout.addWidget(self.widget_4)
        self.hboxlayout.addWidget(self.widget_3)
        self.verticalLayout_2.addWidget(self.widget_2)
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 894, 27))
        self.menubar.setObjectName("menubar")
        self.menuGame = QtGui.QMenu(self.menubar)
        self.menuGame.setObjectName("menuGame")
        MainWindow.setMenuBar(self.menubar)
        self.actionLoadGame = QtGui.QAction(MainWindow)
        self.actionLoadGame.setObjectName("actionLoadGame")
        self.actionNewGame = QtGui.QAction(MainWindow)
        self.actionNewGame.setObjectName("actionNewGame")
        self.actionExit = QtGui.QAction(MainWindow)
        self.actionExit.setObjectName("actionExit")
        self.actionPlayer_x_player = QtGui.QAction(MainWindow)
        self.actionPlayer_x_player.setObjectName("actionPlayer_x_player")
        self.actionComputer_color = QtGui.QAction(MainWindow)
        self.actionComputer_color.setObjectName("actionComputer_color")
        self.actionNew_bot = QtGui.QAction(MainWindow)
        self.actionNew_bot.setObjectName("actionNew_bot")
        self.actionLoadPosition = QtGui.QAction(MainWindow)
        self.actionLoadPosition.setObjectName("actionLoadPosition")
        self.actionSavePosition = QtGui.QAction(MainWindow)
        self.actionSavePosition.setObjectName("actionSavePosition")
        self.menuGame.addAction(self.actionLoadPosition)
        self.menuGame.addAction(self.actionSavePosition)
        self.menuGame.addAction(self.actionLoadGame)
        self.menuGame.addSeparator()
        self.menuGame.addAction(self.actionExit)
        self.menubar.addAction(self.menuGame.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
コード例 #6
0
class ChessGameWidget(GraphicsWidget):
    def __init__(self):

        super(ChessGameWidget, self).__init__()

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

        # moves
        game_engine = ChessLibGameEngine()
        self.moves = MovesWidget(self.board, game_engine)
        self.moves.newGame()

        self.fen = self.board.fen.text
        self.fen.setParentItem(self.board)
        self.fen.setPos(0, -40)

        # 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-edit"
            ),
            Action(
                self,
                "Analyze",
                settings.keys["mode_analyze"],
                tr("analyze position"),
                self.onShowAnalyze,
                "games-solve",
            ),
        ]
        self._buttons = [b.graphics_button for b in actions]
        for button in self._buttons:
            button._checkable = True
            button._radio = True
        self.addActions(actions)

        size = self.moves.preferredSize()
        x, y = self.board.squares.size().width() + self.board.spacing, size.height()
        self._pack_actions(self.moves.actions(), x + 10, y + 10, False)

        self.onShowMoves()

        layout = QtGui.QGraphicsLinearLayout()
        buttons = self.getGraphicsButtonLayout()
        layout.addItem(buttons)
        layout.setAlignment(buttons, QtCore.Qt.AlignRight)
        layout.addItem(self.moves)
        layout.addItem(self.board)
        layout.setOrientation(QtCore.Qt.Vertical)
        self.setLayout(layout)

    def _pack_actions(self, actions, x, y, is_horizontal):

        # set moves actions
        for idx, action in enumerate(actions):
            action.graphics_button.setParentItem(self)
            if is_horizontal:
                offset = (action.graphics_button.preferredSize().width() + 5) * idx
                action.graphics_button.setPos(x + offset, y)
            else:
                offset = (action.graphics_button.preferredSize().height() + 5) * idx
                action.graphics_button.setPos(x, y + offset)

    def onShowMoves(self):
        self.board.editable = False
        self.moves.setEnabled(True)
        self.fen.fadeOut(settings.animation_duration)
        self._buttons[1].checked = False
        self._buttons[2].checked = False

    def onShowPallete(self):
        self.board.editable = True
        self.moves.setEnabled(False)
        self.fen.fadeIn(settings.animation_duration)
        self._buttons[0].checked = False
        self._buttons[2].checked = False

    def onShowAnalyze(self):
        self._buttons[0].checked = False
        self._buttons[1].checked = False
コード例 #7
0
ファイル: main.py プロジェクト: mbuechmann/kivy-gol
 def build(self):
     self._population = Population(cols=256, rows=256)
     self._board = BoardWidget(width=256, height=256, population = self._population)
     Clock.schedule_interval(self.callback, 0.1)
     return self._board