|
4 | 4 | from PyQt5.QtWebEngineWidgets import * |
5 | 5 | import sys |
6 | 6 |
|
7 | | - |
| 7 | +# Define the main window class |
8 | 8 | class MainWindow(QMainWindow): |
9 | 9 | def __init__(self): |
10 | 10 | super(MainWindow, self).__init__() |
| 11 | + |
| 12 | + # Create a QWebEngineView widget |
11 | 13 | self.browser = QWebEngineView() |
12 | 14 | self.browser.setUrl(QUrl("http://www.google.com")) |
13 | 15 | self.setCentralWidget(self.browser) |
| 16 | + |
| 17 | + # Show the window maximized |
14 | 18 | self.showMaximized() |
| 19 | + |
| 20 | + # Create a navigation toolbar |
15 | 21 | navbar = QToolBar() |
16 | 22 | navbar.adjustSize() |
17 | 23 | self.addToolBar(navbar) |
| 24 | + |
| 25 | + # Add a back button to the toolbar |
18 | 26 | back_btn = QAction("⮜", self) |
19 | 27 | back_btn.triggered.connect(self.browser.back) |
20 | 28 | navbar.addAction(back_btn) |
21 | | - |
| 29 | + |
| 30 | + # Add a forward button to the toolbar |
22 | 31 | forward_btn = QAction("⮞", self) |
23 | 32 | forward_btn.triggered.connect(self.browser.forward) |
24 | 33 | navbar.addAction(forward_btn) |
25 | | - |
| 34 | + |
| 35 | + # Add a reload button to the toolbar |
26 | 36 | reload_btn = QAction("⟳", self) |
27 | 37 | reload_btn.triggered.connect(self.browser.reload) |
28 | 38 | navbar.addAction(reload_btn) |
29 | | - |
| 39 | + |
| 40 | + # Add a URL bar to the toolbar |
30 | 41 | self.url_bar = QLineEdit() |
31 | 42 | self.url_bar.returnPressed.connect(self.open_url) |
32 | 43 | navbar.addWidget(self.url_bar) |
| 44 | + |
| 45 | + # Update the URL bar when the browser URL changes |
33 | 46 | self.browser.urlChanged.connect(self.update_url) |
34 | 47 |
|
| 48 | + # Load the URL entered in the URL bar |
35 | 49 | def open_url(self): |
36 | 50 | url = self.url_bar.text() |
37 | 51 | self.browser.setUrl(QUrl(url)) |
38 | 52 |
|
| 53 | + # Update the URL bar when the browser URL changes |
39 | 54 | def update_url(self, q): |
40 | 55 | self.url_bar.setText(q.toString()) |
41 | 56 |
|
42 | | - |
| 57 | +# Create the application and main window |
43 | 58 | app = QApplication(sys.argv) |
44 | | - |
45 | 59 | QApplication.setApplicationName("EFFLUX browser") |
46 | | - |
47 | 60 | window = MainWindow() |
48 | | - |
49 | 61 | app.exec_() |
0 commit comments