├── Databases.db ├── README.md ├── __pycache__ ├── browser.cpython-36.pyc ├── main.cpython-36.pyc ├── mainBar.cpython-36.pyc ├── mainWindow.cpython-36.pyc ├── window.cpython-36.pyc └── youtube.cpython-36.pyc ├── back.png ├── bookmarks.json ├── bookmarks.png ├── bookmarks.txt ├── browser.py ├── browser.pyc ├── forward.png ├── history.png ├── history.txt ├── home.png ├── main.py ├── mainWindow.py ├── mainWindow.pyc ├── plus.png ├── readme.txt ├── refresh.png ├── screenshot.png ├── search.png ├── settings.png ├── star.png ├── web.png ├── window.py ├── window.pyc ├── youtube.py └── youtube.pyc /Databases.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/Databases.db -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python browser 2 | Simplified web browser made in python for a college project. 3 | Web browser has bookmarks, history, multiple tabs, toolbar. 4 | It was made on Ubuntu for Ubuntu. 5 | 6 | ![](screenshot.png) 7 | 8 | ## Setup 9 | 10 | 1. Install PyQt5 11 | Ubuntu 12 | ```sh 13 | sudo apt-get install python3-pyqt5 14 | 15 | ``` 16 | 17 | 2. Install QtWebKit 18 | 19 | ```sh 20 | sudo apt-get install python3-pyqt5.qtwebkit 21 | ``` 22 | 3. Run 23 | ```sh 24 | python3 main.py 25 | ``` 26 | *** 27 | ## Meta 28 | 29 | Lazar Bojanic
30 | [@Linkedin](https://www.linkedin.com/in/lbojanic/)
31 | lazar.bojanic@hotmail.rs
32 | [@GitHub](https://github.com/LBojanic)
33 |
34 | Djordje Dimovic
35 | [@Linkedin](https://www.linkedin.com/in/dimovicd/)
36 | dimovicdj@gmail.com
37 | [@GitHub](https://github.com/dimovicdj) 38 | -------------------------------------------------------------------------------- /__pycache__/browser.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/__pycache__/browser.cpython-36.pyc -------------------------------------------------------------------------------- /__pycache__/main.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/__pycache__/main.cpython-36.pyc -------------------------------------------------------------------------------- /__pycache__/mainBar.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/__pycache__/mainBar.cpython-36.pyc -------------------------------------------------------------------------------- /__pycache__/mainWindow.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/__pycache__/mainWindow.cpython-36.pyc -------------------------------------------------------------------------------- /__pycache__/window.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/__pycache__/window.cpython-36.pyc -------------------------------------------------------------------------------- /__pycache__/youtube.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/__pycache__/youtube.cpython-36.pyc -------------------------------------------------------------------------------- /back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/back.png -------------------------------------------------------------------------------- /bookmarks.json: -------------------------------------------------------------------------------- 1 | [{"elements": {"Google": "https://www.google.com/", "Yahoo": "https://www.yahoo.com/"}, "name": "Section 1"}, {"elements": {"Insta": "https://www.instagram.com/?hl=sr", "Face": "https://www.facebook.com/"}, "name": "Social networks"}, {"elements": {"Google": "https://www.google.com/"}, "name": "Folder2"}, {"name": "Folder3", "elements": {"youtube - Google \u043f\u0440\u0435\u0442\u0440\u0430\u0433\u0430": "https://www.google.com/search?q=youtube"}}] -------------------------------------------------------------------------------- /bookmarks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/bookmarks.png -------------------------------------------------------------------------------- /bookmarks.txt: -------------------------------------------------------------------------------- 1 | dsds;https://www.google.com/ 2 | -------------------------------------------------------------------------------- /browser.py: -------------------------------------------------------------------------------- 1 | from window import * 2 | 3 | class Browser(QGraphicsView): 4 | 5 | def __init__(self, parent): 6 | super(Browser, self).__init__(parent) 7 | self.page = Window(self) 8 | 9 | self.setScene(self.page) 10 | 11 | -------------------------------------------------------------------------------- /browser.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/browser.pyc -------------------------------------------------------------------------------- /forward.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/forward.png -------------------------------------------------------------------------------- /history.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/history.png -------------------------------------------------------------------------------- /history.txt: -------------------------------------------------------------------------------- 1 | Google;https://www.google.com/ 2 | YouTube;https://www.youtube.com/ 3 | Google;http://www.google.com/ 4 | -------------------------------------------------------------------------------- /home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/home.png -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from mainWindow import * 2 | from youtube import * 3 | 4 | 5 | def main(): 6 | app = QApplication(sys.argv) 7 | 8 | if len(sys.argv) < 2: 9 | win = MainWindow() 10 | win.showMaximized() 11 | else: 12 | win = Youtube(sys.argv[1]) 13 | win.show() 14 | app.exec_() 15 | 16 | if __name__ == '__main__': 17 | sys.exit(main()) 18 | -------------------------------------------------------------------------------- /mainWindow.py: -------------------------------------------------------------------------------- 1 | from browser import * 2 | 3 | class MainWindow(QMainWindow): 4 | def __init__(self,parent=None): 5 | super(MainWindow, self).__init__(parent) #super(subClass, instance).__init__(parent) 6 | self.setGeometry(10, 10, 1000, 800) #setGeometry(topLeftX, topLeftY, width, height) 7 | 8 | self.setWindowTitle('Browser') 9 | self.setWindowIcon(QIcon('web.png')) 10 | 11 | 12 | self.addressBar = QLineEdit() 13 | self.addressBar.setPlaceholderText('Search with Google or enter address') 14 | 15 | self.createBrowser() # Method that creates graphics view 16 | 17 | #---------------------Toolbar buttons section----------------------- 18 | tb = self.addToolBar("File") 19 | tb.setMovable(False) 20 | self.backAction = QAction(QIcon('back.png'), 'Back', self) 21 | self.backAction.setShortcut('Ctrl+B') 22 | self.backAction.triggered.connect(self.browser.page.backButtonPush) 23 | 24 | self.forwardAction = QAction(QIcon('forward.png'), 'Forward', self) 25 | self.forwardAction.setShortcut('Ctrl+F') 26 | self.forwardAction.triggered.connect(self.browser.page.forwardButtonPush) 27 | 28 | self.refreshAction = QAction(QIcon('refresh.png'), 'Refresh', self) 29 | self.refreshAction.setShortcut('Ctrl+R') 30 | self.refreshAction.triggered.connect(self.browser.page.refreshButtonPush) 31 | 32 | self.homeAction = QAction(QIcon('home.png'), 'Home', self) 33 | self.homeAction.setShortcut('Ctrl+H') 34 | self.homeAction.triggered.connect(self.browser.page.homeButtonPush) 35 | 36 | self.goAction = QAction(QIcon('search.png'), 'Go', self) 37 | self.goAction.setShortcut(Qt.Key_Return) 38 | self.goAction.triggered.connect(lambda: self.browser.page.goButtonPush(self.addressBar.text())) 39 | 40 | 41 | self.bookmarkAction = QAction(QIcon('star.png'), 'Add bookmark', self) 42 | self.bookmarkAction.setShortcut('Ctrl+B') 43 | self.bookmarkAction.triggered.connect(self.browser.page.addBookmarkPush) 44 | 45 | self.historyAction = QAction(QIcon('history.png'), 'History', self) 46 | self.historyAction.setShortcut('Ctrl+H') 47 | self.historyAction.triggered.connect(self.browser.page.historyButtonPush) 48 | 49 | self.bookmarksAction = QAction(QIcon('bookmarks.png'), 'Bookmarks', self) 50 | self.bookmarksAction.setShortcut('Ctrl+V') 51 | self.bookmarksAction.triggered.connect(self.browser.page.bookmarksButtonPush) 52 | 53 | 54 | 55 | tb.addAction(self.backAction) 56 | tb.addAction(self.forwardAction) 57 | tb.addAction(self.refreshAction) 58 | tb.addAction(self.homeAction) 59 | tb.addWidget(self.addressBar) 60 | tb.addAction(self.goAction) 61 | tb.addAction(self.bookmarkAction) 62 | tb.addAction(self.historyAction) 63 | tb.addAction(self.bookmarksAction) 64 | 65 | 66 | 67 | def createBrowser(self): 68 | self.browser = Browser(self) 69 | self.setCentralWidget(self.browser) 70 | 71 | 72 | def closeEvent(self, event): 73 | 74 | file = open('history.txt', 'a+', encoding='utf-8') # a+ mode opens in read+write, appending to end of file and creating file if it doesn't exist 75 | 76 | 77 | for i in self.browser.page.history: 78 | file.write((i + '\n')) 79 | 80 | file.close() 81 | 82 | reply = QMessageBox.question(self, 'Confirm close', 83 | "You are about to exit. Are you sure you want to continue?", QMessageBox.Yes | 84 | QMessageBox.No, QMessageBox.Yes) # parent, title, message, buttons, default button 85 | 86 | if reply == QMessageBox.Yes: 87 | event.accept() 88 | else: 89 | event.ignore() 90 | 91 | -------------------------------------------------------------------------------- /mainWindow.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/mainWindow.pyc -------------------------------------------------------------------------------- /plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/plus.png -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | https://github.com/dimovicdj/python-browser 2 | Potrebni su pyqt5 i pyqt5 webkit 3 | Program se pokrece sa python3 main.py 4 | Program je napravljen za Ubuntu 5 | Lazar Bojanic lazar.bojanic@hotmail.rs 6 | Djordje Dimovic dimovicdj@gmail.com 7 | -------------------------------------------------------------------------------- /refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/refresh.png -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/screenshot.png -------------------------------------------------------------------------------- /search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/search.png -------------------------------------------------------------------------------- /settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/settings.png -------------------------------------------------------------------------------- /star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/star.png -------------------------------------------------------------------------------- /web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/web.png -------------------------------------------------------------------------------- /window.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import json 3 | from PyQt5.QtWidgets import * 4 | from PyQt5.QtGui import * 5 | from PyQt5.QtCore import * 6 | from PyQt5.QtWebKit import * 7 | from PyQt5.QtWebKitWidgets import * 8 | 9 | class Window(QGraphicsScene): 10 | 11 | def __init__(self, view): 12 | super(Window, self).__init__(view) 13 | 14 | _layout = QVBoxLayout(view) 15 | 16 | self.view = view 17 | self.tabs = QTabWidget() 18 | self.tabs.setTabsClosable(True) 19 | self.tabs.currentChanged.connect(self.currentTabChanged) 20 | self.tabs.tabCloseRequested.connect(self.closeCurrentTab) 21 | 22 | self.history = [] # list of strings, string = "title;URL" needed for writing history in a file 23 | self.historyForEachTab = {} # key = tabIndex, value = tabIndexHistory - needed for back and forward methods 24 | self.addNewTab() 25 | 26 | button = QPushButton(QIcon('plus.png'), '') 27 | button.setStatusTip('Open a new tab') 28 | button.clicked.connect(self.addNewTab) 29 | self.tabs.setCornerWidget(button, Qt.TopLeftCorner) 30 | 31 | self.setBackgroundBrush(QBrush(QColor(230, 230, 230))) 32 | 33 | _layout.addWidget(self.tabs) 34 | 35 | file = open('history.txt', 'r') 36 | 37 | self.lines = file.readlines() 38 | 39 | file.close() 40 | 41 | def addNewTab(self): 42 | 43 | qurl = QUrl('www.google.com') 44 | 45 | web = QWebView() 46 | web.load(QUrl("https://www.google.com")) 47 | 48 | i = self.tabs.addTab(web, "Google") 49 | 50 | self.tabs.setCurrentIndex(i) 51 | 52 | web.urlChanged.connect(lambda qurl, web=web: self.update_urlbar(qurl, web)) 53 | web.loadFinished.connect(lambda _, i=i, web=web: self.tabs.setTabText(i, web.title())) 54 | web.loadFinished.connect(lambda _, qurl=qurl, web=web: self.addToHistory(web.title(), web.url().toString())) 55 | 56 | self.historyForEachTab[i] = self.tabs.currentWidget().page().history() 57 | 58 | def addToHistory(self, title, link): 59 | 60 | if(len(self.history) == 0): 61 | self.history.append(''.join((title, ';', link))) 62 | return 63 | 64 | if(self.history[-1] != ''.join((title, ';', link))): 65 | self.history.append(''.join((title, ';', link))) 66 | 67 | def update_urlbar(self, q, browser=None): 68 | 69 | if browser != self.tabs.currentWidget(): 70 | return 71 | 72 | self.parent().parent().addressBar.setText(q.toString()) 73 | 74 | def currentTabChanged(self, i): 75 | qurl = self.tabs.currentWidget().url() 76 | self.update_urlbar(qurl, self.tabs.currentWidget()) 77 | self.updateTitle(self.tabs.currentWidget()) 78 | 79 | def updateTitle(self, browser): 80 | if browser != self.tabs.currentWidget(): 81 | return 82 | 83 | title = self.tabs.currentWidget().title() 84 | self.view.parent().setWindowTitle(title) 85 | 86 | def closeCurrentTab(self, i): 87 | 88 | print(i) 89 | if self.tabs.count() < 2: 90 | return 91 | 92 | for j in range(i, self.tabs.count() - 1): 93 | self.historyForEachTab[j] = self.historyForEachTab[j+1] 94 | 95 | for j in range(i, self.tabs.count()): 96 | self.tabs.widget(j).loadFinished.disconnect() 97 | self.tabs.widget(j).loadFinished.connect(lambda _, i=j-1, web=self.tabs.widget(j): self.tabs.setTabText(i, web.title())) 98 | self.tabs.widget(j).loadFinished.connect(lambda _, web=self.tabs.widget(j): self.addToHistory(web.title(), web.url().toString())) 99 | 100 | self.tabs.removeTab(i) 101 | # History Button 102 | def historyButtonPush(self): 103 | self.popUp = QWidget() 104 | 105 | self.popUp.setWindowTitle('History') 106 | self.popUp.setMinimumSize(400, 400) 107 | 108 | layout = QVBoxLayout() 109 | 110 | self.list = QListWidget() 111 | 112 | for line in self.lines: 113 | list = line.split(';') 114 | url = QUrl(list[1]) 115 | self.list.addItem(QListWidgetItem(list[0].strip() + ' - ' + list[1].strip())) 116 | 117 | for line in self.history: 118 | list = line.split(';') 119 | url = QUrl(list[1]) 120 | self.list.addItem(QListWidgetItem(list[0].strip() + ' - ' + list[1].strip())) 121 | 122 | button = QPushButton('Delete History') 123 | button.clicked.connect(self.deleteAllHistory) 124 | 125 | layout = QVBoxLayout() 126 | layout.addWidget(self.list) 127 | layout.addWidget(button) 128 | self.popUp.setLayout(layout) 129 | 130 | self.list.itemActivated.connect(self.doubleClickHistory) 131 | self.list.itemClicked.connect(self.leftClickOnHistoryListElement) 132 | 133 | self.popUp.show() 134 | 135 | def doubleClickHistory(self, item): 136 | list = item.text().split(' - ') 137 | self.tabs.currentWidget().load(QUrl(list[1])) 138 | 139 | self.popUp.close() 140 | 141 | def leftClickOnHistoryListElement(self, item): 142 | 143 | self.popUp.setContextMenuPolicy(Qt.CustomContextMenu) 144 | 145 | self.historyRightClickMenu = QMenu() 146 | 147 | self.item = item 148 | 149 | menuItem = self.historyRightClickMenu.addAction('Open') 150 | menuItem.triggered.connect(self.openHistory) 151 | 152 | menuItem = self.historyRightClickMenu.addAction('Open in a New Tab') 153 | menuItem.triggered.connect(self.openHistoryInNewTab) 154 | 155 | menuItem = self.historyRightClickMenu.addAction('Bookmark page') 156 | menuItem.triggered.connect(self.addBookmarkFromHistory) 157 | 158 | 159 | self.popUp.customContextMenuRequested.connect(self.showHistoryRightClickMenu) 160 | 161 | def deleteAllHistory(self): 162 | self.history = [] 163 | self.lines = [] 164 | file = open('history.txt', 'w+') 165 | lines = file.readlines() 166 | file.close() 167 | 168 | self.popUp.close() 169 | 170 | def showHistoryRightClickMenu(self, QPos): 171 | parentPosition = self.popUp.mapToGlobal(QPoint(0, 0)) 172 | menuPosition = parentPosition + QPos 173 | self.historyRightClickMenu.move(menuPosition) 174 | self.historyRightClickMenu.show() 175 | 176 | 177 | def openHistory(self): 178 | list = self.item.text().split(' - ') 179 | self.tabs.currentWidget().load(QUrl(list[1])) 180 | 181 | print(list[1]) 182 | 183 | self.popUp.close() 184 | 185 | def openHistoryInNewTab(self): 186 | list = self.item.text().split(' - ') 187 | q = QUrl(list[1]) 188 | 189 | web = QWebView() 190 | web.load(q) 191 | web.setMinimumHeight(qApp.primaryScreen().size().height()-160) 192 | 193 | i = self.tabs.addTab(web, "Google") 194 | 195 | self.tabs.setCurrentIndex(i) 196 | 197 | web.urlChanged.connect(lambda qurl, web=web: self.update_urlbar(qurl, web)) 198 | web.loadFinished.connect(lambda _, i=i, web=web: self.tabs.setTabText(i, web.title())) 199 | web.loadFinished.connect(lambda _, web=web: self.addToHistory(web.title(), web.url().toString())) 200 | 201 | self.historyForEachTab[i] = self.tabs.currentWidget().page().history() 202 | 203 | self.popUp.close() 204 | 205 | 206 | def addBookmarkFromHistory(self): 207 | list = self.item.text().split(' - ') 208 | print(list[0]) 209 | self.popUp = QDialog() 210 | layout = QVBoxLayout() 211 | 212 | button = QPushButton('Done') 213 | self.add = QLineEdit() 214 | self.add.setPlaceholderText('Name') 215 | self.inCategory = QLineEdit() 216 | self.inCategory.setPlaceholderText('Folder') 217 | 218 | layout.addWidget(self.inCategory) 219 | layout.addWidget(self.add) 220 | layout.addWidget(button) 221 | 222 | self.popUp.setLayout(layout) 223 | 224 | button.clicked.connect(lambda _, title=list[0] , url=list[1] : self.saveBookmark(title, url)) 225 | 226 | self.popUp.setWindowTitle('Page Bookmarked') 227 | self.popUp.setMaximumSize(300, 200) 228 | 229 | self.popUp.show() 230 | 231 | 232 | 233 | 234 | 235 | ############################################# 236 | 237 | # Bookmark Button 238 | 239 | def bookmarksButtonPush(self): 240 | self.popUp = QWidget() 241 | 242 | self.popUp.setWindowTitle('Bookmarks') 243 | self.popUp.setMinimumSize(400, 400) 244 | 245 | self.list = QListWidget() 246 | 247 | file = open('bookmarks.json', 'r') 248 | 249 | categories = json.load(file) 250 | 251 | for category in categories: 252 | self.list.addItem(QListWidgetItem('- - - - - ' + category['name'] + ' folder - - - - -')) 253 | for (name, link) in category['elements'].items(): 254 | self.list.addItem(QListWidgetItem(name.strip())) 255 | 256 | file.close() 257 | 258 | layout = QVBoxLayout() 259 | layout.addWidget(self.list) 260 | 261 | self.popUp.setLayout(layout) 262 | 263 | self.list.itemClicked.connect(self.leftClickOnBookmarkListElement) 264 | 265 | self.list.itemActivated.connect(self.doubleClickBookmark) 266 | 267 | self.popUp.show() 268 | 269 | 270 | 271 | def doubleClickBookmark(self, item): 272 | file = open('bookmarks.json', 'r') 273 | 274 | categories = json.load(file) 275 | 276 | for category in categories: 277 | if(item.text().strip() in category['elements']): 278 | q = QUrl(category['elements'][item.text().strip()].strip()) 279 | if(q.scheme() == ""): 280 | q.setScheme("http") 281 | self.tabs.currentWidget().load(q) 282 | self.popUp.close() 283 | 284 | file.close() 285 | 286 | def leftClickOnBookmarkListElement(self, item): 287 | 288 | self.popUp.setContextMenuPolicy(Qt.CustomContextMenu) 289 | 290 | self.bookmarkRightClickMenu = QMenu() 291 | 292 | self.item = item 293 | menuItem = self.bookmarkRightClickMenu.addAction('Open') 294 | menuItem.triggered.connect(self.openBookmark) 295 | 296 | menuItem = self.bookmarkRightClickMenu.addAction('Open in a New Tab') 297 | menuItem.triggered.connect(self.openBookmarkInNewTab) 298 | 299 | menuItem = self.bookmarkRightClickMenu.addAction('Delete bookmark') 300 | menuItem.triggered.connect(self.deleteBookmark) 301 | 302 | self.popUp.customContextMenuRequested.connect(self.showBookmarkRightClickMenu) 303 | 304 | 305 | def showBookmarkRightClickMenu(self, QPos): 306 | parentPosition = self.popUp.mapToGlobal(QPoint(0, 0)) 307 | menuPosition = parentPosition + QPos 308 | self.bookmarkRightClickMenu.move(menuPosition) 309 | self.bookmarkRightClickMenu.show() 310 | 311 | def openBookmarkInNewTab(self): 312 | 313 | file = open('bookmarks.json', 'r') 314 | 315 | global q 316 | q = '' 317 | categories = json.load(file) 318 | 319 | for category in categories: 320 | if(self.item.text().strip() in category['elements']): 321 | q = QUrl(category['elements'][self.item.text().strip()].strip()) 322 | if(q.scheme() == ""): 323 | q.setScheme("http") 324 | self.popUp.close() 325 | 326 | file.close() 327 | 328 | if(q == ''): 329 | return 330 | 331 | web = QWebView() 332 | web.load(q) 333 | web.setMinimumHeight(qApp.primaryScreen().size().height()-160) 334 | 335 | i = self.tabs.addTab(web, "Google") 336 | 337 | self.tabs.setCurrentIndex(i) 338 | 339 | web.urlChanged.connect(lambda qurl, web=web: self.update_urlbar(qurl, web)) 340 | web.loadFinished.connect(lambda _, i=i, web=web: self.tabs.setTabText(i, web.title())) 341 | 342 | self.historyForEachTab[i] = self.tabs.currentWidget().page().history() 343 | 344 | 345 | def openBookmark(self): 346 | file = open('bookmarks.json', 'r') 347 | 348 | categories = json.load(file) 349 | 350 | for category in categories: 351 | if(self.item.text().strip() in category['elements']): 352 | q = QUrl(category['elements'][self.item.text().strip()].strip()) 353 | if(q.scheme() == ""): 354 | q.setScheme("http") 355 | self.tabs.currentWidget().load(q) 356 | self.popUp.close() 357 | 358 | file.close() 359 | 360 | 361 | def deleteBookmark(self): 362 | file = open('bookmarks.json', 'r') 363 | 364 | categories = json.load(file) 365 | 366 | file.close() 367 | file = open('bookmarks.json', 'w+') 368 | 369 | delete = 0 370 | element = '' 371 | 372 | for category in categories: 373 | if(self.item.text() in category['elements']): 374 | category['elements'].pop(self.item.text()) 375 | self.item.setHidden(True) 376 | if(not category['elements']): 377 | delete = 1 378 | element = category 379 | 380 | if(delete == 1): 381 | categories.pop(categories.index(element)) 382 | 383 | 384 | json.dump(categories, file) 385 | file.close() 386 | 387 | ################################################# 388 | 389 | # AddBookmark Button 390 | 391 | def addBookmarkPush(self): 392 | self.popUp = QDialog() 393 | layout = QVBoxLayout() 394 | 395 | button = QPushButton('Done') 396 | self.add = QLineEdit() 397 | self.add.setPlaceholderText('Name') 398 | self.inCategory = QLineEdit() 399 | self.inCategory.setPlaceholderText('Folder') 400 | 401 | layout.addWidget(self.inCategory) 402 | layout.addWidget(self.add) 403 | layout.addWidget(button) 404 | 405 | self.popUp.setLayout(layout) 406 | 407 | button.clicked.connect(self.saveBookmark) 408 | 409 | self.popUp.setWindowTitle('Page Bookmarked') 410 | self.popUp.setMaximumSize(300, 200) 411 | 412 | self.popUp.show() 413 | 414 | def saveBookmark(self, title = None, url = None): 415 | 416 | if(url is None): 417 | qtitle = self.add.text().strip() 418 | qurl = self.tabs.currentWidget().url().toString().strip() 419 | else: 420 | qtitle = title 421 | qurl = url 422 | 423 | file = open('bookmarks.json', 'r') 424 | 425 | categories = json.load(file) 426 | 427 | file.close() 428 | 429 | if(self.add.text().strip() == '' or self.inCategory.text().strip() == ''): 430 | return 431 | 432 | for category in categories: 433 | if(self.add.text() in category['elements']): 434 | return 435 | 436 | file = open('bookmarks.json', 'w+') 437 | 438 | s = 0 439 | for category in categories: 440 | if(category['name'].strip() == self.inCategory.text().strip()): 441 | s = 1 442 | category['elements'][qtitle] = qurl 443 | 444 | if(s == 0): 445 | categories.append({'name':self.inCategory.text().strip(), 'elements':{qtitle:qurl}}) 446 | 447 | json.dump(categories, file) 448 | 449 | self.popUp.close() 450 | file.close() 451 | ########################################### 452 | 453 | 454 | def forwardButtonPush(self): 455 | self.historyForEachTab[self.tabs.currentIndex()].forward() 456 | 457 | def backButtonPush(self): 458 | self.historyForEachTab[self.tabs.currentIndex()].back() 459 | 460 | def refreshButtonPush(self): 461 | self.tabs.currentWidget().reload() 462 | 463 | def homeButtonPush(self): 464 | self.tabs.currentWidget().load(QUrl('https://www.google.com/')) 465 | 466 | def goButtonPush(self, address): 467 | tmp = address 468 | 469 | if(tmp == ''): 470 | return 471 | 472 | q = QUrl(tmp) 473 | if(q.scheme() == ""): 474 | q.setScheme("http") 475 | 476 | if(tmp.find('.') != -1 and tmp.find(' ') == -1): 477 | self.tabs.currentWidget().load(q) 478 | 479 | else: 480 | l = tmp.split() 481 | link = 'https://www.google.com/search?q=' + l[0] 482 | for i in range(1, len(l)): 483 | link += '+' + l[i] 484 | self.tabs.currentWidget().load(QUrl(link)) 485 | 486 | 487 | -------------------------------------------------------------------------------- /window.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/window.pyc -------------------------------------------------------------------------------- /youtube.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import json 3 | from PyQt5.QtWidgets import * 4 | from PyQt5.QtGui import * 5 | from PyQt5.QtCore import * 6 | from PyQt5.QtWebKit import * 7 | from PyQt5.QtWebKitWidgets import * 8 | 9 | class Youtube(QMainWindow): 10 | 11 | def __init__(self, page, parent=None): 12 | super(Youtube, self).__init__(parent) 13 | 14 | self.setFixedSize(1200, 800) 15 | 16 | web = QWebView() 17 | web.load(QUrl('http://' + page.lower())) 18 | 19 | view = QGraphicsView(self) 20 | view.setFixedSize(1200, 800) 21 | view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) 22 | view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) 23 | 24 | _layout = QVBoxLayout(view) 25 | 26 | scene = QGraphicsScene(self) 27 | 28 | _layout.addWidget(web) 29 | view.setScene(scene) 30 | 31 | 32 | -------------------------------------------------------------------------------- /youtube.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackIQ/PyBrowser/944274f2acb5b9db377b99359ef36f2b543cf652/youtube.pyc --------------------------------------------------------------------------------