本文整理汇总了Python中PyQt5.QtWebEngineWidgets.QWebEngineView.page方法的典型用法代码示例。如果您正苦于以下问题:Python QWebEngineView.page方法的具体用法?Python QWebEngineView.page怎么用?Python QWebEngineView.page使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWebEngineWidgets.QWebEngineView
的用法示例。
在下文中一共展示了QWebEngineView.page方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Window
# 需要导入模块: from PyQt5.QtWebEngineWidgets import QWebEngineView [as 别名]
# 或者: from PyQt5.QtWebEngineWidgets.QWebEngineView import page [as 别名]
class Window(BaseWindow):
def __init__(self):
self.debug=1
self.app = QApplication(sys.argv)
self.desktop= QApplication.desktop()
self.web = QWebEngineView()
self.icon = QIcon(ICON)
#self.web.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
self.web.titleChanged.connect(self.title_changed)
self.web.iconUrlChanged.connect(self.icon_changed)
self.web.page().windowCloseRequested.connect(self.close_window)
self.web.page().geometryChangeRequested.connect(self.set_geometry)
def show(self,window_state):
if window_state == "maximized" and not self.web.isMaximized():
self.web.showNormal()
self.web.showMaximized()
elif window_state == "fullscreen" and not self.web.isFullScreen():
self.web.showNormal()
self.web.showFullScreen()
elif window_state == "normal":
self.web.showNormal()
else:
self.web.show()
def run(self):
return self.app.exec_()
def set_debug(self, debuglevel):
self.debug=debuglevel
def set_geometry(self,geom ):
self.web.setGeometry(geom)
def close_window(self):
sys.exit()
def icon_changed(self):
if not self.icon.isNull():
self.web.setWindowIcon(self.icon)
def title_changed(self, title):
self.web.setWindowTitle(title)
def load_url(self,url):
self.url=QUrl.fromEncoded(url)
self.web.setUrl(self.url)
def set_size(self,width, height):
if width<=0:
width=640
if height<=0:
height=480
left=(self.desktop.width()-width)/2
top=(self.desktop.height()-height)/2
self.web.setGeometry(left,top,width,height)
示例2: Example
# 需要导入模块: from PyQt5.QtWebEngineWidgets import QWebEngineView [as 别名]
# 或者: from PyQt5.QtWebEngineWidgets.QWebEngineView import page [as 别名]
class Example(QWidget):
def __init__(self):
super().__init__()
self.resize(640, 320)
self.setWindowTitle('PyQt-5 WebEngine')
page = "https://www.google.com"
self.url = QLineEdit(page)
self.url.setPlaceholderText(page)
self.go = QPushButton("Ir")
self.go.clicked.connect(self.btnIrClicked)
self.nav_bar = QHBoxLayout()
self.nav_bar.addWidget(self.url)
self.nav_bar.addWidget(self.go)
self.progress = QProgressBar()
self.progress.setValue(0)
html = """
<!DOCTYPE HTML>
<html>
<head>
<title>Example Local HTML</title>
</head>
<body>
<p>Este es un archivo <code>HTML</code> local.</p>
<p>Si deseas acceder página indica su <code>URL</code> y presiona <b>Ir</b></p>
</body>
</html>
"""
self.web_view = QWebEngineView()
self.web_view.loadProgress.connect(self.webLoading)
self.web_view.setHtml(html)
root = QVBoxLayout()
root.addLayout(self.nav_bar)
root.addWidget(self.web_view)
root.addWidget(self.progress)
self.setLayout(root)
def btnIrClicked(self, event):
url = QUrl(self.url.text())
self.web_view.page().load(url)
def webLoading(self, event):
self.progress.setValue(event)
示例3: DrrrWindow
# 需要导入模块: from PyQt5.QtWebEngineWidgets import QWebEngineView [as 别名]
# 或者: from PyQt5.QtWebEngineWidgets.QWebEngineView import page [as 别名]
class DrrrWindow(ShadowsWindow):
def __init__(self):
super(DrrrWindow, self).__init__()
self.setWindowTitle("Drrr Chat Room")
self.setWindowIcon(QIcon('./img/drrr.ico'))
# w = WebView()
# w.show()
self.getSetting()
self.WebView = QWebEngineView()
# self.WebView.load(QUrl("file:///E:/Project/DrrrPC/img/index.html"))
self.WebView.setZoomFactor(0.8)
# 设置加载网页,和网页加载完成以及加载过程信号与槽函数关联
self.WebView.loadStarted.connect(self.loadStarted)
self.WebView.loadFinished.connect(self.loadFinished)
self.WebView.loadProgress.connect(self.loading)
self.cookieJar = QNetworkCookieJar()
# self.WebView.page().networkAccessManager().setCookieJar(self.cookieJar)
# self.WebView.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
# self.WebView.page().linkClicked.connect(self.linkClicked)
# self.WebView.page().contentsChanged.connect(self.contentsChanged)
# self.WebView.page().networkAccessManager().setHeader(QNetworkRequest.ContentTypeHeader, QVariant("text/html; charset=GBK"))
# 重定义QWebEnginePage中javaScriptAlert等函数
self.WebView.page().javaScriptAlert = self._javascript_alert
self.WebView.page().javaScriptConsoleMessage = self._javascript_console_message
self.WebView.page().javaScriptConfirm = self._javascript_confirm
self.WebView.page().javaScriptPrompt = self._javascript_prompt
# NetworkAccessManager
# self.NetworkAccessManager = QNetworkAccessManager()
# self.WebView.page().setNetworkAccessManager(self.NetworkAccessManager)
# self.NetworkAccessManager.finished.connect(self.NetworkAccessManagerReplyFinished)
# self.NetworkAccessManager.get(QNetworkRequest(QUrl("http://www.baidu.com")))
# self.old_manager = self.WebView.page().networkAccessManager()
# self.new_manager = NetworkAccessManager(self.old_manager)
# self.WebView.page().setNetworkAccessManager(self.new_manager)
self.titlebar = titleBar()
self.statusBar = StatusWindow()
# 中心窗口布局
self.contentLayout = QVBoxLayout()
self.contentWidget = QWidget()
self.contentWidget.gridLayout = QtWidgets.QGridLayout(self.contentWidget)
self.contentWidget.gridLayout.addLayout(self.contentLayout, 0, 0, 1, 1)
self.contentLayout.addWidget(self.WebView)
self.contentWidget.gridLayout.setContentsMargins(0,0,0,0)
self.contentLayout.setContentsMargins(1,0,1,0)
self.contentWidget.setStyleSheet("""
border-left: 1px solid black;
border-right: 1px solid black;
""")
# self.titlebar.titlebarBotton = QPushButton(self.titlebar)
# self.titlebar.titlebarBotton.setText('Push ME')
# self.titlebar.titlebarBotton.clicked.connect(self.getData)
self.main_layout = QVBoxLayout()
self.main_layout.addWidget(self.titlebar)
self.main_layout.addWidget(self.contentWidget)
self.main_layout.addWidget(self.statusBar)
self.main_layout.setSpacing(0)
# 窗口属性
self.setWindowFlags(Qt.Widget | QtCore.Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_NoSystemBackground, True)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground,True)
self.widget = QWidget()
self.setCentralWidget(self.widget)
self.widget.setLayout(self.main_layout)
self.widget.setMouseTracking(True)
# self.resize(500,650)
self.resize(650,650)
# self.setMaximumHeight(660)
self.center()
# 将三个按钮点击信号与相关槽函数相关联
self.titlebar.min_button.clicked.connect(self.hideIt)
self.titlebar.max_button.clicked.connect(self.MaxAndNormal)
self.titlebar.close_button.clicked.connect(self.closeIt)
# 状态栏进度条:将LoadProgress信号与loading槽函数相关联
self.WebView.loadProgress.connect(self.loading)
# notice sound
# self.player =
self.WebView.setHtml(WaitingHTML)
self.show()
self.WebView.setStyleSheet("""
QWebView {
background-color:black
}
#.........这里部分代码省略.........
示例4: QApplication
# 需要导入模块: from PyQt5.QtWebEngineWidgets import QWebEngineView [as 别名]
# 或者: from PyQt5.QtWebEngineWidgets.QWebEngineView import page [as 别名]
from PyQt5.QtWebChannel import QWebChannel
import sys
# 创建一个 application实例
app = QApplication(sys.argv)
win = QWidget()
win.setWindowTitle('Web页面中的JavaScript与 QWebEngineView交互例子')
# 创建一个垂直布局器
layout = QVBoxLayout()
win.setLayout(layout)
# 创建一个 QWebEngineView 对象
view = QWebEngineView()
htmlUrl = 'http://127.0.0.1:8020/web/index.html'
view.load( QUrl( htmlUrl ))
# 创建一个 QWebChannel对象,用来传递pyqt参数到JavaScript
channel = QWebChannel( )
myObj = MySharedObject()
channel.registerObject( "bridge", myObj )
view.page().setWebChannel(channel)
# 把QWebView和button加载到layout布局中
layout.addWidget(view)
# 显示窗口和运行app
win.show()
sys.exit(app.exec_())
示例5: HelpDialog
# 需要导入模块: from PyQt5.QtWebEngineWidgets import QWebEngineView [as 别名]
# 或者: from PyQt5.QtWebEngineWidgets.QWebEngineView import page [as 别名]
class HelpDialog(QObject, LogMixin):
"""Class implementing qthelp viewer dialog"""
def __init__(self, qthelp_file, parent = None):
"""
Constructor of HelpDialog
:param qthelp_file: full path to qthelp helpfile
"""
super(HelpDialog,self).__init__(parent)
# instantiate help engine
helpEngine = QHelpEngine(qthelp_file)
helpEngine.setupData()
self._helpEngine = helpEngine
# base dialog widget
self.ui = QDialog(None, QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowMinMaxButtonsHint | QtCore.Qt.WindowCloseButtonHint )
self.ui.setWindowTitle("HelpViewer")
self.ui.setWindowIcon(QIcon(":/images/prog_icons/help/help.ico"))
# Create webview for help information
# and assign a custom URL scheme handler for scheme "qthelp)
self._wv = QWebEngineView(self.ui)
self._urlschemehandler = HelpSchemeHandler(self._helpEngine, self._wv.page().profile())
self._wv.page().profile().installUrlSchemeHandler(b'qthelp', self._urlschemehandler)
# get help content overview widget
self._helpContent = self._helpEngine.contentWidget()
self._helpIndex = self._helpEngine.indexWidget()
self._helpSearchQuery = self._helpEngine.searchEngine().queryWidget()
self._helpSearchResult = self._helpEngine.searchEngine().resultWidget()
self._se = self._helpEngine.searchEngine()
self._se.reindexDocumentation()
self._helpSearchQuery.search.connect(self.search)
# create QSplitter
self._splitterMain = QSplitter(QtCore.Qt.Vertical)
self._splitterMain.setOpaqueResize(False)
self._splitterSearch = QSplitter(QtCore.Qt.Horizontal)
self._splitterSearch.setOpaqueResize(False)
self._splitterUpper = QSplitter(QtCore.Qt.Horizontal)
self._splitterUpper.setOpaqueResize(False)
self._splitterLower = QSplitter(QtCore.Qt.Horizontal)
self._splitterLower.setOpaqueResize(False)
# create horzLayout
self._horzLayoutSearch = QHBoxLayout()
self._horzLayoutUpper = QHBoxLayout()
self._horzLayoutLower = QHBoxLayout()
# create vertLayout
self._vertLayout = QVBoxLayout()
# main widgets
self._upperWidget = QWidget()
self._lowerWidget = QWidget()
self._btnReset = QPushButton()
self._btnReset.setMaximumHeight(23)
self._btnReset.setMaximumWidth(100)
# build search structure
self._splitterSearch.insertWidget(0, self._helpSearchQuery)
self._splitterSearch.insertWidget(1, self._btnReset)
# build upper inner structure
self._splitterUpper.insertWidget(0, self._helpContent)
self._splitterUpper.insertWidget(1, self._wv)
self._horzLayoutUpper.addWidget(self._splitterUpper)
self._upperWidget.setLayout(self._horzLayoutUpper)
# build lower inner structure
self._splitterLower.insertWidget(0, self._helpIndex)
self._splitterLower.insertWidget(1, self._helpSearchResult)
self._horzLayoutLower.addWidget(self._splitterLower)
self._lowerWidget.setLayout(self._horzLayoutLower)
# build outer structure
self._splitterMain.insertWidget(0, self._splitterSearch)
self._splitterMain.insertWidget(1, self._upperWidget)
self._splitterMain.insertWidget(2, self._lowerWidget)
self._helpSearchResult.hide()
self._btnReset.hide()
self._vertLayout.addWidget(self._splitterMain)
self.ui.setLayout(self._vertLayout)
# set splitter width
w = self._splitterUpper.geometry().width()
self._splitterUpper.setSizes([w*(1/4), w*(3/4)])
w = self._splitterLower.geometry().width()
self._splitterLower.setSizes([w*(1/5), w*(4/5)])
h = self._splitterMain.geometry().height()
self._splitterMain.setSizes([h*(1/9), h*(7/9), h*(1/9)])
#.........这里部分代码省略.........
示例6: BrowserWindow
# 需要导入模块: from PyQt5.QtWebEngineWidgets import QWebEngineView [as 别名]
# 或者: from PyQt5.QtWebEngineWidgets.QWebEngineView import page [as 别名]
class BrowserWindow(QWidget):
urlChanged = pyqtSignal()
def __init__(self, svc, url='', windowType=QWebEnginePage.WebBrowserWindow, isLatent=False):
super().__init__()
self.svc = svc
self.hoveredUrl = ''
self.isLatent = isLatent
self.isLoading = False
self.nextUrl = QUrl('')
self.initUI(windowType)
if url != '':
self.cmdLine.setText(url)
self.handleCommand()
else:
self.beginEnteringCommand(None)
def beginEnteringCommand(self, cmd):
self.cmdLine.setFocus(Qt.OtherFocusReason)
if cmd is None:
self.cmdLine.setText(self.webView.page().url().toDisplayString())
self.cmdLine.selectAll()
else:
self.cmdLine.setText(cmd)
def handleCommand(self):
cmd = self.cmdLine.text()
if cmd.startswith('?'):
self.webView.page().load(QUrl('https://duckduckgo.com/?q=' + cmd[1:].strip()))
elif cmd.startswith('/'):
self.webView.page().findText(cmd[1:].strip())
else:
url = urlparse(cmd)
if url.scheme == '':
url = url._replace(scheme='https')
self.webView.page().load(QUrl(url.geturl()))
def toggleSource(self):
url = self.webView.page().url().toDisplayString()
if url == '': return
prefix = 'view-source:'
if url.startswith(prefix):
url = url[len(prefix):]
else:
url = prefix + url
self.webView.page().load(QUrl(url))
@pyqtSlot(str)
def onLinkHovered(self, url):
self.hoveredUrl = url
self.urlChanged.emit()
def url(self):
if self.isLoading:
return self.nextUrl
else:
return self.webView.page().url()
@pyqtSlot()
def onUrlChanged(self):
if self.hoveredUrl != '':
self.urlLabel.setText('<span style="color: gray">{}</span>'.format(html.escape(self.hoveredUrl)))
else:
self.urlLabel.setText(html.escape(self.url().toDisplayString()))
@pyqtSlot()
def onTitleChanged(self):
title = self.webView.page().title()
if title == '':
self.setWindowTitle('shower')
else:
self.setWindowTitle('shower: ' + title)
def addShortcut(self, key, handler):
shortcut = QShortcut(QKeySequence(key), self)
shortcut.activated.connect(handler)
return shortcut
@pyqtSlot()
def onLoadStarted(self):
self.isLoading = True
self.stopShortcut.setEnabled(True)
self.progressLabel.setText('<span style="color: yellow">[ 0%]</span>')
@pyqtSlot(int)
def onLoadProgress(self, n):
if n == 100:
self.progressLabel.setText('<span style="color: green">[100]</span>'.format(n))
else:
self.progressLabel.setText('<span style="color: yellow">[{:2d}%]</span>'.format(n))
@pyqtSlot()
def onLoadFinished(self):
self.isLoading = False
self.stopShortcut.setEnabled(False)
self.urlChanged.emit()
def initUI(self, windowType):
self.setStyleSheet("""
#.........这里部分代码省略.........
示例7: MainWindow
# 需要导入模块: from PyQt5.QtWebEngineWidgets import QWebEngineView [as 别名]
# 或者: from PyQt5.QtWebEngineWidgets.QWebEngineView import page [as 别名]
class MainWindow(QMainWindow):
"""Main window class."""
def __init__(self):
"""Init class."""
super(MainWindow, self).__init__()
self.pixmap_syncthingui = QPixmap(":/images/syncthingui.svg")
tf = QTransform()
self.pixmap_syncthingui0 = QPixmap(":/images/syncthingui.svg")
tf.rotate(90.0)
self.pixmap_syncthingui1 = self.pixmap_syncthingui0.transformed(tf)
tf.rotate(180.0)
self.pixmap_syncthingui2 = self.pixmap_syncthingui0.transformed(tf)
tf.rotate(270.0)
self.pixmap_syncthingui3 = self.pixmap_syncthingui0.transformed(tf)
self.init_gui()
self.init_menu()
self.init_systray()
self.run()
def init_gui(self):
"""init gui setup"""
self.setWindowIcon(QIcon(self.pixmap_syncthingui))
self.progressbar = QProgressBar()
self.statusBar().showMessage(getoutput(SYNCTHING + ' --version'))
self.statusBar().addPermanentWidget(self.progressbar)
self.setWindowTitle(__doc__.strip().capitalize())
self.setMinimumSize(900, 600)
self.setMaximumSize(1280, 1024)
self.resize(self.minimumSize())
self.center()
# QWebView
# self.view = QWebView(self)
self.view = QWebEngineView(self)
self.view.loadStarted.connect(self.start_loading)
self.view.loadFinished.connect(self.finish_loading)
self.view.loadProgress.connect(self.loading)
self.view.titleChanged.connect(self.set_title)
self.view.page().linkHovered.connect(
lambda link_txt: self.statusBar().showMessage(link_txt[:99], 3000))
QShortcut("Ctrl++", self, activated=lambda:
self.view.setZoomFactor(self.view.zoomFactor() + 0.2))
QShortcut("Ctrl+-", self, activated=lambda:
self.view.setZoomFactor(self.view.zoomFactor() - 0.2))
QShortcut("Ctrl+0", self, activated=lambda: self.view.setZoomFactor(1))
QShortcut("Ctrl+q", self, activated=lambda: self.close())
# syncthing console
self.consolewidget = QWidget(self)
# TODO: start at specify (w,h)
self.consolewidget.setMinimumSize(QSize(200, 100))
# TODO: setStyleSheet
# self.consolewidget.setStyleSheet("margin:0px; padding: 0px; \
# border:1px solid rgb(0, 0, 0);")
# border-radius: 40px;")
# TODO read syncthing console visible from setting
# self.consolewidget.setVisible(False)
# self.consolewidget.showEvent
# self.consoletextedit = QPlainTextEdit(parent=self.consolewidget)
self.consoletoolbar = QWidget(self)
hlayout = QHBoxLayout()
hlayout
self.consoletoolbar.setLayout(hlayout)
self.consoletextedit = QTextEdit(parent=self.consolewidget)
self.consoletextedit.setWordWrapMode(QTextOption.NoWrap)
# self.consoletextedit.setStyleSheet(" border:1px solid rgb(0, 0, 0);")
# self.consoletextedit.setStyleSheet("margin:0px; padding: 0px;")
layout = QVBoxLayout()
layout.addWidget(self.consoletoolbar)
layout.addWidget(self.consoletextedit)
self.consolewidget.setLayout(layout)
self.splitter = QSplitter(Qt.Vertical)
self.splitter.addWidget(self.view)
self.splitter.addWidget(self.consolewidget)
# process
self.process = QProcess()
self.process.error.connect(self._process_failed)
# QProcess emits `readyRead` when there is data to be read
self.process.readyRead.connect(self._process_dataReady)
self.process.stateChanged.connect(self._process_stateChanged)
# Just to prevent accidentally running multiple times
# Disable the button when process starts, and enable it when it finishes
# self.process.started.connect(lambda: self.runButton.setEnabled(False))
# self.process.finished.connect(lambda: self.runButton.setEnabled(True))
# backend options
self.chrt = QCheckBox("Smooth CPU ", checked=True)
self.ionice = QCheckBox("Smooth HDD ", checked=True)
self.chrt.setToolTip("Use Smooth CPUs priority (recommended)")
self.ionice.setToolTip("Use Smooth HDDs priority (recommended)")
self.chrt.setStatusTip(self.chrt.toolTip())
self.ionice.setStatusTip(self.ionice.toolTip())
#.........这里部分代码省略.........
示例8: X0h
# 需要导入模块: from PyQt5.QtWebEngineWidgets import QWebEngineView [as 别名]
# 或者: from PyQt5.QtWebEngineWidgets.QWebEngineView import page [as 别名]
#.........这里部分代码省略.........
def getLeftPartWidth(self):
return 620
def initializeTabs(self):
current_tab = self.tabs_widget.currentIndex()
size = len(self.tabs)
for index in range(0, size):
self.tabs_widget.removeTab(size-1-index)
self.tabs = [gui.createTabPage(self.tabs_widget, "X-ray Server Ouput"),
gui.createTabPage(self.tabs_widget, "Critical Angle for TER"),
gui.createTabPage(self.tabs_widget, "Darwin Curve (" + u"\u03C3" + " Pol.)"),
gui.createTabPage(self.tabs_widget, "Darwin Curve (" + u"\u03C0" + " Pol.)"),
]
for tab in self.tabs:
tab.setFixedHeight(650)
tab.setFixedWidth(750)
self.plot_canvas = [None, None, None]
self.tabs_widget.setCurrentIndex(current_tab)
def js_callback(self, result):
pass
def _callable_1(self, html):
self.original_signal = self.x0h_input.loadFinished
self.x0h_input.loadFinished.connect(self.loadFinished)
self.x0h_input.setHidden(True)
self.x0h_input.page().runJavaScript("document.getElementById('submit-btn').click()", self.js_callback)
def loadFinished(self):
self.x0h_input.page().toHtml(self._callable_2)
def _callable_2(self, html):
try:
self.x0h_input.loadFinished.disconnect()
self.x0h_input.back()
self.x0h_input.setHidden(False)
response_1 = self.clear_response(html)
response_2 = self.clear_response(html)
self.tabs_widget.setCurrentIndex(0)
self.x0h_output.setHtml(response_1)
data0, data1, data2 = self.extract_plots(response_2)
exchange_data = DataExchangeObject("XRAYSERVER", "X0H")
exchange_data.add_content("reflectivity", data0)
exchange_data.add_content("reflectivity_units_to_degrees", 1.0)
exchange_data.add_content("x-ray_diffraction_profile_sigma", data1)
exchange_data.add_content("x-ray_diffraction_profile_sigma_units_to_degrees", 0.000277777805)
exchange_data.add_content("x-ray_diffraction_profile_pi", data2)
exchange_data.add_content("x-ray_diffraction_profile_pi_units_to_degrees", 0.000277777805)
self.send("xrayserver_data", exchange_data)
except urllib.error.HTTPError as e:
self.x0h_output.setHtml('The server couldn\'t fulfill the request.\nError Code: '