-
Notifications
You must be signed in to change notification settings - Fork 2
/
SuSol.py
4746 lines (4014 loc) · 192 KB
/
SuSol.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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#coding: utf8
from __future__ import print_function, unicode_literals
from PyQt4 import QtGui, QtCore
from misc import *
from copy import deepcopy
from time import time, localtime, strftime
from sqlite3 import connect
import sys
import solver2
import generator
import webbrowser
from os.path import isfile
if not isfile("data.db"):
soubor = open("data.db", "w+")
soubor.close()
db = connect("data.db")
db.execute("CREATE TABLE uzivatele(jmeno text)")
db.execute("CREATE TABLE sudoku_zadani(id integer primary key,identifikator text,uzivatel text,puvod text,zadani text,datum text)")
db.execute("CREATE TABLE sudoku_rozreseno(id integer primary key,uzivatel text,identifikator text,zadani text,doplneno text,kandidati text,barvy text,akronymy text,poznamky text,cas text,datum text)")
db.execute("CREATE TABLE settings(uzivatel text,barva1 text,barva2 text,barva3 text,barva4 text,barva5 text,barva6 text,barva7 text,barva8 text,barva9 text,kurzor text,doplneno text,souradnice text,font text,cbsouradnice text,cbkandidati text,styl text)")
db.execute("CREATE TABLE sudoku_soutez(id integer primary key,cas text,uzivatel text,obtiznost text,zadani text,datum text)")
db.commit()
else:
db = connect("data.db")
uzivatel = ""
class VlastniSudokuDialog(QtGui.QDialog):
def acceptDialog(self):
self.limit = self.cisla.value()
self.singlesol = self.jednoznacne.isChecked()
self.bf = self.bf.isChecked()
self.close()
self.isAccepted = True
def rejectDialog(self):
self.close()
self.isAccepted = False
def __init__(self):
super(VlastniSudokuDialog,self).__init__()
self.isAccepted = None
self.resize(300,230)
self.setWindowTitle("Vlastní sudoku")
self.jednoznacne = QtGui.QCheckBox(self)
self.bf = QtGui.QCheckBox(self)
self.cisla = QtGui.QSpinBox(self)
self.label = QtGui.QLabel(self)
self.label.setText("Minimální počet zadaných čísel")
self.cisla.setRange(0,80)
self.cisla.setToolTip("Počet čísel, které po vygenerování budou předvyplněna")
self.jednoznacne.setText("Jednoznačné řešení")
self.jednoznacne.setToolTip("Sudoku bude mít právě jedno řešení")
self.bf.setText("Použít hrubou sílu při testu jednoznačnosti")
self.bf.setToolTip("Při testu jednoznačnosti se při řešení použije hrubá síla\nVýsledkem je trochu těžší sudoku")
self.jednoznacne.move(8,30)
self.bf.move(8,80)
self.cisla.move(8,130)
self.label.move(70,130)
tlacitka = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel,parent=self)
tlacitka.accepted.connect(self.acceptDialog)
tlacitka.rejected.connect(self.rejectDialog)
tlacitka.move(100,200)
class VysledkyDialog(QtGui.QDialog):
def paintEvent(self, QPaintEvent):
painter = QtGui.QPainter(self)
painter.setPen(QtGui.QColor("#000000"))
painter.setBrush(QtGui.QColor("#ffffff"))
painter.drawRect(130,220,250,250)
for i in range(1,9,1):
painter.drawLine(130,220+i*250/9,380,220+i*250/9)
painter.drawLine(130+i*250/9,220,130+i*250/9,470)
pismo = QtGui.QFont(okno.pismoCeleAplikace)
pismo.setPixelSize(20)
painter.setFont(pismo)
for i in range(0,9,1):
for j in range(0,9,1):
if self.aktivniSudoku[j][i] != 0:
painter.drawText(130+(i+0.4)*250/9,220+(j+0.85)*250/9,str(self.aktivniSudoku[j][i]))
painter.setBrush(QtGui.QColor("#000000"))
for i in range(0,4,1):
painter.drawRect(130,220+250*i/3,250,2)
painter.drawRect(130+250*i/3,220,2,250)
painter.end()
def acceptDialog(self):
self.close()
okno.zadani = deepcopy(self.aktivniSudoku)
okno.zadaniBackup = deepcopy(self.aktivniSudoku)
okno.zobrazElementy("reseni")
okno.update()
def rejectDialog(self):
self.close()
okno.update()
def vybranRadek(self):
try:
cisloRadku = self.tabulka.currentItem().row()
aktivniID = self.tabulka.item(cisloRadku,0).text()
except AttributeError:
aktivniID = 1
# sudoku_z_db = string2sudoku(DB2list(db.execute("SELECT zadani FROM sudoku_soutez WHERE id="+str(aktivniID)))[0])
sudoku_z_db = string2sudoku(DB2list(db.execute("SELECT zadani FROM sudoku_soutez WHERE id=?",[str(aktivniID)]))[0])
for i in range(0,9,1):
self.aktivniSudoku[i] = deepcopy(sudoku_z_db[i])
self.update()
def __init__(self,level):
super(VysledkyDialog,self).__init__()
seznam_z_db = wideDB2list(db.execute("SELECT id,cas,uzivatel,obtiznost,datum FROM sudoku_soutez WHERE obtiznost='"+"gen. ("+level+")' ORDER BY cas"))
db.commit()
self.aktivniSudoku = [
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0]
]
self.resize(500,500)
self.setFixedSize(500,500)
self.setWindowTitle("Výsledky")
self.tabulka = QtGui.QTableWidget(self)
self.tabulka.setMinimumWidth(500)
self.tabulka.setFixedHeight(200)
self.tabulka.setColumnCount(5)
self.tabulka.setColumnWidth(0,92)
self.tabulka.setColumnWidth(1,92)
self.tabulka.setColumnWidth(2,92)
self.tabulka.setColumnWidth(3,92)
self.tabulka.setColumnWidth(4,92)
self.tabulka.setRowCount(len(seznam_z_db))
self.tabulka.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.tabulka.setHorizontalHeaderLabels(["#","Čas","Uživatel","Obtížnost","Datum"])
self.tabulka.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.tabulka.setSortingEnabled(True)
self.tabulka.itemSelectionChanged.connect(self.vybranRadek)
self.tabulka.cellDoubleClicked.connect(self.acceptDialog)
self.tabulka.selectRow(0)
for i in range(0,len(seznam_z_db),1):
for j in range(0,5,1):
self.tabulka.setItem(i, j, QtGui.QTableWidgetItem(unicode(seznam_z_db[i][j])))
tlacitka = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Close,parent=self)
tlacitka.accepted.connect(self.acceptDialog)
tlacitka.rejected.connect(self.rejectDialog)
tlacitka.move(400,475)
self.resitStejne = QtGui.QPushButton(self)
self.resitStejne.setText("Otevřít sudoku v tréninkovém režimu")
self.resitStejne.move(10,475)
self.resitStejne.clicked.connect(self.acceptDialog)
class LoadFromDBDialog(QtGui.QDialog):
def paintEvent(self, QPaintEvent):
painter = QtGui.QPainter(self)
painter.setPen(QtGui.QColor("#000000"))
painter.setBrush(QtGui.QColor("#ffffff"))
painter.drawRect(130,220,250,250)
for i in range(1,9,1):
painter.drawLine(130,220+i*250/9,380,220+i*250/9)
painter.drawLine(130+i*250/9,220,130+i*250/9,470)
pismo = QtGui.QFont(okno.pismoCeleAplikace)
pismo.setPixelSize(20)
painter.setFont(pismo)
for i in range(0,9,1):
for j in range(0,9,1):
if self.aktivniSudoku[j][i] != 0:
painter.drawText(130+(i+0.4)*250/9,220+(j+0.85)*250/9,str(self.aktivniSudoku[j][i]))
painter.setBrush(QtGui.QColor("#000000"))
for i in range(0,4,1):
painter.drawRect(130,220+250*i/3,250,2)
painter.drawRect(130+250*i/3,220,2,250)
painter.end()
def acceptDialog(self):
self.close()
okno.zadani = deepcopy(self.aktivniSudoku)
okno.zadaniBackup = deepcopy(self.aktivniSudoku)
okno.update()
def rejectDialog(self):
self.close()
okno.update()
def vybranRadek(self):
try:
cisloRadku = self.tabulka.currentItem().row()
aktivniID = self.tabulka.item(cisloRadku,0).text()
except AttributeError:
aktivniID = 1
# sudoku_z_db = string2sudoku(DB2list(db.execute("SELECT zadani FROM sudoku_zadani WHERE id="+str(aktivniID)))[0])
sudoku_z_db = string2sudoku(DB2list(db.execute("SELECT zadani FROM sudoku_zadani WHERE id=?",[str(aktivniID)]))[0])
for i in range(0,9,1):
self.aktivniSudoku[i] = deepcopy(sudoku_z_db[i])
self.update()
def __init__(self):
super(LoadFromDBDialog,self).__init__()
seznam_z_db = wideDB2list(db.execute("SELECT id,datum,uzivatel,identifikator,puvod FROM sudoku_zadani"))
db.commit()
self.aktivniSudoku = [
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0]
]
self.resize(500,500)
self.setFixedSize(500,500)
self.setWindowTitle("Načíst z databáze")
self.tabulka = QtGui.QTableWidget(self)
self.tabulka.setMinimumWidth(500)
self.tabulka.setFixedHeight(200)
self.tabulka.setColumnCount(5)
self.tabulka.setColumnWidth(0,92)
self.tabulka.setColumnWidth(1,92)
self.tabulka.setColumnWidth(2,92)
self.tabulka.setColumnWidth(3,92)
self.tabulka.setColumnWidth(4,92)
self.tabulka.setRowCount(len(seznam_z_db))
self.tabulka.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.tabulka.setHorizontalHeaderLabels(["#","Datum","Uživatel","Identifikátor","Původ"])
self.tabulka.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.tabulka.setSortingEnabled(True)
self.tabulka.itemSelectionChanged.connect(self.vybranRadek)
self.tabulka.cellDoubleClicked.connect(self.acceptDialog)
self.tabulka.selectRow(0)
for i in range(0,len(seznam_z_db),1):
for j in range(0,5,1):
self.tabulka.setItem(i, j, QtGui.QTableWidgetItem(unicode(seznam_z_db[i][j])))
tlacitka = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel,parent=self)
tlacitka.accepted.connect(self.acceptDialog)
tlacitka.rejected.connect(self.rejectDialog)
tlacitka.move(330,475)
class LoadFromDBDialog2(QtGui.QDialog):
def paintEvent(self, QPaintEvent):
painter = QtGui.QPainter(self)
painter.setPen(QtGui.QColor("#000000"))
painter.setBrush(QtGui.QColor("#ffffff"))
painter.drawRect(130,220,250,250)
for i in range(1,9,1):
painter.drawLine(130,220+i*250/9,380,220+i*250/9)
painter.drawLine(130+i*250/9,220,130+i*250/9,470)
pismo = QtGui.QFont(okno.pismoCeleAplikace)
pismo.setPixelSize(20)
painter.setFont(pismo)
for i in range(0,9,1):
for j in range(0,9,1):
if self.aktivniSudoku[j][i] != 0:
painter.setPen(QtGui.QColor("#000000"))
painter.drawText(130+(i+0.4)*250/9,220+(j+0.85)*250/9,str(self.aktivniSudoku[j][i]))
if self.predtimDoplneno[j][i] != 0:
painter.setPen(QtGui.QColor("#0000ff"))
painter.drawText(130+(i+0.4)*250/9,220+(j+0.85)*250/9,str(self.predtimDoplneno[j][i]))
painter.setPen(QtGui.QColor("#000000"))
painter.setBrush(QtGui.QColor("#000000"))
for i in range(0,4,1):
painter.drawRect(130,220+250*i/3,250,2)
painter.drawRect(130+250*i/3,220,2,250)
painter.end()
def acceptDialog(self):
self.close()
try:
cisloRadku = self.tabulka.currentItem().row()
aktivniID = self.tabulka.item(cisloRadku,0).text()
except AttributeError:
aktivniID = 1
# load = wideDB2list(db.execute("SELECT zadani,doplneno,kandidati,barvy,akronymy,poznamky,cas FROM sudoku_rozreseno WHERE id="+str(aktivniID)))[0]
load = wideDB2list(db.execute("SELECT zadani,doplneno,kandidati,barvy,akronymy,poznamky,cas FROM sudoku_rozreseno WHERE id=?",[str(aktivniID)]))[0]
okno.zadani = deepcopy(string2sudoku(load[0]))
okno.reseni = deepcopy(string2sudoku(load[1]))
okno.kandidati = deepcopy(string2cand(load[2]))
okno.barvy = deepcopy(string2cand(load[3]))
okno.akronymy = deepcopy(string2note(load[4]))
okno.poznamky = deepcopy(string2note(load[5]))
okno.time = string2time(load[6])
okno.zadaniBackup = deepcopy(okno.zadani)
okno.zobrazElementy("reseni",noreset=True)
okno.update()
def rejectDialog(self):
self.close()
okno.update()
def vybranRadek(self):
try:
cisloRadku = self.tabulka.currentItem().row()
aktivniID = self.tabulka.item(cisloRadku,0).text()
except AttributeError:
aktivniID = 1
# sudoku_z_db = string2sudoku(DB2list(db.execute("SELECT zadani FROM sudoku_rozreseno WHERE id="+str(aktivniID)))[0])
sudoku_z_db = string2sudoku(DB2list(db.execute("SELECT zadani FROM sudoku_rozreseno WHERE id=?",[str(aktivniID)]))[0])
# reseni_z_db = string2sudoku(DB2list(db.execute("SELECT doplneno FROM sudoku_rozreseno WHERE id="+str(aktivniID)))[0])
reseni_z_db = string2sudoku(DB2list(db.execute("SELECT doplneno FROM sudoku_rozreseno WHERE id=?",[str(aktivniID)]))[0])
for i in range(0,9,1):
self.aktivniSudoku[i] = deepcopy(sudoku_z_db[i])
self.predtimDoplneno[i] = deepcopy(reseni_z_db[i])
self.update()
def __init__(self):
super(LoadFromDBDialog2,self).__init__()
# seznam_z_db = wideDB2list(db.execute("SELECT id,datum,uzivatel,identifikator FROM sudoku_rozreseno WHERE uzivatel='"+unicode(okno.uzivatel)+"'"))
seznam_z_db = wideDB2list(db.execute("SELECT id,datum,uzivatel,identifikator FROM sudoku_rozreseno WHERE uzivatel=?",[unicode(okno.uzivatel)]))
db.commit()
pole = []
for i in range(0,len(seznam_z_db),1):
# zadani = wideDB2list(db.execute("SELECT zadani FROM sudoku_rozreseno WHERE id="+str(seznam_z_db[i][0])))[0][0]
zadani = wideDB2list(db.execute("SELECT zadani FROM sudoku_rozreseno WHERE id=?",[str(seznam_z_db[i][0])]))[0][0]
# reseni = wideDB2list(db.execute("SELECT doplneno FROM sudoku_rozreseno WHERE id="+str(seznam_z_db[i][0])))[0][0]
reseni = wideDB2list(db.execute("SELECT doplneno FROM sudoku_rozreseno WHERE id=?",[str(seznam_z_db[i][0])]))[0][0]
db.commit()
pole.append([])
zadano = 81-zadani.count("0")
k_reseni = 81-zadano
reseno = reseni.count("1")+reseni.count("2")+reseni.count("3")+reseni.count("4")+reseni.count("5")+reseni.count("6")+reseni.count("7")+reseni.count("8")+reseni.count("9")
pomer = str(reseno)+"/"+str(k_reseni)+" ("+str(100*reseno/k_reseni)+"%)"
pole[i].append(seznam_z_db[i][0])
pole[i].append(seznam_z_db[i][1])
pole[i].append(seznam_z_db[i][2])
pole[i].append(seznam_z_db[i][3])
pole[i].append(pomer)
self.aktivniSudoku = [
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0]
]
self.predtimDoplneno = [
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0]
]
self.resize(500,500)
self.setFixedSize(500,500)
self.setWindowTitle("Moje sudoku")
self.tabulka = QtGui.QTableWidget(self)
self.tabulka.setMinimumWidth(500)
self.tabulka.setFixedHeight(200)
self.tabulka.setColumnCount(5)
self.tabulka.setColumnWidth(0,92)
self.tabulka.setColumnWidth(1,92)
self.tabulka.setColumnWidth(2,92)
self.tabulka.setColumnWidth(3,92)
self.tabulka.setColumnWidth(4,92)
self.tabulka.setRowCount(len(seznam_z_db))
self.tabulka.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.tabulka.setHorizontalHeaderLabels(["#","Datum","Uživatel","Identifikátor","Doplněno"])
self.tabulka.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.tabulka.setSortingEnabled(True)
self.tabulka.itemSelectionChanged.connect(self.vybranRadek)
self.tabulka.cellDoubleClicked.connect(self.acceptDialog)
self.tabulka.selectRow(0)
for i in range(0,len(seznam_z_db),1):
for j in range(0,5,1):
self.tabulka.setItem(i, j, QtGui.QTableWidgetItem(unicode(pole[i][j])))
tlacitka = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel,parent=self)
tlacitka.accepted.connect(self.acceptDialog)
tlacitka.rejected.connect(self.rejectDialog)
tlacitka.move(330,475)
class DBInsertDialog(QtGui.QDialog):
def acceptDialog(self):
identifikator = unicode(self.entry.text())
# db.execute("INSERT INTO sudoku_zadani VALUES(NULL,'"+unicode(identifikator)+"','"+unicode(okno.uzivatel)+"','"+unicode(okno.puvod)+"','"+unicode(sudoku2string(okno.zadani))+"','"+unicode(strftime("%Y-%m-%d %H:%M:%S", localtime()))+"')")
db.execute("INSERT INTO sudoku_zadani VALUES (NULL,?,?,?,?,?)",[unicode(identifikator),unicode(okno.uzivatel),unicode(okno.puvod),unicode(sudoku2string(okno.zadani)),unicode(strftime("%Y-%m-%d %H:%M:%S", localtime()))])
db.commit()
self.close()
def rejectDialog(self):
self.close()
okno.reject1 = True
def keyPressEvent(self, QKeyEvent):
if QKeyEvent.key() == QtCore.Qt.Key_Return:
self.acceptDialog()
elif QKeyEvent.key() == QtCore.Qt.Key_Escape:
self.rejectDialog()
def __init__(self):
super(DBInsertDialog,self).__init__()
self.setWindowTitle("Uložit do databáze")
self.resize(300,300)
self.label = QtGui.QLabel(self)
self.label.setText("Identifikátor:")
self.label.move(50,50)
self.entry = QtGui.QLineEdit(self)
self.entry.setMinimumWidth(200)
self.entry.move(50,100)
self.entry.setFocus()
self.label2 =QtGui.QLabel(self)
self.label2.setText("Hint: Toto sudoku se nenachází v databázi. Pro pokračování musí být uloženo, aby k němu potom bylo možno v budoucnosti přistupovat.")
self.label2.setWordWrap(True)
self.label2.move(50,150)
tlacitka = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel,parent=self)
tlacitka.accepted.connect(self.acceptDialog)
tlacitka.rejected.connect(self.rejectDialog)
tlacitka.move(60,260)
class DBInsertDialog2(QtGui.QDialog):
def acceptDialog(self):
identifikator = unicode(self.entry.text())
# db.execute("INSERT INTO sudoku_rozreseno VALUES(NULL,'"+unicode(okno.uzivatel)+"','"+unicode(identifikator)+"','"+unicode(sudoku2string(okno.zadani))+"','"+unicode(sudoku2string(okno.reseni))+"','"+unicode(cand2string(okno.kandidati))+"','"+unicode(cand2string(okno.barvy))+"','"+unicode(note2string(okno.akronymy))+"','"+unicode(note2string(okno.poznamky))+"','"+unicode(okno.cas.text()[5:])+"','"+unicode(strftime("%Y-%m-%d %H:%M:%S", localtime()))+"')")
db.execute("INSERT INTO sudoku_rozreseno VALUES (NULL,?,?,?,?,?,?,?,?,?,?)",[unicode(okno.uzivatel),unicode(identifikator),unicode(sudoku2string(okno.zadani)),unicode(sudoku2string(okno.reseni)),unicode(cand2string(okno.kandidati)),unicode(cand2string(okno.barvy)),unicode(note2string(okno.akronymy)),unicode(note2string(okno.poznamky)),unicode(okno.cas.text()[5:]),unicode(strftime("%Y-%m-%d %H:%M:%S", localtime()))])
db.commit()
self.close()
okno.ukecanejBanner.setText("Sudoku uloženo.")
def rejectDialog(self):
self.close()
okno.reject1 = True
def keyPressEvent(self, QKeyEvent):
if QKeyEvent.key() == QtCore.Qt.Key_Return:
self.acceptDialog()
elif QKeyEvent.key() == QtCore.Qt.Key_Escape:
self.rejectDialog()
def __init__(self):
super(DBInsertDialog2,self).__init__()
self.setWindowTitle("Uložit do databáze")
self.resize(300,300)
self.label = QtGui.QLabel(self)
self.label.setText("Identifikátor:")
self.label.move(50,50)
self.entry = QtGui.QLineEdit(self)
self.entry.setMinimumWidth(200)
self.entry.move(50,100)
self.entry.setFocus()
self.label2 =QtGui.QLabel(self)
self.label2.setText("Hint: Uložte si rozřešené sudoku, abyste jej mohli kdykoli dokončit. Sudoku naleznete v záložce \"Moje sudoku\" pod svým uživatelským jménem.")
self.label2.setWordWrap(True)
self.label2.move(50,150)
tlacitka = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel,parent=self)
tlacitka.accepted.connect(self.acceptDialog)
tlacitka.rejected.connect(self.rejectDialog)
tlacitka.move(60,260)
class UserSelectDialog(QtGui.QDialog):
def acceptDialog(self):
global uzivatel
self.zabit = False
if self.rb1.isChecked():
uzivatel = unicode(self.entry.text())
seznam_v_db = DB2list(db.execute("SELECT * FROM uzivatele").fetchall())
if uzivatel in seznam_v_db:
QtGui.QMessageBox.critical(None,"Chyba","Toto uživatelské jméno již existuje. Zvol si jiné.")
return False
if len(uzivatel) == 0:
QtGui.QMessageBox.critical(None,"Chyba","Zadejte uživatelské jméno.")
return False
# db.execute("INSERT INTO uzivatele VALUES ('"+unicode(uzivatel)+"')")
db.execute("INSERT INTO uzivatele VALUES (?)",[unicode(uzivatel)])
# db.execute("INSERT INTO settings VALUES ('"+unicode(uzivatel)+"','#8888ff','#88ff88','#ff8888','#ffff88','#ff88ff','#88ffff','#880088','#888800','#008888','#ffbbbb','#0000ff','#888888','Arial','1','0','"+unicode(QtGui.QStyleFactory.keys()[0])+"')")
db.execute("INSERT INTO settings VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",[unicode(uzivatel),'#8888ff','#88ff88','#ff8888','#ffff88','#ff88ff','#88ffff','#880088','#888800','#008888','#ffbbbb','#0000ff','#888888','Arial','1','0',unicode(QtGui.QStyleFactory.keys()[0])])
elif self.rb2.isChecked():
uzivatel = self.combobox.currentText()
db.commit()
try:
okno.fetchSettings()
except NameError:
pass
self.close()
def rejectDialog(self):
exit()
def closeEvent(self, QCloseEvent):
if self.zabit:
exit()
def keyPressEvent(self, QKeyEvent):
key = QKeyEvent.key()
if key == QtCore.Qt.Key_Return:
self.acceptDialog()
def click2(self):
self.entry.setDisabled(True)
self.combobox.setDisabled(False)
self.rb1.setFocus()
self.combobox.setFocus()
def click1(self):
self.entry.setDisabled(False)
self.combobox.setDisabled(True)
self.rb2.setFocus()
self.entry.setFocus()
def __init__(self):
super(UserSelectDialog,self).__init__()
self.zabit = True
self.resize(300,300)
self.setWindowTitle("SuSol - Zvolit uživatele")
self.rb1 = QtGui.QRadioButton(self)
self.rb1.setText("Založit nového")
self.rb1.move(0,150)
self.rb1.clicked.connect(self.click1)
self.rb2 = QtGui.QRadioButton(self)
self.rb2.setText("Vybrat existujícího")
self.rb2.setChecked(True)
self.rb2.clicked.connect(self.click2)
self.combobox = QtGui.QComboBox(self)
seznam_v_db = DB2list(db.execute("SELECT * FROM uzivatele").fetchall())
for i in range(0,len(seznam_v_db),1):
self.combobox.addItem(seznam_v_db[i])
self.combobox.move(50,50)
self.combobox.setMinimumWidth(200)
self.entry = QtGui.QLineEdit(self)
self.entry.move(50,200)
self.entry.setMinimumWidth(200)
self.entry.setDisabled(True)
self.combobox.setFocus()
tlacitka = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel,parent=self)
tlacitka.move(115,260)
tlacitka.accepted.connect(self.acceptDialog)
tlacitka.rejected.connect(self.rejectDialog)
if len(seznam_v_db) == 0:
self.rb2.setDisabled(True)
self.rb1.setChecked(True)
self.entry.setDisabled(False)
self.entry.setFocus()
class UserSelectDialog2(QtGui.QDialog):
def acceptDialog(self):
self.zabit = True
if self.rb1.isChecked():
okno.uzivatel = unicode(self.entry.text())
seznam_v_db = DB2list(db.execute("SELECT * FROM uzivatele").fetchall())
if okno.uzivatel in seznam_v_db:
QtGui.QMessageBox.critical(None,"Chyba","Toto uživatelské jméno již existuje. Zvol si jiné.")
return False
if len(uzivatel) == 0:
QtGui.QMessageBox.critical(None,"Chyba","Zadejte uživatelské jméno.")
return False
# db.execute("INSERT INTO uzivatele VALUES ('"+unicode(okno.uzivatel)+"')")
db.execute("INSERT INTO uzivatele VALUES (?)",[unicode(uzivatel)])
# db.execute("INSERT INTO settings VALUES ('"+unicode(okno.uzivatel)+"','#8888ff','#88ff88','#ff8888','#ffff88','#ff88ff','#88ffff','#880088','#888800','#008888','#ffbbbb','#0000ff','#888888','Arial','1','0','"+unicode(QtGui.QStyleFactory.keys()[0])+"')")
db.execute("INSERT INTO settings VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",[unicode(uzivatel),'#8888ff','#88ff88','#ff8888','#ffff88','#ff88ff','#88ffff','#880088','#888800','#008888','#ffbbbb','#0000ff','#888888','Arial','1','0',unicode(QtGui.QStyleFactory.keys()[0])])
elif self.rb2.isChecked():
okno.uzivatel = self.combobox.currentText()
okno.mainMenu4.setTitle("&Uživatel: "+okno.uzivatel)
db.commit()
okno.fetchSettings()
self.close()
okno.update()
def rejectDialog(self):
self.close()
okno.update()
def click2(self):
self.entry.setDisabled(True)
self.combobox.setDisabled(False)
self.rb1.setFocus()
self.combobox.setFocus()
def click1(self):
self.entry.setDisabled(False)
self.combobox.setDisabled(True)
self.rb2.setFocus()
self.entry.setFocus()
def __init__(self):
super(UserSelectDialog2,self).__init__()
self.resize(300,300)
self.setWindowTitle("Zvolit uživatele")
self.rb1 = QtGui.QRadioButton(self)
self.rb1.setText("Založit nového")
self.rb1.move(0,150)
self.rb1.clicked.connect(self.click1)
self.rb2 = QtGui.QRadioButton(self)
self.rb2.setText("Vybrat existujícího")
self.rb2.setChecked(True)
self.rb2.clicked.connect(self.click2)
self.combobox = QtGui.QComboBox(self)
seznam_v_db = DB2list(db.execute("SELECT * FROM uzivatele").fetchall())
for i in range(0,len(seznam_v_db),1):
self.combobox.addItem(seznam_v_db[i])
self.combobox.move(50,50)
self.combobox.setMinimumWidth(200)
self.entry = QtGui.QLineEdit(self)
self.entry.move(50,200)
self.entry.setMinimumWidth(200)
self.entry.setDisabled(True)
self.combobox.setFocus()
tlacitka = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel,parent=self)
tlacitka.move(115,260)
tlacitka.accepted.connect(self.acceptDialog)
tlacitka.rejected.connect(self.rejectDialog)
class ShortNoteDialog(QtGui.QDialog):
def setTitle(self,title):
self.setWindowTitle(title)
def setDefaultText(self,text):
self.editShortNoteTB.setText(unicode(text))
def acceptDialog(self):
self.signal = True
self.obsah = unicode(self.editShortNoteTB.text())
if len(self.obsah) > 8:
warn = QtGui.QMessageBox.warning(None,"Varování","Akronym nemůže být delší než 8 znaků.")
self.obsah = ""
elif "|" in self.obsah:
warn = QtGui.QMessageBox.warning(None,"Varování","Akronym obsahuje nepovolený znak: |")
self.obsah = ""
else:
self.close()
def rejectDialog(self):
self.close()
def __init__(self):
super(ShortNoteDialog, self).__init__()
self.obsah = ""
self.signal = False
self.resize(250,50)
layout = QtGui.QVBoxLayout(self)
self.editShortNoteTB = QtGui.QLineEdit()
tlacitka = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel)
tlacitka.accepted.connect(self.acceptDialog)
tlacitka.rejected.connect(self.rejectDialog)
layout.addWidget(self.editShortNoteTB)
layout.addWidget(tlacitka)
class LongNoteDialog(QtGui.QDialog):
def setTitle(self,title):
self.setWindowTitle(title)
def setDefaultText(self,text):
self.editLongNoteTB.setText(text)
def acceptDialog(self):
self.signal = True
self.obsah = unicode(self.editLongNoteTB.toPlainText())
if "|" in self.obsah:
warn = QtGui.QMessageBox.warning(None,"Varování","Poznámka obsahuje nepovolený znak: |")
self.obsah = ""
else:
self.close()
def rejectDialog(self):
self.close()
def __init__(self):
super(LongNoteDialog,self).__init__()
QtGui.QShortcut(QtGui.QKeySequence("Ctrl+Return"),self,self.acceptDialog)
self.obsah = ""
self.signal = False
self.resize(250,250)
layout = QtGui.QVBoxLayout(self)
self.editLongNoteTB = QtGui.QTextEdit()
tlacitka = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel)
tlacitka.accepted.connect(self.acceptDialog)
tlacitka.rejected.connect(self.rejectDialog)
layout.addWidget(self.editLongNoteTB)
layout.addWidget(tlacitka)
class RemoveColorDialog(QtGui.QDialog):
def click1(self):
self.color1.setText("x")
self.color1.setChecked(True)
self.color2.setText("")
self.color2.setChecked(False)
self.color3.setText("")
self.color3.setChecked(False)
self.color4.setText("")
self.color4.setChecked(False)
self.color5.setText("")
self.color5.setChecked(False)
self.color6.setText("")
self.color6.setChecked(False)
self.color7.setText("")
self.color7.setChecked(False)
self.color8.setText("")
self.color8.setChecked(False)
self.color9.setText("")
self.color9.setChecked(False)
def click2(self):
self.color2.setText("x")
self.color2.setChecked(True)
self.color1.setText("")
self.color1.setChecked(False)
self.color3.setText("")
self.color3.setChecked(False)
self.color4.setText("")
self.color4.setChecked(False)
self.color5.setText("")
self.color5.setChecked(False)
self.color6.setText("")
self.color6.setChecked(False)
self.color7.setText("")
self.color7.setChecked(False)
self.color8.setText("")
self.color8.setChecked(False)
self.color9.setText("")
self.color9.setChecked(False)
def click3(self):
self.color3.setText("x")
self.color3.setChecked(True)
self.color2.setText("")
self.color2.setChecked(False)
self.color1.setText("")
self.color1.setChecked(False)
self.color4.setText("")
self.color4.setChecked(False)
self.color5.setText("")
self.color5.setChecked(False)
self.color6.setText("")
self.color6.setChecked(False)
self.color7.setText("")
self.color7.setChecked(False)
self.color8.setText("")
self.color8.setChecked(False)
self.color9.setText("")
self.color9.setChecked(False)
def click4(self):
self.color4.setText("x")
self.color4.setChecked(True)
self.color2.setText("")
self.color2.setChecked(False)
self.color3.setText("")
self.color3.setChecked(False)
self.color1.setText("")
self.color1.setChecked(False)
self.color5.setText("")
self.color5.setChecked(False)
self.color6.setText("")
self.color6.setChecked(False)
self.color7.setText("")
self.color7.setChecked(False)
self.color8.setText("")
self.color8.setChecked(False)
self.color9.setText("")
self.color9.setChecked(False)
def click5(self):
self.color5.setText("x")
self.color5.setChecked(True)
self.color2.setText("")
self.color2.setChecked(False)
self.color3.setText("")
self.color3.setChecked(False)
self.color4.setText("")
self.color4.setChecked(False)
self.color1.setText("")
self.color1.setChecked(False)
self.color6.setText("")
self.color6.setChecked(False)
self.color7.setText("")
self.color7.setChecked(False)
self.color8.setText("")
self.color8.setChecked(False)
self.color9.setText("")
self.color9.setChecked(False)
def click6(self):
self.color6.setText("x")
self.color6.setChecked(True)
self.color2.setText("")
self.color2.setChecked(False)
self.color3.setText("")
self.color3.setChecked(False)
self.color4.setText("")
self.color4.setChecked(False)
self.color5.setText("")
self.color5.setChecked(False)
self.color1.setText("")
self.color1.setChecked(False)
self.color7.setText("")
self.color7.setChecked(False)
self.color8.setText("")
self.color8.setChecked(False)
self.color9.setText("")
self.color9.setChecked(False)
def click7(self):
self.color7.setText("x")
self.color7.setChecked(True)
self.color2.setText("")
self.color2.setChecked(False)
self.color3.setText("")
self.color3.setChecked(False)
self.color4.setText("")
self.color4.setChecked(False)
self.color5.setText("")
self.color5.setChecked(False)
self.color6.setText("")
self.color6.setChecked(False)
self.color1.setText("")
self.color1.setChecked(False)
self.color8.setText("")
self.color8.setChecked(False)
self.color9.setText("")
self.color9.setChecked(False)
def click8(self):
self.color8.setText("x")
self.color8.setChecked(True)
self.color2.setText("")
self.color2.setChecked(False)
self.color3.setText("")
self.color3.setChecked(False)
self.color4.setText("")
self.color4.setChecked(False)
self.color5.setText("")
self.color5.setChecked(False)
self.color6.setText("")
self.color6.setChecked(False)
self.color7.setText("")
self.color7.setChecked(False)
self.color1.setText("")
self.color1.setChecked(False)
self.color9.setText("")
self.color9.setChecked(False)
def click9(self):
self.color9.setText("x")
self.color9.setChecked(True)
self.color2.setText("")
self.color2.setChecked(False)
self.color3.setText("")
self.color3.setChecked(False)
self.color4.setText("")
self.color4.setChecked(False)
self.color5.setText("")
self.color5.setChecked(False)
self.color6.setText("")
self.color6.setChecked(False)
self.color7.setText("")
self.color7.setChecked(False)
self.color8.setText("")
self.color8.setChecked(False)
self.color1.setText("")
self.color1.setChecked(False)
def provest1(self):
obsah = unicode(self.entry.text())
if len(obsah) != 2:
warn = QtGui.QMessageBox.warning(None,"Varování","Neplatné souřadnice políčka.")
return False
pism = alpha2num(obsah[0])
if pism == -1:
warn = QtGui.QMessageBox.warning(None,"Varování","Neplatné souřadnice políčka.")
return False
cis = obsah[1]
if cis not in ("1","2","3","4","5","6","7","8","9"):
warn = QtGui.QMessageBox.warning(None,"Varování","Neplatné souřadnice políčka.")
return False
cis = int(cis)