Skip to content

Commit 0228a28

Browse files
Update akemu.py
1 parent cdeb9a6 commit 0228a28

File tree

1 file changed

+54
-13
lines changed

1 file changed

+54
-13
lines changed

src/akemu.py

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
Этот модуль реализует приложение Akemu для работы с буфером обмена.
3+
Программа автоматически отслеживает изменения в буфере обмена и позволяет воспроизводить текст,
4+
состоящий в буфере, с помощью виртуальной клавиатуры.
5+
"""
16
import random
27
import time
38
import pyperclip
@@ -6,7 +11,14 @@
611

712

813
class Akemu(customtkinter.CTk):
14+
"""
15+
Главное окно приложения Akemu, которое отображает таймер,
16+
буфер обмена и кнопки для запуска действий.
17+
"""
918
def __init__(self, *args, **kwargs):
19+
"""
20+
Инициализация главного окна.
21+
"""
1022
super().__init__(*args, **kwargs)
1123

1224
self.title("Akemu")
@@ -15,16 +27,21 @@ def __init__(self, *args, **kwargs):
1527
self.resizable(width=False, height=False)
1628
self.attributes('-topmost', 1)
1729

18-
logo_label = customtkinter.CTkLabel(self, text="Буфер обмена",
19-
font=customtkinter.CTkFont(size=20, weight="bold"))
30+
logo_label = customtkinter.CTkLabel(
31+
self, text="Буфер обмена", font=customtkinter.CTkFont(size=20, weight="bold")
32+
)
2033
logo_label.grid(row=0, column=0, padx=20, pady=(20, 0))
21-
self.countdown_label = customtkinter.CTkLabel(self, text="00:03",
22-
font=customtkinter.CTkFont(size=20, weight="bold"))
34+
35+
self.countdown_label = customtkinter.CTkLabel(
36+
self, text="00:03", font=customtkinter.CTkFont(size=20, weight="bold")
37+
)
2338
self.countdown_label.grid(row=0, column=1, padx=(95, 20), pady=(20, 0))
39+
2440
self.textbox = customtkinter.CTkTextbox(self, width=300, height=240)
2541
self.textbox.grid(row=1, column=0, padx=20, pady=(20, 0), sticky="nsew", columnspan=2)
2642
self.textbox.insert("0.0", pyperclip.paste())
2743
self.textbox.configure(state='disabled')
44+
2845
button = customtkinter.CTkButton(self, text="Начать", command=self.execute_commands)
2946
button.grid(row=2, column=0, padx=20, pady=20, sticky="ew", columnspan=2)
3047

@@ -33,45 +50,69 @@ def __init__(self, *args, **kwargs):
3350

3451
keyboard.add_hotkey('ctrl + b', self.execute_commands_hotkey)
3552

36-
def execute_commands_hotkey(self):
53+
def execute_commands_hotkey(self) -> None:
54+
"""
55+
Запускает выполнение команд с задержкой при нажатии горячей клавиши.
56+
"""
3757
time.sleep(0.5)
3858
self.start_typing()
3959

40-
def execute_commands(self):
60+
def execute_commands(self) -> None:
61+
"""
62+
Запускает выполнение команд после отсчета времени.
63+
"""
4164
self.start_countdown()
4265
self.after(4000, self.start_typing)
4366

44-
def start_countdown(self):
67+
def start_countdown(self) -> None:
68+
"""
69+
Начинает отсчет времени.
70+
"""
4571
self.countdown(3)
4672

47-
def countdown(self, count):
73+
def countdown(self, count: int) -> None:
74+
"""
75+
Отсчитывает время и обновляет метку на экране.
76+
"""
4877
if count >= 0:
4978
mins, secs = divmod(count, 60)
50-
timer = '{:02d}:{:02d}'.format(mins, secs)
79+
timer = f'{mins:02d}:{secs:02d}'
5180
self.countdown_label.configure(text=timer)
5281
self.after(1000, self.countdown, count - 1)
5382
else:
5483
self.countdown_label.configure(text="00:03")
5584

5685
@staticmethod
57-
def type_text(buffer):
86+
def type_text(buffer: str) -> None:
87+
"""
88+
Печатает текст из буфера обмена с задержкой.
89+
"""
5890
for character in buffer:
5991
if keyboard.is_pressed('p'):
6092
break
6193
keyboard.write(character, delay=random.uniform(0.095, 0.15))
6294

63-
def start_typing(self):
95+
def start_typing(self) -> None:
96+
"""
97+
Начинает печатать текст из буфера обмена.
98+
"""
6499
buffer = pyperclip.paste()
65100
self.type_text(buffer)
66101

67-
def check_clipboard(self):
102+
def check_clipboard(self) -> None:
103+
"""
104+
Проверяет буфер обмена на изменения.
105+
"""
68106
new_clipboard_content = pyperclip.paste()
69107
if new_clipboard_content != self.clipboard_content:
70108
self.clipboard_content = new_clipboard_content
71109
self.update_textbox()
72110
self.after(1000, self.check_clipboard)
73111

74-
def update_textbox(self):
112+
def update_textbox(self) -> None:
113+
"""
114+
Обновляет текст в поле ввода.
115+
"""
75116
current_position = self.textbox.index('insert')
76117
self.textbox.configure(state='normal')
77118
self.textbox.delete('1.0', 'end')

0 commit comments

Comments
 (0)