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

Upload New File

parent 4228cac8
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import *
import numpy as np
import copy
from PyQt5.QtGui import *
from Classes import *
import copy
class Button(QToolButton):
def __init__(self, text, parent=None):
super(Button, self).__init__(parent)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
self.setText(text)
def sizeHint(self):
size = super(Button, self).sizeHint()
size.setHeight(size.height() + 20)
size.setWidth(max(size.width(), size.height()))
return size
class Grille_sudoku(QWidget):
Numcases = 82
ordi = Ordinateur()
def __init__(self, parent=None):
super(Grille_sudoku, self).__init__(parent)
painter = QPainter()
painter.begin(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.setPen(Qt.red)
painter.setBrush(Qt.white)
painter.drawLine(10, 11, 11, -1000)
self.digitButtons = []
self.grille_utilise = None
for i in range(Grille_sudoku.Numcases):
self.digitButtons.append(self.createButton(str(i),
self.setItem))
self.BSolution = QPushButton('Solution')
self.BSolution.clicked.connect(self.donner_solution)
mainLayout = QGridLayout()
mainLayout.setSizeConstraint(QLayout.SetFixedSize)
for i in range(0,9):
for j in range(0,9):
mainLayout.addWidget(self.digitButtons[i+(j-1)*9],i,j)
#mainLayout.addWidget(self.BSolution,10,0)
self.setLayout(mainLayout)
#création de la menu bar
widget = QWidget()
topFiller = QWidget()
topFiller.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
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")
def createButton(self, text, member):
button = Button('')
button.clicked.connect(member)
return button
def charger_une_grille(self,grille):
for i in range(0,len(grille)):
for j in range (0,len(grille)):
if grille[i,j]==0:
self.digitButtons[i + (j - 1) * 9].setText('')
else:
self.digitButtons[i+(j-1)*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)
def donner_solution(self):
Grille_sudoku.ordi.solve(self.grille_utilise)
self.charger_une_grille()
def newFile(self):
print(1)
def open(self):
print(2)
def save(self):
print(3)
def solution(self):
print(4)
def createActions(self):
self.newAct = QAction("&Nouvelle Grille", self, shortcut=QKeySequence.New,
statusTip="Create a new file", triggered=self.newFile)
self.solutionAct = QAction("&Afficher Solution", self, shortcut=QKeySequence.Print,
statusTip="Print the document", triggered=self.solution)
self.openAct = QAction("&Charger...", self, shortcut=QKeySequence.Open,
statusTip="Open an existing file", triggered=self.open)
self.saveAct = QAction("&Sauvegarder ...", self, shortcut=QKeySequence.Save,
statusTip="Save the document to disk", triggered=self.save)
def createMenus(self):
self.myQMenuBar = QMenuBar(self)
self.fileMenu = self.myQMenuBar.addMenu("Menu")
self.fileMenu.addAction(self.newAct)
self.fileMenu.addAction(self.solutionAct)
self.fileMenu.addSeparator()
self.fileMenu.addAction(self.openAct)
self.fileMenu.addAction(self.saveAct)
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, 0, 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_())
\ No newline at end of file
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