Files
clearpilot/system/clearpilot/tools/webview.py
Your Name 43dcaeb3cd wip
2024-04-27 00:48:30 -05:00

85 lines
2.9 KiB
Python

import os
import sys
import signal
from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QGraphicsView, QGraphicsScene
from PyQt5.QtCore import Qt, QUrl, QPointF, QTimer
from PyQt5.QtGui import QCursor, QPixmap, QTransform
from PyQt5.QtWebEngineWidgets import QWebEngineView
webview = None
def on_load_finished(arg):
global webview
if arg: # Check if the page load was successful
webview.setZoomFactor(2)
class RotatedWindow(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.rotation_angle = 90
self.cursor_rotation_timer = QTimer(self)
self.cursor_rotation_timer.timeout.connect(self.rotateCursor)
self.cursor_rotation_timer.start(1000) # Rotate the cursor every 1 second
def rotateCursor(self):
current_cursor = self.cursor()
pixmap = current_cursor.pixmap()
rotated_pixmap = pixmap.transformed(QTransform().rotate(self.rotation_angle))
rotated_cursor = QCursor(rotated_pixmap)
self.setCursor(rotated_cursor)
def create_webview_app():
global webview
# 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)
desktop = QApplication.desktop()
screen_geometry = desktop.availableGeometry(desktop.primaryScreen())
window = RotatedWindow()
window.setWindowTitle("Qt WebView Example")
window.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
window.setGeometry(0, 0, screen_geometry.height(), screen_geometry.width())
window.setStyleSheet("background-color: white;")
window.showFullScreen()
scene = QGraphicsScene()
view = QGraphicsView(scene, window)
view.setGeometry(0, 0, window.width(), window.height())
view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
# Create WebView
webview = QWebEngineView()
webview.load(QUrl("https://cdpn.io/yananas/fullpage/rwvZvY"))
webview.setGeometry(0, 0, window.width(), window.height())
webview.loadFinished.connect(on_load_finished)
# Add WebView to the scene
proxy_webview = scene.addWidget(webview)
view.setScene(scene)
view.rotate(window.rotation_angle) # Rotate the view by 90 degrees
# Layout setup
window_layout = QHBoxLayout(window)
window_layout.addWidget(view)
window_layout.setContentsMargins(0, 0, 0, 0)
window.setLayout(window_layout)
return app, window
def main():
signal.signal(signal.SIGINT, signal.SIG_DFL) # Enable Ctrl+C to terminate the application
app, window = create_webview_app()
exit_code = app.exec_()
sys.exit(exit_code)
if __name__ == "__main__":
main()