-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxxxx.py
More file actions
76 lines (76 loc) · 3.13 KB
/
xxxx.py
File metadata and controls
76 lines (76 loc) · 3.13 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
import sys
#importing Widgtes
from PyQt5.QtWidgets import *
#importing Engine Widgets
from PyQt5.QtWebEngineWidgets import *
#importing QtCore to use Qurl
from PyQt5.QtCore import *
#main window class (to create a window)-sub class of QMainWindow class
class Window(QMainWindow):
#defining constructor function
def __init__(self):
#creating connnection with parent class constructor
super(Window,self).__init__()
#---------------------adding browser-------------------
self.browser = QWebEngineView()
#setting url for browser, you can use any other url also
self.browser.setUrl(QUrl('https://www.bing.com/'))
#to display google search engine on our browser
self.setCentralWidget(self.browser)
#-------------------full screen mode------------------
#to display browser in full screen mode, you may comment below line if you don't want to open your browser in full screen mode
self.showMaximized()
#----------------------navbar-------------------------
#creating a navigation bar for the browser
navbar = QToolBar()
#adding created navbar
self.addToolBar(navbar)
#-----------------prev Button-----------------
#creating prev button
prevBtn = QAction('<',self)
#when triggered set connection
prevBtn.triggered.connect(self.browser.back)
# adding prev button to the navbar
navbar.addAction(prevBtn)
#-----------------next Button---------------
nextBtn = QAction('>',self)
nextBtn.triggered.connect(self.browser.forward)
navbar.addAction(nextBtn)
#-----------refresh Button--------------------
refreshBtn = QAction('{_|',self)
refreshBtn.triggered.connect(self.browser.reload)
navbar.addAction(refreshBtn)
#-----------home button----------------------
homeBtn = QAction('[]',self)
#when triggered call home method
homeBtn.triggered.connect(self.home)
navbar.addAction(homeBtn)
#---------------------search bar---------------------------------
#to maintain a single line
self.searchBar = QLineEdit()
#when someone presses return(enter) call loadUrl method
self.searchBar.returnPressed.connect(self.loadUrl)
#adding created seach bar to navbar
navbar.addWidget(self.searchBar)
#if url in the searchBar is changed then call updateUrl method
self.browser.urlChanged.connect(self.updateUrl)
#method to navigate back to home page
def home(self):
self.browser.setUrl(QUrl('https://bing.com/'))
#method to load the required url
def loadUrl(self):
#fetching entered url from searchBar
url = self.searchBar.text()
#loading url
self.browser.setUrl(QUrl(url))
#method to update the url
def updateUrl(self, url):
#changing the content(text) of searchBar
self.searchBar.setText(url.toString())
MyApp = QApplication(sys.argv)
#setting application name
QApplication.setApplicationName('Avoura Browser')
#creating window
window = Window()
#executing created app
MyApp.exec_()