-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditBar.py
141 lines (113 loc) · 6.1 KB
/
editBar.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
from tkinter import Frame,Button,LEFT
from tkinter import filedialog
from filterFrame import FilterFrame
from adjustFrame import AdjustFrame
import cv2
class EditBar(Frame):
def __init__(self,master=None):
Frame.__init__(self,master=master)
self.new_button = Button(self,text='New')
self.save_button = Button(self,text="Save")
self.save_as_button = Button(self,text="Save As")
self.draw_button = Button(self,text="Draw")
self.crop_button = Button(self,text="Crop")
self.filter_button = Button(self,text="Filter")
self.adjust_button = Button(self,text="Adjust")
self.clear_button = Button(self,text="Clear")
self.new_button.bind("<ButtonRelease>",self.new_button_released)
self.save_button.bind("<ButtonRelease>",self.save_button_released)
self.draw_button.bind("<ButtonRelease>",self.draw_button_released)
self.crop_button.bind("<ButtonRelease>",self.crop_button_released)
self.filter_button.bind("<ButtonRelease>",self.filter_button_released)
self.adjust_button.bind("<ButtonRelease>",self.adjust_button_released)
self.clear_button.bind("<ButtonRelease>",self.clear_button_released)
self.new_button.pack(side=LEFT)
self.save_button.pack(side=LEFT)
self.save_as_button.pack(side=LEFT)
self.draw_button.pack(side=LEFT)
self.crop_button.pack(side=LEFT)
self.filter_button.pack(side=LEFT)
self.adjust_button.pack(side=LEFT)
self.clear_button.pack()
def new_button_released(self,event):
if self.winfo_containing(event.x_root,event.y_root)==self.new_button:
if self.master.is_draw_state:
self.master.image_viewer.deactivate_draw()
if self.master.is_crop_state:
self.master.image_viewer.deactivate_crop()
filename = filedialog.askopenfilename()
image = cv2.imread(filename)
if image is not None:
self.master.filename = filename
self.master.original_image = image.copy()
self.master.processed_image = image.copy()
self.master.image_viewer.show_image()
self.master.is_image_selected = True
def save_button_released(self,event):
if self.winfo_containing(event.x_root,event.y_root) == self.save_button:
if self.master.is_image_selected:
if self.master.is_crop_state:
self.master.image_viewer.deactivate_crop()
if self.master.is_draw_state:
self.master.image_viewer.deactivate_draw()
save_image = self.master.processed_image
image_filename = self.master.filename
cv2.imwrite(image_filename,save_image)
def save_as_button_released(self,event):
if self.winfo_containing(event.x_root,event.y_root)==self.save_as_button:
if self.master.is_image_selected:
if self.master.is_draw_state:
self.master.image_viewer.deactivate_draw()
if self.master.is_crop_state:
self.master.image_viewer.deactivate_crop()
original_file_type = self.master.filename.split('.')[-1]
filename = filedialog.asksaveasfilename()
filename = filename + '.'+original_file_type
save_image = self.master.processed_image
cv2.write(filename,save_image)
self.master.filename = filename
def draw_button_released(self,event):
if self.winfo_containing(event.x_root,event.y_root)==self.draw_button:
if self.master.is_image_selected:
if self.master.is_draw_state:
self.master.image_viewer.deactivate_draw()
if self.master.is_crop_state:
self.master.image_viewer.deactivate_crop()
else:
self.master.image_viewer.activate_draw()
def crop_button_released(self,event):
if self.winfo_containing(event.x_root,event.y_root)==self.crop_button:
if self.master.is_image_selected:
if self.master.is_draw_state:
self.master.image_viewer.deactivate_draw()
if self.master.is_crop_state:
self.master.image_viewer.deactivate_crop()
else:
self.master.image_viewer.activate_crop()
def filter_button_released(self,event):
if self.winfo_containing(event.x_root,event.y_root)==self.filter_button:
if self.master.is_image_selected:
if self.master.is_draw_state:
self.master.image_viewer.deactivate_draw()
if self.master.is_crop_state:
self.master.image_viewer.deactivate_crop()
self.master.filter_frame = FilterFrame(master=self.master)
self.master.filter_frame.grab_set()
def adjust_button_released(self,event):
if self.winfo_containing(event.x_root,event.y_root)==self.adjust_button:
if self.master.is_image_selected:
if self.master.is_draw_state:
self.master.image_viewer.deactivate_draw()
if self.master.is_crop_state:
self.master.image_viewer.deactivate_crop()
self.master.adjust_frame = AdjustFrame(master=self.master)
self.master.adjust_frame.grab_set()
def clear_button_released(self,event):
if self.winfo_containing(event.x_root,event.y_root)==self.clear_button:
if self.master.is_image_selected:
if self.master.is_draw_state:
self.master.image_viewer.deactivate_draw()
if self.master.is_crop_state:
self.master.image_viewer.deactivate_crop()
self.master.processed_image = self.master.original_image.copy()
self.master.image_viewer.show_image()