-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_bormi_tool.py
96 lines (78 loc) · 3.11 KB
/
gui_bormi_tool.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
import tkinter as tk
from tkinter import messagebox, filedialog, ttk
from pathlib import Path
def ask_directories_profile(is_old_known: bool = False, is_new_known: bool = False):
old_profile = None
new_profile = None
if not is_old_known:
old_profile_path = filedialog.askdirectory(
title="Select OLD Firefox profile folder"
)
if not old_profile_path:
return None, None
old_profile = Path(old_profile_path)
if not is_new_known:
new_profile_path = filedialog.askdirectory(
title="Select NEW Firefox profile folder"
)
if not new_profile_path:
return None, None
new_profile = Path(new_profile_path)
return old_profile, new_profile
def select_profiles_gui(profiles):
def on_submit():
nonlocal old_dropdown, new_dropdown
old_profile = profiles_dict[old_dropdown.get()]
new_profile = profiles_dict[new_dropdown.get()]
old_profile_label.config(text=old_profile)
new_profile_label.config(text=new_profile)
root.quit()
root = tk.Tk()
root.title("Select Firefox Profiles")
profiles_dict = {p.name: p for p in profiles}
# Label to display the returned value
old_profile_label = tk.Label(root, text="")
old_profile_label.pack()
tk.Label(root, text="Select OLD Profile:").pack()
old_profile_var = tk.StringVar()
old_dropdown = ttk.Combobox(
root, textvariable=old_profile_var, values=list(profiles_dict.keys())
)
old_dropdown.pack()
tk.Label(root, text="Select NEW Profile:").pack()
new_profile_var = tk.StringVar()
new_dropdown = ttk.Combobox(
root, textvariable=new_profile_var, values=list(profiles_dict.keys())
)
new_dropdown.pack()
# Label to display the returned value
new_profile_label = tk.Label(root, text="")
new_profile_label.pack()
tk.Button(root, text="Start Migration", command=on_submit).pack()
root.mainloop()
return old_profile_label.cget("text"), new_profile_label.cget("text")
def gui_mode(func_list_profiles, func_copy_profile):
root = tk.Tk()
root.withdraw()
profiles = func_list_profiles()
old_profile, new_profile = None, None
if len(profiles) == 0:
messagebox.showwarning("Warning", "No profiles found in the default location.")
old_profile, new_profile = ask_directories_profile()
elif len(profiles) == 1:
response = messagebox.askquestion(
"Single Profile Found", "Can I use this profile as OLD?"
)
if response == "yes":
old_profile = profiles[0]
new_profile, _ = ask_directories_profile(is_old_known=True)
else:
new_profile = profiles[0]
old_profile, _ = ask_directories_profile(is_new_known=True)
elif len(profiles) >= 2:
old_profile, new_profile = select_profiles_gui(profiles)
else:
raise TypeError("Impossible get len of 'profiles' value")
if old_profile and new_profile:
func_copy_profile(old_profile, new_profile)
messagebox.showinfo("Success", "Migration completed successfully!")