-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathip.py
executable file
·53 lines (39 loc) · 1.13 KB
/
ip.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
#!/usr/bin/python
import os
import subprocess
import appindicator
import gtk
ICON = os.path.abspath("./images/icon.png")
def get_ip():
ip = subprocess.check_output('ifconfig |\
grep -o -P "inet addr:([^ ]*)" |\
grep -o -m 1 -P "[0-9.]+"', shell=True)
return ip.strip()
class IPIndicator:
def __init__(self):
self.ip = ""
self.ind = appindicator.Indicator("ip-indicator", ICON,
appindicator.CATEGORY_APPLICATION_STATUS)
self.ind.set_status(appindicator.STATUS_ACTIVE)
self.update()
self.ind.set_menu(self.setup_menu())
def setup_menu(self):
menu = gtk.Menu()
refresh = gtk.MenuItem("Refresh")
refresh.connect("activate", self.on_refresh)
refresh.show()
menu.append(refresh)
return menu
def update(self):
"""
Update the IP address.
"""
ip = get_ip()
if ip != self.ip:
self.ip = ip
self.ind.set_label(ip)
def on_refresh(self, widget):
self.update()
if __name__ == "__main__":
i = IPIndicator()
gtk.main()