Created
August 13, 2018 00:21
-
-
Save ericvicenti/c92686593bd36b80a02808b0b0c9dcac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Qt5 WebEngine Kiosk Runner | |
# deps: apt-get install python-pyqt5.qtwebengine | |
# | |
import sys, os | |
from PyQt5.QtCore import QUrl | |
from PyQt5.QtGui import QIcon | |
from PyQt5.QtWidgets import QApplication, QWidget, QBoxLayout, QPushButton | |
from PyQt5.QtWebEngineWidgets import QWebEngineView | |
# Show top bar with buttons for reload & quit | |
KIOSK_DEBUG = True | |
# Run bare-metal with eglfs | |
KIOSK_EGLFS = False | |
KIOSK_URL = "https://necolas.github.io/react-native-web/examples" | |
class Kiosk(QWidget): | |
def __init__(self, app): | |
QWidget.__init__(self) | |
self.app = app | |
self.webview = QWebEngineView() | |
vboxLayout = QBoxLayout(QBoxLayout.TopToBottom) | |
self.setLayout(vboxLayout) | |
if KIOSK_DEBUG: | |
vboxLayout.addWidget(self.buildDebugBar()) | |
vboxLayout.addWidget(self.webview) | |
def load(self): | |
self.webview.load(QUrl(KIOSK_URL)) | |
def buildDebugBar(self): | |
close = QPushButton(QIcon.fromTheme("window-close"), "") | |
refresh = QPushButton(QIcon.fromTheme("view-refresh"), "") | |
close.clicked.connect(self.app.exit) | |
refresh.clicked.connect(self.webview.reload) | |
hbox = QWidget() | |
hboxLayout = QBoxLayout(QBoxLayout.RightToLeft) | |
hbox.setLayout(hboxLayout) | |
hboxLayout.addWidget(close) | |
hboxLayout.addWidget(refresh) | |
hboxLayout.addStretch() | |
return hbox | |
def main(): | |
if KIOSK_EGLFS: | |
os.putenv("QT_QPA_ENABLE_TERMINAL_KEYBOARD", "1") | |
os.putenv("QT_QPA_PLATFORM", "eglfs") | |
app = QApplication(sys.argv) | |
kiosk = Kiosk(app) | |
kiosk.load() | |
kiosk.showFullScreen() | |
sys.exit(app.exec_()) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment