-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_indicator.py
62 lines (50 loc) · 1.65 KB
/
setup_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
import wx
import subprocess
import sys
"""
Adapted from http://stackoverflow.com/questions/6389580/quick-and-easy-trayicon-with-python#answer-6389727
"""
COUNTRY = ""
TRAY_TOOLTIP = 'Airvpn systray indicator'
TRAY_ICON = 'icon.jpg'
def create_menu_item(menu, label, func):
item = wx.MenuItem(menu, -1, label)
menu.Bind(wx.EVT_MENU, func, id=item.GetId())
menu.AppendItem(item)
return item
class TaskBarIcon(wx.TaskBarIcon):
def __init__(self, frame):
self.frame = frame
super(TaskBarIcon, self).__init__()
self.set_icon(TRAY_ICON)
self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)
def CreatePopupMenu(self):
menu = wx.Menu()
create_menu_item(menu, 'Exiting from {}'.format(COUNTRY), None)
menu.AppendSeparator()
create_menu_item(menu, 'Turn Airvpn off', self.on_turn_off)
return menu
def set_icon(self, path):
icon = wx.IconFromBitmap(wx.Bitmap(path))
self.SetIcon(icon, TRAY_TOOLTIP)
def on_left_down(self, event):
# print 'Tray icon was left-clicked.'
subprocess.Popen(['notify-send', "airvpn is running", "-t", "2000"])
def on_turn_off(self, event):
# print 'Turning off...'
# wx.CallAfter(self.Destroy)
# self.frame.Close()
subprocess.Popen(["sudo", "python", "airvpn_toggler.py", "off"])
class App(wx.App):
def OnInit(self):
frame=wx.Frame(None)
self.SetTopWindow(frame)
TaskBarIcon(frame)
return True
def setup():
app = App(False)
app.MainLoop()
if __name__ == '__main__':
if len(sys.argv) > 1:
COUNTRY = "".join(sys.argv[1:])
setup()