-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrowser.py
53 lines (41 loc) · 1.64 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
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.browser = QWebEngineView()
self.browser.setUrl(QUrl('https://google.com'))
self.setCentralWidget(self.browser)
self.showMaximized()
# Navigation_bar_options
navigation_bar = QToolBar()
self.addToolBar(navigation_bar)
back_button = QAction('Back', self)
back_button.triggered.connect(self.browser.back)
navigation_bar.addAction(back_button)
forward_button = QAction('Forward', self)
forward_button.triggered.connect(self.browser.forward)
navigation_bar.addAction(forward_button)
refresh_button = QAction('Refresh', self)
refresh_button.triggered.connect(self.browser.reload)
navigation_bar.addAction(refresh_button)
self.url_bar = QLineEdit()
self.url_bar.returnPressed.connect(self.fetch_url)
navigation_bar.addWidget(self.url_bar)
self.browser.urlChanged.connect(self.update_url)
def update_url(self, q):
self.url_bar.setText(q.toString())
def fetch_url(self):
url1 = self.url_bar.text()
if '.com' in url1:
url = 'http://'+url1
self.browser.setUrl(QUrl(url))
else:
url = 'https://www.google.com/search?q='+url1
self.browser.setUrl(QUrl(url))
app = QApplication(sys.argv)
QApplication.setApplicationName('Python Web Browser')
window = MainWindow()
app.exec_()