-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_ip_menu.py
49 lines (41 loc) · 1.25 KB
/
get_ip_menu.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
import signal
import os
from gi.repository import Gtk as gtk
from gi.repository import AppIndicator3 as appindicator
from gi.repository import Notify as notify
APPINDICATOR_ID = 'ipIndicator'
def main():
indicator = appindicator.Indicator.new(APPINDICATOR_ID, gtk.STOCK_INFO, appindicator.IndicatorCategory.SYSTEM_SERVICES)
indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
indicator.set_menu(build_menu())
notify.init(APPINDICATOR_ID)
gtk.main()
def build_menu():
menu = gtk.Menu()
item_ip = gtk.MenuItem('IP')
item_ip.connect('activate', ip)
menu.append(item_ip)
item_quit = gtk.MenuItem('Quit')
item_quit.connect('activate', quit)
menu.append(item_quit)
menu.show_all()
return menu
def run_command(cmd):
os.system(cmd + ' > tmp')
detected = False
for line in open('tmp', 'r'):
if detected:
detected = False
return line
if 'eth0' in line:
detected = True
def fetch_ip():
return '192.168.*.*'
def ip(_):
notify.Notification.new("<b>Your IP address</b>", run_command('ifconfig')[20:34], None).show()
def quit(_):
notify.uninit()
gtk.main_quit()
if __name__ == "__main__":
signal.signal(signal.SIGINT, signal.SIG_DFL)
main()