-
Suggestion
-
Resolution: Won't Do
-
Not Evaluated
-
None
-
None
-
None
Sometimes one needs slot arguments to be overloaded. Currently, this requires multiple decorators to be defined inside the application code, which can become very cumbersome.
Therefore, I suggest supporting argument lists in addition to individual arguments, for example:
@Slot(str, [str, list, MyItem], [None, QJSValue, dict], return=[bool, str])
def mySlot(arg1, arg2, arg3):
...
The above code would accept a string as first argument, str, list or MyItem as second argument, the third argument would be optional and support `QJSValue as well as a dict and the return types could be bool or a string.
I've implemented this feature here
import itertools from PySide6.QtCore import Slot as QtSlot class Slot: """ Makes creating Qt Slots with multiple different signatures easier. """ def __init__(self, *args, **kwargs): self.args = args self.kwargs = kwargs def __call__(self, func): new_args = list( itertools.product( *[arg if isinstance(arg, list) else [arg] for arg in self.args] ) ) filtered_new_args = [ [arg for arg in new_arg if arg is not None] for new_arg in new_args ] for new_arg in filtered_new_args: func = QtSlot(*new_arg, **self.kwargs)(func) return func