Initial broken inspector support for QtWebEngine
This commit is contained in:
parent
9851a13981
commit
614893bdd6
@ -41,7 +41,8 @@ import pygments.formatters
|
|||||||
from qutebrowser.commands import userscripts, cmdexc, cmdutils, runners
|
from qutebrowser.commands import userscripts, cmdexc, cmdutils, runners
|
||||||
from qutebrowser.config import config, configexc
|
from qutebrowser.config import config, configexc
|
||||||
from qutebrowser.browser import urlmarks, browsertab
|
from qutebrowser.browser import urlmarks, browsertab
|
||||||
from qutebrowser.browser.webkit import webelem, inspector, downloads, mhtml
|
from qutebrowser.browser.webkit import (webelem, webkitinspector, downloads,
|
||||||
|
mhtml)
|
||||||
from qutebrowser.keyinput import modeman
|
from qutebrowser.keyinput import modeman
|
||||||
from qutebrowser.utils import (message, usertypes, log, qtutils, urlutils,
|
from qutebrowser.utils import (message, usertypes, log, qtutils, urlutils,
|
||||||
objreg, utils, typing)
|
objreg, utils, typing)
|
||||||
@ -1219,7 +1220,7 @@ class CommandDispatcher:
|
|||||||
raise cmdexc.CommandError(str(e))
|
raise cmdexc.CommandError(str(e))
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', name='inspector',
|
@cmdutils.register(instance='command-dispatcher', name='inspector',
|
||||||
scope='window', backend=usertypes.Backend.QtWebKit)
|
scope='window')
|
||||||
def toggle_inspector(self):
|
def toggle_inspector(self):
|
||||||
"""Toggle the web inspector.
|
"""Toggle the web inspector.
|
||||||
|
|
||||||
@ -1232,11 +1233,21 @@ class CommandDispatcher:
|
|||||||
raise cmdexc.CommandError(
|
raise cmdexc.CommandError(
|
||||||
"Please enable developer-extras before using the "
|
"Please enable developer-extras before using the "
|
||||||
"webinspector!")
|
"webinspector!")
|
||||||
tab.data.inspector = inspector.WebInspector()
|
|
||||||
# FIXME:qtwebengine have a proper API for this
|
# FIXME:qtwebengine have a proper API for this
|
||||||
page = tab._widget.page() # pylint: disable=protected-access
|
if tab.backend == usertypes.Backend.QtWebKit:
|
||||||
tab.data.inspector.setPage(page)
|
tab.data.inspector = webkitinspector.WebInspector()
|
||||||
tab.data.inspector.show()
|
page = tab._widget.page() # pylint: disable=protected-access
|
||||||
|
tab.data.inspector.setPage(page)
|
||||||
|
tab.data.inspector.show()
|
||||||
|
elif tab.backend == usertypes.Backend.QtWebEngine:
|
||||||
|
from qutebrowser.browser.webengine import webengineinspector
|
||||||
|
tab.data.inspector = webengineinspector.WebInspector()
|
||||||
|
try:
|
||||||
|
tab.data.inspector.load()
|
||||||
|
except webengineinspector.WebInspectorError as e:
|
||||||
|
raise cmdexc.CommandError(e)
|
||||||
|
tab.data.inspector.show()
|
||||||
elif tab.data.inspector.isVisible():
|
elif tab.data.inspector.isVisible():
|
||||||
tab.data.inspector.hide()
|
tab.data.inspector.hide()
|
||||||
else:
|
else:
|
||||||
|
91
qutebrowser/browser/webengine/webengineinspector.py
Normal file
91
qutebrowser/browser/webengine/webengineinspector.py
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||||
|
|
||||||
|
# Copyright 2015-2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||||
|
#
|
||||||
|
# This file is part of qutebrowser.
|
||||||
|
#
|
||||||
|
# qutebrowser is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# qutebrowser is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"""Customized QWebInspector."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import base64
|
||||||
|
import binascii
|
||||||
|
|
||||||
|
from PyQt5.QtCore import QUrl
|
||||||
|
from PyQt5.QtWidgets import QWidget
|
||||||
|
from PyQt5.QtWebEngineWidgets import QWebEngineView
|
||||||
|
|
||||||
|
from qutebrowser.utils import log, objreg
|
||||||
|
from qutebrowser.misc import miscwidgets
|
||||||
|
|
||||||
|
|
||||||
|
# FIXME:qtwebengine should we move the geometry stuff to some mixin?
|
||||||
|
|
||||||
|
|
||||||
|
class WebInspectorError(Exception):
|
||||||
|
|
||||||
|
"""Raised when the inspector could not be initialized."""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class WebInspector(QWidget):
|
||||||
|
|
||||||
|
"""A web inspector for QtWebEngine which stores its geometry."""
|
||||||
|
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.port = None
|
||||||
|
self._view = QWebEngineView()
|
||||||
|
self._layout = miscwidgets.WrapperLayout(self._view, self)
|
||||||
|
self.setFocusProxy(self._view)
|
||||||
|
self._view.setParent(self)
|
||||||
|
|
||||||
|
def load(self):
|
||||||
|
envvar = 'QTWEBENGINE_REMOTE_DEBUGGING'
|
||||||
|
if envvar not in os.environ:
|
||||||
|
raise WebInspectorError(
|
||||||
|
"Debugging is not set up correctly. Did you restart after "
|
||||||
|
"setting developer-extras?")
|
||||||
|
port = int(os.environ[envvar])
|
||||||
|
url = QUrl('http://localhost:{}/'.format(port))
|
||||||
|
self._view.load(url)
|
||||||
|
|
||||||
|
# self._load_state_geometry()
|
||||||
|
|
||||||
|
# def closeEvent(self, e):
|
||||||
|
# """Save the geometry when closed."""
|
||||||
|
# state_config = objreg.get('state-config')
|
||||||
|
# data = bytes(self.saveGeometry())
|
||||||
|
# geom = base64.b64encode(data).decode('ASCII')
|
||||||
|
# state_config['geometry']['inspector'] = geom
|
||||||
|
# super().closeEvent(e)
|
||||||
|
|
||||||
|
# def _load_state_geometry(self):
|
||||||
|
# """Load the geometry from the state file."""
|
||||||
|
# state_config = objreg.get('state-config')
|
||||||
|
# try:
|
||||||
|
# data = state_config['geometry']['inspector']
|
||||||
|
# geom = base64.b64decode(data, validate=True)
|
||||||
|
# except KeyError:
|
||||||
|
# # First start
|
||||||
|
# pass
|
||||||
|
# except binascii.Error:
|
||||||
|
# log.misc.exception("Error while reading geometry")
|
||||||
|
# else:
|
||||||
|
# log.init.debug("Loading geometry from {}".format(geom))
|
||||||
|
# ok = self.restoreGeometry(geom)
|
||||||
|
# if not ok:
|
||||||
|
# log.init.warning("Error while loading geometry.")
|
@ -24,12 +24,14 @@ Module attributes:
|
|||||||
constants.
|
constants.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
# pylint: disable=no-name-in-module,import-error,useless-suppression
|
# pylint: disable=no-name-in-module,import-error,useless-suppression
|
||||||
from PyQt5.QtWebEngineWidgets import QWebEngineSettings
|
from PyQt5.QtWebEngineWidgets import QWebEngineSettings
|
||||||
# pylint: enable=no-name-in-module,import-error,useless-suppression
|
# pylint: enable=no-name-in-module,import-error,useless-suppression
|
||||||
|
|
||||||
from qutebrowser.config import websettings
|
from qutebrowser.config import websettings, config
|
||||||
from qutebrowser.utils import objreg
|
from qutebrowser.utils import objreg, utils
|
||||||
|
|
||||||
|
|
||||||
class Attribute(websettings.Attribute):
|
class Attribute(websettings.Attribute):
|
||||||
@ -61,6 +63,11 @@ def update_settings(section, option):
|
|||||||
def init():
|
def init():
|
||||||
"""Initialize the global QWebSettings."""
|
"""Initialize the global QWebSettings."""
|
||||||
# FIXME:qtwebengine set paths in profile
|
# FIXME:qtwebengine set paths in profile
|
||||||
|
|
||||||
|
if config.get('general', 'developer-extras'):
|
||||||
|
# FIXME:qtwebengine Make sure we call globalSettings *after* this...
|
||||||
|
os.environ['QTWEBENGINE_REMOTE_DEBUGGING'] = str(utils.random_port())
|
||||||
|
|
||||||
websettings.init_mappings(MAPPINGS)
|
websettings.init_mappings(MAPPINGS)
|
||||||
objreg.get('config').changed.connect(update_settings)
|
objreg.get('config').changed.connect(update_settings)
|
||||||
|
|
||||||
|
@ -176,8 +176,7 @@ def data(readonly=False):
|
|||||||
"icons."),
|
"icons."),
|
||||||
|
|
||||||
('developer-extras',
|
('developer-extras',
|
||||||
SettingValue(typ.Bool(), 'false',
|
SettingValue(typ.Bool(), 'false'),
|
||||||
backends=[usertypes.Backend.QtWebKit]),
|
|
||||||
"Enable extra tools for Web developers.\n\n"
|
"Enable extra tools for Web developers.\n\n"
|
||||||
"This needs to be enabled for `:inspector` to work and also adds "
|
"This needs to be enabled for `:inspector` to work and also adds "
|
||||||
"an _Inspect_ entry to the context menu."),
|
"an _Inspect_ entry to the context menu."),
|
||||||
|
Loading…
Reference in New Issue
Block a user