Fix empty command handling

This commit is contained in:
Florian Bruhin 2014-01-17 12:00:13 +01:00
parent 4e9527fb4c
commit b14f3f63c5
3 changed files with 16 additions and 9 deletions

View File

@ -9,7 +9,7 @@ def main():
mw = MainWindow()
cp = cmdutils.CommandParser()
kp = KeyParser()
kp = KeyParser(mw)
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)
@ -23,7 +23,7 @@ def main():
cmds['tabclose'].signal.connect(mw.tabs.close_act)
cmds['tabprev'].signal.connect(mw.tabs.switch_prev)
cmds['tabnext'].signal.connect(mw.tabs.switch_next)
kp.from_cmd_dict(cmds, mw)
kp.from_cmd_dict(cmds)
mw.show()
sys.exit(app.exec_())

View File

@ -1,11 +1,6 @@
from PyQt5.QtCore import pyqtSignal
from qutebrowser.commands.utils import Command
class Empty(Command):
nargs = 0
name = ''
key = ':'
class Open(Command):
nargs = 1
key = 'o'

View File

@ -3,14 +3,23 @@ from PyQt5.QtWidgets import QShortcut
from PyQt5.QtGui import QKeySequence
class KeyParser(QObject):
keyparent = None
set_cmd_text = pyqtSignal(str)
id_to_cmd = {}
def from_cmd_dict(self, d, parent):
def __init__(self, keyparent):
super().__init__()
self.keyparent = keyparent
sc = QShortcut(keyparent)
sc.setKey(QKeySequence(':'))
sc.setContext(Qt.WidgetWithChildrenShortcut)
sc.activated.connect(self.handle_empty)
def from_cmd_dict(self, d):
for cmd in d.values():
if cmd.key is not None:
print('reg: {} -> {}'.format(cmd.name, cmd.key))
sc = QShortcut(parent)
sc = QShortcut(self.keyparent)
sc.setKey(QKeySequence(cmd.key))
sc.setContext(Qt.WidgetWithChildrenShortcut)
sc.activated.connect(self.handle)
@ -22,3 +31,6 @@ class KeyParser(QObject):
self.set_cmd_text.emit(':{} '.format(cmd.name))
else:
cmd.run()
def handle_empty(self):
self.set_cmd_text.emit(':')