-
Notifications
You must be signed in to change notification settings - Fork 0
/
jk_web.py
87 lines (57 loc) · 2.6 KB
/
jk_web.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
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *
class jkweb():
def __init__(self):
#get all widget from PyQt5
self.window = QWidget()
#set the title of web browser
self.window.setWindowTitle("JehanKandy Web Browser")
#get box layout for web browser
self.layout = QVBoxLayout()
#buttons in horizontal
self.horizontal = QHBoxLayout()
#for Url Bar
self.url_bar = QTextEdit()
self.url_bar.setMaximumHeight(30) #size of url bar
#for Go button
self.go_btn = QPushButton("GO")
self.go_btn.setMinimumHeight(30) #size of GO button
#for Back button
self.back_btn = QPushButton("<-")
self.back_btn.setMinimumHeight(30) #size of Back button
#for Forward button
self.forward_btn = QPushButton("->")
self.forward_btn.setMinimumHeight(30) #size of Forward button
#now add buttons and url box on the browser
self.horizontal.addWidget(self.url_bar) #for url bar
self.horizontal.addWidget(self.go_btn) #for GO Button
self.horizontal.addWidget(self.back_btn) #for Back Button
self.horizontal.addWidget(self.forward_btn) #for GO Button
#now create the browser
self.browser = QWebEngineView()
#when someone click the go button
self.go_btn.clicked.connect(lambda: self.navigation(self.url_bar.toPlainText()))
#when someone click the back button
self.back_btn.clicked.connect(self.browser.back)
#when someone click the forward button
self.forward_btn.clicked.connect(self.browser.forward)
#add horizontal Layout
self.layout.addLayout(self.horizontal)
#add all Widget
self.layout.addWidget(self.browser)
#set the Strating page
self.browser.setUrl(QUrl("http://google.com"))
#display the browser
self.window.setLayout(self.layout)
self.window.show()
#now create browser functions
def navigation(self, url):
#check url not strat with http:
if not url.startswith("http"):
url = "http://" + url
self.url_bar.setText(url)
self.browser.setUrl(QUrl(url))
app = QApplication([])
window = jkweb()
app.exec_()