This repository has been archived by the owner on Mar 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xautolock_indicator.py
63 lines (48 loc) · 1.75 KB
/
xautolock_indicator.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
from PyQt5.QtWidgets import QApplication, QSystemTrayIcon, QMenu, QAction
from PyQt5.QtGui import QIcon
import sys, os
current_path = os.path.abspath(os.path.dirname(sys.argv[0])) + "/"
class tray_icon(QSystemTrayIcon):
enabled_icon = "caffeine-cup-full.svg"
disabled_icon = "caffeine-cup-empty.svg"
script_name = "script.sh"
is_enabled = False
def __init__(self, parent=None):
QSystemTrayIcon.__init__(self, parent=None)
# Initial state
self.set_disabled()
# Right Click
right_menu = RightClicked()
self.setContextMenu(right_menu)
# left click
self.activated.connect(self.toggle)
def set_enabled(self):
icon = QIcon(current_path + self.enabled_icon)
self.setIcon(icon)
def set_disabled(self):
icon = QIcon(current_path + self.disabled_icon)
self.setIcon(icon)
def toggle(self, reason):
# if left clicked
if(reason == QSystemTrayIcon.Trigger):
if(self.is_enabled):
self.set_disabled()
self.is_enabled = False
os.system(current_path + self.script_name + " " + "enable")
print("Disabled")
else:
self.set_enabled()
self.is_enabled = True
os.system(current_path + self.script_name + " " + "disable")
print("Enabled")
class RightClicked(QMenu):
def __init__(self, parent=None):
QMenu.__init__(self, parent=None)
action = QAction("Exit", self)
action.triggered.connect(lambda : QApplication.exit(0))
self.addAction(action)
if __name__ == "__main__":
app = QApplication(sys.argv)
tray = tray_icon(app)
tray.show()
sys.exit(app.exec_())