Last active
January 4, 2016 09:58
-
-
Save RyanHope/8605140 to your computer and use it in GitHub Desktop.
A simple Python script that renders a URL in a simple window using PySide/Qt.
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
#!/usr/bin/env python | |
import sys, os | |
import argparse | |
from PySide.QtCore import * | |
from PySide.QtGui import * | |
from PySide.QtWebKit import * | |
class ValidateURL(argparse.Action): | |
def __call__(self, parser, args, values, option_string=None): | |
url = QUrl(values) | |
if not url.isValid(): | |
raise argparse.ArgumentError(self, 'invalid') | |
if url.scheme() == '': | |
if not os.path.exists(url.toLocalFile()): | |
raise argparse.ArgumentError(self, 'local file does not exist') | |
elif url.scheme() != 'http' and url.scheme() != 'https' and url.scheme() != 'file': | |
raise argparse.ArgumentError(self, 'unsupported url scheme') | |
setattr(args, self.dest, url) | |
parser = argparse.ArgumentParser() | |
parser.add_argument("URL", help="The URL to render.", action=ValidateURL) | |
parser.add_argument("-F", "--fullscreen", action="store_true", | |
help="Render URL using the fullscreen.") | |
args = parser.parse_args() | |
app = QApplication(sys.argv) | |
desktop = app.desktop() | |
screenRect = desktop.screenGeometry(desktop.primaryScreen()) | |
windowRect = QRect(0, 0, 800, 600) | |
if screenRect.width() < 800: | |
windowRect.setWidth(screenRect.width()) | |
if screenRect.height() < 600: | |
windowRect.setHeight(screenRect.height()) | |
windowRect.moveCenter(screenRect.center()) | |
web = QWebView() | |
web.setGeometry(windowRect) | |
web.load(args.URL) | |
if args.fullscreen: | |
web.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) | |
web.showFullScreen() | |
else: | |
web.show() | |
web.raise_() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment