-
Notifications
You must be signed in to change notification settings - Fork 37
/
gui.py
57 lines (47 loc) · 1.63 KB
/
gui.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
import sys
import traceback
import threading
import tkinter as tk
from tkinter.filedialog import askopenfile
from decrypt import decrypt_file, CustomException
class StdoutRedirector(object):
def __init__(self, text_widget):
self.text_space = text_widget
def write(self, string):
self.text_space.insert('end', string)
self.text_space.see('end')
def open_file():
file = askopenfile(filetypes=[
("PDF/CAJ Files", "*")])
if not file:
return
src = file.name
dst_array = src.split(".")[:-1]
dst_array.append("dec")
dst_array.append("pdf")
dst = ".".join(dst_array)
print("开始解密", src)
threading.Thread(target=decrypt_background, args=(src, dst)).start()
def decrypt_background(src, dst):
try:
decrypt_file(src, dst)
print("解密成功!解密后的文件为:", dst)
except Exception as exc:
if not isinstance(exc, CustomException):
print("[Error] 解密失败,未知错误: ", str(exc))
else:
print("[Error] 解密失败,", str(exc))
print("\n如果你需要帮助,请复制以下信息到GitHub ( https://github.com/301Moved/ScienceDecrypting/issues/new ) 上提交Issue")
print("-" * 64)
traceback.print_exc()
if __name__ == "__main__":
root = tk.Tk()
root.title("ScienceDecrypting")
root.geometry("800x600")
btn = tk.Button(root, text='选择要解密的文件', command=lambda: open_file())
btn.pack(side=tk.TOP, pady=20)
LOG = tk.Text(root)
LOG.pack()
sys.stdout = StdoutRedirector(LOG)
sys.stderr = StdoutRedirector(LOG)
tk.mainloop()