-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui4.py
426 lines (345 loc) · 10.4 KB
/
gui4.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
from pathlib import Path
from queue import Queue
import threading
from tkinter import *
from tkinter import Tk, Canvas, Entry, Text, Button, PhotoImage, filedialog, Label, messagebox, Checkbutton, simpledialog
import subprocess
import createim
import tkinter as tk
import json
from tkinter import ttk
from datetime import datetime
from PIL import Image, ImageTk
OUTPUT_PATH = Path(__file__).parent
ASSETS_PATH = OUTPUT_PATH / Path(r"assets4/frame0")
def center_window(window,height=600,width=500):
window.update_idletasks()
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
x = (screen_width - width) // 2
y = (screen_height - height) // 2
window.geometry(f"{width}x{height}+{x}+{y}")
def relative_to_assets(path: str) -> Path:
return ASSETS_PATH / Path(path)
window = Tk()
center_window(window)
window.wm_iconname("Image your disk")
window.title("IYD Imaging Process")
im = Image.open('assets0/favicon.ico')
photo = ImageTk.PhotoImage(im)
window.wm_iconphoto(True, photo)
window.wm_iconname("IYD")
window.geometry("600x500")
window.configure(bg = "#545252")
result_queue1 = Queue()
result_queue2 = Queue()
canvas = Canvas(
window,
bg = "#545252",
height = 500,
width = 600,
bd = 0,
highlightthickness = 0,
relief = "ridge"
)
canvas.place(x = 0, y = 0)
button_image_1 = PhotoImage(
file=relative_to_assets("button_1.png"))
button_1 = Button(
image=button_image_1,
borderwidth=0,
highlightthickness=0,
relief="flat"
)
button_1.place(
x=271.0,
y=43.0,
width=329.0,
height=319.0
)
canvas.create_rectangle(
0.0,
0.0,
271.0,
500.0,
fill="#212121",
outline="")
image_image_1 = PhotoImage(
file=relative_to_assets("image_1.png"))
image_1 = canvas.create_image(
128.0,
249.0,
image=image_image_1
)
canvas.create_rectangle(
302.0,
83.0,
528.0,
118.0,
fill="#D9D9D9",
outline="")
canvas.create_rectangle(
302.0,
268.0,
529.0,
303.0,
fill="#D9D9D9",
outline="")
canvas.create_rectangle(
302.0,
173.0,
528.0,
208.0,
fill="#D9D9D9",
outline="")
entry_image_1 = PhotoImage(
file=relative_to_assets("entry_1.png"))
entry_bg_1 = canvas.create_image(
428.0,
100.0,
image=entry_image_1
)
def browse_file1():
file_path = filedialog.askopenfilename()
if file_path:
# entry_1.delete(0, Tk.END)
entry_1.insert(0, file_path)
def browse_file3():
file_path = filedialog.askdirectory()
if file_path:
# entry_1.delete(0, Tk.END)
entry_3.insert(0, file_path)
browse_button = Button(window, text="BF",fg="white",width=2,bg="#333333", command=browse_file1)
browse_button.pack(pady=10)
browse_button.place(x=546, y=85)
browse_button2 = Button(window, text="BF",fg="white",width=2,bg="#333333", command=browse_file3)
browse_button2.pack(pady=10)
browse_button2.place(x=546, y=269)
entry_1 = Entry(
bd=0,
bg="#D9D9D9",
fg="#000716",
highlightthickness=0
)
entry_1.place(
x=328.0,
y=83.0,
width=200.0,
height=32.0
)
entry_image_2 = PhotoImage(
file=relative_to_assets("entry_2.png"))
entry_bg_2 = canvas.create_image(
428.0,
190.0,
image=entry_image_2
)
entry_2 = Entry(
bd=0,
bg="#D9D9D9",
fg="#000716",
highlightthickness=0
)
entry_2.place(
x=328.0,
y=173.0,
width=200.0,
height=32.0
)
entry_image_3 = PhotoImage(
file=relative_to_assets("entry_3.png"))
entry_bg_3 = canvas.create_image(
427.0,
284.5,
image=entry_image_3
)
entry_3 = Entry(
bd=0,
bg="#D9D9D9",
fg="#000716",
highlightthickness=0
)
entry_3.place(
x=328.0,
y=268.0,
width=198.0,
height=31.0
)
selected_format = StringVar()
# global comp = False
# global encr = False
# passkey = ""
encr = False
passkey = ""
comp = False # Initialize comp as False
def on_checkbox_click1():
global encr, passkey
if encr_var.get() == 1:
result = simpledialog.askstring("Encrypt using GPG", "Set Passphrase:", show='*')
if result is None or result.strip() == "":
messagebox.showwarning("Warning", "Please enter valid passphrase!")
encr_var.set(0)
else:
encr = True
passkey = result
else:
print("Encryption not applied")
def on_checkbox_click2():
global comp
if comp_var.get() == 1:
comp = True
messagebox.showwarning("Warning", "Compression may cause data hindernace!")
print("compression applied")
else:
print("compression not applied")
encr_var = IntVar()
comp_var = IntVar()
checkbutton_encr = Checkbutton(
window,
text="Encrypt (GPG)",
variable=encr_var,
onvalue=1,
offvalue=0,
width=12,
command=on_checkbox_click1,
bg="#545252",
font=("Arial", 12),
relief="raised",
padx=10,
pady=5,
)
checkbutton_encr.place(x=439, y=375)
checkbutton_comp = Checkbutton(
window,
text="Compress (gzip)",
variable=comp_var,
onvalue=1,
width=12,
offvalue=0,
command=on_checkbox_click2,
bg="#545252",
font=("Arial", 12),
relief="raised",
padx=10,
pady=5,
)
checkbutton_comp.place(x=276, y=375)
def main_win():
global encr
global passkey
global comp
task1_completed = threading.Event()
task2_completed = threading.Event()
def update_progress_label(text):
progress_label.config(text=text)
def update_progress_bar():
progress_bar_1.start(20)
def stop_progress_bar():
progress_bar_1.stop()
def create_image_task():
window.after(0, update_progress_bar)
final_name = entry_3.get()+"/"+entry_2.get()
image_start, image_end = createim.create_image(entry_1.get(), final_name)
window.after(0, lambda: update_progress_label("image created..."))
window.after(0, lambda: update_progress_label("Computing Image..."))
image_md5, image_sha1 = createim.image_hash(entry_3.get()+"/"+entry_2.get())
is_comp = False
if comp:
window.after(0, lambda: update_progress_label("Compressing please wait..."))
createim.compress_disk_image3(entry_3.get() + "/" + entry_2.get())
window.after(0, lambda: update_progress_label("Compression completed..."))
is_comp = True
if encr:
window.after(0, lambda: update_progress_label("Encrypting please wait..."))
if is_comp:
final_name = entry_3.get() + "/" + entry_2.get()+".gz"
print(final_name)
else:
final_name = entry_3.get() + "/" + entry_2.get()
print(final_name)
output_file_name = final_name + "GPG"
print(output_file_name)
print("passkey"+passkey)
createim.encrypt_with_gpg(final_name, output_file_name , passkey)
window.after(0, lambda: update_progress_label("encryption completed..."))
# return image_start, image_end, image_md5, image_sha1
result_queue1.put((image_start, image_end, image_md5, image_sha1, entry_1.get(), entry_2.get(), entry_3.get()))
task1_completed.set()
def gen_hash():
window.after(0, update_progress_bar)
print("Generating hash")
drive_md5, drive_sha1 = createim.compute_drive_hash(entry_1.get())
window.after(0, lambda: update_progress_label("hashes generated..."))
# return drive_md5, drive_sha1
result_queue2.put((drive_md5, drive_sha1))
task2_completed.set()
def check_tasks():
if task1_completed.is_set() and task2_completed.is_set():
stop_progress_bar()
progress_label.config(text="Tasks completed. Close the window.")
window.after(1000, window.destroy)
on_next_click2()
# window.destroy()
else:
window.after(100, check_tasks)
# def get_1(image_start, image_end, image_md5, image_sha1):
# return image_start, image_end, image_md5, image_sha1
# def get_2(drive_md5, drive_sha1):
# return drive_md5, drive_sha1
window = tk.Tk()
window.title("IYD-Creating Image")
center_window(window)
window.geometry("300x150")
style = ttk.Style()
style.configure("TProgressbar", thickness=20)
progress_label = Label(window, text="Progressing...", font=("Arial", 12))
progress_label.pack(pady=10)
progress_bar_1 = ttk.Progressbar(window, style="TProgressbar", orient="horizontal", length=250, mode="indeterminate")
progress_bar_1.pack(pady=20)
t1 = threading.Thread(target=create_image_task)
t2 = threading.Thread(target=gen_hash)
t1.start()
t2.start()
window.after(100, check_tasks)
window.mainloop()
def on_next_click1():
if len(entry_1.get()) == 0 or len(entry_2.get()) == 0 or len(entry_3.get()) == 0:
messagebox.showwarning("Warning", "Please enter all the fields!")
else:
main_win()
def on_next_click2():
import sys
image_start, image_end, image_md5, image_sha1, volume_loc, image_loc, saving_loc = result_queue1.get()
drive_md5, drive_sha1 = result_queue2.get()
# print(image_start, image_end, image_md5, image_sha1, drive_md5, drive_sha1)
# image_start_str = image_start.strftime('%Y-%m-%d %H:%M:%S') if isinstance(image_start, datetime) else str(image_start)
# image_end_str = image_end.strftime('%Y-%m-%d %H:%M:%S') if isinstance(image_end, datetime) else str(image_end)
image_start_str = str(image_start)
image_end_str = str(image_end)
results = {
'image_start': image_start_str,
'image_end': image_end_str,
'image_md5': image_md5,
'image_sha1': image_sha1,
'volume_loc': volume_loc,
'image_loc': image_loc,
'saving_loc': saving_loc,
'drive_md5': drive_md5,
'drive_sha1': drive_sha1
}
with open("results.json", "w") as file:
json.dump(results, file)
window.destroy()
import gui6
def on_back_click():
window.destroy()
import sys
# subprocess.run(["python3", "gui3.py"])
subprocess.run(["sudo", "myenv/bin/python3", "gui3.py"])
done = 00
next_button = Button(window, text="Next", command=on_next_click1, width=10, bg="#333333", fg="white")
next_button.place(x=452, y=455)
back_button = Button(window, text="Back", command=on_back_click, width=10, bg="#333333", fg="white")
back_button.place(x=312, y=455)
window.resizable(False, False)
window.mainloop()