67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
import os
|
|
import sys
|
|
from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QGraphicsView, QGraphicsScene
|
|
from PyQt5.QtCore import Qt, QUrl, QTimer
|
|
from PyQt5.QtGui import QCursor, QPixmap, QTransform
|
|
from PyQt5.QtWebEngineWidgets import QWebEngineView
|
|
import rotation
|
|
|
|
def create_webview_app():
|
|
# Set environment for Wayland
|
|
os.environ["XDG_RUNTIME_DIR"] = "/var/tmp/weston"
|
|
os.environ["WAYLAND_DISPLAY"] = "wayland-0"
|
|
os.environ["QT_QPA_PLATFORM"] = "wayland"
|
|
os.environ["QT_WAYLAND_SHELL_INTEGRATION"] = "wl-shell"
|
|
|
|
# Application setup
|
|
app = QApplication(sys.argv)
|
|
window = QWidget()
|
|
window.setWindowTitle("Qt WebView Example")
|
|
window.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
|
|
sg = QApplication.desktop().availableGeometry(window)
|
|
window.setGeometry(0, 0, sg.height(), sg.width())
|
|
window.setStyleSheet("background-color: black;")
|
|
|
|
scene = QGraphicsScene()
|
|
view = QGraphicsView(scene, window)
|
|
view.setGeometry(0, 0, sg.width(), sg.height())
|
|
view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
|
|
webview = QWebEngineView()
|
|
webview.load(QUrl("https://cdpn.io/yananas/fullpage/rwvZvY"))
|
|
webview.setGeometry(0, 0, sg.width(), sg.height())
|
|
scene.addWidget(webview)
|
|
view.setScene(scene)
|
|
|
|
window_layout = QHBoxLayout(window)
|
|
window_layout.addWidget(view)
|
|
|
|
window.setLayout(window_layout)
|
|
|
|
window.showFullScreen()
|
|
|
|
window_handle = window.windowHandle()
|
|
rotation.rotate_display(window_handle)
|
|
|
|
# Delay rotation using QTimer
|
|
# QTimer.singleShot(1000, lambda: rotate_display(window))
|
|
|
|
return app, window
|
|
|
|
def rotate_display(window):
|
|
window_handle = window.windowHandle()
|
|
if window_handle:
|
|
print("Rotating display.")
|
|
try:
|
|
print(int(window_handle.winId()))
|
|
rotation.rotate_display(int(window_handle.winId()))
|
|
except Exception as e:
|
|
print(f"Error rotating display: {e}")
|
|
else:
|
|
print("Window handle is not valid.")
|
|
|
|
if __name__ == "__main__":
|
|
app, _ = create_webview_app()
|
|
sys.exit(app.exec_())
|