Combine hint signals into a single one
This commit is contained in:
parent
39fd6a6062
commit
eabac17c58
@ -21,7 +21,7 @@
|
||||
|
||||
import itertools
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QUrl, QObject, QSizeF
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QUrl, QObject, QSizeF, QTimer
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtWidgets import QWidget
|
||||
|
||||
@ -60,7 +60,7 @@ class WebTabError(Exception):
|
||||
"""Base class for various errors."""
|
||||
|
||||
|
||||
class TabData(QObject):
|
||||
class TabData:
|
||||
|
||||
"""A simple namespace with a fixed set of attributes.
|
||||
|
||||
@ -73,8 +73,7 @@ class TabData(QObject):
|
||||
hint_target: Override for open_target for hints.
|
||||
"""
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
def __init__(self):
|
||||
self.keep_icon = False
|
||||
self.viewing_source = False
|
||||
self.inspector = None
|
||||
@ -87,21 +86,6 @@ class TabData(QObject):
|
||||
else:
|
||||
return self.open_target
|
||||
|
||||
@pyqtSlot(usertypes.ClickTarget)
|
||||
def _on_start_hinting(self, hint_target):
|
||||
"""Emitted before a hinting-click takes place.
|
||||
|
||||
Args:
|
||||
hint_target: A ClickTarget member to set self.hint_target to.
|
||||
"""
|
||||
log.webview.debug("Setting force target to {}".format(hint_target))
|
||||
self.hint_target = hint_target
|
||||
|
||||
@pyqtSlot()
|
||||
def _on_stop_hinting(self):
|
||||
log.webview.debug("Finishing hinting.")
|
||||
self.hint_target = None
|
||||
|
||||
|
||||
class AbstractPrinting:
|
||||
|
||||
@ -489,7 +473,7 @@ class AbstractTab(QWidget):
|
||||
# self.search = AbstractSearch(parent=self)
|
||||
# self.printing = AbstractPrinting()
|
||||
|
||||
self.data = TabData(parent=self)
|
||||
self.data = TabData()
|
||||
self._layout = miscwidgets.WrapperLayout(self)
|
||||
self._widget = None
|
||||
self._progress = 0
|
||||
@ -501,11 +485,7 @@ class AbstractTab(QWidget):
|
||||
# FIXME:qtwebengine Should this be public api via self.hints?
|
||||
# Also, should we get it out of objreg?
|
||||
hintmanager = hints.HintManager(win_id, self.tab_id, parent=self)
|
||||
hintmanager.mouse_event.connect(self._on_hint_mouse_event)
|
||||
# pylint: disable=protected-access
|
||||
hintmanager.start_hinting.connect(self.data._on_start_hinting)
|
||||
hintmanager.stop_hinting.connect(self.data._on_stop_hinting)
|
||||
# pylint: enable=protected-access
|
||||
hintmanager.hint_events.connect(self._on_hint_events)
|
||||
objreg.register('hintmanager', hintmanager, scope='tab',
|
||||
window=self.win_id, tab=self.tab_id)
|
||||
|
||||
@ -536,15 +516,20 @@ class AbstractTab(QWidget):
|
||||
"""Send the given event to the underlying widget."""
|
||||
raise NotImplementedError
|
||||
|
||||
@pyqtSlot('QMouseEvent')
|
||||
def _on_hint_mouse_event(self, evt):
|
||||
@pyqtSlot(usertypes.ClickTarget, list)
|
||||
def _on_hint_events(self, target, events):
|
||||
"""Post a new mouse event from a hintmanager."""
|
||||
# FIXME:qtwebengine Will this implementation work for QtWebEngine?
|
||||
# We probably need to send the event to the
|
||||
# focusProxy()?
|
||||
log.modes.debug("Hint triggered, focusing {!r}".format(self))
|
||||
log.modes.debug("Sending hint events to {!r} with target {}".format(
|
||||
self, target))
|
||||
self._widget.setFocus()
|
||||
self.post_event(evt)
|
||||
self.data.hint_target = target
|
||||
|
||||
for evt in events:
|
||||
self.post_event(evt)
|
||||
|
||||
def reset_target():
|
||||
self.data.hint_target = None
|
||||
QTimer.singleShot(0, reset_target)
|
||||
|
||||
@pyqtSlot(QUrl)
|
||||
def _on_link_clicked(self, url):
|
||||
|
@ -185,16 +185,10 @@ class HintActions(QObject):
|
||||
"""Actions which can be done after selecting a hint.
|
||||
|
||||
Signals:
|
||||
mouse_event: Mouse event to be posted in the web view.
|
||||
arg: A QMouseEvent
|
||||
start_hinting: Emitted when hinting starts, before a link is clicked.
|
||||
arg: The ClickTarget to use.
|
||||
stop_hinting: Emitted after a link was clicked.
|
||||
hint_events: Emitted with a ClickTarget and a list of hint event.s
|
||||
"""
|
||||
|
||||
mouse_event = pyqtSignal('QMouseEvent')
|
||||
start_hinting = pyqtSignal(usertypes.ClickTarget)
|
||||
stop_hinting = pyqtSignal()
|
||||
hint_events = pyqtSignal(usertypes.ClickTarget, list) # QMouseEvent list
|
||||
|
||||
def __init__(self, win_id, parent=None):
|
||||
super().__init__(parent)
|
||||
@ -235,7 +229,6 @@ class HintActions(QObject):
|
||||
log.hints.debug("{} on '{}' at position {}".format(
|
||||
action, elem.debug_text(), pos))
|
||||
|
||||
self.start_hinting.emit(target_mapping[context.target])
|
||||
if context.target in [Target.tab, Target.tab_fg, Target.tab_bg,
|
||||
Target.window]:
|
||||
modifiers = Qt.ControlModifier
|
||||
@ -261,11 +254,10 @@ class HintActions(QObject):
|
||||
|
||||
if context.target == Target.current:
|
||||
elem.remove_blank_target()
|
||||
for evt in events:
|
||||
self.mouse_event.emit(evt)
|
||||
|
||||
self.hint_events.emit(target_mapping[context.target], events)
|
||||
if elem.is_text_input() and elem.is_editable():
|
||||
QTimer.singleShot(0, context.tab.caret.move_to_end_of_document)
|
||||
QTimer.singleShot(0, self.stop_hinting.emit)
|
||||
|
||||
def yank(self, url, context):
|
||||
"""Yank an element to the clipboard or primary selection.
|
||||
@ -408,9 +400,7 @@ class HintManager(QObject):
|
||||
Target.spawn: "Spawn command via hint",
|
||||
}
|
||||
|
||||
mouse_event = pyqtSignal('QMouseEvent')
|
||||
start_hinting = pyqtSignal(usertypes.ClickTarget)
|
||||
stop_hinting = pyqtSignal()
|
||||
hint_events = pyqtSignal(usertypes.ClickTarget, list) # QMouseEvent list
|
||||
|
||||
def __init__(self, win_id, tab_id, parent=None):
|
||||
"""Constructor."""
|
||||
@ -421,9 +411,7 @@ class HintManager(QObject):
|
||||
self._word_hinter = WordHinter()
|
||||
|
||||
self._actions = HintActions(win_id)
|
||||
self._actions.start_hinting.connect(self.start_hinting)
|
||||
self._actions.stop_hinting.connect(self.stop_hinting)
|
||||
self._actions.mouse_event.connect(self.mouse_event)
|
||||
self._actions.hint_events.connect(self.hint_events)
|
||||
|
||||
mode_manager = objreg.get('mode-manager', scope='window',
|
||||
window=win_id)
|
||||
|
Loading…
Reference in New Issue
Block a user