Last active
May 30, 2017 18:11
-
-
Save rafael-neri/65b48fd926a4a6a91fe7374e26a499f6 to your computer and use it in GitHub Desktop.
Example Python3 + QT5 + Web
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/python3 | |
# -*- coding: utf-8 -*- | |
import os | |
import sys | |
from PyQt5.QtWidgets import QApplication | |
from PyQt5.QtWebKitWidgets import QWebView | |
from PyQt5.QtGui import QIcon | |
from PyQt5.QtCore import QUrl | |
from PyQt5.QtCore import QSize | |
if __name__ == "__main__": | |
# Create application | |
app = QApplication([]) | |
# Create View | |
web = QWebView() | |
# Set Title | |
web.setWindowTitle("My Application") | |
# Set icon | |
icon = QIcon() | |
icon.addFile(":/my-icon.png", QSize(32,32)) | |
web.setWindowIcon(icon) | |
# Define geometry | |
width, height = 800, 600 | |
web.resize(width, height) | |
# Define Position | |
x = y = None | |
if(x is None or y is None): | |
web.move(app.desktop().screen().rect().center() - web.rect().center()) # center | |
else: | |
web.move(int(x), int(y)) | |
# Show Debug | |
debug = False | |
if debug: | |
# Enable extra tools for developers | |
from PyQt5.QtWebKit import QWebSettings | |
web.page().settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True) | |
# Html | |
html = QUrl("file://" + os.getcwd() + "/index.html") | |
web.load(html) | |
# Load Pyjs File from | |
from directory.filename import PyFileClass | |
PyFileClass = PyFileClass() | |
web.page().mainFrame().addToJavaScriptWindowObject("PyFileClass", PyFileclass) | |
# Show webview | |
web.show() | |
# Quit application | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment