Split commands to commands/utils
This commit is contained in:
parent
bcc2fa9653
commit
61c90f293c
@ -2,25 +2,28 @@ import sys
|
||||
from PyQt5.QtWidgets import QWidget, QApplication
|
||||
from qutebrowser.widgets.mainwindow import MainWindow
|
||||
from qutebrowser.keys import KeyParser
|
||||
import qutebrowser.commands as cmds
|
||||
import qutebrowser.commands.utils as cmdutils
|
||||
|
||||
def main():
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
mw = MainWindow()
|
||||
cp = cmds.CommandParser()
|
||||
cp = cmdutils.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)
|
||||
cp.error.connect(mw.status.disp_error)
|
||||
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
|
||||
cmds.cmd_dict['tabclose'].signal.connect(mw.tabs.close_act)
|
||||
cmds.cmd_dict['tabprev'].signal.connect(mw.tabs.switch_prev)
|
||||
cmds.cmd_dict['tabnext'].signal.connect(mw.tabs.switch_next)
|
||||
kp.from_cmd_dict(cmds.cmd_dict, mw)
|
||||
mw.show()
|
||||
|
||||
cmdutils.register_all()
|
||||
cmds = cmdutils.cmd_dict
|
||||
cmds['open'].signal.connect(mw.tabs.openurl)
|
||||
cmds['tabopen'].signal.connect(mw.tabs.tabopen)
|
||||
cmds['quit'].signal.connect(QApplication.closeAllWindows) # FIXME
|
||||
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)
|
||||
|
||||
mw.show()
|
||||
sys.exit(app.exec_())
|
||||
|
42
qutebrowser/commands/commands.py
Normal file
42
qutebrowser/commands/commands.py
Normal file
@ -0,0 +1,42 @@
|
||||
from PyQt5.QtCore import pyqtSignal
|
||||
from qutebrowser.commands.utils import Command
|
||||
|
||||
class Empty(Command):
|
||||
nargs = 0
|
||||
name = ''
|
||||
key = ':'
|
||||
|
||||
class Open(Command):
|
||||
nargs = 1
|
||||
name = 'open'
|
||||
key = 'o'
|
||||
signal = pyqtSignal(str)
|
||||
|
||||
class TabOpen(Command):
|
||||
nargs = 1
|
||||
name = 'tabopen'
|
||||
key = 'Shift+o'
|
||||
signal = pyqtSignal(str)
|
||||
|
||||
class TabClose(Command):
|
||||
nargs = 0
|
||||
name = 'tabclose'
|
||||
key = 'd'
|
||||
signal = pyqtSignal()
|
||||
|
||||
class TabNext(Command):
|
||||
nargs = 0
|
||||
name = 'tabnext'
|
||||
key = 'Shift+j'
|
||||
signal = pyqtSignal()
|
||||
|
||||
class TabPrev(Command):
|
||||
nargs = 0
|
||||
name = 'tabprev'
|
||||
key = 'Shift+k'
|
||||
signal = pyqtSignal()
|
||||
|
||||
class Quit(Command):
|
||||
nargs = 0
|
||||
name = 'quit'
|
||||
signal = pyqtSignal()
|
@ -1,14 +1,15 @@
|
||||
from PyQt5.QtCore import QObject, pyqtSignal
|
||||
import inspect, sys
|
||||
import qutebrowser.commands.commands
|
||||
|
||||
cmd_dict = {}
|
||||
|
||||
def register_all():
|
||||
def is_cmd(obj):
|
||||
return (inspect.isclass(obj) and obj.__module__ == __name__ and
|
||||
obj.__name__.endswith('Cmd'))
|
||||
return (inspect.isclass(obj) and
|
||||
obj.__module__ == 'qutebrowser.commands.commands')
|
||||
|
||||
for (name, cls) in inspect.getmembers(sys.modules[__name__], is_cmd):
|
||||
for (name, cls) in inspect.getmembers(commands, is_cmd):
|
||||
cls.bind()
|
||||
|
||||
class CommandParser(QObject):
|
||||
@ -57,45 +58,3 @@ class Command(QObject):
|
||||
self.signal.emit(argv[0])
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
class EmptyCmd(Command):
|
||||
nargs = 0
|
||||
name = ''
|
||||
key = ':'
|
||||
|
||||
class OpenCmd(Command):
|
||||
nargs = 1
|
||||
name = 'open'
|
||||
key = 'o'
|
||||
signal = pyqtSignal(str)
|
||||
|
||||
class TabOpenCmd(Command):
|
||||
nargs = 1
|
||||
name = 'tabopen'
|
||||
key = 'Shift+o'
|
||||
signal = pyqtSignal(str)
|
||||
|
||||
class TabCloseCmd(Command):
|
||||
nargs = 0
|
||||
name = 'tabclose'
|
||||
key = 'd'
|
||||
signal = pyqtSignal()
|
||||
|
||||
class TabNextCmd(Command):
|
||||
nargs = 0
|
||||
name = 'tabnext'
|
||||
key = 'Shift+j'
|
||||
signal = pyqtSignal()
|
||||
|
||||
class TabPrevCmd(Command):
|
||||
nargs = 0
|
||||
name = 'tabprev'
|
||||
key = 'Shift+k'
|
||||
signal = pyqtSignal()
|
||||
|
||||
class QuitCmd(Command):
|
||||
nargs = 0
|
||||
name = 'quit'
|
||||
signal = pyqtSignal()
|
||||
|
||||
register_all()
|
Loading…
Reference in New Issue
Block a user