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

Update IHM_Sudoku.py

parent 05cb6da3
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import *
import numpy as np
import copy
from PyQt5.QtGui import *
from Classes import *
import copy
from PyQt5.QtGui import QFont
from datetime import datetime
from time import gmtime, strftime
from more_itertools import locate
......@@ -67,16 +65,11 @@ class Grille_sudoku(QWidget):
bottomFiller = QWidget()
bottomFiller.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
vbox = QVBoxLayout()
vbox.setContentsMargins(5, 5, 5, 5)
vbox.addWidget(topFiller)
vbox.addWidget(bottomFiller)
widget.setLayout(vbox)
self.createActions()
self.createMenus()
self.setWindowTitle("Grille de Sudoku")
self.nouvelle_grille()
def createButtonWhite(self, text, member):
button = Button('')
......@@ -102,7 +95,7 @@ class Grille_sudoku(QWidget):
def setItem(self):
clickedButton = self.sender()
items = ('1','2','3','4','5','6','7','8','9')
item, ok = QInputDialog.getItem(self, "QInputDialog.getItem()",
item, ok = QInputDialog.getItem(self, "Choix du Chiffre",
"Chiffres", items, 0, False)
if ok and item:
pos = list(locate(self.digitButtons, lambda x: x == clickedButton))
......@@ -110,10 +103,11 @@ class Grille_sudoku(QWidget):
self.grille_utilise[pos // 9, pos - 9 * (pos // 9)] = item
clickedButton.setText(item)
def nouvelle_grille(self):
grl = Grille()
items = ('Facile','Moyen','Difficile')
item, ok = QInputDialog.getItem(self, "QInputDialog.getItem()",
item, ok = QInputDialog.getItem(self, "Choix de la Difficulté",
"Difficulté", items, 0, False)
if ok and item == 'Facile':
grl.génération(5000)
......@@ -134,13 +128,14 @@ class Grille_sudoku(QWidget):
fileName, _ = QFileDialog.getOpenFileName(self,
"QFileDialog.getOpenFileName()", self.openFileNameLabel,
"All Files (*);;Text Files (*.txt)", options=options)
fichier = open(fileName, "r")
lignes = fichier.readlines()
grille = np.zeros((9, 9), dtype=int)
for i in range(9):
for j in range(9):
grille[i, j] = lignes[i + 1][j]
self.charger_une_grille(grille)
if fileName:
fichier = open(fileName, "r")
lignes = fichier.readlines()
grille = np.zeros((9, 9), dtype=int)
for i in range(9):
for j in range(9):
grille[i, j] = lignes[i + 1][j]
self.charger_une_grille(grille)
def save(self):
user = "louis"
......@@ -161,9 +156,8 @@ class Grille_sudoku(QWidget):
ordi = Ordinateur()
ordi.solve(self.grille_utilise)
grille = ordi.solution[0]
print(grille)
self.ajout = Correction()
self.ajout.charger_une_grille2(grille)
self.ajout.charger_une_grille_solution(grille)
self.ajout.show()
......@@ -191,10 +185,9 @@ class Grille_sudoku(QWidget):
self.fileMenu.addAction(self.saveAct)
class Correction(Grille_sudoku):
Numcases = 82
ordi = Ordinateur()
k = True
compteur = 0
def __init__(self, parent=None):
super(Grille_sudoku, self).__init__(parent)
......@@ -206,46 +199,39 @@ class Correction(Grille_sudoku):
for j in range(0, 3):
if Grille_sudoku.k:
for u in range(0, 3):
self.digitButtons.append(self.createButtonGrey("",
self.setItem))
self.digitButtons.append(self.createButtonGrey(""))
Grille_sudoku.k = False
else:
for u in range(0, 3):
self.digitButtons.append(self.createButtonWhite("",
self.setItem))
self.digitButtons.append(self.createButtonWhite(""))
Grille_sudoku.k = True
mainLayout = QGridLayout()
mainLayout.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.setHorizontalSpacing(15)
mainLayout.setVerticalSpacing(15)
self.setLayout(mainLayout)
self.setWindowTitle("Solution")
def createButtonWhite(self, text, member):
def createButtonWhite(self, text):
button = Button('')
button.clicked.connect(member)
button.setStyleSheet("background-color : white")
return button
def createButtonGrey(self, text, member):
def createButtonGrey(self, text):
button = Button('')
button.clicked.connect(member)
button.setStyleSheet("background-color : lightgray")
return button
def charger_une_grille2(self,grille):
def charger_une_grille_solution(self,grille):
for i in range(0,len(grille)):
for j in range(0,len(grille)):
if grille[i,j] == 0:
......@@ -254,29 +240,11 @@ class Correction(Grille_sudoku):
self.digitButtons[i + j * 9].setText(str(grille[i,j]))
self.grille_utilise = copy.deepcopy(grille)
def setItem(self):
clickedButton = self.sender()
items = ('1','2','3','4','5','6','7','8','9')
item, ok = QInputDialog.getItem(self, "QInputDialog.getItem()",
"Chiffres", items, 0, False)
if ok and item:
clickedButton.setText(item)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
calc = Grille_sudoku()
GE = np.array([[1, 2, 3, 4, 5, 6, 7, 8, 9],
[4, 5, 6, 7, 8, 9, 1, 2, 3],
[7, 8, 9, 1, 2, 3, 4, 5, 6],
[2, 3, 4, 5, 6, 7, 8, 9, 1],
[5, 6, 7, 8, 9, 1, 2, 3, 4], # génération de la grille élémentaire
[8, 9, 1, 2, 3, 4, 5, 6, 7],
[3, 4, 5, 6, 7, 8, 9, 1, 2],
[6, 7, 8, 9, 1, 2, 3, 4, 5],
[9, 1, 2, 3, 4, 5, 6, 7, 8]])
calc.charger_une_grille(GE)
calc.show()
sys.exit(app.exec_())
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