-
Notifications
You must be signed in to change notification settings - Fork 13
/
browser.py
executable file
·98 lines (72 loc) · 2.86 KB
/
browser.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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os, sys, gi
gi.require_version('Gtk', '3.0')
gi.require_version('WebKit', '3.0')
from gi.repository import Gtk, WebKit
class Browser:
def __init__(self):
self.builder = Gtk.Builder()
self.builder.add_from_file("core/browser.glade")
self.builder.connect_signals(self)
self.toolbar1 = self.builder.get_object("toolbar1")
self.back = self.builder.get_object("back")
self.forward = self.builder.get_object("forward")
self.refresh = self.builder.get_object("refresh")
self.stop = self.builder.get_object("stop")
self.url = self.builder.get_object("url")
self.spinner = self.builder.get_object("spinner")
self.progressbar = self. builder.get_object("progressbar")
self.window = self.builder.get_object("window1")
self.window.connect('destroy', lambda w: Gtk.main_quit())
self.scrolledwindow = self.builder.get_object("scrolledwindow")
self.window.show_all()
self.webview = WebKit.WebView()
self.scrolledwindow.add(self.webview)
self.webview.open('http://google.com')
self.webview.connect('title-changed', self.change_title)
self.webview.connect('load-committed', self.change_url)
self.webview.connect('load-committed', self.spinner_on)
self.webview.connect('load_finished',self.spinner_off)
#self.webview.connect('load-committed', self.progress_on)
#self.webview.connect('load-progress-changed', self.progress_change)
#self.webview.connect('document_load_finished',self.progress_off)
self.webview.show()
def on_url_activate(self, widget):
url = widget.get_text()
if url.startswith('http://') or url.startswith('https://'):
self.webview.open(url)
else:
url = 'http://' + url
self.url.set_text(url)
self.webview.open(url)
def on_refresh_clicked(self, widget):
self.webview.reload()
def on_back_clicked(self, widget):
self.webview.go_back()
def on_forward_clicked(self, widget):
self.webview.go_forward()
def on_stop_clicked(self, widget):
self.webview.stop_loading()
def change_title(self, widget, frame, title):
self.window.set_title(title + ' - AnLinux-Browser')
def change_url(self, widget, frame):
uri = frame.get_uri()
self.url.set_text(uri)
self.back.set_sensitive(self.webview.can_go_back() )
self.forward.set_sensitive(self.webview.can_go_forward() )
def spinner_on(self,widget,frame):
self.spinner.start()
def spinner_off(self, widget,frame):
self.spinner.stop()
#def progress_on(self,widget,frame):
#self.progressbar.pulse()
#def progress_change(self,wiget,frame):
# self.progressbar.set_pulse_step(.5)
#def progress_off(self,widget,frame):
#self.progressbar.set_pulse_step(0)
def main ():
app = Browser()
Gtk.main()
if __name__ == "__main__":
main()