Add contents_size_changed to tab API
This commit is contained in:
parent
c764733472
commit
c5a91004f5
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QUrl, QObject, QPoint
|
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QUrl, QObject, QPoint, QSizeF
|
||||||
from PyQt5.QtGui import QIcon
|
from PyQt5.QtGui import QIcon
|
||||||
from PyQt5.QtWidgets import QWidget, QLayout
|
from PyQt5.QtWidgets import QWidget, QLayout
|
||||||
|
|
||||||
@ -482,6 +482,7 @@ class AbstractTab(QWidget):
|
|||||||
new_tab_requested = pyqtSignal(QUrl)
|
new_tab_requested = pyqtSignal(QUrl)
|
||||||
url_changed = pyqtSignal(QUrl)
|
url_changed = pyqtSignal(QUrl)
|
||||||
shutting_down = pyqtSignal()
|
shutting_down = pyqtSignal()
|
||||||
|
contents_size_changed = pyqtSignal(QSizeF)
|
||||||
|
|
||||||
def __init__(self, win_id, parent=None):
|
def __init__(self, win_id, parent=None):
|
||||||
self.win_id = win_id
|
self.win_id = win_id
|
||||||
|
@ -64,8 +64,6 @@ class HintContext:
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
frames: The QWebFrames to use.
|
frames: The QWebFrames to use.
|
||||||
destroyed_frames: id()'s of QWebFrames which have been destroyed.
|
|
||||||
(Workaround for https://github.com/The-Compiler/qutebrowser/issues/152)
|
|
||||||
all_elems: A list of all (elem, label) namedtuples ever created.
|
all_elems: A list of all (elem, label) namedtuples ever created.
|
||||||
elems: A mapping from key strings to (elem, label) namedtuples.
|
elems: A mapping from key strings to (elem, label) namedtuples.
|
||||||
May contain less elements than `all_elems` due to filtering.
|
May contain less elements than `all_elems` due to filtering.
|
||||||
@ -95,7 +93,6 @@ class HintContext:
|
|||||||
self.to_follow = None
|
self.to_follow = None
|
||||||
self.rapid = False
|
self.rapid = False
|
||||||
self.frames = []
|
self.frames = []
|
||||||
self.destroyed_frames = []
|
|
||||||
self.args = []
|
self.args = []
|
||||||
self.mainframe = None
|
self.mainframe = None
|
||||||
self.tab = None
|
self.tab = None
|
||||||
@ -179,22 +176,6 @@ class HintManager(QObject):
|
|||||||
elem.label.removeFromDocument()
|
elem.label.removeFromDocument()
|
||||||
except webelem.IsNullError:
|
except webelem.IsNullError:
|
||||||
pass
|
pass
|
||||||
for f in self._context.frames:
|
|
||||||
log.hints.debug("Disconnecting frame {}".format(f))
|
|
||||||
if id(f) in self._context.destroyed_frames:
|
|
||||||
# WORKAROUND for
|
|
||||||
# https://github.com/The-Compiler/qutebrowser/issues/152
|
|
||||||
log.hints.debug("Frame has been destroyed, ignoring.")
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
f.contentsSizeChanged.disconnect(self.on_contents_size_changed)
|
|
||||||
except TypeError:
|
|
||||||
# It seems we can get this here:
|
|
||||||
# TypeError: disconnect() failed between
|
|
||||||
# 'contentsSizeChanged' and 'on_contents_size_changed'
|
|
||||||
# See # https://github.com/The-Compiler/qutebrowser/issues/263
|
|
||||||
pass
|
|
||||||
log.hints.debug("Disconnected.")
|
|
||||||
text = self._get_text()
|
text = self._get_text()
|
||||||
message_bridge = objreg.get('message-bridge', scope='window',
|
message_bridge = objreg.get('message-bridge', scope='window',
|
||||||
window=self._win_id)
|
window=self._win_id)
|
||||||
@ -656,12 +637,6 @@ class HintManager(QObject):
|
|||||||
log.hints.vdebug("No match on '{}'!".format(text))
|
log.hints.vdebug("No match on '{}'!".format(text))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _connect_frame_signals(self):
|
|
||||||
"""Connect the contentsSizeChanged signals to all frames."""
|
|
||||||
for f in self._context.frames:
|
|
||||||
log.hints.debug("Connecting frame {}".format(f))
|
|
||||||
f.contentsSizeChanged.connect(self.on_contents_size_changed)
|
|
||||||
|
|
||||||
def _check_args(self, target, *args):
|
def _check_args(self, target, *args):
|
||||||
"""Check the arguments passed to start() and raise if they're wrong.
|
"""Check the arguments passed to start() and raise if they're wrong.
|
||||||
|
|
||||||
@ -847,11 +822,6 @@ class HintManager(QObject):
|
|||||||
except qtutils.QtValueError:
|
except qtutils.QtValueError:
|
||||||
raise cmdexc.CommandError("No URL set for this page yet!")
|
raise cmdexc.CommandError("No URL set for this page yet!")
|
||||||
self._context.frames = webelem.get_child_frames(mainframe)
|
self._context.frames = webelem.get_child_frames(mainframe)
|
||||||
for frame in self._context.frames:
|
|
||||||
# WORKAROUND for
|
|
||||||
# https://github.com/The-Compiler/qutebrowser/issues/152
|
|
||||||
frame.destroyed.connect(functools.partial(
|
|
||||||
self._context.destroyed_frames.append, id(frame)))
|
|
||||||
self._context.args = args
|
self._context.args = args
|
||||||
self._context.mainframe = mainframe
|
self._context.mainframe = mainframe
|
||||||
self._context.group = group
|
self._context.group = group
|
||||||
|
@ -425,3 +425,7 @@ class WebEngineTab(browsertab.AbstractTab):
|
|||||||
view.iconChanged.connect(self.icon_changed)
|
view.iconChanged.connect(self.icon_changed)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
log.stub('iconChanged, on Qt < 5.7')
|
log.stub('iconChanged, on Qt < 5.7')
|
||||||
|
try:
|
||||||
|
page.contentsSizeChanged.connect(self.contents_size_changed)
|
||||||
|
except AttributeError:
|
||||||
|
log.stub('contentsSizeChanged, on Qt < 5.7')
|
||||||
|
@ -25,7 +25,7 @@ import xml.etree.ElementTree
|
|||||||
|
|
||||||
from PyQt5.QtCore import pyqtSlot, Qt, QEvent, QUrl, QPoint, QTimer
|
from PyQt5.QtCore import pyqtSlot, Qt, QEvent, QUrl, QPoint, QTimer
|
||||||
from PyQt5.QtGui import QKeyEvent
|
from PyQt5.QtGui import QKeyEvent
|
||||||
from PyQt5.QtWebKitWidgets import QWebPage
|
from PyQt5.QtWebKitWidgets import QWebPage, QWebFrame
|
||||||
from PyQt5.QtWebKit import QWebSettings
|
from PyQt5.QtWebKit import QWebSettings
|
||||||
from PyQt5.QtPrintSupport import QPrinter
|
from PyQt5.QtPrintSupport import QPrinter
|
||||||
|
|
||||||
@ -572,6 +572,14 @@ class WebKitTab(browsertab.AbstractTab):
|
|||||||
"""Emit iconChanged with a QIcon like QWebEngineView does."""
|
"""Emit iconChanged with a QIcon like QWebEngineView does."""
|
||||||
self.icon_changed.emit(self._widget.icon())
|
self.icon_changed.emit(self._widget.icon())
|
||||||
|
|
||||||
|
@pyqtSlot(QWebFrame)
|
||||||
|
def _on_frame_created(self, frame):
|
||||||
|
"""Connect the contentsSizeChanged signal of each frame."""
|
||||||
|
# FIXME:qtwebengine those could theoretically regress:
|
||||||
|
# https://github.com/The-Compiler/qutebrowser/issues/152
|
||||||
|
# https://github.com/The-Compiler/qutebrowser/issues/263
|
||||||
|
frame.contentsSizeChanged.connect(self.contents_size_changed)
|
||||||
|
|
||||||
def _connect_signals(self):
|
def _connect_signals(self):
|
||||||
view = self._widget
|
view = self._widget
|
||||||
page = view.page()
|
page = view.page()
|
||||||
|
Loading…
Reference in New Issue
Block a user