Start implementing decorator
This commit is contained in:
parent
d4df78b75f
commit
dcc3993091
@ -40,23 +40,13 @@ class Command(QObject):
|
|||||||
# we should probably have some kind of typing / argument casting for args
|
# we should probably have some kind of typing / argument casting for args
|
||||||
# this might be combined with help texts or so as well
|
# this might be combined with help texts or so as well
|
||||||
|
|
||||||
nargs = 0
|
def __init__(self, name, split_args, hide, nargs, handler):
|
||||||
name = None
|
|
||||||
mainname = None
|
|
||||||
signal = None
|
|
||||||
count = False
|
|
||||||
split_args = True
|
|
||||||
signal = pyqtSignal(tuple)
|
|
||||||
hide = False
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
if self.name is None:
|
self.name = name
|
||||||
self.name = self.__class__.__name__.lower()
|
self.split_args = split_args
|
||||||
if isinstance(self.name, str):
|
self.hide = hide
|
||||||
self.mainname = self.name
|
self.nargs = nargs
|
||||||
else:
|
self.handler = handler
|
||||||
self.mainname = self.name[0]
|
|
||||||
|
|
||||||
def check(self, args):
|
def check(self, args):
|
||||||
"""Check if the argument count is valid.
|
"""Check if the argument count is valid.
|
||||||
|
@ -47,6 +47,23 @@ def register_all():
|
|||||||
cmd_dict[n] = obj
|
cmd_dict[n] = obj
|
||||||
|
|
||||||
|
|
||||||
|
def register_cmd(func, name=None, split_args=True, hide=False):
|
||||||
|
"""Decorator to register a new command handler."""
|
||||||
|
global cmd_dict
|
||||||
|
names = []
|
||||||
|
if name is None:
|
||||||
|
name = func.__name__.lower()
|
||||||
|
if isinstance(name, str):
|
||||||
|
mainname = name
|
||||||
|
names.append(name)
|
||||||
|
else:
|
||||||
|
mainname = name[0]
|
||||||
|
names += name
|
||||||
|
cmd = Command(mainname, split_args, hide, handler=func)
|
||||||
|
for name in names:
|
||||||
|
cmd_dict[name] = cmd
|
||||||
|
|
||||||
|
|
||||||
class SearchParser(QObject):
|
class SearchParser(QObject):
|
||||||
|
|
||||||
"""Parse qutebrowser searches.
|
"""Parse qutebrowser searches.
|
||||||
|
Loading…
Reference in New Issue
Block a user