1
+ """
2
+ Этот модуль реализует приложение Akemu для работы с буфером обмена.
3
+ Программа автоматически отслеживает изменения в буфере обмена и позволяет воспроизводить текст,
4
+ состоящий в буфере, с помощью виртуальной клавиатуры.
5
+ """
1
6
import random
2
7
import time
3
8
import pyperclip
6
11
7
12
8
13
class Akemu (customtkinter .CTk ):
14
+ """
15
+ Главное окно приложения Akemu, которое отображает таймер,
16
+ буфер обмена и кнопки для запуска действий.
17
+ """
9
18
def __init__ (self , * args , ** kwargs ):
19
+ """
20
+ Инициализация главного окна.
21
+ """
10
22
super ().__init__ (* args , ** kwargs )
11
23
12
24
self .title ("Akemu" )
@@ -15,16 +27,21 @@ def __init__(self, *args, **kwargs):
15
27
self .resizable (width = False , height = False )
16
28
self .attributes ('-topmost' , 1 )
17
29
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
+ )
20
33
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
+ )
23
38
self .countdown_label .grid (row = 0 , column = 1 , padx = (95 , 20 ), pady = (20 , 0 ))
39
+
24
40
self .textbox = customtkinter .CTkTextbox (self , width = 300 , height = 240 )
25
41
self .textbox .grid (row = 1 , column = 0 , padx = 20 , pady = (20 , 0 ), sticky = "nsew" , columnspan = 2 )
26
42
self .textbox .insert ("0.0" , pyperclip .paste ())
27
43
self .textbox .configure (state = 'disabled' )
44
+
28
45
button = customtkinter .CTkButton (self , text = "Начать" , command = self .execute_commands )
29
46
button .grid (row = 2 , column = 0 , padx = 20 , pady = 20 , sticky = "ew" , columnspan = 2 )
30
47
@@ -33,45 +50,69 @@ def __init__(self, *args, **kwargs):
33
50
34
51
keyboard .add_hotkey ('ctrl + b' , self .execute_commands_hotkey )
35
52
36
- def execute_commands_hotkey (self ):
53
+ def execute_commands_hotkey (self ) -> None :
54
+ """
55
+ Запускает выполнение команд с задержкой при нажатии горячей клавиши.
56
+ """
37
57
time .sleep (0.5 )
38
58
self .start_typing ()
39
59
40
- def execute_commands (self ):
60
+ def execute_commands (self ) -> None :
61
+ """
62
+ Запускает выполнение команд после отсчета времени.
63
+ """
41
64
self .start_countdown ()
42
65
self .after (4000 , self .start_typing )
43
66
44
- def start_countdown (self ):
67
+ def start_countdown (self ) -> None :
68
+ """
69
+ Начинает отсчет времени.
70
+ """
45
71
self .countdown (3 )
46
72
47
- def countdown (self , count ):
73
+ def countdown (self , count : int ) -> None :
74
+ """
75
+ Отсчитывает время и обновляет метку на экране.
76
+ """
48
77
if count >= 0 :
49
78
mins , secs = divmod (count , 60 )
50
- timer = '{ :02d}:{:02d}'. format ( mins , secs )
79
+ timer = f' { mins :02d} :{ secs :02d} '
51
80
self .countdown_label .configure (text = timer )
52
81
self .after (1000 , self .countdown , count - 1 )
53
82
else :
54
83
self .countdown_label .configure (text = "00:03" )
55
84
56
85
@staticmethod
57
- def type_text (buffer ):
86
+ def type_text (buffer : str ) -> None :
87
+ """
88
+ Печатает текст из буфера обмена с задержкой.
89
+ """
58
90
for character in buffer :
59
91
if keyboard .is_pressed ('p' ):
60
92
break
61
93
keyboard .write (character , delay = random .uniform (0.095 , 0.15 ))
62
94
63
- def start_typing (self ):
95
+ def start_typing (self ) -> None :
96
+ """
97
+ Начинает печатать текст из буфера обмена.
98
+ """
64
99
buffer = pyperclip .paste ()
65
100
self .type_text (buffer )
66
101
67
- def check_clipboard (self ):
102
+ def check_clipboard (self ) -> None :
103
+ """
104
+ Проверяет буфер обмена на изменения.
105
+ """
68
106
new_clipboard_content = pyperclip .paste ()
69
107
if new_clipboard_content != self .clipboard_content :
70
108
self .clipboard_content = new_clipboard_content
71
109
self .update_textbox ()
72
110
self .after (1000 , self .check_clipboard )
73
111
74
- def update_textbox (self ):
112
+ def update_textbox (self ) -> None :
113
+ """
114
+ Обновляет текст в поле ввода.
115
+ """
75
116
current_position = self .textbox .index ('insert' )
76
117
self .textbox .configure (state = 'normal' )
77
118
self .textbox .delete ('1.0' , 'end' )
0 commit comments