-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjigsaw_solver_screen.py
61 lines (48 loc) · 2.82 KB
/
jigsaw_solver_screen.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
import tkinter
import tkinter.messagebox
from tkinter import Tk, filedialog
import ntpath
import json
from PIL import Image
import sys
import os
import customtkinter
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
x_folder_path = os.path.join(parent_dir, 'jigsaw-genius\\solvers\\part_2\\')
sys.path.append(x_folder_path)
from main import solve_jigsaw
class JigsawSolverScreen(tkinter.Frame):
def __init__(self, parent, controller):
tkinter.Frame.__init__(self, parent, background='#191919')
self.controller = controller
self.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(0, weight=1)
# crate the main frame
self.main_frame = customtkinter.CTkFrame(self)
self.main_frame.grid(row=0, column=0, rowspan=4, columnspan=4, sticky="nsew", padx=10 , pady=20)
self.main_frame.grid_columnconfigure((0,1), weight=1)
# self.main_frame.grid_rowconfigure((1), weight=1)
# create search options frame
self.back_button = customtkinter.CTkButton(self.main_frame, text='back', command=lambda: controller.show_frame("JigsawScreen"), fg_color="transparent", border_width=2, text_color=("gray10", "#DCE4EE"))
self.back_button.grid(row=1, column=0, padx=(20, 20), pady=(20, 20), sticky="w")
self.label_1 = customtkinter.CTkLabel(self.main_frame, text="Select The Jigsaw:", font=customtkinter.CTkFont(size=24, weight="normal"))
self.label_1.grid(row=2, column=0, columnspan=4, padx=30, pady=(30,30))
self.jigsaw_button = customtkinter.CTkButton(self.main_frame, text='Jigsaw', command=lambda: controller.show_frame("GridJigsawScreen"))
self.jigsaw_button.grid(row=3, column=0, padx=30, pady = (50,50), sticky="n")
self.solve_button = customtkinter.CTkButton(self.main_frame, text='solve', command=lambda: controller.show_frame("HomeScreen"))
self.solve_button.grid(row=4, column=0, padx=30, pady = (50,50), sticky="n")
# Variables to store puzzle and hint image paths
self.jigsaw_image_path = None
self.jigsaw_button.configure(command=self.select_jigsaw_image)
self.solve_button.configure(command=self.get_rows_cols)
def select_jigsaw_image(self):
self.jigsaw_image_path = filedialog.askopenfilename(title="Select Jigsaw Image", filetypes=[("Image Files", "*.png;*.jpg;*.jpeg")])
if self.jigsaw_image_path:
print(f"jigsaw Image Selected: {self.jigsaw_image_path}") # You can handle this path as needed
def get_rows_cols(self):
print(self.jigsaw_image_path)
if(self.jigsaw_image_path == None):
tkinter.messagebox.showerror("Error", "Enter Jigsaw")
else:
self.jigsaw_image_path = self.jigsaw_image_path.replace("/", "\\")
solve_jigsaw(self.jigsaw_image_path)