Fix empty command handling
This commit is contained in:
parent
4e9527fb4c
commit
b14f3f63c5
@ -9,7 +9,7 @@ def main():
|
|||||||
|
|
||||||
mw = MainWindow()
|
mw = MainWindow()
|
||||||
cp = cmdutils.CommandParser()
|
cp = cmdutils.CommandParser()
|
||||||
kp = KeyParser()
|
kp = KeyParser(mw)
|
||||||
kp.set_cmd_text.connect(mw.status.cmd.set_cmd)
|
kp.set_cmd_text.connect(mw.status.cmd.set_cmd)
|
||||||
mw.status.cmd.got_cmd.connect(cp.parse)
|
mw.status.cmd.got_cmd.connect(cp.parse)
|
||||||
mw.status.cmd.got_cmd.connect(mw.setFocus)
|
mw.status.cmd.got_cmd.connect(mw.setFocus)
|
||||||
@ -23,7 +23,7 @@ def main():
|
|||||||
cmds['tabclose'].signal.connect(mw.tabs.close_act)
|
cmds['tabclose'].signal.connect(mw.tabs.close_act)
|
||||||
cmds['tabprev'].signal.connect(mw.tabs.switch_prev)
|
cmds['tabprev'].signal.connect(mw.tabs.switch_prev)
|
||||||
cmds['tabnext'].signal.connect(mw.tabs.switch_next)
|
cmds['tabnext'].signal.connect(mw.tabs.switch_next)
|
||||||
kp.from_cmd_dict(cmds, mw)
|
kp.from_cmd_dict(cmds)
|
||||||
|
|
||||||
mw.show()
|
mw.show()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
from PyQt5.QtCore import pyqtSignal
|
from PyQt5.QtCore import pyqtSignal
|
||||||
from qutebrowser.commands.utils import Command
|
from qutebrowser.commands.utils import Command
|
||||||
|
|
||||||
class Empty(Command):
|
|
||||||
nargs = 0
|
|
||||||
name = ''
|
|
||||||
key = ':'
|
|
||||||
|
|
||||||
class Open(Command):
|
class Open(Command):
|
||||||
nargs = 1
|
nargs = 1
|
||||||
key = 'o'
|
key = 'o'
|
||||||
|
@ -3,14 +3,23 @@ from PyQt5.QtWidgets import QShortcut
|
|||||||
from PyQt5.QtGui import QKeySequence
|
from PyQt5.QtGui import QKeySequence
|
||||||
|
|
||||||
class KeyParser(QObject):
|
class KeyParser(QObject):
|
||||||
|
keyparent = None
|
||||||
set_cmd_text = pyqtSignal(str)
|
set_cmd_text = pyqtSignal(str)
|
||||||
id_to_cmd = {}
|
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():
|
for cmd in d.values():
|
||||||
if cmd.key is not None:
|
if cmd.key is not None:
|
||||||
print('reg: {} -> {}'.format(cmd.name, cmd.key))
|
print('reg: {} -> {}'.format(cmd.name, cmd.key))
|
||||||
sc = QShortcut(parent)
|
sc = QShortcut(self.keyparent)
|
||||||
sc.setKey(QKeySequence(cmd.key))
|
sc.setKey(QKeySequence(cmd.key))
|
||||||
sc.setContext(Qt.WidgetWithChildrenShortcut)
|
sc.setContext(Qt.WidgetWithChildrenShortcut)
|
||||||
sc.activated.connect(self.handle)
|
sc.activated.connect(self.handle)
|
||||||
@ -22,3 +31,6 @@ class KeyParser(QObject):
|
|||||||
self.set_cmd_text.emit(':{} '.format(cmd.name))
|
self.set_cmd_text.emit(':{} '.format(cmd.name))
|
||||||
else:
|
else:
|
||||||
cmd.run()
|
cmd.run()
|
||||||
|
|
||||||
|
def handle_empty(self):
|
||||||
|
self.set_cmd_text.emit(':')
|
||||||
|
Loading…
Reference in New Issue
Block a user