Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fff6b50

Browse files
Merge pull request avinashkranjan#384 from Sloth-Panda/b2
added a simple web browser made using python
2 parents 3ae1a12 + 4403af3 commit fff6b50

File tree

4 files changed

+165
-0
lines changed

4 files changed

+165
-0
lines changed

‎Broswer/README.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Web Browser
2+
3+
## Description
4+
5+
This is a simple web browser made using python with just functionality to have access to the complete gsuite(google suite) and the default search engine here is google.
6+
7+
## Set Up
8+
9+
To use this on your local machine follow the [Readme](https://github.com/avinashkranjan/Amazing-Python-Scripts/blob/master/README.md) of this repo and clone this project to your machine and from there cd into this "Browser" folder and run the script and you can see this working.
10+
11+
## Screenshots
12+
13+
<img src="b1.png">
14+
<img src="b2.png">

‎Broswer/b1.png‎

162 KB
Loading[フレーム]

‎Broswer/b2.png‎

42.2 KB
Loading[フレーム]

‎Broswer/browser.py‎

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# importing required libraries
2+
from PyQt5.QtCore import *
3+
from PyQt5.QtWidgets import *
4+
from PyQt5.QtGui import *
5+
from PyQt5.QtWebEngineWidgets import *
6+
from PyQt5.QtPrintSupport import *
7+
import os
8+
import sys
9+
10+
# creating main window class
11+
class MainWindow(QMainWindow):
12+
13+
# constructor
14+
def __init__(self, *args, **kwargs):
15+
super(MainWindow, self).__init__(*args, **kwargs)
16+
17+
# creating a QWebEngineView
18+
self.browser = QWebEngineView()
19+
20+
# setting default browser url as google
21+
self.browser.setUrl(QUrl("http://google.com"))
22+
23+
# adding action when url get changed
24+
self.browser.urlChanged.connect(self.update_urlbar)
25+
26+
# adding action when loading is finished
27+
self.browser.loadFinished.connect(self.update_title)
28+
29+
# set this browser as central widget or main window
30+
self.setCentralWidget(self.browser)
31+
32+
# creating a status bar object
33+
self.status = QStatusBar()
34+
35+
# adding status bar to the main window
36+
self.setStatusBar(self.status)
37+
38+
# creating QToolBar for navigation
39+
navtb = QToolBar("Navigation")
40+
41+
# adding this tool bar tot he main window
42+
self.addToolBar(navtb)
43+
44+
# adding actions to the tool bar
45+
# creating a action for back
46+
back_btn = QAction("Back", self)
47+
48+
# setting status tip
49+
back_btn.setStatusTip("Back to previous page")
50+
51+
# adding action to the back button
52+
# making browser go back
53+
back_btn.triggered.connect(self.browser.back)
54+
55+
# adding this action to tool bar
56+
navtb.addAction(back_btn)
57+
58+
# similarly for forward action
59+
next_btn = QAction("Forward", self)
60+
next_btn.setStatusTip("Forward to next page")
61+
62+
# adding action to the next button
63+
# making browser go forward
64+
next_btn.triggered.connect(self.browser.forward)
65+
navtb.addAction(next_btn)
66+
67+
# similarly for reload action
68+
reload_btn = QAction("Reload", self)
69+
reload_btn.setStatusTip("Reload page")
70+
71+
# adding action to the reload button
72+
# making browser to reload
73+
reload_btn.triggered.connect(self.browser.reload)
74+
navtb.addAction(reload_btn)
75+
76+
# similarly for home action
77+
home_btn = QAction("Home", self)
78+
home_btn.setStatusTip("Go home")
79+
home_btn.triggered.connect(self.navigate_home)
80+
navtb.addAction(home_btn)
81+
82+
# adding a separator in the tool bar
83+
navtb.addSeparator()
84+
85+
# creating a line edit for the url
86+
self.urlbar = QLineEdit()
87+
88+
# adding action when return key is pressed
89+
self.urlbar.returnPressed.connect(self.navigate_to_url)
90+
91+
# adding this to the tool bar
92+
navtb.addWidget(self.urlbar)
93+
94+
# adding stop action to the tool bar
95+
stop_btn = QAction("Stop", self)
96+
stop_btn.setStatusTip("Stop loading current page")
97+
98+
# adding action to the stop button
99+
# making browser to stop
100+
stop_btn.triggered.connect(self.browser.stop)
101+
navtb.addAction(stop_btn)
102+
103+
# showing all the components
104+
self.show()
105+
106+
# method for updating the title of the window
107+
def update_title(self):
108+
title = self.browser.page().title()
109+
self.setWindowTitle("% s - Epic Browser" % title)
110+
111+
# method called by the home action
112+
def navigate_home(self):
113+
114+
# open the google
115+
self.browser.setUrl(QUrl("http://www.google.com"))
116+
117+
# method called by the line edit when return key is pressed
118+
def navigate_to_url(self):
119+
120+
# getting url and converting it to QUrl objetc
121+
q = QUrl(self.urlbar.text())
122+
123+
# if url is scheme is blank
124+
if q.scheme() == "":
125+
# set url scheme to html
126+
q.setScheme("http")
127+
128+
# set the url to the browser
129+
self.browser.setUrl(q)
130+
131+
# method for updating url
132+
# this method is called by the QWebEngineView object
133+
def update_urlbar(self, q):
134+
135+
# setting text to the url bar
136+
self.urlbar.setText(q.toString())
137+
138+
# setting cursor position of the url bar
139+
self.urlbar.setCursorPosition(0)
140+
141+
# creating a pyQt5 application
142+
app = QApplication(sys.argv)
143+
144+
# setting name to the application
145+
app.setApplicationName("Epic Browser")
146+
147+
# creating a main window object
148+
window = MainWindow()
149+
150+
# loop
151+
app.exec_()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /