Start implementing eventFilter in ModeManager
This commit is contained in:
parent
a33c9827d6
commit
8f44b56923
1
THANKS
1
THANKS
@ -54,6 +54,7 @@ channels:
|
|||||||
- scummos
|
- scummos
|
||||||
- svuorela
|
- svuorela
|
||||||
- kpj
|
- kpj
|
||||||
|
- hyde
|
||||||
|
|
||||||
Thanks to these projects which were essential while developing qutebrowser:
|
Thanks to these projects which were essential while developing qutebrowser:
|
||||||
- Python
|
- Python
|
||||||
|
@ -45,7 +45,7 @@ import qutebrowser.utils.harfbuzz as harfbuzz
|
|||||||
harfbuzz.fix()
|
harfbuzz.fix()
|
||||||
|
|
||||||
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox
|
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox
|
||||||
from PyQt5.QtCore import pyqtSlot, QTimer, QEventLoop
|
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QTimer, QEventLoop, QEvent
|
||||||
|
|
||||||
import qutebrowser
|
import qutebrowser
|
||||||
import qutebrowser.commands.utils as cmdutils
|
import qutebrowser.commands.utils as cmdutils
|
||||||
@ -129,7 +129,8 @@ class QuteBrowser(QApplication):
|
|||||||
}
|
}
|
||||||
self._init_cmds()
|
self._init_cmds()
|
||||||
self.mainwindow = MainWindow()
|
self.mainwindow = MainWindow()
|
||||||
modemanager.init(self.mainwindow.tabs.keypress, self._keyparsers, self)
|
modemanager.init(self._keyparsers, self)
|
||||||
|
self.installEventFilter(modemanager.manager)
|
||||||
self.setQuitOnLastWindowClosed(False)
|
self.setQuitOnLastWindowClosed(False)
|
||||||
|
|
||||||
self._connect_signals()
|
self._connect_signals()
|
||||||
@ -249,6 +250,7 @@ class QuteBrowser(QApplication):
|
|||||||
tabs.currentChanged.connect(self.mainwindow.update_inspector)
|
tabs.currentChanged.connect(self.mainwindow.update_inspector)
|
||||||
|
|
||||||
# status bar
|
# status bar
|
||||||
|
# FIXME what to do here?
|
||||||
tabs.keypress.connect(status.keypress)
|
tabs.keypress.connect(status.keypress)
|
||||||
for obj in [kp["normal"], tabs]:
|
for obj in [kp["normal"], tabs]:
|
||||||
obj.set_cmd_text.connect(cmd.set_cmd_text)
|
obj.set_cmd_text.connect(cmd.set_cmd_text)
|
||||||
|
@ -23,25 +23,24 @@ Module attributes:
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSignal, QObject
|
from PyQt5.QtCore import pyqtSignal, QObject, QEvent
|
||||||
|
|
||||||
|
|
||||||
manager = None
|
manager = None
|
||||||
|
|
||||||
|
|
||||||
def init(source, parsers=None, parent=None):
|
def init(parsers=None, parent=None):
|
||||||
"""Initialize the global ModeManager.
|
"""Initialize the global ModeManager.
|
||||||
|
|
||||||
This needs to be done by hand because the import time is before Qt is ready
|
This needs to be done by hand because the import time is before Qt is ready
|
||||||
for everything.
|
for everything.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
source: The keypress source signal.
|
|
||||||
parsers: A dict of KeyParsers to register.
|
parsers: A dict of KeyParsers to register.
|
||||||
parent: Parent to use for ModeManager.
|
parent: Parent to use for ModeManager.
|
||||||
"""
|
"""
|
||||||
global manager
|
global manager
|
||||||
manager = ModeManager(source, parsers, parent)
|
manager = ModeManager(parsers, parent)
|
||||||
|
|
||||||
|
|
||||||
def enter(mode):
|
def enter(mode):
|
||||||
@ -64,7 +63,6 @@ class ModeManager(QObject):
|
|||||||
"""Manager for keyboard modes.
|
"""Manager for keyboard modes.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
_source: The keypress source signal.
|
|
||||||
_handlers: A dictionary of modes and their handlers.
|
_handlers: A dictionary of modes and their handlers.
|
||||||
mode: The current mode.
|
mode: The current mode.
|
||||||
|
|
||||||
@ -78,15 +76,13 @@ class ModeManager(QObject):
|
|||||||
entered = pyqtSignal(str)
|
entered = pyqtSignal(str)
|
||||||
leaved = pyqtSignal(str)
|
leaved = pyqtSignal(str)
|
||||||
|
|
||||||
def __init__(self, sourcesig, parsers=None, parent=None):
|
def __init__(self, parsers=None, parent=None):
|
||||||
"""Constructor.
|
"""Constructor.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
sourcesig: The signal which gets emitted on a keypress.
|
|
||||||
parsers: A list of parsers to register.
|
parsers: A list of parsers to register.
|
||||||
"""
|
"""
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._source = sourcesig
|
|
||||||
self._handlers = {}
|
self._handlers = {}
|
||||||
self.mode = None
|
self.mode = None
|
||||||
if parsers is not None:
|
if parsers is not None:
|
||||||
@ -112,11 +108,17 @@ class ModeManager(QObject):
|
|||||||
oldmode = self.mode
|
oldmode = self.mode
|
||||||
logging.debug("Switching mode: {} -> {}".format(oldmode, mode))
|
logging.debug("Switching mode: {} -> {}".format(oldmode, mode))
|
||||||
if oldmode is not None:
|
if oldmode is not None:
|
||||||
try:
|
|
||||||
self._source.disconnect(self._handlers[oldmode])
|
|
||||||
except TypeError:
|
|
||||||
logging.debug("Could not disconnect mode {}".format(oldmode))
|
|
||||||
self.leaved.emit(oldmode)
|
self.leaved.emit(oldmode)
|
||||||
self._source.connect(self._handlers[mode])
|
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.entered.emit(mode)
|
self.entered.emit(mode)
|
||||||
|
|
||||||
|
def eventFilter(self, obj, evt):
|
||||||
|
if evt.type() not in [QEvent.KeyPress, QEvent.KeyRelease]:
|
||||||
|
return False
|
||||||
|
elif self.mode == "insert":
|
||||||
|
return False
|
||||||
|
elif evt.type() == QEvent.KeyPress:
|
||||||
|
self._handlers[self.mode](evt)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
@ -28,6 +28,7 @@ from PyQt5.QtWebKitWidgets import QWebView, QWebPage
|
|||||||
import qutebrowser.utils.url as urlutils
|
import qutebrowser.utils.url as urlutils
|
||||||
import qutebrowser.config.config as config
|
import qutebrowser.config.config as config
|
||||||
import qutebrowser.utils.message as message
|
import qutebrowser.utils.message as message
|
||||||
|
import qutebrowser.utils.modemanager as modemanager
|
||||||
from qutebrowser.browser.webpage import BrowserPage
|
from qutebrowser.browser.webpage import BrowserPage
|
||||||
from qutebrowser.browser.hints import HintManager
|
from qutebrowser.browser.hints import HintManager
|
||||||
from qutebrowser.utils.signals import SignalCache
|
from qutebrowser.utils.signals import SignalCache
|
||||||
@ -269,7 +270,7 @@ class BrowserTab(QWebView):
|
|||||||
hitresult = frame.hitTestContent(pos)
|
hitresult = frame.hitTestContent(pos)
|
||||||
if hitresult.isContentEditable():
|
if hitresult.isContentEditable():
|
||||||
logging.debug("Clicked editable element!")
|
logging.debug("Clicked editable element!")
|
||||||
self.setFocus()
|
modemanager.enter("insert")
|
||||||
|
|
||||||
if self._force_open_target is not None:
|
if self._force_open_target is not None:
|
||||||
self._open_target = self._force_open_target
|
self._open_target = self._force_open_target
|
||||||
|
Loading…
Reference in New Issue
Block a user