-
Notifications
You must be signed in to change notification settings - Fork 0
/
SudokuGUI.py
587 lines (572 loc) · 31 KB
/
SudokuGUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'SudokuGUI.ui'
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QDialog, QApplication, QMainWindow
import numpy as np
from Sudoku import SudokuSolver
import sys
DIM = 9
INVALID_VALUE = "Invalid Values Entered\n" + \
"Enter Only Numbers Between 1 And 9\n" + \
"Leave Blank Boxes Blank"
INVALID_ARRAY = "Entered Sudoku Grid UNSOLVABLE"
class Ui_canvas(object):
def setupUi(self, canvas):
self.grid = np.repeat(None, DIM*DIM).reshape((DIM,DIM))
canvas.setObjectName("canvas")
canvas.resize(824, 461)
self.centralwidget = QtWidgets.QWidget(canvas)
self.centralwidget.setObjectName("centralwidget")
self.gridLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 111, 111))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.UL_ll = QtWidgets.QTextEdit(self.gridLayoutWidget)
self.UL_ll.setTabChangesFocus(True)
self.UL_ll.setObjectName("UL_ll")
self.gridLayout.addWidget(self.UL_ll, 3, 0, 1, 1)
self.UL_ul = QtWidgets.QTextEdit(self.gridLayoutWidget)
self.UL_ul.setTabChangesFocus(True)
self.UL_ul.setLineWrapMode(QtWidgets.QTextEdit.NoWrap)
self.UL_ul.setLineWrapColumnOrWidth(1)
self.UL_ul.setObjectName("UL_ul")
self.gridLayout.addWidget(self.UL_ul, 0, 0, 1, 1)
self.UL_ml = QtWidgets.QTextEdit(self.gridLayoutWidget)
self.UL_ml.setTabChangesFocus(True)
self.UL_ml.setObjectName("UL_ml")
self.gridLayout.addWidget(self.UL_ml, 1, 0, 1, 1)
self.UL_lm = QtWidgets.QTextEdit(self.gridLayoutWidget)
self.UL_lm.setTabChangesFocus(True)
self.UL_lm.setObjectName("UL_lm")
self.gridLayout.addWidget(self.UL_lm, 3, 1, 1, 1)
self.UL_mm = QtWidgets.QTextEdit(self.gridLayoutWidget)
self.UL_mm.setTabChangesFocus(True)
self.UL_mm.setObjectName("UL_mm")
self.gridLayout.addWidget(self.UL_mm, 1, 1, 1, 1)
self.UL_um = QtWidgets.QTextEdit(self.gridLayoutWidget)
self.UL_um.setTabChangesFocus(True)
self.UL_um.setObjectName("UL_um")
self.gridLayout.addWidget(self.UL_um, 0, 1, 1, 1)
self.UL_lr = QtWidgets.QTextEdit(self.gridLayoutWidget)
self.UL_lr.setTabChangesFocus(True)
self.UL_lr.setObjectName("UL_lr")
self.gridLayout.addWidget(self.UL_lr, 3, 2, 1, 1)
self.UL_mr = QtWidgets.QTextEdit(self.gridLayoutWidget)
self.UL_mr.setTabChangesFocus(True)
self.UL_mr.setObjectName("UL_mr")
self.gridLayout.addWidget(self.UL_mr, 1, 2, 1, 1)
self.UL_ur = QtWidgets.QTextEdit(self.gridLayoutWidget)
self.UL_ur.setTabChangesFocus(True)
self.UL_ur.setObjectName("UL_ur")
self.gridLayout.addWidget(self.UL_ur, 0, 2, 1, 1)
self.gridLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget)
self.gridLayoutWidget_2.setGeometry(QtCore.QRect(10, 270, 111, 111))
self.gridLayoutWidget_2.setObjectName("gridLayoutWidget_2")
self.gridLayout_2 = QtWidgets.QGridLayout(self.gridLayoutWidget_2)
self.gridLayout_2.setContentsMargins(0, 0, 0, 0)
self.gridLayout_2.setObjectName("gridLayout_2")
self.LL_ll = QtWidgets.QTextEdit(self.gridLayoutWidget_2)
self.LL_ll.setTabChangesFocus(True)
self.LL_ll.setObjectName("LL_ll")
self.gridLayout_2.addWidget(self.LL_ll, 3, 0, 1, 1)
self.LL_ul = QtWidgets.QTextEdit(self.gridLayoutWidget_2)
self.LL_ul.setTabChangesFocus(True)
self.LL_ul.setObjectName("LL_ul")
self.gridLayout_2.addWidget(self.LL_ul, 0, 0, 1, 1)
self.LL_ml = QtWidgets.QTextEdit(self.gridLayoutWidget_2)
self.LL_ml.setTabChangesFocus(True)
self.LL_ml.setObjectName("LL_ml")
self.gridLayout_2.addWidget(self.LL_ml, 1, 0, 1, 1)
self.LL_lm = QtWidgets.QTextEdit(self.gridLayoutWidget_2)
self.LL_lm.setTabChangesFocus(True)
self.LL_lm.setObjectName("LL_lm")
self.gridLayout_2.addWidget(self.LL_lm, 3, 1, 1, 1)
self.LL_mm = QtWidgets.QTextEdit(self.gridLayoutWidget_2)
self.LL_mm.setTabChangesFocus(True)
self.LL_mm.setObjectName("LL_mm")
self.gridLayout_2.addWidget(self.LL_mm, 1, 1, 1, 1)
self.LL_um = QtWidgets.QTextEdit(self.gridLayoutWidget_2)
self.LL_um.setTabChangesFocus(True)
self.LL_um.setObjectName("LL_um")
self.gridLayout_2.addWidget(self.LL_um, 0, 1, 1, 1)
self.LL_lr = QtWidgets.QTextEdit(self.gridLayoutWidget_2)
self.LL_lr.setTabChangesFocus(True)
self.LL_lr.setObjectName("LL_lr")
self.gridLayout_2.addWidget(self.LL_lr, 3, 2, 1, 1)
self.LL_mr = QtWidgets.QTextEdit(self.gridLayoutWidget_2)
self.LL_mr.setTabChangesFocus(True)
self.LL_mr.setObjectName("LL_mr")
self.gridLayout_2.addWidget(self.LL_mr, 1, 2, 1, 1)
self.LL_ur = QtWidgets.QTextEdit(self.gridLayoutWidget_2)
self.LL_ur.setTabChangesFocus(True)
self.LL_ur.setObjectName("LL_ur")
self.gridLayout_2.addWidget(self.LL_ur, 0, 2, 1, 1)
self.gridLayoutWidget_3 = QtWidgets.QWidget(self.centralwidget)
self.gridLayoutWidget_3.setGeometry(QtCore.QRect(140, 140, 111, 111))
self.gridLayoutWidget_3.setObjectName("gridLayoutWidget_3")
self.gridLayout_3 = QtWidgets.QGridLayout(self.gridLayoutWidget_3)
self.gridLayout_3.setContentsMargins(0, 0, 0, 0)
self.gridLayout_3.setObjectName("gridLayout_3")
self.MM_ll = QtWidgets.QTextEdit(self.gridLayoutWidget_3)
self.MM_ll.setTabChangesFocus(True)
self.MM_ll.setObjectName("MM_ll")
self.gridLayout_3.addWidget(self.MM_ll, 3, 0, 1, 1)
self.MM_ul = QtWidgets.QTextEdit(self.gridLayoutWidget_3)
self.MM_ul.setTabChangesFocus(True)
self.MM_ul.setObjectName("MM_ul")
self.gridLayout_3.addWidget(self.MM_ul, 0, 0, 1, 1)
self.MM_ml = QtWidgets.QTextEdit(self.gridLayoutWidget_3)
self.MM_ml.setTabChangesFocus(True)
self.MM_ml.setObjectName("MM_ml")
self.gridLayout_3.addWidget(self.MM_ml, 1, 0, 1, 1)
self.MM_lm = QtWidgets.QTextEdit(self.gridLayoutWidget_3)
self.MM_lm.setTabChangesFocus(True)
self.MM_lm.setObjectName("MM_lm")
self.gridLayout_3.addWidget(self.MM_lm, 3, 1, 1, 1)
self.MM_mm = QtWidgets.QTextEdit(self.gridLayoutWidget_3)
self.MM_mm.setTabChangesFocus(True)
self.MM_mm.setObjectName("MM_mm")
self.gridLayout_3.addWidget(self.MM_mm, 1, 1, 1, 1)
self.MM_um = QtWidgets.QTextEdit(self.gridLayoutWidget_3)
self.MM_um.setTabChangesFocus(True)
self.MM_um.setObjectName("MM_um")
self.gridLayout_3.addWidget(self.MM_um, 0, 1, 1, 1)
self.MM_lr = QtWidgets.QTextEdit(self.gridLayoutWidget_3)
self.MM_lr.setTabChangesFocus(True)
self.MM_lr.setObjectName("MM_lr")
self.gridLayout_3.addWidget(self.MM_lr, 3, 2, 1, 1)
self.MM_mr = QtWidgets.QTextEdit(self.gridLayoutWidget_3)
self.MM_mr.setTabChangesFocus(True)
self.MM_mr.setObjectName("MM_mr")
self.gridLayout_3.addWidget(self.MM_mr, 1, 2, 1, 1)
self.MM_ur = QtWidgets.QTextEdit(self.gridLayoutWidget_3)
self.MM_ur.setTabChangesFocus(True)
self.MM_ur.setObjectName("MM_ur")
self.gridLayout_3.addWidget(self.MM_ur, 0, 2, 1, 1)
self.gridLayoutWidget_4 = QtWidgets.QWidget(self.centralwidget)
self.gridLayoutWidget_4.setGeometry(QtCore.QRect(140, 10, 111, 111))
self.gridLayoutWidget_4.setObjectName("gridLayoutWidget_4")
self.gridLayout_4 = QtWidgets.QGridLayout(self.gridLayoutWidget_4)
self.gridLayout_4.setContentsMargins(0, 0, 0, 0)
self.gridLayout_4.setObjectName("gridLayout_4")
self.UM_ll = QtWidgets.QTextEdit(self.gridLayoutWidget_4)
self.UM_ll.setTabChangesFocus(True)
self.UM_ll.setObjectName("UM_ll")
self.gridLayout_4.addWidget(self.UM_ll, 3, 0, 1, 1)
self.UM_ul = QtWidgets.QTextEdit(self.gridLayoutWidget_4)
self.UM_ul.setTabChangesFocus(True)
self.UM_ul.setObjectName("UM_ul")
self.gridLayout_4.addWidget(self.UM_ul, 0, 0, 1, 1)
self.UM_ml = QtWidgets.QTextEdit(self.gridLayoutWidget_4)
self.UM_ml.setTabChangesFocus(True)
self.UM_ml.setObjectName("UM_ml")
self.gridLayout_4.addWidget(self.UM_ml, 1, 0, 1, 1)
self.UM_lm = QtWidgets.QTextEdit(self.gridLayoutWidget_4)
self.UM_lm.setTabChangesFocus(True)
self.UM_lm.setObjectName("UM_lm")
self.gridLayout_4.addWidget(self.UM_lm, 3, 1, 1, 1)
self.UM_mm = QtWidgets.QTextEdit(self.gridLayoutWidget_4)
self.UM_mm.setTabChangesFocus(True)
self.UM_mm.setObjectName("UM_mm")
self.gridLayout_4.addWidget(self.UM_mm, 1, 1, 1, 1)
self.UM_um = QtWidgets.QTextEdit(self.gridLayoutWidget_4)
self.UM_um.setTabChangesFocus(True)
self.UM_um.setObjectName("UM_um")
self.gridLayout_4.addWidget(self.UM_um, 0, 1, 1, 1)
self.UM_lr = QtWidgets.QTextEdit(self.gridLayoutWidget_4)
self.UM_lr.setTabChangesFocus(True)
self.UM_lr.setObjectName("UM_lr")
self.gridLayout_4.addWidget(self.UM_lr, 3, 2, 1, 1)
self.UM_mr = QtWidgets.QTextEdit(self.gridLayoutWidget_4)
self.UM_mr.setTabChangesFocus(True)
self.UM_mr.setObjectName("UM_mr")
self.gridLayout_4.addWidget(self.UM_mr, 1, 2, 1, 1)
self.UM_ur = QtWidgets.QTextEdit(self.gridLayoutWidget_4)
self.UM_ur.setTabChangesFocus(True)
self.UM_ur.setObjectName("UM_ur")
self.gridLayout_4.addWidget(self.UM_ur, 0, 2, 1, 1)
self.gridLayoutWidget_5 = QtWidgets.QWidget(self.centralwidget)
self.gridLayoutWidget_5.setGeometry(QtCore.QRect(10, 140, 111, 111))
self.gridLayoutWidget_5.setObjectName("gridLayoutWidget_5")
self.gridLayout_5 = QtWidgets.QGridLayout(self.gridLayoutWidget_5)
self.gridLayout_5.setContentsMargins(0, 0, 0, 0)
self.gridLayout_5.setObjectName("gridLayout_5")
self.ML_ll = QtWidgets.QTextEdit(self.gridLayoutWidget_5)
self.ML_ll.setTabChangesFocus(True)
self.ML_ll.setObjectName("ML_ll")
self.gridLayout_5.addWidget(self.ML_ll, 3, 0, 1, 1)
self.ML_ul = QtWidgets.QTextEdit(self.gridLayoutWidget_5)
self.ML_ul.setTabChangesFocus(True)
self.ML_ul.setObjectName("ML_ul")
self.gridLayout_5.addWidget(self.ML_ul, 0, 0, 1, 1)
self.ML_ml = QtWidgets.QTextEdit(self.gridLayoutWidget_5)
self.ML_ml.setTabChangesFocus(True)
self.ML_ml.setObjectName("ML_ml")
self.gridLayout_5.addWidget(self.ML_ml, 1, 0, 1, 1)
self.ML_lm = QtWidgets.QTextEdit(self.gridLayoutWidget_5)
self.ML_lm.setTabChangesFocus(True)
self.ML_lm.setObjectName("ML_lm")
self.gridLayout_5.addWidget(self.ML_lm, 3, 1, 1, 1)
self.ML_mm = QtWidgets.QTextEdit(self.gridLayoutWidget_5)
self.ML_mm.setTabChangesFocus(True)
self.ML_mm.setObjectName("ML_mm")
self.gridLayout_5.addWidget(self.ML_mm, 1, 1, 1, 1)
self.ML_um = QtWidgets.QTextEdit(self.gridLayoutWidget_5)
self.ML_um.setTabChangesFocus(True)
self.ML_um.setObjectName("ML_um")
self.gridLayout_5.addWidget(self.ML_um, 0, 1, 1, 1)
self.ML_lr = QtWidgets.QTextEdit(self.gridLayoutWidget_5)
self.ML_lr.setTabChangesFocus(True)
self.ML_lr.setObjectName("ML_lr")
self.gridLayout_5.addWidget(self.ML_lr, 3, 2, 1, 1)
self.ML_mr = QtWidgets.QTextEdit(self.gridLayoutWidget_5)
self.ML_mr.setTabChangesFocus(True)
self.ML_mr.setObjectName("ML_mr")
self.gridLayout_5.addWidget(self.ML_mr, 1, 2, 1, 1)
self.ML_ur = QtWidgets.QTextEdit(self.gridLayoutWidget_5)
self.ML_ur.setTabChangesFocus(True)
self.ML_ur.setObjectName("ML_ur")
self.gridLayout_5.addWidget(self.ML_ur, 0, 2, 1, 1)
self.gridLayoutWidget_6 = QtWidgets.QWidget(self.centralwidget)
self.gridLayoutWidget_6.setGeometry(QtCore.QRect(270, 10, 111, 111))
self.gridLayoutWidget_6.setObjectName("gridLayoutWidget_6")
self.gridLayout_6 = QtWidgets.QGridLayout(self.gridLayoutWidget_6)
self.gridLayout_6.setContentsMargins(0, 0, 0, 0)
self.gridLayout_6.setObjectName("gridLayout_6")
self.UR_ll = QtWidgets.QTextEdit(self.gridLayoutWidget_6)
self.UR_ll.setTabChangesFocus(True)
self.UR_ll.setObjectName("UR_ll")
self.gridLayout_6.addWidget(self.UR_ll, 3, 0, 1, 1)
self.UR_ul = QtWidgets.QTextEdit(self.gridLayoutWidget_6)
self.UR_ul.setTabChangesFocus(True)
self.UR_ul.setObjectName("UR_ul")
self.gridLayout_6.addWidget(self.UR_ul, 0, 0, 1, 1)
self.UR_ml = QtWidgets.QTextEdit(self.gridLayoutWidget_6)
self.UR_ml.setTabChangesFocus(True)
self.UR_ml.setObjectName("UR_ml")
self.gridLayout_6.addWidget(self.UR_ml, 1, 0, 1, 1)
self.UR_lm = QtWidgets.QTextEdit(self.gridLayoutWidget_6)
self.UR_lm.setTabChangesFocus(True)
self.UR_lm.setObjectName("UR_lm")
self.gridLayout_6.addWidget(self.UR_lm, 3, 1, 1, 1)
self.UR_um = QtWidgets.QTextEdit(self.gridLayoutWidget_6)
self.UR_um.setTabChangesFocus(True)
self.UR_um.setObjectName("UR_um")
self.gridLayout_6.addWidget(self.UR_um, 0, 1, 1, 1)
self.UR_lr = QtWidgets.QTextEdit(self.gridLayoutWidget_6)
self.UR_lr.setTabChangesFocus(True)
self.UR_lr.setObjectName("UR_lr")
self.gridLayout_6.addWidget(self.UR_lr, 3, 2, 1, 1)
self.UR_mr = QtWidgets.QTextEdit(self.gridLayoutWidget_6)
self.UR_mr.setTabChangesFocus(True)
self.UR_mr.setObjectName("UR_mr")
self.gridLayout_6.addWidget(self.UR_mr, 1, 2, 1, 1)
self.UR_ur = QtWidgets.QTextEdit(self.gridLayoutWidget_6)
self.UR_ur.setTabChangesFocus(True)
self.UR_ur.setObjectName("UR_ur")
self.gridLayout_6.addWidget(self.UR_ur, 0, 2, 1, 1)
self.UR_mm = QtWidgets.QTextEdit(self.gridLayoutWidget_6)
self.UR_mm.setTabChangesFocus(True)
self.UR_mm.setObjectName("UR_mm")
self.gridLayout_6.addWidget(self.UR_mm, 1, 1, 1, 1)
self.gridLayoutWidget_7 = QtWidgets.QWidget(self.centralwidget)
self.gridLayoutWidget_7.setGeometry(QtCore.QRect(270, 140, 111, 111))
self.gridLayoutWidget_7.setObjectName("gridLayoutWidget_7")
self.gridLayout_7 = QtWidgets.QGridLayout(self.gridLayoutWidget_7)
self.gridLayout_7.setContentsMargins(0, 0, 0, 0)
self.gridLayout_7.setObjectName("gridLayout_7")
self.MR_ll = QtWidgets.QTextEdit(self.gridLayoutWidget_7)
self.MR_ll.setTabChangesFocus(True)
self.MR_ll.setObjectName("MR_ll")
self.gridLayout_7.addWidget(self.MR_ll, 3, 0, 1, 1)
self.MR_ul = QtWidgets.QTextEdit(self.gridLayoutWidget_7)
self.MR_ul.setTabChangesFocus(True)
self.MR_ul.setObjectName("MR_ul")
self.gridLayout_7.addWidget(self.MR_ul, 0, 0, 1, 1)
self.MR_ml = QtWidgets.QTextEdit(self.gridLayoutWidget_7)
self.MR_ml.setTabChangesFocus(True)
self.MR_ml.setObjectName("MR_ml")
self.gridLayout_7.addWidget(self.MR_ml, 1, 0, 1, 1)
self.MR_lm = QtWidgets.QTextEdit(self.gridLayoutWidget_7)
self.MR_lm.setTabChangesFocus(True)
self.MR_lm.setObjectName("MR_lm")
self.gridLayout_7.addWidget(self.MR_lm, 3, 1, 1, 1)
self.MR_mm = QtWidgets.QTextEdit(self.gridLayoutWidget_7)
self.MR_mm.setTabChangesFocus(True)
self.MR_mm.setObjectName("MR_mm")
self.gridLayout_7.addWidget(self.MR_mm, 1, 1, 1, 1)
self.MR_um = QtWidgets.QTextEdit(self.gridLayoutWidget_7)
self.MR_um.setTabChangesFocus(True)
self.MR_um.setObjectName("MR_um")
self.gridLayout_7.addWidget(self.MR_um, 0, 1, 1, 1)
self.MR_lr = QtWidgets.QTextEdit(self.gridLayoutWidget_7)
self.MR_lr.setTabChangesFocus(True)
self.MR_lr.setObjectName("MR_lr")
self.gridLayout_7.addWidget(self.MR_lr, 3, 2, 1, 1)
self.MR_mr = QtWidgets.QTextEdit(self.gridLayoutWidget_7)
self.MR_mr.setTabChangesFocus(True)
self.MR_mr.setObjectName("MR_mr")
self.gridLayout_7.addWidget(self.MR_mr, 1, 2, 1, 1)
self.MR_ur = QtWidgets.QTextEdit(self.gridLayoutWidget_7)
self.MR_ur.setTabChangesFocus(True)
self.MR_ur.setObjectName("MR_ur")
self.gridLayout_7.addWidget(self.MR_ur, 0, 2, 1, 1)
self.gridLayoutWidget_8 = QtWidgets.QWidget(self.centralwidget)
self.gridLayoutWidget_8.setGeometry(QtCore.QRect(270, 270, 111, 111))
self.gridLayoutWidget_8.setObjectName("gridLayoutWidget_8")
self.gridLayout_8 = QtWidgets.QGridLayout(self.gridLayoutWidget_8)
self.gridLayout_8.setContentsMargins(0, 0, 0, 0)
self.gridLayout_8.setObjectName("gridLayout_8")
self.LR_ll = QtWidgets.QTextEdit(self.gridLayoutWidget_8)
self.LR_ll.setTabChangesFocus(True)
self.LR_ll.setObjectName("LR_ll")
self.gridLayout_8.addWidget(self.LR_ll, 3, 0, 1, 1)
self.LR_ul = QtWidgets.QTextEdit(self.gridLayoutWidget_8)
self.LR_ul.setTabChangesFocus(True)
self.LR_ul.setObjectName("LR_ul")
self.gridLayout_8.addWidget(self.LR_ul, 0, 0, 1, 1)
self.LR_ml = QtWidgets.QTextEdit(self.gridLayoutWidget_8)
self.LR_ml.setTabChangesFocus(True)
self.LR_ml.setObjectName("LR_ml")
self.gridLayout_8.addWidget(self.LR_ml, 1, 0, 1, 1)
self.LR_lm = QtWidgets.QTextEdit(self.gridLayoutWidget_8)
self.LR_lm.setTabChangesFocus(True)
self.LR_lm.setObjectName("LR_lm")
self.gridLayout_8.addWidget(self.LR_lm, 3, 1, 1, 1)
self.LR_mm = QtWidgets.QTextEdit(self.gridLayoutWidget_8)
self.LR_mm.setTabChangesFocus(True)
self.LR_mm.setObjectName("LR_mm")
self.gridLayout_8.addWidget(self.LR_mm, 1, 1, 1, 1)
self.LR_um = QtWidgets.QTextEdit(self.gridLayoutWidget_8)
self.LR_um.setTabChangesFocus(True)
self.LR_um.setObjectName("LR_um")
self.gridLayout_8.addWidget(self.LR_um, 0, 1, 1, 1)
self.LR_lr = QtWidgets.QTextEdit(self.gridLayoutWidget_8)
self.LR_lr.setTabChangesFocus(True)
self.LR_lr.setObjectName("LR_lr")
self.gridLayout_8.addWidget(self.LR_lr, 3, 2, 1, 1)
self.LR_mr = QtWidgets.QTextEdit(self.gridLayoutWidget_8)
self.LR_mr.setTabChangesFocus(True)
self.LR_mr.setObjectName("LR_mr")
self.gridLayout_8.addWidget(self.LR_mr, 1, 2, 1, 1)
self.LR_ur = QtWidgets.QTextEdit(self.gridLayoutWidget_8)
self.LR_ur.setTabChangesFocus(True)
self.LR_ur.setLineWrapMode(QtWidgets.QTextEdit.NoWrap)
self.LR_ur.setObjectName("LR_ur")
self.gridLayout_8.addWidget(self.LR_ur, 0, 2, 1, 1)
self.gridLayoutWidget_9 = QtWidgets.QWidget(self.centralwidget)
self.gridLayoutWidget_9.setGeometry(QtCore.QRect(140, 270, 111, 111))
self.gridLayoutWidget_9.setObjectName("gridLayoutWidget_9")
self.gridLayout_9 = QtWidgets.QGridLayout(self.gridLayoutWidget_9)
self.gridLayout_9.setContentsMargins(0, 0, 0, 0)
self.gridLayout_9.setObjectName("gridLayout_9")
self.LM_ll = QtWidgets.QTextEdit(self.gridLayoutWidget_9)
self.LM_ll.setTabChangesFocus(True)
self.LM_ll.setObjectName("LM_ll")
self.gridLayout_9.addWidget(self.LM_ll, 3, 0, 1, 1)
self.LM_ul = QtWidgets.QTextEdit(self.gridLayoutWidget_9)
self.LM_ul.setTabChangesFocus(True)
self.LM_ul.setObjectName("LM_ul")
self.gridLayout_9.addWidget(self.LM_ul, 0, 0, 1, 1)
self.LM_ml = QtWidgets.QTextEdit(self.gridLayoutWidget_9)
self.LM_ml.setTabChangesFocus(True)
self.LM_ml.setObjectName("LM_ml")
self.gridLayout_9.addWidget(self.LM_ml, 1, 0, 1, 1)
self.LM_lm = QtWidgets.QTextEdit(self.gridLayoutWidget_9)
self.LM_lm.setTabChangesFocus(True)
self.LM_lm.setObjectName("LM_lm")
self.gridLayout_9.addWidget(self.LM_lm, 3, 1, 1, 1)
self.LM_mm = QtWidgets.QTextEdit(self.gridLayoutWidget_9)
self.LM_mm.setTabChangesFocus(True)
self.LM_mm.setObjectName("LM_mm")
self.gridLayout_9.addWidget(self.LM_mm, 1, 1, 1, 1)
self.LM_um = QtWidgets.QTextEdit(self.gridLayoutWidget_9)
self.LM_um.setTabChangesFocus(True)
self.LM_um.setObjectName("LM_um")
self.gridLayout_9.addWidget(self.LM_um, 0, 1, 1, 1)
self.LM_lr = QtWidgets.QTextEdit(self.gridLayoutWidget_9)
self.LM_lr.setTabChangesFocus(True)
self.LM_lr.setObjectName("LM_lr")
self.gridLayout_9.addWidget(self.LM_lr, 3, 2, 1, 1)
self.LM_mr = QtWidgets.QTextEdit(self.gridLayoutWidget_9)
self.LM_mr.setTabChangesFocus(True)
self.LM_mr.setObjectName("LM_mr")
self.gridLayout_9.addWidget(self.LM_mr, 1, 2, 1, 1)
self.LM_ur = QtWidgets.QTextEdit(self.gridLayoutWidget_9)
self.LM_ur.setTabChangesFocus(True)
self.LM_ur.setObjectName("LM_ur")
self.gridLayout_9.addWidget(self.LM_ur, 0, 2, 1, 1)
self.message_box = QtWidgets.QPlainTextEdit(self.centralwidget)
self.message_box.setGeometry(QtCore.QRect(410, 180, 371, 201))
self.message_box.setReadOnly(True)
self.message_box.setObjectName("message_box")
self.solve_button = QtWidgets.QPushButton(self.centralwidget)
self.solve_button.setGeometry(QtCore.QRect(410, 30, 141, 61))
self.solve_button.setObjectName("solve_button")
self.solve_button.clicked.connect(self.solve)
self.enable_algorithm_check = QtWidgets.QCheckBox(self.centralwidget)
self.enable_algorithm_check.setGeometry(QtCore.QRect(410, 110, 161, 20))
self.enable_algorithm_check.setChecked(True)
self.enable_algorithm_check.setObjectName("enable_algorithm_check")
self.enable_brute_check = QtWidgets.QCheckBox(self.centralwidget)
self.enable_brute_check.setGeometry(QtCore.QRect(410, 140, 141, 20))
self.enable_brute_check.setChecked(True)
self.enable_brute_check.setObjectName("enable_brute_check")
self.clear_button = QtWidgets.QPushButton(self.centralwidget)
self.clear_button.setGeometry(QtCore.QRect(580, 30, 141, 61))
self.clear_button.setObjectName("clear_button")
self.clear_button.clicked.connect(self.clear)
canvas.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(canvas)
self.menubar.setGeometry(QtCore.QRect(0, 0, 824, 26))
self.menubar.setObjectName("menubar")
canvas.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(canvas)
self.statusbar.setObjectName("statusbar")
canvas.setStatusBar(self.statusbar)
self.retranslateUi(canvas)
QtCore.QMetaObject.connectSlotsByName(canvas)
canvas.setTabOrder(self.UL_ul, self.UL_um)
canvas.setTabOrder(self.UL_um, self.UL_ur)
canvas.setTabOrder(self.UL_ur, self.UM_ul)
canvas.setTabOrder(self.UM_ul, self.UM_um)
canvas.setTabOrder(self.UM_um, self.UM_ur)
canvas.setTabOrder(self.UM_ur, self.UR_ul)
canvas.setTabOrder(self.UR_ul, self.UR_um)
canvas.setTabOrder(self.UR_um, self.UR_ur)
canvas.setTabOrder(self.UR_ur, self.UL_ml)
canvas.setTabOrder(self.UL_ml, self.UL_mm)
canvas.setTabOrder(self.UL_mm, self.UL_mr)
canvas.setTabOrder(self.UL_mr, self.UM_ml)
canvas.setTabOrder(self.UM_ml, self.UM_mm)
canvas.setTabOrder(self.UM_mm, self.UM_mr)
canvas.setTabOrder(self.UM_mr, self.UR_ml)
canvas.setTabOrder(self.UR_ml, self.UR_mm)
canvas.setTabOrder(self.UR_mm, self.UR_mr)
canvas.setTabOrder(self.UR_mr, self.UL_ll)
canvas.setTabOrder(self.UL_ll, self.UL_lm)
canvas.setTabOrder(self.UL_lm, self.UL_lr)
canvas.setTabOrder(self.UL_lr, self.UM_ll)
canvas.setTabOrder(self.UM_ll, self.UM_lm)
canvas.setTabOrder(self.UM_lm, self.UM_lr)
canvas.setTabOrder(self.UM_lr, self.UR_ll)
canvas.setTabOrder(self.UR_ll, self.UR_lm)
canvas.setTabOrder(self.UR_lm, self.UR_lr)
canvas.setTabOrder(self.UR_lr, self.ML_ul)
canvas.setTabOrder(self.ML_ul, self.ML_um)
canvas.setTabOrder(self.ML_um, self.ML_ur)
canvas.setTabOrder(self.ML_ur, self.MM_ul)
canvas.setTabOrder(self.MM_ul, self.MM_um)
canvas.setTabOrder(self.MM_um, self.MM_ur)
canvas.setTabOrder(self.MM_ur, self.MR_ul)
canvas.setTabOrder(self.MR_ul, self.MR_um)
canvas.setTabOrder(self.MR_um, self.MR_ur)
canvas.setTabOrder(self.MR_ur, self.ML_ml)
canvas.setTabOrder(self.ML_ml, self.ML_mm)
canvas.setTabOrder(self.ML_mm, self.ML_mr)
canvas.setTabOrder(self.ML_mr, self.MM_ml)
canvas.setTabOrder(self.MM_ml, self.MM_mm)
canvas.setTabOrder(self.MM_mm, self.MM_mr)
canvas.setTabOrder(self.MM_mr, self.MR_ml)
canvas.setTabOrder(self.MR_ml, self.MR_mm)
canvas.setTabOrder(self.MR_mm, self.MR_mr)
canvas.setTabOrder(self.MR_mr, self.ML_ll)
canvas.setTabOrder(self.ML_ll, self.ML_lm)
canvas.setTabOrder(self.ML_lm, self.ML_lr)
canvas.setTabOrder(self.ML_lr, self.MM_ll)
canvas.setTabOrder(self.MM_ll, self.MM_lm)
canvas.setTabOrder(self.MM_lm, self.MM_lr)
canvas.setTabOrder(self.MM_lr, self.MR_ll)
canvas.setTabOrder(self.MR_ll, self.MR_lm)
canvas.setTabOrder(self.MR_lm, self.MR_lr)
canvas.setTabOrder(self.MR_lr, self.LL_ul)
canvas.setTabOrder(self.LL_ul, self.LL_um)
canvas.setTabOrder(self.LL_um, self.LL_ur)
canvas.setTabOrder(self.LL_ur, self.LM_ul)
canvas.setTabOrder(self.LM_ul, self.LM_um)
canvas.setTabOrder(self.LM_um, self.LM_ur)
canvas.setTabOrder(self.LM_ur, self.LR_ul)
canvas.setTabOrder(self.LR_ul, self.LR_um)
canvas.setTabOrder(self.LR_um, self.LR_ur)
canvas.setTabOrder(self.LR_ur, self.LL_ml)
canvas.setTabOrder(self.LL_ml, self.LL_mm)
canvas.setTabOrder(self.LL_mm, self.LL_mr)
canvas.setTabOrder(self.LL_mr, self.LM_ml)
canvas.setTabOrder(self.LM_ml, self.LM_mm)
canvas.setTabOrder(self.LM_mm, self.LM_mr)
canvas.setTabOrder(self.LM_mr, self.LR_ml)
canvas.setTabOrder(self.LR_ml, self.LR_mm)
canvas.setTabOrder(self.LR_mm, self.LR_mr)
canvas.setTabOrder(self.LR_mr, self.LL_ll)
canvas.setTabOrder(self.LL_ll, self.LL_lm)
canvas.setTabOrder(self.LL_lm, self.LL_lr)
canvas.setTabOrder(self.LL_lr, self.LM_ll)
canvas.setTabOrder(self.LM_ll, self.LM_lm)
canvas.setTabOrder(self.LM_lm, self.LM_lr)
canvas.setTabOrder(self.LM_lr, self.LR_ll)
canvas.setTabOrder(self.LR_ll, self.LR_lm)
canvas.setTabOrder(self.LR_lm, self.LR_lr)
canvas.setTabOrder(self.LR_lr, self.solve_button)
canvas.setTabOrder(self.solve_button, self.clear_button)
canvas.setTabOrder(self.clear_button, self.enable_algorithm_check)
canvas.setTabOrder(self.enable_algorithm_check, self.enable_brute_check)
canvas.setTabOrder(self.enable_brute_check, self.message_box)
self.grid[0,:] = np.array([ self.UL_ul, self.UL_um, self.UL_ur, self.UM_ul, self.UM_um, self.UM_ur, self.UR_ul, self.UR_um, self.UR_ur])
self.grid[1,:] = np.array([ self.UL_ml, self.UL_mm, self.UL_mr, self.UM_ml, self.UM_mm, self.UM_mr, self.UR_ml, self.UR_mm, self.UR_mr])
self.grid[2,:] = np.array([ self.UL_ll, self.UL_lm, self.UL_lr, self.UM_ll, self.UM_lm, self.UM_lr, self.UR_ll, self.UR_lm, self.UR_lr])
self.grid[3,:] = np.array([ self.ML_ul, self.ML_um, self.ML_ur, self.MM_ul, self.MM_um, self.MM_ur, self.MR_ul, self.MR_um, self.MR_ur])
self.grid[4,:] = np.array([ self.ML_ml, self.ML_mm, self.ML_mr, self.MM_ml, self.MM_mm, self.MM_mr, self.MR_ml, self.MR_mm, self.MR_mr])
self.grid[5,:] = np.array([ self.ML_ll, self.ML_lm, self.ML_lr, self.MM_ll, self.MM_lm, self.MM_lr, self.MR_ll, self.MR_lm, self.MR_lr])
self.grid[6,:] = np.array([ self.LL_ul, self.LL_um, self.LL_ur, self.LM_ul, self.LM_um, self.LM_ur, self.LR_ul, self.LR_um, self.LR_ur])
self.grid[7,:] = np.array([ self.LL_ml, self.LL_mm, self.LL_mr, self.LM_ml, self.LM_mm, self.LM_mr, self.LR_ml, self.LR_mm, self.LR_mr])
self.grid[8,:] = np.array([ self.LL_ll, self.LL_lm, self.LL_lr, self.LM_ll, self.LM_lm, self.LM_lr, self.LR_ll, self.LR_lm, self.LR_lr])
def retranslateUi(self, canvas):
_translate = QtCore.QCoreApplication.translate
canvas.setWindowTitle(_translate("canvas", "Sudoku Solver"))
self.solve_button.setText(_translate("canvas", "Solve"))
self.enable_algorithm_check.setText(_translate("canvas", "Enable Algorithm"))
self.enable_brute_check.setText(_translate("canvas", "Enable Brute Force"))
self.clear_button.setText(_translate("canvas", "Clear"))
def clear(self):
for i in range(DIM):
for j in range(DIM):
self.grid[i,j].setPlainText("")
self.message_box.setPlainText("")
def fillGrid(self, sud):
for i in range(DIM):
for j in range(DIM):
self.grid[i,j].setPlainText(str(sud[i,j].value))
def solve(self):
numbers = np.zeros((DIM,DIM))
for i in range(DIM):
for j in range(DIM):
val = self.grid[i,j].toPlainText()
if val.strip() == "":
numbers[i,j] = 0
elif not val.isdigit() or int(float(val)) < 1 or int(float(val)) > 9:
self.message_box.setPlainText(INVALID_VALUE)
return
else:
numbers[i,j] = int(float(val))
sudoku = SudokuSolver()
sudoku.load_grid(numbers)
message = sudoku.solve(self.enable_algorithm_check.checkState(), self.enable_brute_check.isChecked())
self.message_box.setPlainText(message)
self.fillGrid(sudoku.grid)
#print(numbers)
class AppWindow(QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_canvas()
self.ui.setupUi(self)
self.show()
app = QApplication(sys.argv)
w = AppWindow()
w.show()
sys.exit(app.exec_())