Advertisement
silver2row

Trying some pyqt5 source from somewhere...

Dec 15th, 2020
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.94 KB | None | 0 0
  1. import sys
  2. import webview
  3. from flask import Flask, render_template
  4. from PyQt5.QtCore import QSize, Qt
  5. from PyQt5.QtGui import *
  6. from PyQt5.QtWebKit import *
  7. from PyQt5.QtWidgets import *
  8. from PyQt5.QtWebKitWidgets import QWebView
  9.  
  10. class WebWidget(QWidget):
  11.  
  12.     def paintEvent(self, event):
  13.         painter = QPainter()
  14.         painter.begin(self)
  15.         painter.setBrush(Qt.white)
  16.         painter.setPen(Qt.black)
  17.         painter.drawRect(self.rect().adjusted(0, 0, -1, -1))
  18.         painter.setBrush(Qt.red)
  19.         painter.setPen(Qt.NoPen)
  20.         painter.drawRect(self.width()/4, self.height()/4,
  21.                          self.width()/2, self.height()/2)
  22.         painter.end()
  23.  
  24.     def sizeHint(self):
  25.         return QSize(100, 100)
  26.  
  27. class WebPluginFactory(QWebPluginFactory):
  28.  
  29.     def __init__(self, parent = None):
  30.         QWebPluginFactory.__init__(self, parent)
  31.  
  32.     def create(self, mimeType, url, names, values):
  33.         if mimeType == "x-pyqt/widget":
  34.             return WebWidget()
  35.  
  36.     def plugins(self):
  37.         plugin = QWebPluginFactory.Plugin()
  38.         plugin.name = "PyQt Widget"
  39.         plugin.description = "An example Web plugin written with PyQt."
  40.         mimeType = QWebPluginFactory.MimeType()
  41.         mimeType.name = "x-pyqt/widget"
  42.         mimeType.description = "PyQt widget"
  43.         mimeType.fileExtensions = []
  44.         plugin.mimeTypes = [mimeType]
  45.         print("plugins")
  46.         return [plugin]
  47.  
  48. if __name__ == "__main__":
  49.  
  50.     app = QApplication(sys.argv)
  51.     QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True)
  52.     server = Flask(__name__, template_folder='templates') # comment out if necessary
  53.     view = webview.create_window('Hello to All!','templates/Mike.html') # comment out if necessary
  54.     view = QWebView()
  55.     factory = WebPluginFactory()
  56.     view.page().setPluginFactory(factory)
  57.     view.setHtml()
  58.     view.show()
  59.     sys.exit(app.exec_())
  60.     webview.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement