Commit b8de249e authored by Maël RENAULT's avatar Maël RENAULT
Browse files

Update IHM_Sudoku.py

parent d5785595
......@@ -29,6 +29,8 @@ class Grille_sudoku(QWidget):
super(Grille_sudoku, self).__init__(parent)
self.digitButtons = []
self.digitButtonsWhite = []
self.digitButtonsGrey = []
self.grille_utilise = None
for i in range(0,9):
......@@ -45,19 +47,27 @@ class Grille_sudoku(QWidget):
self.setItem))
Grille_sudoku.k = True
mainLayout = QGridLayout()
mainLayout.setSizeConstraint(QLayout.SetFixedSize)
mainLayout2 = QGridLayout(self)
testWidget = QFrame()
testWidget.setFixedSize(600,600)
testWidget.setObjectName("myWidget")
testWidget.setStyleSheet("#myWidget {background-image:url(Fond_sudoku.jpg)}")
mainLayout = QGridLayout(self)
testWidget.setLayout(mainLayout)
mainLayout2.setSizeConstraint(QLayout.SetFixedSize)
for i in range(0,9):
for j in range(0,9):
mainLayout.addWidget(self.digitButtons[i+j*9],i,j)
mainLayout.addWidget(self.digitButtons[i+j*9],i+2,j)
mainLayout.setHorizontalSpacing(15)
mainLayout.setVerticalSpacing(15)
mainLayout.setHorizontalSpacing(25)
mainLayout.setVerticalSpacing(25)
self.setLayout(mainLayout)
#création de la menu bar
widget = QWidget()
topFiller = QWidget()
topFiller.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
......@@ -67,6 +77,10 @@ class Grille_sudoku(QWidget):
self.createActions()
self.createMenus()
label = QLabel(self)
label.setFixedSize(0,20)
mainLayout2.addWidget(label,0,1)
mainLayout2.addWidget(testWidget,1,0)
self.setWindowTitle("Grille de Sudoku")
self.nouvelle_grille()
......@@ -75,12 +89,14 @@ class Grille_sudoku(QWidget):
button = Button('')
button.clicked.connect(member)
button.setStyleSheet("background-color : white")
self.digitButtonsWhite.append(button)
return button
def createButtonGrey(self, text, member):
button = Button('')
button.clicked.connect(member)
button.setStyleSheet("background-color : lightgray")
self.digitButtonsGrey.append(button)
return button
def charger_une_grille(self,grille):
......@@ -106,8 +122,13 @@ class Grille_sudoku(QWidget):
if grille_solution[pos % 9, pos//9] == int(item):
self.grille_utilise[pos % 9, pos // 9] = int(item)
clickedButton.setText(item)
if clickedButton in self.digitButtonsWhite:
clickedButton.setStyleSheet("background-color : white")
elif clickedButton in self.digitButtonsGrey:
clickedButton.setStyleSheet("background-color : lightgray ")
else:
print("erreur")
clickedButton.setText(item)
clickedButton.setStyleSheet("background-color : red")
def nouvelle_grille(self):
......@@ -161,13 +182,11 @@ class Grille_sudoku(QWidget):
def solution(self):
ordi = Ordinateur()
ordi.solve(self.grille_utilise)
grille = ordi.solution[0]
grille_solution = ordi.solution[0]
self.ajout = Correction()
self.ajout.charger_une_grille_solution(grille)
self.ajout.charger_une_grille_solution(grille_solution)
self.ajout.show()
def createActions(self):
self.newAct = QAction("&Nouvelle Grille", self, shortcut=QKeySequence.New,
statusTip="Crée une nouvelle grille", triggered=self.nouvelle_grille)
......@@ -191,7 +210,6 @@ class Grille_sudoku(QWidget):
self.fileMenu.addAction(self.saveAct)
class Correction(Grille_sudoku):
Numcases = 82
k = True
......@@ -199,34 +217,47 @@ class Correction(Grille_sudoku):
super(Grille_sudoku, self).__init__(parent)
self.digitButtons = []
self.grille_utilise = None
for i in range(0, 9):
Grille_sudoku.k = (i // 3 == 0 or i // 3 == 2)
for j in range(0, 3):
if Grille_sudoku.k:
for u in range(0, 3):
self.digitButtons.append(self.createButtonGrey(""))
self.digitButtons.append(self.createButtonGrey("",
))
Grille_sudoku.k = False
else:
for u in range(0, 3):
self.digitButtons.append(self.createButtonWhite(""))
self.digitButtons.append(self.createButtonWhite("",
))
Grille_sudoku.k = True
mainLayout = QGridLayout()
mainLayout.setSizeConstraint(QLayout.SetFixedSize)
mainLayout2 = QGridLayout(self)
testWidget = QFrame()
testWidget.setFixedSize(600, 600)
testWidget.setObjectName("myWidget")
testWidget.setStyleSheet("#myWidget {background-image:url(Fond_sudoku.jpg)}")
mainLayout = QGridLayout(self)
testWidget.setLayout(mainLayout)
mainLayout2.setSizeConstraint(QLayout.SetFixedSize)
for i in range(0, 9):
for j in range(0, 9):
mainLayout.addWidget(self.digitButtons[i + j * 9], i, j)
mainLayout.addWidget(self.digitButtons[i + j * 9], i + 2, j)
mainLayout.setHorizontalSpacing(15)
mainLayout.setVerticalSpacing(15)
mainLayout.setHorizontalSpacing(25)
mainLayout.setVerticalSpacing(25)
self.setLayout(mainLayout)
mainLayout2.addWidget(testWidget)
self.setWindowTitle("Solution")
def createButtonWhite(self, text):
button = Button('')
button.setStyleSheet("background-color : white")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment