-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.py
76 lines (55 loc) · 1.76 KB
/
manager.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
from importlib import reload
from multiprocessing import Process
import customtkinter as ctk
import userbot
class BotControlApp:
def __init__(self, master):
ctk.set_default_color_theme('green')
self.master = master
self.master.title("Managing bot")
self.label = ctk.CTkLabel(master, text='Stopped')
self.label.pack(pady=10)
ctk.CTkButton(
master, text='Start', command=self.start_bot
).pack(pady=10)
ctk.CTkButton(
master, text='Stop', command=self.stop_bot
).pack(pady=10)
ctk.CTkButton(
master, text='Restart', command=self.restart_bot
).pack(pady=10)
ctk.CTkButton(
master, text='Quit', text_color='#ea0002', bg_color='#ffffff', command=self.quit_app
).pack(pady=10)
self.is_bot_runned = False
self.bot = None
def start_bot(self):
if self.is_bot_runned:
return
self.is_bot_runned = True
self.update_label()
reload(userbot)
self.bot = Process(target=userbot.main)
self.bot.start()
def stop_bot(self):
if self.is_bot_runned:
self.is_bot_runned = False
self.update_label()
self.bot.terminate()
self.bot.join()
print('Bot was stopped!')
def restart_bot(self):
if self.is_bot_runned:
self.stop_bot()
self.start_bot()
def update_label(self):
self.label.configure(
text='Started' if self.is_bot_runned else 'Stopped'
)
def quit_app(self):
self.stop_bot()
self.master.quit()
if __name__ == "__main__":
root = ctk.CTk()
app = BotControlApp(root)
root.mainloop()