47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
# main.py
|
|
import sys
|
|
from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget
|
|
from PyQt6.QtWebEngineWidgets import QWebEngineView
|
|
from PyQt6.QtCore import QUrl
|
|
|
|
from config import MAIN_URL
|
|
from bridge import PythonJSBridge
|
|
|
|
|
|
class BrowserWindow(QMainWindow):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.setWindowTitle("QT6 Браузер")
|
|
self.resize(1000, 800)
|
|
|
|
container = QWidget()
|
|
layout = QVBoxLayout()
|
|
|
|
self.browser = QWebEngineView()
|
|
self.browser.setUrl(QUrl(MAIN_URL))
|
|
|
|
layout.addWidget(self.browser)
|
|
container.setLayout(layout)
|
|
self.setCentralWidget(container)
|
|
|
|
self.browser.page().loadFinished.connect(self.on_page_loaded)
|
|
|
|
def on_page_loaded(self, ok):
|
|
if ok:
|
|
self.bridge = PythonJSBridge(self.browser)
|
|
|
|
def send_counter(self):
|
|
self.counter += 1
|
|
self.bridge.send_event_to_js("counter", {"value": self.counter})
|
|
|
|
|
|
def main():
|
|
app = QApplication(sys.argv)
|
|
window = BrowserWindow()
|
|
window.show()
|
|
sys.exit(app.exec())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|