-
Notifications
You must be signed in to change notification settings - Fork 2
/
canaima-ayuda
executable file
·81 lines (67 loc) · 2.09 KB
/
canaima-ayuda
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
#!/usr/bin/python
# coding=utf-8
import gtkhtml2
import gtk
import urllib
import urlparse
import os
opener = urllib.FancyURLopener()
currentUrl = None
def is_relative_to_server(url):
parts = urlparse.urlparse(url)
if parts[0] or parts[1]:
return 0
return 1
def open_url(url):
uri = resolve_uri(url)
return opener.open(uri)
def resolve_uri(uri):
if is_relative_to_server(uri):
return urlparse.urljoin(currentUrl, uri)
return uri
def request_url(document, url, stream):
f = open_url(url)
stream.write(f.read())
def link_clicked(document, link):
print 'link_clicked:', link
global currentUrl
if (link =="app://xchat"):
os.system ("/usr/bin/xchat")
elif (link =="app://firefox"):
os.system("/usr/bin/firefox")
elif (link =="app://amsn"):
os.system("/usr/bin/amsn")
else:
try:
f = open_url(link)
except OSError:
print "failed to open", link
return
currentUrl = resolve_uri(link)
document.clear()
headers = f.info()
mime = headers.getheader('Content-type').split(';')[0]
if mime:
document.open_stream(mime)
else:
document.open_stream('text/plain')
document.write_stream(f.read())
document.close_stream()
document = gtkhtml2.Document()
document.connect('request_url', request_url)
document.connect('link_clicked', link_clicked)
document.clear()
document.open_stream('text/html')
document.write_stream('<html> <body background="canaima-ayuda.png"> <table width="800" height="600"> <tr><td width="50%"> </td><td><div style="height: 100px;"> </div><a href="app://firefox" ><img src="navegar.png"/></a><div style="height: 50px;"> </div><a href="app://amsn" ><img src="chat.png"/></a><div style="height: 50px;"> </div><a href="app://xchat" ><img src="soporte.png"/></a></td></tr> </table> </body> </html>')
document.close_stream()
def request_object(*args):
print 'request object', args
view = gtkhtml2.View()
view.set_document(document)
view.connect('request_object', request_object)
window = gtk.Window()
window.add(view)
window.set_default_size(800, 600)
window.set_title("Canaima - Herramienta de ayuda rápida");
window.show_all()
gtk.main()