Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import webview
- from flask import Flask, render_template
- from PyQt5.QtCore import QSize, Qt
- from PyQt5.QtGui import *
- from PyQt5.QtWebKit import *
- from PyQt5.QtWidgets import *
- from PyQt5.QtWebKitWidgets import QWebView
- class WebWidget(QWidget):
- def paintEvent(self, event):
- painter = QPainter()
- painter.begin(self)
- painter.setBrush(Qt.white)
- painter.setPen(Qt.black)
- painter.drawRect(self.rect().adjusted(0, 0, -1, -1))
- painter.setBrush(Qt.red)
- painter.setPen(Qt.NoPen)
- painter.drawRect(self.width()/4, self.height()/4,
- self.width()/2, self.height()/2)
- painter.end()
- def sizeHint(self):
- return QSize(100, 100)
- class WebPluginFactory(QWebPluginFactory):
- def __init__(self, parent = None):
- QWebPluginFactory.__init__(self, parent)
- def create(self, mimeType, url, names, values):
- if mimeType == "x-pyqt/widget":
- return WebWidget()
- def plugins(self):
- plugin = QWebPluginFactory.Plugin()
- plugin.name = "PyQt Widget"
- plugin.description = "An example Web plugin written with PyQt."
- mimeType = QWebPluginFactory.MimeType()
- mimeType.name = "x-pyqt/widget"
- mimeType.description = "PyQt widget"
- mimeType.fileExtensions = []
- plugin.mimeTypes = [mimeType]
- print("plugins")
- return [plugin]
- if __name__ == "__main__":
- app = QApplication(sys.argv)
- QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True)
- server = Flask(__name__, template_folder='templates') # comment out if necessary
- view = webview.create_window('Hello to All!','templates/Mike.html') # comment out if necessary
- view = QWebView()
- factory = WebPluginFactory()
- view.page().setPluginFactory(factory)
- view.setHtml()
- view.show()
- sys.exit(app.exec_())
- webview.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement