-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
280 lines (219 loc) · 6.52 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
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
from tkinter import *
from tkinter import filedialog
from tkinter import messagebox
from PIL import Image, ImageTk
import threading
import os
from img_stg import ImgStg
from file_handler import fileHandler
from utils import compatible_path
#ALL PATHS
DIR_PATH = compatible_path(os.path.dirname(os.path.realpath(__file__)))
TEXT_PATH = ""
IMAGE_PATH = ""
DEST_PATH = DIR_PATH
ERROR = ""
STG = ImgStg()
RESOURCES = f"{DIR_PATH}\\resources\\"
LOGS = {
"img_path":0,
"txt_path":0,
"dest_path":0
}
def change_log(reset=False):
text_log = ""
T.config(state=NORMAL)
T.delete('1.0', END)
if reset == False:
# TEXT PATH
if LOGS["txt_path"] == 0:
text_log += "(?)-TEXT FILE IS NOT SELECTED!(not required for data extraction)\n\n"
else:
text_log += "(OK)-TEXT FILE IS SELECTED.\n\n"
# IMAGE PATH
if LOGS["img_path"] == 0:
text_log += "(?)-IMAGE FILE IS NOT SELECTED!\n\n"
else:
text_log += "(OK)-IMAGE FILE IS SELECTED.\n\n"
# DESTINATION PATH
if LOGS["dest_path"] == 0:
text_log += "(?)-DEST FOLDER IS NOT SELECTED!\n\n"
else:
text_log += "(OK)-DEST FOLDER IS SELECTED.\n\n"
T.insert(END,text_log)
T.config(state=DISABLED)
def get_error(mode="embed"):
"""
This function checks if the required paths are selected.
and returns 0 if there is no error.
"""
global ERROR
if mode == "embed": # if embed is selected
if TEXT_PATH == "":
messagebox.showinfo("INFO", "TEXT PATH IS NOT SELECTED !")
return 1
if IMAGE_PATH =="":
messagebox.showinfo("INFO", "IMAGE PATH IS NOT SELECTED !")
return 1
return 0
def select_text_btn():
"""
this function selects the text file and checks if it is a txt file.
"""
global TEXT_PATH
TEXT_PATH = filedialog.askopenfilename()
if "txt" != TEXT_PATH[len(TEXT_PATH)-3:]:
TEXT_PATH = ""
else:
LOGS["txt_path"] = 1
change_log()
def select_img_btn():
"""
this function selects the image file and checks if it is a image file.
"""
global IMAGE_PATH, IMAGE
IMAGE_PATH = filedialog.askopenfilename()
IMAGE = ImageTk.PhotoImage(Image.open(compatible_path(IMAGE_PATH)).resize((295,279)))
label1.configure(image=IMAGE)
label1.image=IMAGE
LOGS["img_path"] = 1
change_log()
def select_dest_btn():
"""
this function selects the destination folder.
"""
global DEST_PATH
DEST_PATH = filedialog.askdirectory()
LOGS["dest_path"] = 1
change_log()
def embed_btn():
"""
this function starts the embedding process.
"""
if get_error("embed") == 0:
text = fileHandler.read(TEXT_PATH)
print(text,IMAGE_PATH)
threading.Thread(target=STG._merge_txt, args=(IMAGE_PATH,TEXT_PATH,DEST_PATH)).start()
def extract_btn():
"""
this function starts the extraction process.
"""
if get_error("extract") == 0:
threading.Thread(target=STG._unmerge_txt, args=(IMAGE_PATH, DEST_PATH)).start()
def reset_btn():
"""
this function resets the settings.
"""
global TEXT_PATH, IMAGE_PATH, DEST_PATH
if messagebox.askquestion("Reset Settings", "Are you sure ?\nSelected paths will be deleted !") == "yes":
TEXT_PATH = ""
IMAGE_PATH = ""
DEST_PATH = DIR_PATH
LOGS["txt_path"] = 0
LOGS["img_path"] = 0
LOGS["dest_path"] = 0
T.delete('1.0', END)
label1.configure(image="")
label1.image=""
change_log(reset=True)
# GUI - TKINTER
window = Tk()
window.title("Emimg") # title of the window
window.geometry("689x665") # size of the window
window.configure(bg = "#ffffff") # background color of the window
canvas = Canvas(
window,
bg = "#ffffff",
height = 665,
width = 689,
bd = 0,
highlightthickness = 0,
relief = "ridge")
canvas.place(x = 0, y = 0)
background_img = PhotoImage(file = compatible_path(RESOURCES + "background.png"))
background = canvas.create_image(
344.5, 332.5,
image=background_img)
img0 = PhotoImage(file = compatible_path(RESOURCES + "img0.png"))
b0 = Button(
image = img0,
borderwidth = 0,
highlightthickness = 0,
command = reset_btn,
relief = "flat")
b0.place(
x = 606, y = 227,
width = 69,
height = 72)
img1 = PhotoImage(file= compatible_path(RESOURCES + "img1.png"))
b1 = Button(
image = img1,
borderwidth = 0,
highlightthickness = 0,
command = embed_btn,
activebackground="#E8CCCC",
relief = "flat")
b1.place(
x = 21, y = 450,
width = 108,
height = 111)
img2 = PhotoImage(file = compatible_path(RESOURCES + "img2.png"))
b2 = Button(
image = img2,
borderwidth = 0,
highlightthickness = 0,
command = extract_btn,
activebackground="#E6C7C7",
relief = "flat")
b2.place(
x = 195, y = 450,
width = 108,
height = 111)
img3 = PhotoImage(file = compatible_path(RESOURCES + "img3.png"))
b3 = Button(
image = img3,
borderwidth = 0,
highlightthickness = 0,
command = select_dest_btn,
activebackground="#EAD1D1",
relief = "flat")
b3.place(
x = 21, y = 316,
width = 74,
height = 75)
img4 = PhotoImage(file = compatible_path(RESOURCES + "img4.png"))
b4 = Button(
image = img4,
borderwidth = 0,
highlightthickness = 0,
command = select_img_btn,
activebackground="#EBD3D3",
relief = "flat")
b4.place(
x = 21, y = 230,
width = 74,
height = 75)
img5 = PhotoImage(file = compatible_path(RESOURCES + "img5.png"))
b5 = Button(
image = img5,
borderwidth = 0,
highlightthickness = 0,
command = select_text_btn,
activebackground="#ECD6D6",
relief = "flat")
b5.place(
x = 21, y = 144,
width = 74,
height = 75)
# compatible_path function is used to make the path compatible with the os !
IMAGE = Image.open(compatible_path(RESOURCES) + "no_image.png")
p1 = PhotoImage(file = compatible_path(RESOURCES + "ico_menu.png"))
window.iconphoto(False, p1)
label1 = Label()
label1.place(x=360, y=360)
T = Text(window, height = 5, width = 65)
T.insert(END, "...")
T.place(x=55, y=35)
T.config(borderwidth=0,state=DISABLED)
window.resizable(False, False)
window.mainloop()