Loading controller/menuController.py +18 −1 Original line number Diff line number Diff line Loading @@ -16,11 +16,28 @@ class MenuController: self.game = None self.displayMenu() def lauchApplication(self): def launchApplication(self): self.menu.window.show() def displayMenu(self): self.menu.displayGames() self.menu.menuAction.triggered.connect(self.displayMenu) for gameButton in self.menu.gameButtons: if gameButton.game == GameEnum.DYCK_WORD_TO_BINARY_TREE: gameButton.clicked.triggered.connect(self.on_DyckWordToBinaryTree_Button_Pressed) elif gameButton.game == GameEnum.BINARY_TREE_TO_DYCK_WORD: gameButton.clicked.triggered.connect(self.on_binaryTreeToDyckWord_Button_Pressed) elif gameButton.game == GameEnum.BINARY_TREE_TO_PLANAR_TREE: gameButton.clicked.triggered.connect(self.on_binaryTreeToPlanarTree_Button_Pressed) elif gameButton.game == GameEnum.PLANAR_TREE_TO_BINARY_TREE: gameButton.clicked.triggered.connect(self.on_planarTreeToBinaryTree_Button_Pressed) elif gameButton.game == GameEnum.PLANAR_TREE_TO_DYCK_WORD: gameButton.clicked.triggered.connect(self.on_PlanarTreeToDyckWord_Button_Pressed) elif gameButton.game == GameEnum.DYCK_WORD_TO_PLANAR_TREE: gameButton.clicked.triggered.connect(self.on_DyckWordToPlanarTree_Button_Pressed) """def displayMenu(self): self.menu.displayGames()""" def displayLevels(self, nbLevel, levelController): self.menu.displayLevels(nbLevel, levelController) Loading main.py +1 −1 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ from view.menu import Menu def launchApplication(): qapp = QApplication(sys.argv) controller = MenuController() controller.lauchApplication() controller.launchApplication() qapp.exec_() Loading model/node.py +14 −1 Original line number Diff line number Diff line Loading @@ -549,6 +549,12 @@ class IncompleteNode(PlanarNode): self.parent = (node, index) def numberNodes(self, index=0, brothers=None): """ this method is used to number each node of the tree with a prefixed route :param index: the number of the next node of the tree :param brothers: a list of the next nodes which will be numbered """ if brothers is None: brothers = [] self.index = index Loading @@ -560,6 +566,13 @@ class IncompleteNode(PlanarNode): self.children[0].numberNodes(index + 1, newBrothers) def completeNode(self, index: int, nodeType: str, tree): """ this method allows to complete a tree which has at least 1 incomplete node :param index: the index of the incomplete node that will be completed :param nodeType: the type of completion, if it is "branch", a child we be added to the incomplete node, otherwise, the incomplete node will become a planar node (a complete node) :param tree: the tree on which an incomplete node will be completed """ if index == self.index: if nodeType == "branch": self.addChild(IncompleteNode([])) Loading Loading @@ -784,7 +797,7 @@ def randomTree(nbInternNodes): if root != nodeIndex: parent = chosenNode.parent # we randomly choose a side: left or right # if we choose right, we will place the choosen node as the right child of the new node and at left, we will # if we choose right, we will place the chosen node as the right child of the new node and at left, we will # place a leaf and vice versa if randint(0, 1) == 0: n = BinaryNode(chosenNode, Leaf()) Loading view/gameButton.py 0 → 100644 +26 −0 Original line number Diff line number Diff line from PyQt5 import QtGui from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt from model.GameEnum import GameEnum class GameButton(QWidget): def __init__(self, game: GameEnum): super(QWidget, self).__init__() self.clicked = QAction() self.game = game self.setAutoFillBackground(True) palette = QPalette() palette.setColor(self.backgroundRole(), QColor(255, 0, 0)) #215, 220, 255 self.setPalette(palette) self.layout = QHBoxLayout() label = QLabel(self.game.name) self.layout.addWidget(label, alignment=Qt.AlignCenter) self.setLayout(self.layout) #self.connect() def mousePressEvent(self, QMouseEvent): self.clicked.trigger() view/menu.py +44 −1 Original line number Diff line number Diff line import sys from math import sqrt from PyQt5.QtWidgets import * from model.GameEnum import nbGames, GameEnum from view.gameButton import GameButton from view.levelButton import LevelButton from view.menuWidget import MenuWidget Loading @@ -22,6 +25,8 @@ class Menu: self.levelLayout = None self.menuWidget = None self.window = MyWindow(None) self.menuAction = QAction() self.gameButtons = [] self.window.setMinimumSize(1000, 500) self.window.setCentralWidget(QWidget()) self.window.centralWidget().setStyleSheet("background: #F2F3F4") Loading @@ -42,9 +47,47 @@ class Menu: def displayGames(self): self.removeCentralLayout() self.menuWidget = MenuWidget(self.controller) self.menuWidget = QWidget() self.gamesLayout = QGridLayout() """nbSteps = int(sqrt(nbGames())) nbColumns = [] for i in range(nbSteps): nbColumns.append(int(nbGames() / nbSteps)) nbGamesToAdd = nbGames() - nbSteps * int(nbGames() / nbSteps) cptRow = 0 while nbGamesToAdd > 0: nbColumns[cptRow] += 1 cptRow += 1 nbGamesToAdd -= 1 cptRow = 0 cptColumn = 0""" cptRow = 0 for i in range(nbGames()): game = GameEnum(i) buttonGame = GameButton(game) buttonGame.clicked.triggered.connect(self.launchGame) self.gameButtons.append(buttonGame) if i < 3: self.gamesLayout.addWidget(buttonGame, cptRow, 0) else: self.gamesLayout.addWidget(buttonGame, cptRow, 1) if i == 2: cptRow = 0 else: cptRow += 1 self.menuWidget.setLayout(self.gamesLayout) self.centralLayout.addWidget(self.menuWidget) def launchGame(self): self.menuAction.trigger() """def displayGames(self): self.removeCentralLayout() self.menuWidget = MenuWidget(self.controller) self.centralLayout.addWidget(self.menuWidget)""" def displayLevels(self, nbLevels, levelController): self.removeCentralLayout() self.menuWidget = QWidget() Loading Loading
controller/menuController.py +18 −1 Original line number Diff line number Diff line Loading @@ -16,11 +16,28 @@ class MenuController: self.game = None self.displayMenu() def lauchApplication(self): def launchApplication(self): self.menu.window.show() def displayMenu(self): self.menu.displayGames() self.menu.menuAction.triggered.connect(self.displayMenu) for gameButton in self.menu.gameButtons: if gameButton.game == GameEnum.DYCK_WORD_TO_BINARY_TREE: gameButton.clicked.triggered.connect(self.on_DyckWordToBinaryTree_Button_Pressed) elif gameButton.game == GameEnum.BINARY_TREE_TO_DYCK_WORD: gameButton.clicked.triggered.connect(self.on_binaryTreeToDyckWord_Button_Pressed) elif gameButton.game == GameEnum.BINARY_TREE_TO_PLANAR_TREE: gameButton.clicked.triggered.connect(self.on_binaryTreeToPlanarTree_Button_Pressed) elif gameButton.game == GameEnum.PLANAR_TREE_TO_BINARY_TREE: gameButton.clicked.triggered.connect(self.on_planarTreeToBinaryTree_Button_Pressed) elif gameButton.game == GameEnum.PLANAR_TREE_TO_DYCK_WORD: gameButton.clicked.triggered.connect(self.on_PlanarTreeToDyckWord_Button_Pressed) elif gameButton.game == GameEnum.DYCK_WORD_TO_PLANAR_TREE: gameButton.clicked.triggered.connect(self.on_DyckWordToPlanarTree_Button_Pressed) """def displayMenu(self): self.menu.displayGames()""" def displayLevels(self, nbLevel, levelController): self.menu.displayLevels(nbLevel, levelController) Loading
main.py +1 −1 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ from view.menu import Menu def launchApplication(): qapp = QApplication(sys.argv) controller = MenuController() controller.lauchApplication() controller.launchApplication() qapp.exec_() Loading
model/node.py +14 −1 Original line number Diff line number Diff line Loading @@ -549,6 +549,12 @@ class IncompleteNode(PlanarNode): self.parent = (node, index) def numberNodes(self, index=0, brothers=None): """ this method is used to number each node of the tree with a prefixed route :param index: the number of the next node of the tree :param brothers: a list of the next nodes which will be numbered """ if brothers is None: brothers = [] self.index = index Loading @@ -560,6 +566,13 @@ class IncompleteNode(PlanarNode): self.children[0].numberNodes(index + 1, newBrothers) def completeNode(self, index: int, nodeType: str, tree): """ this method allows to complete a tree which has at least 1 incomplete node :param index: the index of the incomplete node that will be completed :param nodeType: the type of completion, if it is "branch", a child we be added to the incomplete node, otherwise, the incomplete node will become a planar node (a complete node) :param tree: the tree on which an incomplete node will be completed """ if index == self.index: if nodeType == "branch": self.addChild(IncompleteNode([])) Loading Loading @@ -784,7 +797,7 @@ def randomTree(nbInternNodes): if root != nodeIndex: parent = chosenNode.parent # we randomly choose a side: left or right # if we choose right, we will place the choosen node as the right child of the new node and at left, we will # if we choose right, we will place the chosen node as the right child of the new node and at left, we will # place a leaf and vice versa if randint(0, 1) == 0: n = BinaryNode(chosenNode, Leaf()) Loading
view/gameButton.py 0 → 100644 +26 −0 Original line number Diff line number Diff line from PyQt5 import QtGui from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt from model.GameEnum import GameEnum class GameButton(QWidget): def __init__(self, game: GameEnum): super(QWidget, self).__init__() self.clicked = QAction() self.game = game self.setAutoFillBackground(True) palette = QPalette() palette.setColor(self.backgroundRole(), QColor(255, 0, 0)) #215, 220, 255 self.setPalette(palette) self.layout = QHBoxLayout() label = QLabel(self.game.name) self.layout.addWidget(label, alignment=Qt.AlignCenter) self.setLayout(self.layout) #self.connect() def mousePressEvent(self, QMouseEvent): self.clicked.trigger()
view/menu.py +44 −1 Original line number Diff line number Diff line import sys from math import sqrt from PyQt5.QtWidgets import * from model.GameEnum import nbGames, GameEnum from view.gameButton import GameButton from view.levelButton import LevelButton from view.menuWidget import MenuWidget Loading @@ -22,6 +25,8 @@ class Menu: self.levelLayout = None self.menuWidget = None self.window = MyWindow(None) self.menuAction = QAction() self.gameButtons = [] self.window.setMinimumSize(1000, 500) self.window.setCentralWidget(QWidget()) self.window.centralWidget().setStyleSheet("background: #F2F3F4") Loading @@ -42,9 +47,47 @@ class Menu: def displayGames(self): self.removeCentralLayout() self.menuWidget = MenuWidget(self.controller) self.menuWidget = QWidget() self.gamesLayout = QGridLayout() """nbSteps = int(sqrt(nbGames())) nbColumns = [] for i in range(nbSteps): nbColumns.append(int(nbGames() / nbSteps)) nbGamesToAdd = nbGames() - nbSteps * int(nbGames() / nbSteps) cptRow = 0 while nbGamesToAdd > 0: nbColumns[cptRow] += 1 cptRow += 1 nbGamesToAdd -= 1 cptRow = 0 cptColumn = 0""" cptRow = 0 for i in range(nbGames()): game = GameEnum(i) buttonGame = GameButton(game) buttonGame.clicked.triggered.connect(self.launchGame) self.gameButtons.append(buttonGame) if i < 3: self.gamesLayout.addWidget(buttonGame, cptRow, 0) else: self.gamesLayout.addWidget(buttonGame, cptRow, 1) if i == 2: cptRow = 0 else: cptRow += 1 self.menuWidget.setLayout(self.gamesLayout) self.centralLayout.addWidget(self.menuWidget) def launchGame(self): self.menuAction.trigger() """def displayGames(self): self.removeCentralLayout() self.menuWidget = MenuWidget(self.controller) self.centralLayout.addWidget(self.menuWidget)""" def displayLevels(self, nbLevels, levelController): self.removeCentralLayout() self.menuWidget = QWidget() Loading