forked from 0x-x0/desktopIndicator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindicator.py
116 lines (98 loc) · 2.71 KB
/
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/python2.7
import gtk
import gtk.glade
import appindicator
import sys, os
import signal
import errno
import json
import traceback
import requests
import subprocess
class App(object):
def __init__(self):
try:
self.indicator = Indicator()
except Exception as e:
print e
self.exit(1)
def __del__(self):
self.exit()
def run(self):
gtk.main()
def exit(self, code=0):
print "Killing!!!"
gtk.main_quit()
sys.exit(code)
class Indicator(object):
def __init__(self):
self.indicator = appindicator.Indicator(
"indicatorApp",
"app",
appindicator.CATEGORY_APPLICATION_STATUS)
self.setup_indicator()
def setup_indicator(self):
self.indicator.set_status(appindicator.STATUS_ACTIVE)
self.indicator.set_icon(os.path.abspath('slack.svg'))
self.indicator.set_menu(self.create_menu())
def create_menu(self):
menu = gtk.Menu()
self.add_menu_item("Monitor", self._toggle_monitor, menu)
self.add_menu_item("Offline", self._go_offline, menu)
self.add_menu_separator(menu)
self.add_menu_item("Quit", self._quit, menu)
return menu
def add_menu_item(self, label, handler, menu,
event="activate", MenuItem=gtk.MenuItem, show=True):
item = MenuItem(label)
if label == "Monitor":
item = gtk.CheckMenuItem("Monitor")
item.set_active(True)
self._toggle_monitor(item)
item.connect(event, handler)
menu.append(item)
if show:
item.show()
return item
def add_menu_separator(self, menu, show=True):
item = gtk.SeparatorMenuItem()
menu.append(item)
if show:
item.show()
def _toggle_monitor(self, item):
if (item.get_active() == True):
try:
subprocess.Popen(["pkill -f /bin/sh\ ./monitorBus.sh"], shell=True)
subprocess.Popen(['nohup ./monitorBus.sh > /dev/null 2>&1 &'], shell=True)
except subprocess.CalledProcessError:
print "Error !!"
_quit()
else:
subprocess.Popen(["pkill -f /bin/sh\ ./monitorBus.sh"], shell=True)
def _go_offline(self, item):
self.update_status()
def _quit(self, code=0):
sys.exit(code)
def update_status(self):
status = 'away'
url = ## URL
return self._get(url, status)
def _get(self, url, status):
headers = {
'Content-Type': 'application/json'
}
url+= 'presence=' + status
err = None
response = requests.get(
url,
headers=headers)
print 'Status Update completed with ' + str(response.status_code)
#self.indicator.set_icon(os.path.abspath('sample_icon.svg'))
def main():
try:
app = App()
app.run()
except KeyboardInterrupt:
pass
if __name__ == '__main__':
main()