52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
# main.py
|
|
import sys
|
|
import pythoncom
|
|
from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget
|
|
from PyQt6.QtWebEngineWidgets import QWebEngineView
|
|
from PyQt6.QtCore import QUrl, QThread
|
|
|
|
from config import MAIN_URL
|
|
from bridge import PythonJSBridge
|
|
|
|
class KompasWorker(QThread):
|
|
def run(self):
|
|
pythoncom.CoInitialize()
|
|
|
|
|
|
class BrowserWindow(QMainWindow):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.setWindowTitle("QT6 Браузер")
|
|
self.resize(1366, 768)
|
|
|
|
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()
|