-
Notifications
You must be signed in to change notification settings - Fork 0
/
systray.py
75 lines (67 loc) · 2.26 KB
/
systray.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
import logging
from multiprocessing import shared_memory
import rumps
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
class TranslaterApp(rumps.App):
def __init__(self) -> None:
super(TranslaterApp, self).__init__(
name="Translater", quit_button=None, icon="icon.png"
)
logging.debug("Starting systray icon")
self.shm = shared_memory.SharedMemory(name="Translator")
self.shm.buf[:10] = "Yandex ".encode()
self.yandex = rumps.MenuItem(title="Yandex")
self.yandex.state = True
self.google = rumps.MenuItem(title="Google")
self.google.state = False
self.promt = rumps.MenuItem(title="Promt")
self.promt.state = False
self.exit_button = rumps.MenuItem(title="Exit")
self.menu = [
self.yandex,
self.google,
self.promt,
rumps.separator,
self.exit_button,
]
@rumps.clicked("Yandex")
def yandex_onoff(self, sender) -> None:
"""
For select yandex
"""
logging.debug("You selected Yandex for default translator")
for m in [self.yandex, self.google, self.promt]:
m.state = False
self.shm.buf[:10] = "Yandex ".encode()
sender.state = True
@rumps.clicked("Google")
def google_onoff(self, sender) -> None:
"""
For select google
"""
logging.debug("You selected Google for default translator")
for m in [self.yandex, self.google, self.promt]:
m.state = False
self.shm.buf[:10] = "Google ".encode()
sender.state = True
@rumps.clicked("Promt")
def promt_onoff(self, sender) -> None:
"""
For select promt
"""
logging.debug("You selected Promt for default translator")
for m in [self.yandex, self.google, self.promt]:
m.state = False
self.shm.buf[:10] = "Promt ".encode()
sender.state = True
@rumps.clicked("Exit")
def exit_button_click(self, sender) -> None:
"""
For exit button
"""
logging.debug("The application is shutting down")
self.shm.unlink()
rumps.quit_application()