From 61c90f293c5426f64774def6cef564c11337bf40 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 17 Jan 2014 10:57:27 +0100 Subject: [PATCH] Split commands to commands/utils --- qutebrowser/app.py | 23 +++++---- qutebrowser/commands/commands.py | 42 ++++++++++++++++ .../{commands.py => commands/utils.py} | 49 ++----------------- 3 files changed, 59 insertions(+), 55 deletions(-) create mode 100644 qutebrowser/commands/commands.py rename qutebrowser/{commands.py => commands/utils.py} (61%) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 2e8894751..1e2e01410 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -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_()) diff --git a/qutebrowser/commands/commands.py b/qutebrowser/commands/commands.py new file mode 100644 index 000000000..3f2f41d58 --- /dev/null +++ b/qutebrowser/commands/commands.py @@ -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() diff --git a/qutebrowser/commands.py b/qutebrowser/commands/utils.py similarity index 61% rename from qutebrowser/commands.py rename to qutebrowser/commands/utils.py index 63f0f4579..e243408c4 100644 --- a/qutebrowser/commands.py +++ b/qutebrowser/commands/utils.py @@ -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()