本文整理汇总了Python中PyQt5.QtWebKitWidgets.QWebPage类的典型用法代码示例。如果您正苦于以下问题:Python QWebPage类的具体用法?Python QWebPage怎么用?Python QWebPage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QWebPage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, opts, log):
from calibre.gui2 import secure_web_page
self.log = log
QWebPage.__init__(self)
settings = self.settings()
secure_web_page(settings)
settings.setFontSize(QWebSettings.DefaultFontSize,
opts.pdf_default_font_size)
settings.setFontSize(QWebSettings.DefaultFixedFontSize,
opts.pdf_mono_font_size)
settings.setFontSize(QWebSettings.MinimumLogicalFontSize, 8)
settings.setFontSize(QWebSettings.MinimumFontSize, 8)
std = {'serif':opts.pdf_serif_family, 'sans':opts.pdf_sans_family,
'mono':opts.pdf_mono_family}.get(opts.pdf_standard_font,
opts.pdf_serif_family)
if std:
settings.setFontFamily(QWebSettings.StandardFont, std)
if opts.pdf_serif_family:
settings.setFontFamily(QWebSettings.SerifFont, opts.pdf_serif_family)
if opts.pdf_sans_family:
settings.setFontFamily(QWebSettings.SansSerifFont,
opts.pdf_sans_family)
if opts.pdf_mono_family:
settings.setFontFamily(QWebSettings.FixedFont, opts.pdf_mono_family)
示例2: webpage
def webpage(qnam):
"""Get a new QWebPage object."""
from PyQt5.QtWebKitWidgets import QWebPage
page = QWebPage()
page.networkAccessManager().deleteLater()
page.setNetworkAccessManager(qnam)
return page
示例3: __init__
def __init__(self):
self.log = default_log
QWebPage.__init__(self)
self.js = None
self.evaljs = self.mainFrame().evaluateJavaScript
self.bridge_value = None
nam = self.networkAccessManager()
nam.setNetworkAccessible(nam.NotAccessible)
self.setLinkDelegationPolicy(self.DelegateAllLinks)
示例4: __init__
def __init__(self, log):
self.log = log
QWebPage.__init__(self)
self.js = None
self.evaljs = self.mainFrame().evaluateJavaScript
self.bridge_value = None
nam = self.networkAccessManager()
nam.setNetworkAccessible(nam.NotAccessible)
self.longjs_counter = 0
示例5: webpage
def webpage():
"""Get a new QWebPage object."""
from PyQt5.QtWebKitWidgets import QWebPage
from PyQt5.QtNetwork import QNetworkAccessManager
page = QWebPage()
nam = page.networkAccessManager()
nam.setNetworkAccessible(QNetworkAccessManager.NotAccessible)
return page
示例6: __init__
def __init__(self, parent):
QWebPage.__init__(self, parent)
self.js_loader = None
self._footnote_data = ''
from calibre.gui2.viewer.documentview import apply_basic_settings
settings = self.settings()
apply_basic_settings(settings)
settings.setAttribute(QWebSettings.DeveloperExtrasEnabled, False)
self.setLinkDelegationPolicy(self.DelegateAllLinks)
self.mainFrame().javaScriptWindowObjectCleared.connect(self.add_window_objects)
self.add_window_objects()
示例7: Browser
class Browser(object):
def __init__(self):
self.network_manager = QNetworkAccessManager()
self.network_manager.createRequest = self._create_request
self.network_manager.finished.connect(self._request_finished)
self.web_page = QWebPage()
self.web_page.setNetworkAccessManager(self.network_manager)
self.web_view = QWebView()
self.web_view.setPage(self.web_page)
def _create_request(self, operation, request, data):
print(data.readAll())
reply = QNetworkAccessManager.createRequest(self.network_manager,
operation,
request,
data)
return reply
def _request_finished(self, reply):
if not reply.error() == QNetworkReply.NoError:
# request probably failed
print(reply.error())
print(reply.errorString())
def _make_request(self, url):
request = QNetworkRequest()
request.setUrl(QUrl(url))
return request
def _urlencode_post_data(self, post_data):
post_params = QUrl()
for (key, value) in post_data.items():
post_params.addQueryItem(key, value)
return post_params.encodedQuery()
def perform(self, url, method='GET', post_data=dict()):
request = self._make_request(url)
if method == 'GET':
self.web_view.load(request)
else:
encoded_data = self._urlencode_post_data(post_data)
request.setRawHeader('Content-Type',
QByteArray('application/x-www-form-urlencoded'))
self.web_view.load(request,
QNetworkAccessManager.PostOperation,
encoded_data)
示例8: WebLoader
class WebLoader(QObject):
_finished = pyqtSignal(str)
def __init__(self, key):
super(WebLoader, self).__init__()
# if platform.python_version() < '3.0.0':
# self._key = unicode(key)
self._key = key
self._percent = 0
self._page = QWebPage()
self._page.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
self._page.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
self._page.loadProgress.connect(self.printProgress)
def printProgress(self, percent):
if self._percent >= percent:
cout("\n")
return
else:
cout('#' * (percent - self._percent))
self._percent = percent
def load(self, url):
self._percent = 0
self._url = QUrl.fromUserInput(url)
self._page.mainFrame().load(self._url)
self._page.setViewportSize(QSize(1920, 10000))
print("Loading... %s" % url)
示例9: __init__
def __init__(self, parent=None):
"""
Constructor
@param parent reference to the parent object (QObject)
"""
super(PageThumbnailer, self).__init__(parent)
self.__page = QWebPage(self)
self.__size = QSize(231, 130)
self.__loadTitle = False
self.__title = ""
self.__url = QUrl()
self.__proxy = NetworkAccessManagerProxy(self)
import Helpviewer.HelpWindow
self.__proxy.setPrimaryNetworkAccessManager(
Helpviewer.HelpWindow.HelpWindow.networkAccessManager())
self.__page.setNetworkAccessManager(self.__proxy)
self.__page.mainFrame().setScrollBarPolicy(
Qt.Horizontal, Qt.ScrollBarAlwaysOff)
self.__page.mainFrame().setScrollBarPolicy(
Qt.Vertical, Qt.ScrollBarAlwaysOff)
# Full HD
# Every page should fit in this resolution
self.__page.setViewportSize(QSize(1920, 1080))
示例10: acceptNavigationRequest
def acceptNavigationRequest(self, frame, request, type):
if(type == QWebPage.NavigationTypeLinkClicked):
if(frame == self.mainFrame()):
self.view().link_clicked(request.url())
else:
call_method("open-url", [request.url().toString()])
return False
return QWebPage.acceptNavigationRequest(self, frame, request, type)
示例11: userAgentForUrl
def userAgentForUrl(self, url):
"""Handle reqests for the browser's user agent
Overridden from QWebPage so we can force a user agent from the config.
"""
return (
self.config.get("user_agent")
or QWebPage.userAgentForUrl(self, url)
)
示例12: __init__
def __init__(self):
self.network_manager = QNetworkAccessManager()
self.network_manager.createRequest = self._create_request
self.network_manager.finished.connect(self._request_finished)
self.web_page = QWebPage()
self.web_page.setNetworkAccessManager(self.network_manager)
self.web_view = QWebView()
self.web_view.setPage(self.web_page)
示例13: __init__
def __init__(self, parent):
QWebPage.__init__(self, parent)
settings = self.settings()
apply_settings(settings, config().parse())
settings.setMaximumPagesInCache(0)
secure_web_page(settings)
settings.setAttribute(settings.PrivateBrowsingEnabled, True)
settings.setAttribute(settings.LinksIncludedInFocusChain, False)
settings.setAttribute(settings.DeveloperExtrasEnabled, True)
settings.setDefaultTextEncoding('utf-8')
data = 'data:text/css;charset=utf-8;base64,'
css = '[data-in-split-mode="1"] [data-is-block="1"]:hover { cursor: pointer !important; border-top: solid 5px green !important }'
data += b64encode(css.encode('utf-8'))
settings.setUserStyleSheetUrl(QUrl(data))
self.setNetworkAccessManager(NetworkAccessManager(self))
self.setLinkDelegationPolicy(self.DelegateAllLinks)
self.mainFrame().javaScriptWindowObjectCleared.connect(self.init_javascript)
self.init_javascript()
示例14: acceptNavigationRequest
def acceptNavigationRequest(self, frame, request, type):
if(type == QWebPage.NavigationTypeLinkClicked):
url = request.url().toString()
if(frame == self.mainFrame()):
self.view().load(url)
return False
elif frame == None:
# self.createWindow(QWebPage.WebBrowserWindow, url)
webbrowser.open(request.url().toString())
return False
return QWebPage.acceptNavigationRequest(self, frame, request, type)
示例15: __init__
def __init__(self):
super(FrameCapture, self).__init__()
self._percent = 0
self._page = QWebPage()
self._page.mainFrame().setScrollBarPolicy(Qt.Vertical,
Qt.ScrollBarAlwaysOff)
self._page.mainFrame().setScrollBarPolicy(Qt.Horizontal,
Qt.ScrollBarAlwaysOff)
self._page.loadProgress.connect(self.printProgress)
self._page.loadFinished.connect(self.saveResult)