本文整理汇总了Python中PyQt5.QtWebEngineWidgets.QWebEngineView.settings方法的典型用法代码示例。如果您正苦于以下问题:Python QWebEngineView.settings方法的具体用法?Python QWebEngineView.settings怎么用?Python QWebEngineView.settings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWebEngineWidgets.QWebEngineView
的用法示例。
在下文中一共展示了QWebEngineView.settings方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt5.QtWebEngineWidgets import QWebEngineView [as 别名]
# 或者: from PyQt5.QtWebEngineWidgets.QWebEngineView import settings [as 别名]
def __init__(self, parent=None):
super().__init__(parent)
self.port = None
view = QWebEngineView()
settings = view.settings()
settings.setAttribute(QWebEngineSettings.JavascriptEnabled, True)
self._set_widget(view)
示例2: MainWidow
# 需要导入模块: from PyQt5.QtWebEngineWidgets import QWebEngineView [as 别名]
# 或者: from PyQt5.QtWebEngineWidgets.QWebEngineView import settings [as 别名]
class MainWidow(QWidget):
def __init__(self):
super().__init__()
self.view=QWebEngineView()
self.myprofile=self.getProfile()
self.page=QWebEnginePage(self.myprofile,None)
# self.channel=QWebChannel()
# self.myobject=myObject()
# self.channel.registerObject("xdpy", self.myobject)
# self.page.setWebChannel(self.channel)
self.page.settings().AllowRunningInsecureContent=True;
self.page.settings().JavascriptEnabled=True;
self.view.page=self.page
self.url=QUrl("")
self.view.page.load(self.url)
self.view.show()
self.view.settings().JavascriptEnabled=True
def js_callback(self,result):
print("js_callback:{}".format(result))
def injectJS(self,sourceCode,name):
script = QWebEngineScript();
script.setSourceCode(sourceCode)
script.setName(name)
script.setInjectionPoint(QWebEngineScript.DocumentCreation)
script.setWorldId(QWebEngineScript.MainWorld)
script.setRunsOnSubFrames(True)
self.view.page.scripts().insert(script)
self.page.scripts().insert(script)
def getProfile(self):
profile=QWebEngineProfile("myProfile")
profile.cachePath="/home/yyk/Desktop/cache"
jsFile = constants.QTWEBCHANNELJS_FILE
with open(jsFile, encoding="UTF-8") as file:
js = file.read()
script = QWebEngineScript();
script.setSourceCode(js)
script.setName('qwebchannel.js')
script.setInjectionPoint(QWebEngineScript.DocumentCreation)
script.setWorldId(QWebEngineScript.MainWorld)
script.setRunsOnSubFrames(False)
profile.scripts().insert(script)
return profile
示例3: parse_args
# 需要导入模块: from PyQt5.QtWebEngineWidgets import QWebEngineView [as 别名]
# 或者: from PyQt5.QtWebEngineWidgets.QWebEngineView import settings [as 别名]
parser = argparse.ArgumentParser()
parser.add_argument('url', help='The URL to open')
parser.add_argument('--plugins', '-p', help='Enable plugins',
default=False, action='store_true')
if WEBENGINE:
parser.add_argument('--webengine', help='Use QtWebEngine',
default=False, action='store_true')
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
app = QApplication(sys.argv)
if WEBENGINE and args.webengine:
wv = QWebEngineView()
else:
wv = QWebView()
wv.loadStarted.connect(lambda: print("Loading started"))
wv.loadProgress.connect(lambda p: print("Loading progress: {}%".format(p)))
wv.loadFinished.connect(lambda: print("Loading finished"))
if args.plugins and not WEBENGINE:
wv.settings().setAttribute(QWebSettings.PluginsEnabled, True)
wv.load(QUrl.fromUserInput(args.url))
wv.show()
app.exec_()