0

I need to create a method in a foreign PyQt5 window class at runtime (that will be called later from a different thread with QMetaObject.invokeMethod()). Therefore I cannot use the decorator style. Is there a way to write this around with function calls?

I've learned that this is easy with simple decorators, but the pyqtSlot() has arguments of it's own.

I've come so far:

class win(QMainWindow):
    def __init__(): ...

def fn(self, op): ...

a = win()
a.fn = types.MethodType(fn, a)
a.decofn = pyqtSlot(list)

Now I'm looking for the correct way to pass the original function a.fn to a.decofn, which at this point doesn't yet know about it, right?

3
  • The def fn function should be indentation the class instance module. Commented Jul 8 at 20:07
  • That's what the types.MethodType line accomplishes. The topic is all about getting this function into the class AT RUNTIME, and "decorating" it there (also at runtime). BTW: Decorating it outside and then moving it inside doesn't work (for not very obvious reasons) Commented Jul 9 at 7:14
  • The decorator should not be applied to an instance of the class but to the class, which is why it fails.
    – eyllanesc
    Commented Jul 9 at 21:00

0