This repository was archived by the owner on May 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplayHeader.py
More file actions
executable file
·84 lines (65 loc) · 2.7 KB
/
displayHeader.py
File metadata and controls
executable file
·84 lines (65 loc) · 2.7 KB
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
82
83
84
#!/usr/bin/python
import sys
from gi.repository import Soup, SoupGNOME, Gtk
class displayHeader(Gtk.Box):
@staticmethod
def clicked_button_action (button, dhobject):
# clear the textview
textbuffer = dhobject.textview.get_buffer()
textbuffer.set_text("")
dhobject.textview.set_buffer(textbuffer)
url = dhobject.entry.get_text()
if len(url) == 0:
return
if not url.startswith('http://'):
url = "http://"+ url
message = Soup.Message.new('GET', url)
dhobject.session.send_message(message)
if message.status_code == '200':
# clear the entry
dhobject.entry.set_text('')
print message.status_code
print message.reason_phrase
@staticmethod
def add_log_to_treeview (logger, printer, direction, header_line, textview):
textbuffer = textview.get_buffer()
textbuffer.set_text(textbuffer.get_text(textbuffer.get_start_iter(),
textbuffer.get_end_iter(),
False) +
"%c %s \n" % (direction, header_line))
textview.set_buffer(textbuffer)
def __init__(self):
Gtk.Box.__init__(self)
self.session = Soup.SessionAsync.new()
self.session.add_feature_by_type(SoupGNOME.ProxyResolverGNOME)
self.session.add_feature(Soup.CookieJarText.new("cookies.txt", False))
self.set_spacing(6)
self.set_orientation(Gtk.Orientation.VERTICAL)
hbox = Gtk.Box()
hbox.set_spacing(6)
hbox.set_orientation(Gtk.Orientation.HORIZONTAL)
self.pack_start(hbox, False, True, 6)
self.entry = Gtk.Entry()
self.entry.connect("activate", displayHeader.clicked_button_action, self)
hbox.pack_start(self.entry, True, True, 0)
button = Gtk.Button.new_from_stock(Gtk.STOCK_OK)
button.connect("clicked", displayHeader.clicked_button_action, self)
hbox.pack_start(button, False, False, 0)
scrollwidget = Gtk.ScrolledWindow()
scrollwidget.set_shadow_type(Gtk.ShadowType.IN)
self.pack_start(scrollwidget, True, True, 0)
self.textview = Gtk.TextView()
self.textview.set_editable(False)
scrollwidget.add(self.textview)
Logger = Soup.Logger.new(Soup.LoggerLogLevel.HEADERS, -1)
Logger.set_printer(displayHeader.add_log_to_treeview, self.textview)
self.session.add_feature(Logger)
if __name__ == '__main__':
window = Gtk.Window()
window.connect("delete-event", Gtk.main_quit)
window.set_size_request(340, 400)
window.set_border_width(10)
my_app = displayHeader()
window.add(my_app)
window.show_all()
Gtk.main()