-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain no windows.py
235 lines (184 loc) · 6.32 KB
/
main no windows.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
import os, webbrowser
import sys, random
from pathlib import Path
from tkinter import messagebox, ttk
from tkinter import *
from settings import open_config_editor
try:
import customtkinter as ctk
except:
print("please do ""pip install customtkinter""", file=sys.stderr)
while True:
pass
try:
import pyperclip
except:
print("please do ""pip install pyperclip""", file=sys.stderr)
while True:
pass
try:
import yaml
except:
print("please do ""pip install pyyaml""", file=sys.stderr)
while True:
pass
script_directory = os.path.dirname(os.path.abspath(__file__))
def load_config():
config_path = Path(__file__).parent / "config.yaml"
try:
with open(config_path, "r", encoding="utf-8") as f:
return yaml.safe_load(f)
except Exception as e:
messagebox.showerror("Ошибка", f"Ошибка загрузки конфига: {e}")
sys.exit(1)
def fade_out():
current_alpha = root.attributes("-alpha")
if current_alpha > 0:
new_alpha = max(current_alpha - 0.02, 0.0)
root.attributes("-alpha", new_alpha)
root.after(15, fade_out)
else:
root.destroy()
def passwdGenerator():
letters = config["passwd"]["letters"]
digits = config["passwd"]["digits"]
symbols = config["passwd"]["symbols"]
password = ""
for i in range(0, random.randint(12, 24)):
rand = random.randint(0, 2)
if rand == 0:
password += letters[random.randrange(len(letters))]
if rand == 1:
password += digits[random.randrange(len(digits))]
if rand == 2:
password += symbols[random.randrange(len(symbols))]
pyperclip.copy(password)
messagebox.showinfo(title="Пароль успешно сгенерирован!",
message=f"Ваш пароль: {password}, он скопирован в буфер обмена.")
return password
def openShortcut1():
if chkShortcut(1):
webbrowser.open(config["shortcuts"][f'shortcut1'])
def openShortcut2():
if chkShortcut(2):
webbrowser.open(config["shortcuts"][f'shortcut2'])
def openShortcut3():
if chkShortcut(3):
webbrowser.open(config["shortcuts"][f'shortcut3'])
def chkShortcut(i):
if config["shortcuts"][f'shortcut{i}'] is not None:
return True
else:
return False
def open_config_editor_button():
open_config_editor("config.yaml")
config = load_config()
script_directory = Path(__file__).parent
def configure_styles():
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("blue")
style = ttk.Style()
root.attributes("-alpha", float(config['app']["opacity"]))
style.theme_use("clam")
style.configure("TFrame", background="#2E2E2E")
style.configure("TLabel", background="#2E2E2E", foreground="white", font=("Helvetica", 12))
style.configure("TButton", font=("Helvetica", 10), padding=6)
style.map("TButton",
background=[("active", "#4A4A4A"), ("pressed", "#6A6A6A")],
foreground=[("active", "white")]
)
def openBrowser():
webbrowser.open(config["paths"]["browser_main_page"])
root = Tk()
root.title(config["app"]["title"])
root.geometry(f"{int(config['app']['geometryX'])}x{int(config['app']['geometryY'])}")
root.resizable(config["app"]["resizable"], config["app"]["resizable"])
root.attributes("-alpha", float(config["app"]["opacity"]))
root.configure(bg=config["app"]["background"])
configure_styles()
main_frame = ttk.Frame(root)
main_frame.pack(fill=BOTH, expand=False, padx=20, pady=20)
header_frame = ttk.Frame(main_frame)
header_frame.pack(fill=X, pady=10)
label1 = ttk.Label(header_frame,
text=f"Добро пожаловать, {os.getlogin()}!",
font=("Helvetica", 14, "bold"),
anchor="center")
label1.pack(fill=X)
button_frame = ttk.Frame(main_frame)
button_frame.pack(pady=10, fill=X)
btn_style = ttk.Style()
btn_style.configure("Custom.TButton",
font=config["button_style"]["font"],
padding=config["button_style"]["padding"],
background=config["button_style"]["background"],
foreground=config["button_style"]["foreground"])
btn3 = ctk.CTkButton(
master=button_frame,
text="Запустить браузер",
corner_radius=int(config["button_style"]["corner_radius"]),
command=openBrowser
)
btn3.pack(fill=X, pady=5)
btn4 = ctk.CTkButton(
master=button_frame,
text="Сгенерировать надежный пароль",
corner_radius=int(config["button_style"]["corner_radius"]),
command=passwdGenerator
)
btn4.pack(fill=X, pady=5)
# shortcuts bruuuuuuuuuuuuuuuuuuuuuuuuh
label2 = ttk.Label(button_frame,
text=f"Закладки",
font=("Helvetica", 10, "bold"),
anchor="center")
label2.pack(fill=X, pady=10)
btn5 = ctk.CTkButton(
master=button_frame,
text=config["shortcuts"]["shortcut1_name"],
corner_radius=int(config["button_style"]["corner_radius"]),
command=openShortcut1
)
if config["shortcuts"]["shortcut1"] != 0:
btn5.pack(fill=X, pady=5)
btn6 = ctk.CTkButton(
master=button_frame,
text=config["shortcuts"]["shortcut2_name"],
corner_radius=int(config["button_style"]["corner_radius"]),
command=openShortcut2
)
if config["shortcuts"]["shortcut2"] != 0:
btn6.pack(fill=X, pady=5)
btn7 = ctk.CTkButton(
master=button_frame,
text=config["shortcuts"]["shortcut3_name"],
corner_radius=int(config["button_style"]["corner_radius"]),
command=openShortcut3
)
if config["shortcuts"]["shortcut3"] != 0:
btn7.pack(fill=X, pady=5)
btn8 = ctk.CTkButton(
master=button_frame,
text="Параметры",
corner_radius=int(config["button_style"]["corner_radius"]),
command=open_config_editor_button
)
btn8.pack(fill=X, pady=5)
btn_exit = ctk.CTkButton(
master=button_frame,
text="Выход",
corner_radius=int(config["button_style"]["corner_radius"]),
command=fade_out
)
btn_exit.pack(fill=X, pady=5)
status_bar = ttk.Frame(root, height=20)
status_bar.pack(fill=X, side=BOTTOM)
ttk.Label(status_bar,
text="v1.1",
anchor=W,
style="TLabel").pack(side=LEFT, padx=5)
try:
root.iconbitmap(os.path.join(script_directory, "notepad.ico"))
except:
pass
root.mainloop()