diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 9e5f01758..9a4e304ee 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -49,7 +49,6 @@ import qutebrowser.config.config as config import qutebrowser.network.qutescheme as qutescheme import qutebrowser.config.websettings as websettings import qutebrowser.network.proxy as proxy -import qutebrowser.utils.message as message import qutebrowser.browser.quickmarks as quickmarks from qutebrowser.network.networkmanager import NetworkManager from qutebrowser.config.config import ConfigManager @@ -60,13 +59,11 @@ from qutebrowser.keyinput.modeparsers import (NormalKeyParser, HintKeyParser, PromptKeyParser) from qutebrowser.keyinput.keyparser import PassthroughKeyParser from qutebrowser.commands.managers import CommandManager, SearchManager -from qutebrowser.commands.exceptions import CommandError from qutebrowser.config.iniparsers import ReadWriteConfigParser from qutebrowser.config.lineparser import LineConfigParser from qutebrowser.browser.cookies import CookieJar from qutebrowser.utils.message import MessageBridge -from qutebrowser.utils.misc import (dotted_getattr, get_standard_dir, - actute_warning) +from qutebrowser.utils.misc import get_standard_dir, actute_warning from qutebrowser.utils.readline import ReadlineBridge from qutebrowser.utils.debug import set_trace # pylint: disable=unused-import @@ -142,7 +139,6 @@ class QuteBrowser(QApplication): self.networkmanager = NetworkManager(self.cookiejar) self.commandmanager = CommandManager() self.searchmanager = SearchManager() - self._init_cmds() self.mainwindow = MainWindow() self.modeman.mainwindow = self.mainwindow @@ -310,20 +306,6 @@ class QuteBrowser(QApplication): # pylint: disable=no-member faulthandler.register(signal.SIGUSR1) - def _init_cmds(self): - """Initialisation of the qutebrowser commands. - - Registers all commands and connects their signals. - """ - for key, cmd in sorted(cmdutils.cmd_dict.items()): - cmd.signal.connect(self.command_handler) - if cmd.instance is not None: - func = '.'.join([cmd.instance if cmd.instance else 'app', - cmd.handler.__name__]) - else: - func = cmd.handler.__name__ - logging.debug("Registered command: {} -> {}".format(key, func)) - def _process_init_args(self): """Process initial positional args. @@ -672,30 +654,3 @@ class QuteBrowser(QApplication): """ logging.debug("Shutdown complete, quitting.") self.quit() - - @pyqtSlot(tuple) - def command_handler(self, tpl): - """Handle commands which need an instance.. - - Args: - tpl: An (instance, func, count, args) tuple. - instance: How to get the current instance of the target object - from app.py, as a dotted string, e.g. - 'mainwindow.tabs.cur'. - func: The function name to be called (as string). - count: The count given to the command, or None. - args: A list of arguments given to the command. - """ - (instance, func, count, args) = tpl - if instance == '': - obj = self - else: - obj = dotted_getattr(self, instance) - handler = getattr(obj, func) - try: - if count is not None: - handler(*args, count=count) - else: - handler(*args) - except CommandError as e: - message.error(e) diff --git a/qutebrowser/commands/_command.py b/qutebrowser/commands/_command.py index cdbe41ff4..b53c12eb0 100644 --- a/qutebrowser/commands/_command.py +++ b/qutebrowser/commands/_command.py @@ -21,12 +21,13 @@ import logging from qutebrowser.commands.exceptions import (ArgumentCountError, PrerequisitesError) +from qutebrowser.utils.misc import dotted_getattr -from PyQt5.QtCore import pyqtSignal, QObject, QCoreApplication +from PyQt5.QtCore import QCoreApplication from PyQt5.QtWebKit import QWebSettings -class Command(QObject): +class Command: """Base skeleton for a command. @@ -42,18 +43,12 @@ class Command(QObject): handler: The handler function to call. completion: Completions to use for arguments, as a list of strings. needs_js: Whether the command needs javascript enabled - - Signals: - signal: Gets emitted when something should be called via handle_command - from the app.py context. """ # TODO: # we should probably have some kind of typing / argument casting for args # this might be combined with help texts or so as well - signal = pyqtSignal(tuple) - def __init__(self, name, split, hide, nargs, count, desc, instance, handler, completion, modes, not_modes, needs_js): # I really don't know how to solve this in a better way, I tried. @@ -119,10 +114,6 @@ class Command(QObject): Args: args: Arguments to the command. count: Command repetition count. - - Emit: - signal: When the command has an instance and should be handled from - the app.py context. """ dbgout = ["command called:", self.name] if args: @@ -131,13 +122,18 @@ class Command(QObject): dbgout.append("(count={})".format(count)) logging.debug(' '.join(dbgout)) - if self.instance is not None and self.count and count is not None: - self.signal.emit((self.instance, self.handler.__name__, count, - args)) - elif self.instance is not None: - self.signal.emit((self.instance, self.handler.__name__, None, - args)) - elif count is not None and self.count: - self.handler(*args, count=count) - else: - self.handler(*args) + kwargs = {} + app = QCoreApplication.instance() + + if self.instance is not None: + # Add the 'self' parameter. + if self.instance == '': + obj = app + else: + obj = dotted_getattr(app, self.instance) + args.insert(0, obj) + + if count is not None and self.count: + kwargs = {'count': count} + + self.handler(*args, **kwargs)