-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui.py
157 lines (118 loc) · 5.08 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
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
import tkinter as tk
import customtkinter as ctk
import webbrowser
from PIL import Image, ImageTk
import os
import subprocess
import sys
# Local Imports
from about import create_about_page
from create import create_create_page
from recover import *
import consts
from consts import SEL_BUTTON_FG, BUTTON_FG
tabs = ["Create", "Recover", "About"]
current_tab = "About"
# Dependency functions
def check_directory_exists(directory_path):
return os.path.exists(directory_path) and os.path.isdir(directory_path)
def clone_repo(popup):
ctk.CTkLabel(popup, text="Installing python-shamir-mnemonic", font=("Roboto", 15), text_color=SEL_BUTTON_FG).pack(pady=0)
Label = ctk.CTkLabel(popup, text="Loading...")
Label.pack(pady=5)
error_textbox = ctk.CTkTextbox(popup, height=10, state="normal")
error_textbox.pack(pady=(5), padx=10, fill="both", expand=True)
cmd = "git clone https://github.com/trezor/python-shamir-mnemonic"
result = subprocess.run(cmd, shell=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
Label.configure(text="Done")
error_textbox.pack_forget()
popup.after(200, popup.destroy)
else:
Label.configure(text="Error occurred, see details below:")
error_message = result.stderr.strip() if result.stderr else "Failed to clone repository."
error_textbox.insert("1.0", error_message)
def show_progress_window(parent):
popup = ctk.CTkToplevel(parent)
popup.geometry("550x350")
popup.minsize(550, 350)
popup.title("Downloading Dependencies")
popup.focus()
popup.after(100, lambda: clone_repo(popup))
def check_and_clone_dependency(app):
if not check_directory_exists("python-shamir-mnemonic"):
show_progress_window(app)
else:
print("All dependencies already installed.")
# Tab-Content Functions
def clear_main_content():
for widget in main_content_frame.winfo_children():
widget.destroy()
def update_main_content(tab):
clear_main_content()
if tab == "About":
create_about_page(main_content_frame, switch_tab)
elif tab == "Create":
create_create_page(main_content_frame)
elif tab == "Recover":
create_recover_page(main_content_frame)
# Top bar functions
def switch_tab(tab):
global current_tab
current_tab = tab
update_tab_buttons()
update_main_content(current_tab)
def open_github():
webbrowser.open(GITHUB_URL)
def tab_buttons(top_bar):
for tab in tabs:
button = ctk.CTkButton(top_bar, text=tab, command=lambda tab=tab: switch_tab(tab))
button.pack(side="left", padx=5)
button.tab_name = tab
if tab == current_tab:
button.configure(fg_color=SEL_BUTTON_FG, hover_color=SEL_BUTTON_FG, text_color="black", height=32)
else:
button.configure(fg_color=BUTTON_FG, hover_color=SEL_BUTTON_FG, text_color="white", height=30)
def update_tab_buttons():
for widget in app.winfo_children():
if isinstance(widget, ctk.CTkFrame):
for button in widget.winfo_children():
if isinstance(button, ctk.CTkButton) and hasattr(button, 'tab_name'):
if button.tab_name == current_tab:
button.configure(fg_color=SEL_BUTTON_FG, hover_color=SEL_BUTTON_FG, text_color="black", height=32)
else:
button.configure(fg_color=BUTTON_FG, hover_color=SEL_BUTTON_FG, text_color="white", height=30)
def create_top_bar(parent):
top_bar = ctk.CTkFrame(parent, height=50)
top_bar.pack(side="top", fill="x")
title_label = ctk.CTkLabel(top_bar, text="Polyseed Secret Sharing Tool", font=("Roboto", 20), anchor="w")
title_label.pack(side="left", padx=(10, 20))
tab_buttons(top_bar)
github_icon = ctk.CTkImage(dark_image=Image.open(consts.GITHUB_LOGO_PATH), size=(45,45))
github_icon_label = ctk.CTkLabel(top_bar, text="", image=github_icon, cursor="hand2")
github_icon_label.pack(side="right", padx=10, pady=5)
github_icon_label.bind("<Button-1>", lambda event: open_github())
version_label = ctk.CTkLabel(top_bar, text=f"v{consts.APP_VERSION}", anchor="e")
version_label.pack(side="right")
github_icon_label.image = github_icon
# Start of the application
app = ctk.CTk()
app.title(consts.APP_TITLE)
app.geometry(consts.APP_GEOMETRY)
app.minsize(int(consts.APP_GEOMETRY.split("x")[0]), int(consts.APP_GEOMETRY.split("x")[1]))
ctk.set_appearance_mode("dark")
if getattr(sys, 'frozen', False):
base_path = sys._MEIPASS
consts.WORDLIST_PATH = os.path.join(base_path, consts.WORDLIST_PATH)
consts.MONERO_QR_PATH = os.path.join(base_path, consts.MONERO_QR_PATH)
consts.GITHUB_LOGO_PATH = os.path.join(base_path, consts.GITHUB_LOGO_PATH)
consts.APP_ICON_PATH = os.path.join(base_path, consts.APP_ICON_PATH)
icon = ImageTk.PhotoImage(Image.open(consts.APP_ICON_PATH))
app.wm_iconbitmap()
app.iconphoto(True, icon)
create_top_bar(app)
main_content_frame = ctk.CTkFrame(app)
main_content_frame.pack(fill="both", expand=True)
#check_and_clone_dependency(app)
update_main_content(current_tab)
app.mainloop()