WEB BROWSER Report
WEB BROWSER Report
1. PyQt5
2. sys
3. PyQt5.QtCore
4. PyQt5.QtWidgets
5. PyQt5.QtWebEngineWidgets
In module one we have create the homepage window for the web
browser. We add the four types of buttons in home screen.
1. Python 3.9.5 :
Python 3.9.5 is the newest majir release of the python
programming language and it contains many new features and
optimizations. There’s been 111 commits since 3.9.4 which is a
similar amount compared to 3.8 at the same stage of the relese
cycle.
2. PyQt5 :
PyQt5 is a python binding of the cross platform GUI toolkit Qt,
implemented as a Python pluging. PyQt is free software
developed by the British firm Riverbank computing. It is available
under similar terms Qt version older than 4.5.
3. SYS :
This module provides access to some variable used or maintained
by the interpreter and to functions that interact strongly with the
interpreter.
4. Sys.argv :
The list of command line argument passed to a python script.
Argv is the script name. If the command was execute using the -c
command line option to the interpreter, argv is set to the string ‘-
c’.
Process for making home screen window :
First step open the Pycharm and click “File” and select “New” and
the create a project name after that click “create” button.
Second step after creating a new file “Right” click the project name and
the click “save as” for the python file saving. After thet choose “python
file”
Step 3 : Name the Python file.
Third step after choose python file name the file “Web_Browser” and
then click enter.
Step 4 : The actual code Now you can start coding
IMPLIMENTATION OF MODULE
Below is the step-by-step Approach to create a home Screen window of
the module :
self.browser.urlChanged.connect(self.update_url)
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import*
from PyQt5.QtWebEngineWidgets import *
# navbar
navbar = QToolBar() self.addToolBar(navbar)
self.url_bar = QLineEdit()
self.url_bar.returnPressed.connect(self.navigate_to_url)
navbar.addWidget(self.url_bar)
self.browser.urlChanged.connect(self.update_url)
While testing this module the main focus is to find whether the
program run as we aim, also to cheak that the program runs without
the software we mentioned and used. As reference here we use various
screenshots.
As we discussed to run this program code we need Pycharm and python
of latest version we run the program only on python compiler or
interpreters.
Back :
Forward:
Reload :
Home :
DESIGNING OF MODULE
For creating the logo buttons and display such like black theme we use some
Inbuilt functions like OS for path distribution.
IMPLIMENTATION OF MODULE
Step 1 : The code is given below for Creating a new class for inserting tab
wigets to display web tabs.
# MAIN WINDOW
class MainWindow(QMainWindow):
def init (self, *args, **kwargs):
super(MainWindow, self). init (*args, **kwargs)
# ADD WINDOW ELEMENTS
# ADD TAB WIGDETS TO DISPLAY WEB TABS
self.tabs = QTabWidget()
self.tabs.setDocumentMode(True)
self.tabs.setTabsClosable(True)
self.setCentralWidget(self.tabs)
# ADD DOUBLE CLICK EVENT LISTENER
self.tabs.tabBarDoubleClicked.connect(self.tab_open_doubleclick)
# ADD TAB CLOSE EVENT LISTENER
self.tabs.tabCloseRequested.connect(self.close_current_tab)
# ADD ACTIVE TAB CHANGE EVENT LISTENER
self.tabs.currentChanged.connect(self.current_tab_changed)
# ADD LABEL ICON TO SHOW THE SECURITY STATUS OF THE LOADED URL
self.httpsicon = QLabel()
self.httpsicon.setPixmap(QPixmap(os.path.join('icons', 'cil-lock-unlocked.png')))
navtb.addWidget(self.httpsicon)
# ADD LINE EDIT TO SHOW AND EDIT URLS
self.urlbar = QLineEdit()
navtb.addWidget(self.urlbar)
# LOAD URL WHEN ENTER BUTTON IS PRESSED
self.urlbar.returnPressed.connect(self.navigate_to_url)
# Help menu
help_menu = self.menuBar().addMenu("&Help")
# ADD HELP MENU ACTIONS
navigate_home_action = QAction(QIcon(os.path.join('icons', 'cil-exit-to-
app.png')), "Homepage", self)
navigate_home_action.setStatusTip("Go to Design Homepage")
help_menu.addAction(navigate_home_action)
# NAVIGATE TO DEVELOPER WEBSITE
navigate_home_action.triggered.connect(self.navigate_home)
QTabWidget::tab-bar
{ alignment: left;
}
QLineEdit {
border: 2px solid rgb(0, 36,
36); border-radius: 10px;
padding: 5px;
background-color: rgb(0, 36, 36);
color: rgb(255, 255, 255);
}
QLineEdit:hover {
border: 2px solid rgb(0, 66, 124);
}
QLineEdit:focus{
border: 2px solid rgb(0, 136, 255);
color: rgb(200, 200, 200);
}
QPushButton{
background: rgb(49, 49, 49);
border: 2px solid rgb(0, 36, 36);
background-color: rgb(0, 36,
36); padding: 5px;
border-radius: 10px;
}""")
Step 4: Adding functions in this code.
# ############################################
# FUNCTIONS
##############################################
# ADD NEW WEB TAB
def add_new_tab(self, qurl=None,
label="Blank"): # Check if url value is blank
if qurl is None:
qurl = QUrl('http://www.google.com')#pass empty string to url
# CLOSE TABS
def close_current_tab(self, i):
if self.tabs.count() < 2: #Only close if there is more than one tab
open return
self.tabs.removeTab(i)
else:
# If schema is not https change icon to locked padlock to show that the webpage is unsecure
self.httpsicon.setPixmap(QPixmap(os.path.join('icons', 'cil-lock-unlocked.png')))
self.urlbar.setText(q.toString()
)
self.urlbar.setCursorPosition(0)
# ACTIVE TAB CHANGE ACTIONS
def current_tab_changed(self, i):
# i = tab index
# GET CURRENT TAB URL
qurl =
self.tabs.currentWidget().url() #
UPDATE URL TEXT
self.update_urlbar(qurl, self.tabs.currentWidget())
# UPDATE WINDOWS TITTLE
self.update_title(self.tabs.currentWidget())
title =
self.tabs.currentWidget().page().title()
self.setWindowTitle(title)
self.tabs.currentWidget().setUrl(q)
window =
MainWindow()
app.exec_()
Below the complete program for creating the design phase :
# IMPORTS
import os
import
sys
# MAIN WINDOW
class MainWindow(QMainWindow):
**kwargs)
# ADD WINDOW ELEMENTS
self.tabs = QTabWidget()
self.tabs.setDocumentMode(True)
self.tabs.setTabsClosable(True)
self.setCentralWidget(self.tabs)
self.tabs.tabBarDoubleClicked.connect(self.tab_open_doubleclick
self.tabs.tabCloseRequested.connect(self.close_current_tab
self.tabs.currentChanged.connect(self.current_tab_changed)
navtb = QToolBar("Navigation")
navtb.setIconSize(QSize(16, 16))
self.addToolBar(navtb)
navtb.addAction(back_btn)
back_btn.triggered.connect(lambda: self.tabs.currentWidget().back())
# NEXT WEB PAGE BUTTON
navtb.addAction(next_btn)
next_btn.triggered.connect(lambda: self.tabs.currentWidget().forward())
reload_btn.setStatusTip("Reload page")
navtb.addAction(reload_btn)
reload_btn.triggered.connect(lambda: self.tabs.currentWidget().reload())
navtb.addAction(home_btn)
home_btn.triggered.connect(self.navigate_home)
navtb.addSeparator()
# ADD LABEL ICON TO SHOW THE SECURITY STATUS OF THE LOADED URL
self.httpsicon = QLabel()
self.httpsicon.setPixmap(QPixmap(os.path.join('icons', 'cil-lock-unlocked.png')))
navtb.addWidget(self.httpsicon)
# ADD LINE EDIT TO SHOW AND EDIT URLS
self.urlbar = QLineEdit()
navtb.addWidget(self.urlbar)
self.urlbar.returnPressed.connect(self.navigate_to_url)
navtb.addAction(stop_btn)
stop_btn.triggered.connect(lambda: self.tabs.currentWidget().stop())
# File menu
file_menu =
MENU ACTIONS
file_menu.addAction(new_tab_action)
new_tab_action.triggered.connect(lambda _: self.add_new_tab())
# Help menu
help_menu =
MENU ACTIONS
"Homepage", self)
help_menu.addAction(navigate_home_action)
navigate_home_action.triggered.connect(self.navigate_home)
self.setWindowTitle("ES Browser")
self.setWindowIcon(QIcon(os.path.join('icons', 'cil-screen-desktop.png')))
self.setStyleSheet("""QWidget{ bac
position:
absolute; top: -
0.5em;
padding: 5px;
}
QTabWidget::tab-bar {
alignment: left;
*/ border-radius: 10px;
min-width: 8ex;
padding: 5px;
margin-right: 2px;
QLineEdit {
padding: 5px;
QLineEdit:hover {
QLineEdit:focus{
QPushButton{
padding: 5px;
border-radius: 10px;
}""")
#url = http://www.google.com,
#label = Homepage
self.add_new_tab(QUrl('http://www.google.com'), 'Homepage')
self.show()
# ############################################
# FUNCTIONS
##############################################
# ADD NEW WEB TAB
if qurl is None:
browser = QWebEngineView()
browser.setUrl(qurl)
i = self.tabs.addTab(browser, label)
self.tabs.setCurrentIndex(i)
# On URL change
self.update_urlbar(qurl, browser))
# On loadfinished
self.tabs.setTabText(i, browser.page().title()))
self.add_new_tab()
# CLOSE TABS
if self.tabs.count() < 2: #Only close if there is more than one tab open
return
self.tabs.removeTab(i)
#q = QURL
if browser != self.tabs.currentWidget():
return
# URL Schema
if q.scheme() == 'https':
# If schema is https change icon to locked padlock to show that the webpage is
else:
# If schema is not https change icon to locked padlock to show that the webpage is unsecure
self.httpsicon.setPixmap(QPixmap(os.path.join('icons', 'cil-lock-unlocked.png')))
self.urlbar.setText(q.toString())
self.urlbar.setCursorPosition(0)
# ACTIVE TAB CHANGE ACTIONS
# i = tab index
qurl = self.tabs.currentWidget().url()
self.update_urlbar(qurl,
TITTLE
self.update_title(self.tabs.currentWidget())
if browser != self.tabs.currentWidget():
return
title = self.tabs.currentWidget().page().title()
self.setWindowTitle(title)
q = QUrl(self.urlbar.text())
if q.scheme() == "":
q.setScheme("http")
self.tabs.currentWidget().setUrl(q)
def navigate_home(self):
self.tabs.currentWidget().setUrl(QUrl("http://www.google.com"))
app = QApplication(sys.argv)
# APPLICATION NAME
app.setApplicationName("ES Browser")
app.setOrganizationName("ES Company")
# APPLICATION COMPANY
ORGANISATION
app.setOrganizationDomain("ES.org")
window = MainWindow()
app.exec_()
TESTING OF MODULE
After testing the logo buttons are shown in the deign phase are:
1. Firstlly we finally add logo buttons in the code.
2. We add File drop down menu because a new tab insert in the program.
3. We are shown website which show are secure are not.
4. We also add Help button.
5. Add black theme this is amazing.
6. The new tab and old tab we are close by one click.
Output:-
Module no.3
Module Name:- Adding feature to web browser.
Planning of module
2] voice search
In additional to homepage, we also add a feature of voice search tour browser
so that it will simpler for a user to use that browser. For that we use a python
library that in Pyaudio and speech recognition using that we going to search by
taking a voice input from a user.
DESIGNING OF MODULE
For creating the web browser insert voice search button and renew home
page. We add the basic syntax for easily understand the language.
1] Homepage of browser
<!DOCTYPE html>
<html lang="en">
<head>
<title>Home </title>
</head>
<body>
<div class="search">
<img src="g.png" alt="" class="logo">
<input type="text" placeholder="Search the web" class="inp">
<button class="search _btn" onclick="search()">
<img src="btn.svg" alt=""></button>
</div>
<div class="top-site">
<h3 onclick="hideThis()">Top sites</h3>
<div class="sites">
<a href="https://www.youtube.com/"><div class="site">
<img src="yt.png" alt="">
<h4>YouTube</h4>
</div></a>
<a href="https://www.facebook.com/"><div class="site">
<img src="fb.png" alt="">
<h4>Facebook</h4>
</div></a>
<a href="https://en.wikipedia.org/wiki/Main_Page"> <div class="site">
<img src="wiki.png" alt="">
<h4>Wikipedia</h4>
</div></a>
<a href="https://www.reddit.com/"> <div class="site">
<img src="reddit.png" alt="">
<h4>Reddit</h4>
</div></a>
<a href="https://www.amazon.in/"> <div class="site">
<img src="az.png" alt="">
<h4>Amazon</h4>
</div></a>
<a href="https://twitter.com/"> <div class="site">
<img src="tw.png" alt="">
<h4>Twitter</h4>
</div></a>
</div>
</div>
</body>
<style
>
body{
background:#333
; margin:0;
padding:0;
color:#777;
width:100vw;
}
.search{
width:50%;
margin:200px auto
20px; display:flex;
align-items: center;
height:20px;
padding:8px 5px;
background:none;
border:1px solid
#777; position:
relative;
}
a{
text-decoration:none;
color:#888;
}
.search button{
filter: invert(.5);
width:30px;
height:30px;
margin:0;
border:none;
position:
absolute;
right:5px;
}
.logo{
height:20px
;
width:20px;
border-radius:
50%; margin:0px
5px;
}
input{
margin:0;
background:none
; outline:none;
border:none;
height:100%;
width:80%;
padding :0 10px;
color:#888;
}
.search button img{
width:100%;
height:100%;
}
.top-site{
width:80%;
margin:10px
auto; overflow:
hidden;
}
.top-site h3{
margin:5px 50px;
}
.sites{
display:flex;
align-items:
center; flex-
wrap:wrap;
justify-content:
center; text-align:
center; transition:.4s;
}
.site{
position: relative;
height:100px;
width:100px;
margin:40px
20px;
}
.site img{
height:100%;
width:100%;
background:#fff;
}
.hidden{
height:0px;
overflow:
hidden;
}
</style>
<script>
function hideThis() {
document.querySelector(".sites").classList.toggle("hidden");
}
function search() {
v=
document.querySelector(".inp").value;
if(v.length > 0)
{window.location = "https://www.google.com/search?q="+v;}
}
</script>
</html>
2] VoiceSearch
# ADD HISTORY TAB add voice search feature
def voice_search(self, qurl=None,
label="Blank"):
sr.Microphone(device_index=1)
r=sr.Recognizer()
r.energy_threshold=20000000
text= r.recognize_google(audio)
url='https://www.google.co.in/search?q='
search_url=url+text
# Check if url value is
blank if qurl is None:
qurl = QUrl(search_url)#pass empty string to url
# IMPORTS
import os
import
sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import
* from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import
* import pyaudio
import speech_recognition as sr
import pyttsx3
# MAIN WINDOWpip insta
class MainWindow(QMainWindow):
def init (self, *args, **kwargs):
super(MainWindow, self). init (*args, **kwargs)
# ADD LABEL ICON TO SHOW THE SECURITY STATUS OF THE LOADED URL
self.httpsicon = QLabel()
self.httpsicon.setPixmap(QPixmap(os.path.join('icons', 'cil-lock-unlocked.png')))
navtb.addWidget(self.httpsicon)
# Help menu
help_menu =
self.menuBar().addMenu("&Help") # ADD HELP
MENU ACTIONS
navigate_home_action = QAction(QIcon(os.path.join('icons', 'cil-exit-to-app.png')),
"Homepage", self)
navigate_home_action.setStatusTip("Go to Design Homepage")
help_menu.addAction(navigate_home_action)
# NAVIGATE TO DEVELOPER WEBSITE
navigate_home_action.triggered.connect(self.navigate_home)
QTabWidget::tab-bar
{ alignment: left;
}
QLineEdit {
border: 2px solid rgb(0, 36,
36); border-radius: 10px;
padding: 5px;
background-color: rgb(0, 36, 36);
color: rgb(255, 255, 255);
}
QLineEdit:hover {
border: 2px solid rgb(0, 66, 124);
}
QLineEdit:focus{
border: 2px solid rgb(0, 136, 255);
color: rgb(200, 200, 200);
}
QPushButton{
background: rgb(49, 49, 49);
border: 2px solid rgb(0, 36, 36);
background-color: rgb(0, 36,
36); padding: 5px;
border-radius: 10px;
}""")
# ############################################
# FUNCTIONS
##############################################
# ADD NEW WEB TAB
def add_new_tab(self, qurl=None, label="Blank"):
# Check if url value is
blank if qurl is None:
qurl = QUrl('https://a1malegaonkar.github.io/host/')#pass empty string to url
# CLOSE TABS
def close_current_tab(self, i):
if self.tabs.count() < 2: #Only close if there is more than one tab
open return
self.tabs.removeTab(i)
else:
# If schema is not https change icon to locked padlock to show that the webpage is unsecure
self.httpsicon.setPixmap(QPixmap(os.path.join('icons', 'cil-lock-unlocked.png')))
self.urlbar.setText(q.toString()
)
self.urlbar.setCursorPosition(0)
title =
self.tabs.currentWidget().page().title()
self.setWindowTitle(title)
self.tabs.currentWidget().setUrl(q)
app = QApplication(sys.argv)
# APPLICATION NAME
app.setApplicationName("Browser")
window =
MainWindow()
app.exec_()
TESTING OF MODULE
Output:-
Screen the final Project:
When you click File drop down menu Button:
Voice search :