usr bin python coding utf-8 import pygtk pygtk require import gtk impo

 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
# -*- coding: utf-8 -*-
import pygtk
pygtk.require('2.0')
import gtk
import pynotify
import re
import sys
import urllib2
def close_cb(n, action):
assert action == 'close'
n.close()
gtk.main_quit()
def getip_cb(n, action):
assert action == 'getip'
clipboard = gtk.clipboard_get()
clipboard.clear()
clipboard.set_text(n.ip)
clipboard.store()
n.close()
# gtk.main_quit()
def get_ip():
reg = re.compile(r'IP address is:\s+<\/p>\s+<div class=\"Box\">(.*?)<\/div', re.DOTALL)
body = urllib2.urlopen('http://myip.dk/').read()
return \
reg.findall(body)[0]
if __name__ == '__main__':
if not pynotify.init('MyIP'):
sys.exit(1)
ip = get_ip()
n = pynotify.Notification('(:', u'Ваш IP адрес:\n<b>%s</b>' % ip)
# TODO: use a function call
n.ip = ip
n.set_urgency(pynotify.URGENCY_NORMAL)
n.set_timeout(pynotify.EXPIRES_NEVER)
n.set_category('info')
n.add_action('getip', u'Копировать', getip_cb)
n.add_action('close', u'Закрыть', close_cb)
if not n.show():
sys.exit(1)
gtk.main()