-
Notifications
You must be signed in to change notification settings - Fork 0
/
protocol.py
executable file
·77 lines (66 loc) · 2.16 KB
/
protocol.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
from os import system
import platform
import tkinter as tk
from tkinter import messagebox
from tkinter.filedialog import askopenfilename, asksaveasfilename
from connector import Connector
from editor import Editor
from verifier import Verifier
OS = platform.system()
FILETYPES = [("Image Files", (".png", ".jpg", ".jpeg"))]
def main():
window = tk.Tk()
connector = Connector(window)
connector.pack()
window.mainloop()
if not connector.is_successful():
# triggered only when exiting forcefully
connector.cleanup()
return
conn, role = connector.get_results()
connector.destroy()
window.withdraw()
while True:
filename = askopenfilename(parent=window, filetypes=FILETYPES)
window.deiconify()
if not filename:
conn.close()
return
editor = Editor(window, filename)
editor.pack()
window.mainloop()
if not editor.is_successful():
conn.close()
editor.cleanup()
return
images = editor.get_results()
editor.destroy()
verifier = Verifier(window, conn, role, images)
if verifier.has_paniced():
verifier.cleanup()
return
verifier.pack()
window.mainloop()
if not verifier.is_successful():
verifier.cleanup()
return
image = verifier.get_results()
window.withdraw()
filename = asksaveasfilename(parent=window, filetypes=[("Image Files", ".png")])
if filename:
if not ".png" in filename: filename += ".png"
image.save(filename)
answer = messagebox.askyesno("Question", "One more time?")
window.update()
if not answer or not verifier.ask_resume():
if answer: messagebox.showinfo("Info", "Partner wanted to stop")
print("INFO: One party wanted to stop")
verifier.cleanup()
break
for img in images:
img.close()
verifier.destroy()
if OS == "Windows": system("cls")
elif OS == "Linux": system("clear")
window.destroy()
if __name__ == "__main__": main()