-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.py
53 lines (45 loc) · 1.47 KB
/
App.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
from sudoku import *
import copy
import eel
current_sudoku_onboard = []
updated_sudoku = []
solved_sudoku = []
# python functions exposed to javascript
@eel.expose
def generate_new_sudoku(level):
global current_sudoku_onboard
global updated_sudoku
global solved_sudoku
# generating sudoku for required level
current_sudoku_onboard = Sudoku().generate_sudoku(int(level))
updated_sudoku = copy.deepcopy(current_sudoku_onboard)
# drawing sudoku by calling javascript function from python
eel.draw_sudoku(current_sudoku_onboard)
solved_sudoku = Sudoku().solve(current_sudoku_onboard,visualize=False,draw=False)
@eel.expose
def solve_sudoku(mode):
global current_sudoku_onboard
eel.draw_sudoku(current_sudoku_onboard)
# solving the sudoku (quick mode or visualize)
Sudoku().solve(current_sudoku_onboard, int(mode))
@eel.expose
def validate_sudoku(index,val):
global updated_sudoku
global solved_sudoku
row = int(index)//9
col = int(index)%9
value = 0
updated_sudoku[row][col] = value
if val != "":
value = int(val)
eel.validate(index,Sudoku().validate_cell(updated_sudoku,value,row,col))
else:
eel.validate(index, True)
updated_sudoku[row][col] = value
if updated_sudoku == solved_sudoku:
eel.done()
if __name__ == "__main__":
# initializing eel with the dir containing HTML resources
eel.init("www")
# starting eel server
eel.start('index.html', size=(540, 660))