Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2434

Simplify slot argument overload by allowing iteratable as arguments

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Won't Do
    • Icon: Not Evaluated Not Evaluated
    • None
    • None
    • PySide
    • 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

       

       

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            crmaurei Cristian Maureira-Fredes
            machinekoder Alex Roessler
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes