This repository has been archived by the owner on Sep 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBrowser.pyw
91 lines (73 loc) · 2.92 KB
/
Browser.pyw
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
88
89
90
91
# Imports
import sys
import requests
from PyQt5.QtCore import *
from PyQt5 import QtGui
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
# Set dafault vars
'''searchEngines = {'Google':['http://google.com/?hl=en', 'https://www.google.com/search?q=']}'''
seData = requests.get("https://raw.githubusercontent.com/Parsa-GP/api/gh-pages/search_engines.json")
searchEngines = seData.json()
defaultSE = 'Google'
homePage = searchEngines[defaultSE][0]
searchArgs = searchEngines[defaultSE][1]
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowIcon(QtGui.QIcon('icon.png'))
self.browser = QWebEngineView()
self.browser.setUrl(QUrl(homePage))
self.setCentralWidget(self.browser)
self.showMaximized()
# Add widdgets to navbar
navbar = QToolBar()
self.addToolBar(navbar)
back_btn = QAction('\u25C0', self)
back_btn.triggered.connect(self.browser.back)
navbar.addAction(back_btn)
forward_btn = QAction('\u25B6', self)
forward_btn.triggered.connect(self.browser.forward)
navbar.addAction(forward_btn)
reload_btn = QAction('\u21bb', self)
reload_btn.triggered.connect(self.browser.reload)
navbar.addAction(reload_btn)
home_btn = QAction('\u2302', self)
home_btn.triggered.connect(self.navigate_home)
navbar.addAction(home_btn)
self.url_bar = QLineEdit()
self.url_bar.returnPressed.connect(self.navigate_to_url)
navbar.addWidget(self.url_bar)
self.cb = QComboBox()
self.cb.addItems(searchEngines)
self.cb.currentIndexChanged.connect(self.selectionchange)
navbar.addWidget(self.cb)
self.browser.urlChanged.connect(self.update_url)
self.browser.loadFinished.connect(self.finished_url)
# Functions
def selectionchange(self,i):
global homePage
global searchArgs
homePage = searchEngines[self.cb.currentText()][0]
searchArgs = searchEngines[self.cb.currentText()][1]
def navigate_home(self):
self.browser.setUrl(QUrl(homePage))
def navigate_to_url(self):
url = self.url_bar.text()
if url[0:7] == 'http://' or url[0:8] == 'https://' or url[0:6] == 'about:':
self.url_bar.setText(url)
self.browser.setUrl(QUrl(url))
else:
self.url_bar.setText(f'{searchArgs}{url}')
self.browser.setUrl(QUrl(f'{searchArgs}{url}'))
def update_url(self, q):
address = q.toString()
self.url_bar.setText(q.toString())
def finished_url(self, q):
title = self.browser.page().title()
self.setWindowTitle(f'Browser - {title}')
#Run the app
app = QApplication(sys.argv)
QApplication.setApplicationName('Browser')
window = MainWindow()
app.exec_()