本文整理汇总了Python中PyQt4.QtWebKit.QWebInspector.setPage方法的典型用法代码示例。如果您正苦于以下问题:Python QWebInspector.setPage方法的具体用法?Python QWebInspector.setPage怎么用?Python QWebInspector.setPage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtWebKit.QWebInspector
的用法示例。
在下文中一共展示了QWebInspector.setPage方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show_inspector
# 需要导入模块: from PyQt4.QtWebKit import QWebInspector [as 别名]
# 或者: from PyQt4.QtWebKit.QWebInspector import setPage [as 别名]
def show_inspector(self, event=None):
"""Show the web inspector."""
if not self.inspector:
inspect = QWebInspector()
inspect.setPage(self.page())
self.inspector = inspect
self.inspector.show()
示例2: WebView
# 需要导入模块: from PyQt4.QtWebKit import QWebInspector [as 别名]
# 或者: from PyQt4.QtWebKit.QWebInspector import setPage [as 别名]
class WebView(QWebView):
def __init__(self, parent=None):
QWebView.__init__(self, parent)
self.inspector = QWebInspector(self)
w = QApplication.instance().desktop().availableGeometry(self).width()
self._size_hint = QSize(int(w/3), int(w/2))
self._page = WebPage(self)
self.setPage(self._page)
self.inspector.setPage(self._page)
self.clear()
def sizeHint(self):
return self._size_hint
def refresh(self):
self.pageAction(self.page().Reload).trigger()
@dynamic_property
def scroll_pos(self):
def fget(self):
mf = self.page().mainFrame()
return (mf.scrollBarValue(Qt.Horizontal), mf.scrollBarValue(Qt.Vertical))
def fset(self, val):
mf = self.page().mainFrame()
mf.setScrollBarValue(Qt.Horizontal, val[0])
mf.setScrollBarValue(Qt.Vertical, val[1])
return property(fget=fget, fset=fset)
def clear(self):
self.setHtml(_(
'''
<h3>Live preview</h3>
<p>Here you will see a live preview of the HTML file you are currently editing.
The preview will update automatically as you make changes.
<p style="font-size:x-small; color: gray">Note that this is a quick preview
only, it is not intended to simulate an actual ebook reader. Some
aspects of your ebook will not work, such as, page breaks,
page margins and embedded fonts that use font name aliasing.
'''))
def inspect(self):
self.inspector.parent().show()
self.inspector.parent().raise_()
self.pageAction(self.page().InspectElement).trigger()
def contextMenuEvent(self, ev):
menu = QMenu(self)
ca = self.pageAction(QWebPage.Copy)
if ca.isEnabled():
menu.addAction(ca)
menu.addAction(actions['reload-preview'])
menu.addAction(QIcon(I('debug.png')), _('Inspect element'), self.inspect)
menu.exec_(ev.globalPos())
示例3: toggleInspector
# 需要导入模块: from PyQt4.QtWebKit import QWebInspector [as 别名]
# 或者: from PyQt4.QtWebKit.QWebInspector import setPage [as 别名]
def toggleInspector(self):
if self.__inspector_window is None:
self.settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
web_inspector = QWebInspector()
web_inspector.setPage(self.page())
self.__inspector_window = QMainWindow(self)
self.__inspector_window.setCentralWidget(web_inspector)
self.__inspector_window.resize(900, 600)
self.__inspector_window.setVisible(False)
self.__inspector_window.setVisible(not self.__inspector_window.isVisible())
示例4: WebInspector
# 需要导入模块: from PyQt4.QtWebKit import QWebInspector [as 别名]
# 或者: from PyQt4.QtWebKit.QWebInspector import setPage [as 别名]
class WebInspector(QWidget):
def __init__(self, parent):
QWidget.__init__(self, parent)
vbox = QVBoxLayout(self)
self._webInspector = QWebInspector(self)
vbox.addWidget(self._webInspector)
self.btnDock = QPushButton(translations.TR_UNDOCK)
vbox.addWidget(self.btnDock)
ExplorerContainer.register_tab(translations.TR_TAB_WEB_INSPECTOR, self)
def refresh_inspector(self):
self._webInspector.hide()
self._webInspector.show()
def set_inspection_page(self, page):
self._webInspector.setPage(page)
self._webInspector.setVisible(True)
示例5: WebView
# 需要导入模块: from PyQt4.QtWebKit import QWebInspector [as 别名]
# 或者: from PyQt4.QtWebKit.QWebInspector import setPage [as 别名]
class WebView(QWebView):
def __init__(self, parent=None):
QWebView.__init__(self, parent)
self.inspector = QWebInspector(self)
w = QApplication.instance().desktop().availableGeometry(self).width()
self._size_hint = QSize(int(w/3), int(w/2))
self._page = WebPage(self)
self.setPage(self._page)
self.inspector.setPage(self._page)
self.clear()
def sizeHint(self):
return self._size_hint
def refresh(self):
self.pageAction(self.page().Reload).trigger()
@dynamic_property
def scroll_pos(self):
def fget(self):
mf = self.page().mainFrame()
return (mf.scrollBarValue(Qt.Horizontal), mf.scrollBarValue(Qt.Vertical))
def fset(self, val):
mf = self.page().mainFrame()
mf.setScrollBarValue(Qt.Horizontal, val[0])
mf.setScrollBarValue(Qt.Vertical, val[1])
return property(fget=fget, fset=fset)
def clear(self):
self.setHtml('<p>')
def inspect(self):
self.inspector.parent().show()
self.inspector.parent().raise_()
self.pageAction(self.page().InspectElement).trigger()
def contextMenuEvent(self, ev):
menu = QMenu(self)
menu.addAction(actions['reload-preview'])
menu.addAction(QIcon(I('debug.png')), _('Inspect element'), self.inspect)
menu.exec_(ev.globalPos())
示例6: WebInspector
# 需要导入模块: from PyQt4.QtWebKit import QWebInspector [as 别名]
# 或者: from PyQt4.QtWebKit.QWebInspector import setPage [as 别名]
class WebInspector(QDialog):
def __init__(self, parent, page):
QDialog.__init__(self, parent)
self.setWindowTitle(_('Inspect book code'))
self.setWindowIcon(QIcon(I('debug.png')))
l = QVBoxLayout()
self.setLayout(l)
self.inspector = QWebInspector(self)
self.inspector.setPage(page)
l.addWidget(self.inspector)
self.bb = bb = QDialogButtonBox(QDialogButtonBox.Close)
l.addWidget(bb)
bb.accepted.connect(self.accept)
bb.rejected.connect(self.reject)
self.resize(self.sizeHint())
geom = gprefs.get('viewer_inspector_geom', None)
if geom is not None:
self.restoreGeometry(geom)
def save_geometry(self):
gprefs['viewer_inspector_geom'] = bytearray(self.saveGeometry())
def closeEvent(self, ev):
self.save_geometry()
return QDialog.closeEvent(self, ev)
def accept(self):
self.save_geometry()
QDialog.accept(self)
def reject(self):
self.save_geometry()
QDialog.reject(self)
示例7: WebInspector
# 需要导入模块: from PyQt4.QtWebKit import QWebInspector [as 别名]
# 或者: from PyQt4.QtWebKit.QWebInspector import setPage [as 别名]
class WebInspector(QWidget):
"""WebInspector widget class"""
def __init__(self, parent):
QWidget.__init__(self, parent)
vbox = QVBoxLayout(self)
self._webInspector = QWebInspector(self)
vbox.addWidget(self._webInspector)
self.btnDock = QPushButton(translations.TR_UNDOCK)
vbox.addWidget(self.btnDock)
ExplorerContainer.register_tab(translations.TR_TAB_WEB_INSPECTOR, self)
IDE.register_service('web_inspector', self)
def refresh_inspector(self):
"""Refresh WebInspector widget by hiding and showing"""
self._webInspector.hide()
self._webInspector.show()
def set_inspection_page(self, page):
"""Method to load an argument page object on the WebInspector"""
self._webInspector.setPage(page)
self._webInspector.setVisible(True)
示例8: GRobot
# 需要导入模块: from PyQt4.QtWebKit import QWebInspector [as 别名]
# 或者: from PyQt4.QtWebKit.QWebInspector import setPage [as 别名]
#.........这里部分代码省略.........
self.manager = self.page.networkAccessManager()
#TODO:Think about how to handle the network accessible signal
#self.manager.networkAccessibleChanged.connect()
self.manager.finished.connect(self._request_ended)
self.manager.sslErrors.connect(self._on_manager_ssl_errors)
# Cache
self.cache = QNetworkDiskCache()
self.cache.setCacheDirectory(cache_dir)
self.manager.setCache(self.cache)
# Cookie jar
self.cookie_jar = QNetworkCookieJar()
self.manager.setCookieJar(self.cookie_jar)
# User Agent
self.page.setUserAgent(self.user_agent)
self.page.networkAccessManager().authenticationRequired \
.connect(self._authenticate)
self.page.networkAccessManager().proxyAuthenticationRequired \
.connect(self._authenticate)
self.main_frame = self.page.mainFrame()
self.webview = None
self.viewport_size = viewport_size
self.webview = QtWebKit.QWebView()
self.webview.setPage(self.page)
self.webview.show() if display else self.webview.hide()
self.set_viewport_size(*viewport_size)
self.page.settings().setAttribute(QtWebKit.QWebSettings.PluginsEnabled, plugins_enabled)
self.page.settings().setAttribute(QtWebKit.QWebSettings.JavaEnabled, java_enabled)
self.page.settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, self.develop)
self.enable_image = image_enabled
self.enable_javascript = javascript_enabled
#always open link in current window instead of new window
self.page.setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
self.page.linkClicked.connect(self._link_clicked)
#start the qt main loop
GRobot._loop = QtMainLoop(GRobot._app)
GRobot._loop.start()
GRobot.exit_lock.release()
@property
def popup_messages(self):
return self._popup_messages
@popup_messages.setter
def popup_messages(self, value):
self._popup_messages = unicode(value)
@property
def url(self):
示例9: __init__
# 需要导入模块: from PyQt4.QtWebKit import QWebInspector [as 别名]
# 或者: from PyQt4.QtWebKit.QWebInspector import setPage [as 别名]
def __init__(self, urls, parent=None):
KParts.MainWindow.__init__(self, parent)
QWebSettings.globalSettings().setAttribute(
QWebSettings.DeveloperExtrasEnabled, True)
self.setWindowIcon(KIcon('text-editor'))
self.kate = KTextEditor.EditorChooser.editor()
self.editor = self.kate.createDocument(self).createView(self)
doc = self.editor.document()
self.editor.setContextMenu(self.editor.defaultContextMenu())
sizegrip = create_grip(self.editor)
sizegrip.show() #TODO: only show on windowstate change
self.renderer = Renderer(self)
@doc.textChanged.connect
def _start_markdown(doc=None, old_range=None, new_range=None):
"""Runs the renderer if it’s not currently rendering"""
if not self.renderer.isRunning():
self.renderer.start()
@self.renderer.finished.connect
def _stop_markdown():
"""
Replaces the preview HTML with the newly rendered one
and restores the scroll position
"""
url = self.editor.document().url().resolved(QUrl('.'))
self.preview.setHtml(self.renderer.html, url) #baseurl für extenes zeug
self.preview.page().mainFrame().setScrollPosition(self.renderer.scrollpos)
self.editor.document().documentNameChanged.connect(self.refresh_document)
self.guiFactory().addClient(self.editor)
self.setCentralWidget(self.editor)
self.toolbar = KToolBar(i18n('Markdowner Toolbar'), self)
self.toolbar.setWindowTitle(self.toolbar.objectName())
self.preview_button = self.toolbar.addAction(KIcon('document-preview'), i18n('Show Preview'))
self.preview_button.setCheckable(True)
self.preview = QWebView()
self.preview.settings().setUserStyleSheetUrl(base64css())
self.preview.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
self.preview.linkClicked.connect(self.intercept_link)
with self.setup_dock(self.preview, i18n('Preview'), Qt.RightDockWidgetArea) as dock:
page = self.preview.page()
palette = page.palette()
palette.setBrush(QPalette.Base, Qt.transparent)
page.setPalette(palette)
self.preview.setAttribute(Qt.WA_TranslucentBackground)
self.preview.setAttribute(Qt.WA_OpaquePaintEvent, False)
dock.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
dock.visibilityChanged.connect(self.preview_button.setChecked)
self.preview_button.triggered.connect(dock.setVisible)
inspector = QWebInspector()
with self.setup_dock(inspector, i18n('Inspector'), Qt.BottomDockWidgetArea) as dock:
inspector.setPage(self.preview.page())
dock.hide()
inspect_action = self.preview.page().action(QWebPage.InspectElement)
inspect_action.triggered.connect(dock.show)
if len(urls) != 0:
self.editor.document().openUrl(urls[0])
#TODO: spellcheck
self.setAutoSaveSettings()
self.kate.readConfig(self.autoSaveConfigGroup().config())
示例10: saveTranslations
# 需要导入模块: from PyQt4.QtWebKit import QWebInspector [as 别名]
# 或者: from PyQt4.QtWebKit.QWebInspector import setPage [as 别名]
def saveTranslations(self, translations):
pass
@pyqtSlot(int, result=str)
def open_files(self, mode):
a = QFileDialog()
if mode == 1:
v = a.getOpenFileNames(caption="Импорт файлов rpm...", filter="RPM Files (*.rpm);;Any files (*.*)")
return json.dumps(str(v))
elif mode == 2:
return a.getExistingDirectory(options=QFileDialog.ShowDirsOnly)
elif mode == 3:
return a.getOpenFileName()
if __name__ == '__main__':
app = QApplication(sys.argv)
view = Browser()
view.page().mainFrame().addToJavaScriptWindowObject("Bridge", view)
view.setWindowTitle("Handsome Localizer v1.0")
view.load(QUrl("html/main.html"))
view.setVisible(True)
view.setMinimumWidth(1024)
view.setMinimumHeight(480)
view.page().settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
inspector = QWebInspector()
inspector.setPage(view.page())
inspector.setVisible(True)
app.exec_()
示例11: SynopticWidget
# 需要导入模块: from PyQt4.QtWebKit import QWebInspector [as 别名]
# 或者: from PyQt4.QtWebKit.QWebInspector import setPage [as 别名]
class SynopticWidget(QtGui.QWidget):
"""
A Qt widget displaying a SVG synoptic in a webview.
This widget does not have a "backend", so it's intended
to be subclassed to add control system specific behavior.
See TaurusSynopticWidget for a TANGO implementation.
"""
subscribe = QtCore.pyqtSignal(str)
def __init__(self, url=None, parent=None, *args, **kwargs):
super(SynopticWidget, self).__init__(parent)
self.subscribe.connect(self._handle_subscriptions)
self._url = url
self._setup_ui(url)
def _setup_ui(self, url=None, section=None):
self.hbox = hbox = QtGui.QHBoxLayout(self)
self.hbox.setContentsMargins(0, 0, 0, 0)
self.hbox.layout().setContentsMargins(0, 0, 0, 0)
self.setLayout(self.hbox)
if url:
self.set_url(url, section)
def set_url(self, url, section=None):
# TODO: probably breaks things if the url is already set
self._url = url
self.splitter = QtGui.QSplitter(self)
self.splitter.setOrientation(QtCore.Qt.Vertical)
self.hbox.addWidget(self.splitter)
view = self._create_view(url, section)
self._setup_inspector(view)
self.splitter.addWidget(view)
print "set_url", url
def _create_view(self, html=None, section=None):
"Create the webview that will display the synoptic itself"
view = QWebView(self)
# This is supposedly an optimisation. Disable if there are
# graphical artifacts or something.
view.settings().TiledBackingStoreEnabled = True
view.setRenderHint(QtGui.QPainter.TextAntialiasing, False)
page = LoggingWebPage()
view.setPage(page)
view.setContextMenuPolicy(QtCore.Qt.PreventContextMenu)
# setup the JS interface
frame = view.page().mainFrame()
self.js = JSInterface(frame)
self.js.subscription.connect(self.subscribe)
# mouse interaction signals
self.clicked = self.js.leftclicked
self.rightClicked = self.js.rightclicked
self.hovered = self.js.hovered
self.clicked.connect(self._on_click)
self.rightClicked.connect(self._on_rightclick)
self.hovered.connect(self._on_hover)
# Inject JSInterface into the JS global namespace as "Backend"
def addBackend():
frame.addToJavaScriptWindowObject('Backend', self.js)
view.connect(frame, QtCore.SIGNAL("javaScriptWindowObjectCleared()"), addBackend)
# load the page
# need to set the "base URL" for the webview to find the
# resources (js, css).
base_url = QtCore.QUrl().fromLocalFile(
os.path.abspath(os.path.dirname(__file__)) + "/web/")
# some ugly magic to get the path to the SVG file right. It
# needs to be absolute because local paths go to the base URL.
abspath = os.path.dirname(os.path.abspath(html))
with open(html) as f:
text = f.read().replace("${path}", abspath) # TODO: use template
view.setHtml(text, base_url)
return view
def _setup_inspector(self, view):
"""Create a WebInspector widget connected to the WebView. This allows inspecting
the DOM, debugging javascript, logging, etc. Can be toggled using F12."""
self._inspector = None
page = view.page()
def toggle_inspector():
if self._inspector:
self._inspector.setVisible(not self._inspector.isVisible())
else:
# create the inspector "on demand"
page.settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
self._inspector = QWebInspector(self)
self._inspector.setPage(page)
self.splitter.addWidget(self._inspector)
#.........这里部分代码省略.........
示例12: Web_Page
# 需要导入模块: from PyQt4.QtWebKit import QWebInspector [as 别名]
# 或者: from PyQt4.QtWebKit.QWebInspector import setPage [as 别名]
#.........这里部分代码省略.........
self.SETTINGS.setAttribute( QWebSettings.LocalContentCanAccessFileUrls, True );
self.SETTINGS.setAttribute( QWebSettings.XSSAuditingEnabled, True );
self.SETTINGS.setAttribute( QWebSettings.AcceleratedCompositingEnabled, True );
self.SETTINGS.setAttribute( QWebSettings.TiledBackingStoreEnabled, False );
self.SETTINGS.setAttribute( QWebSettings.FrameFlatteningEnabled, False );
self.SETTINGS.setAttribute( QWebSettings.SiteSpecificQuirksEnabled, True );
# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
self.SETTINGS.enablePersistentStorage( self.PARENT.STORAGE_ROOT );
self.SETTINGS.setLocalStoragePath( self.PARENT.STORAGE_ROOT+"local_storage/" );
self.SETTINGS.setIconDatabasePath ( self.PARENT.STORAGE_ROOT+"icons_path/" )
self.SETTINGS.setMaximumPagesInCache ( 10 );
# FIXME: Create settings config file [TO-CONFIG.FILE]
self.SETTINGS.setOfflineWebApplicationCachePath( self.PARENT.STORAGE_ROOT+"/cache/" );
self.SETTINGS.setOfflineWebApplicationCacheQuota ( 25 * 1024 *1024 );
self.SETTINGS.setOfflineStoragePath( self.PARENT.STORAGE_ROOT );
self.SETTINGS.setOfflineStorageDefaultQuota ( 25 * 1024 *1024 );
#self.SETTINGS.setObjectCacheCapacities (int cacheMinDeadCapacity, int cacheMaxDead, int totalCapacity)
# -------------------------------------------------------------------
self.INSPECTOR = QWebInspector( None );
"""
__init__ (self, QWidget parent = None)
closeEvent (self, QCloseEvent event)
bool event (self, QEvent)
hideEvent (self, QHideEvent event)
QWebPage page (self)
resizeEvent (self, QResizeEvent event)
setPage (self, QWebPage page)
showEvent (self, QShowEvent event)
QSize sizeHint (self)
"""
# -------------------------------------------------------------------
self.INIT();
# -------------------------------------------------------------------
# =======================================================================
def INIT( self ):
# -------------------------------------------------------------------
self.HEADERS["User-Agent"] = self.USER_AGENT;
# -------------------------------------------------------------------
# =======================================================================
def POST_INIT( self ):
# -------------------------------------------------------------------
self.PROGRESS_BAR = QFrame( self.PARENT.WEB_VIEWS[ self.UID ]["WEB_VIEW"] );
self.PROGRESS_BAR.setStyleSheet( "QFrame{ background-color: #F00; }" );
self.PROGRESS_BAR.setGeometry( 0, 0, 0, 5 );
# -------------------------------------------------------------------
# =======================================================================
def EXEC_JS( self, _JS ):
# -------------------------------------------------------------------
#frame = self.PARENT.WEB_VIEW.page().mainFrame();
#frame = self.mainFrame();
#frame.evaluateJavaScript( _JS );