-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
120 lines (91 loc) · 4.02 KB
/
main.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
import tkinter as tk
from tkinter import ttk, Toplevel, Frame, Button, messagebox
from app_options import AppOptions # tried to make a button
from image_manager import ImageManager
from editor_options import EditorOptions
from history_of_edits import History
class Main(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.file_location = ""
self.original_image = None
self.processed_image = None
self.image_properties = None
self.advanced_tools = None
self.in_crop_mode = False
self.undo_performed = False
self.history = []
self.item_clicked = False
self.is_saved = False
self.configure(bg="#6b6b6b")
self.title("Image Editor")
self.geometry("1440x810")
self.resizable(True, True)
# Creates a frame for the main window
main_frame = tk.Frame(self, bg="#6b6b6b")
main_frame.pack(fill=tk.BOTH, expand=True)
self.app_options = AppOptions(master=main_frame)
self.app_options.pack(side=tk.TOP, fill=tk.X, padx=10, pady=10)
separator1 = ttk.Separator(master=main_frame, orient=tk.HORIZONTAL)
separator1.pack(fill=tk.X, padx=10, pady=5)
self.editor_options = EditorOptions(master=main_frame)
self.editor_options.pack(side=tk.LEFT, fill=tk.Y, padx=20, pady=10)
separator4 = ttk.Separator(master=main_frame, orient=tk.VERTICAL)
separator4.pack(side=tk.LEFT, fill=tk.Y, padx=10, pady=10)
self.image_viewer = ImageManager(master=main_frame)
self.image_viewer.pack(side=tk.LEFT, fill=tk.BOTH,
padx=20, pady=10, expand=True)
separator5 = ttk.Separator(master=main_frame, orient=tk.VERTICAL)
separator5.pack(side=tk.LEFT, fill=tk.Y, padx=10, pady=10)
self.history_of_edits = History(master=main_frame)
self.history_of_edits.pack(side=tk.LEFT, fill=tk.Y, padx=10, pady=10)
# Bindings
self.bind("<Control-z>", self.history_of_edits.undo_action)
self.bind('<Control-y>', self.history_of_edits.redo_action)
self.bind("<MouseWheel>", self.image_viewer._zoom)
self.bind("<Control-equal>", self.image_viewer._zoom_in)
self.bind("<Control-minus>", self.image_viewer._zoom_out)
self.protocol("WM_DELETE_WINDOW", self._on_closing)
def _switch_crop_to_off(self):
"""
Switches the crop mode to off.
"""
self.in_crop_mode = False
def _on_closing(self, event=None):
"""
Prompts the user to save the image before closing the window.
"""
if not self.is_saved:
save_prompt = tk.Toplevel(self)
save_prompt.title("Save Image")
save_prompt.geometry("300x100")
save_prompt.resizable(False, False)
save_prompt.configure(bg="#6b6b6b")
save_question = tk.Label(
save_prompt, text="Would you like to save your image?", bg="#6b6b6b", fg="white")
save_question.pack(anchor="center")
save_button = tk.Button(
save_prompt, text="Save", width=4, height=2, command=self._combine_save)
save_button.pack(anchor="center", padx=25, pady=10, side=tk.LEFT)
no_button = tk.Button(save_prompt, text="No",
width=4, height=2, command=self.destroy)
no_button.pack(anchor="center", padx=25, pady=10, side=tk.RIGHT)
# Intercept window closing event
self.protocol("WM_DELETE_WINDOW",
lambda: self._close_window(save_prompt))
else:
self.destroy()
def _close_window(self, window):
"""
Closes the window and destroys the window object.
Parameters:
window (tk.Toplevel): The window to be closed.
"""
window.destroy()
self.destroy()
def _combine_save(self):
"""
Combines the save and destroy methods.
"""
self.app_options.save_button_click()
self.destroy()