Add per-tab inspector like dwb.

This also means the webinspector will always be detached / in its own window.
This commit is contained in:
Florian Bruhin 2014-05-26 15:35:05 +02:00
parent 62407eef33
commit fa01bfbbad
4 changed files with 26 additions and 30 deletions

View File

@ -342,7 +342,6 @@ class QuteBrowser(QApplication):
# misc # misc
self.lastWindowClosed.connect(self.shutdown) self.lastWindowClosed.connect(self.shutdown)
tabs.quit.connect(self.shutdown) tabs.quit.connect(self.shutdown)
tabs.currentChanged.connect(self.mainwindow.update_inspector)
# status bar # status bar
self.modeman.entered.connect(status.on_mode_entered) self.modeman.entered.connect(status.on_mode_entered)

View File

@ -25,6 +25,7 @@ from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt, QObject from PyQt5.QtCore import Qt, QObject
from PyQt5.QtGui import QClipboard from PyQt5.QtGui import QClipboard
from PyQt5.QtPrintSupport import QPrintDialog, QPrintPreviewDialog from PyQt5.QtPrintSupport import QPrintDialog, QPrintPreviewDialog
from PyQt5.QtWebKitWidgets import QWebInspector
import qutebrowser.commands.utils as cmdutils import qutebrowser.commands.utils as cmdutils
import qutebrowser.config.config as config import qutebrowser.config.config as config
@ -625,6 +626,29 @@ class CommandDispatcher(QObject):
url = quickmarks.get(name) url = quickmarks.get(name)
self._tabs.tabopen(url, background=True) self._tabs.tabopen(url, background=True)
@cmdutils.register(instance='mainwindow.tabs.cmd', name='inspector')
def toggle_inspector(self):
"""Toggle the web inspector."""
cur = self._tabs.currentWidget()
if cur.inspector is None:
if not config.get('webkit', 'developer-extras-enabled'):
message.error("Please enable developer-extras before using "
"the webinspector!")
return
cur.inspector = QWebInspector()
cur.inspector.setPage(cur.page_)
cur.inspector.show()
elif cur.inspector.isVisible():
cur.inspector.hide()
else:
if not config.get('webkit', 'developer-extras-enabled'):
message.error("Please enable developer-extras before using "
"the webinspector!")
return
else:
cur.inspector.show()
@cmdutils.register(instance='mainwindow.tabs.cmd', modes=['insert'], @cmdutils.register(instance='mainwindow.tabs.cmd', modes=['insert'],
hide=True) hide=True)
def open_editor(self): def open_editor(self):

View File

@ -22,7 +22,6 @@ from base64 import b64decode
from PyQt5.QtCore import pyqtSlot, QRect, QPoint, QCoreApplication from PyQt5.QtCore import pyqtSlot, QRect, QPoint, QCoreApplication
from PyQt5.QtWidgets import QWidget, QVBoxLayout from PyQt5.QtWidgets import QWidget, QVBoxLayout
from PyQt5.QtWebKitWidgets import QWebInspector
import qutebrowser.commands.utils as cmdutils import qutebrowser.commands.utils as cmdutils
import qutebrowser.config.config as config import qutebrowser.config.config as config
@ -44,7 +43,6 @@ class MainWindow(QWidget):
Attributes: Attributes:
tabs: The TabbedBrowser widget. tabs: The TabbedBrowser widget.
status: The StatusBar widget. status: The StatusBar widget.
inspector: The QWebInspector.
_vbox: The main QVBoxLayout. _vbox: The main QVBoxLayout.
""" """
@ -74,9 +72,6 @@ class MainWindow(QWidget):
self._vbox.addWidget(self.tabs) self._vbox.addWidget(self.tabs)
self.completion = CompletionView(self) self.completion = CompletionView(self)
self.inspector = QWebInspector()
self.inspector.hide()
self._vbox.addWidget(self.inspector)
self.status = StatusBar() self.status = StatusBar()
self._vbox.addWidget(self.status) self._vbox.addWidget(self.status)
@ -111,30 +106,6 @@ class MainWindow(QWidget):
bottomright = self.status.geometry().topRight() bottomright = self.status.geometry().topRight()
self.completion.setGeometry(QRect(topleft, bottomright)) self.completion.setGeometry(QRect(topleft, bottomright))
@cmdutils.register(instance='mainwindow', name='inspector')
def toggle_inspector(self):
"""Toggle the web inspector."""
if self.inspector.isVisible():
self.inspector.hide()
self.resize_completion()
else:
if not config.get('webkit', 'developer-extras-enabled'):
self.status.disp_error("Please enable developer-extras before "
"using the webinspector!")
else:
self.inspector.show()
self.resize_completion()
@pyqtSlot()
def update_inspector(self):
"""Update the web inspector if the page changed."""
self.inspector.setPage(self.tabs.currentWidget().page())
if self.inspector.isVisible():
# For some odd reason, we need to do this so the inspector actually
# shows some content...
self.inspector.hide()
self.inspector.show()
@cmdutils.register(instance='mainwindow', name=['quit', 'q'], nargs=0) @cmdutils.register(instance='mainwindow', name=['quit', 'q'], nargs=0)
def close(self): def close(self):
"""Extend close() so we can register it as a command.""" """Extend close() so we can register it as a command."""

View File

@ -55,6 +55,7 @@ class WebView(QWebView):
work. work.
progress: loading progress of this page. progress: loading progress of this page.
scroll_pos: The current scroll position as (x%, y%) tuple. scroll_pos: The current scroll position as (x%, y%) tuple.
inspector: The QWebInspector used for this webview.
_url_text: The current URL as string. _url_text: The current URL as string.
Accessed via url_text property. Accessed via url_text property.
_load_status: loading status of this page (index into LoadStatus) _load_status: loading status of this page (index into LoadStatus)
@ -86,6 +87,7 @@ class WebView(QWebView):
super().__init__(parent) super().__init__(parent)
self._load_status = LoadStatus.none self._load_status = LoadStatus.none
self.tabbedbrowser = parent self.tabbedbrowser = parent
self.inspector = None
self.scroll_pos = (-1, -1) self.scroll_pos = (-1, -1)
self._old_scroll_pos = (-1, -1) self._old_scroll_pos = (-1, -1)
self._shutdown_callback = None self._shutdown_callback = None