Add keybindings
This commit is contained in:
parent
6eaf719298
commit
746e7a90ad
@ -1,6 +1,7 @@
|
||||
import sys
|
||||
from PyQt5.QtWidgets import QWidget, QApplication
|
||||
from qutebrowser.widgets.mainwindow import MainWindow
|
||||
from qutebrowser.keys import KeyParser
|
||||
import qutebrowser.commands as cmds
|
||||
|
||||
def main():
|
||||
@ -8,11 +9,14 @@ def main():
|
||||
|
||||
mw = MainWindow()
|
||||
cp = cmds.CommandParser()
|
||||
kp = KeyParser()
|
||||
kp.set_cmd_text.connect(mw.status.cmd.set_cmd)
|
||||
mw.status.cmd.got_cmd.connect(cp.parse)
|
||||
mw.status.cmd.got_cmd.connect(mw.setFocus)
|
||||
cmds.cmd_dict['open'].signal.connect(mw.tabs.openurl)
|
||||
cmds.cmd_dict['tabopen'].signal.connect(mw.tabs.tabopen)
|
||||
cmds.cmd_dict['quit'].signal.connect(QApplication.closeAllWindows) # FIXME
|
||||
kp.from_cmd_dict(cmds.cmd_dict, mw.tabs)
|
||||
mw.show()
|
||||
|
||||
sys.exit(app.exec_())
|
||||
|
@ -27,6 +27,7 @@ class CommandParser(QObject):
|
||||
class Command(QObject):
|
||||
nargs = 0
|
||||
name = ''
|
||||
key = None
|
||||
signal = None
|
||||
|
||||
@classmethod
|
||||
@ -48,6 +49,7 @@ class Command(QObject):
|
||||
class OpenCmd(Command):
|
||||
nargs = 1
|
||||
name = 'open'
|
||||
key = 'o'
|
||||
signal = pyqtSignal(str)
|
||||
|
||||
def run(self, argv):
|
||||
@ -56,6 +58,7 @@ class OpenCmd(Command):
|
||||
class TabOpenCmd(Command):
|
||||
nargs = 1
|
||||
name = 'tabopen'
|
||||
key = 'Shift+o'
|
||||
signal = pyqtSignal(str)
|
||||
|
||||
def run(self, argv):
|
||||
|
23
qutebrowser/keys.py
Normal file
23
qutebrowser/keys.py
Normal file
@ -0,0 +1,23 @@
|
||||
from PyQt5.QtCore import QObject, Qt, pyqtSignal
|
||||
from PyQt5.QtWidgets import QShortcut
|
||||
from PyQt5.QtGui import QKeySequence
|
||||
|
||||
class KeyParser(QObject):
|
||||
set_cmd_text = pyqtSignal(str)
|
||||
id_to_cmd = {}
|
||||
|
||||
def from_cmd_dict(self, d, parent):
|
||||
for cmd in d.values():
|
||||
if cmd.key is not None:
|
||||
sc = QShortcut(parent)
|
||||
sc.setKey(QKeySequence(cmd.key))
|
||||
sc.setContext(Qt.WidgetWithChildrenShortcut)
|
||||
sc.activated.connect(self.handle)
|
||||
self.id_to_cmd[sc.id()] = cmd
|
||||
|
||||
def handle(self):
|
||||
cmd = self.id_to_cmd[self.sender().id()]
|
||||
text = ':' + cmd.name
|
||||
if cmd.nargs and cmd.nargs != 0:
|
||||
text += ' '
|
||||
self.set_cmd_text.emit(text)
|
@ -47,6 +47,10 @@ class StatusCommand(QLineEdit):
|
||||
self.setText('')
|
||||
self.got_cmd.emit(text)
|
||||
|
||||
def set_cmd(self, text):
|
||||
self.setText(text)
|
||||
self.setFocus()
|
||||
|
||||
class CmdValidator(QValidator):
|
||||
def validate(self, string, pos):
|
||||
if string.startswith(':'):
|
||||
|
Loading…
Reference in New Issue
Block a user