Custom signals and slots using pya

edited August 1 in Python scripting


I am trying to create new class derived from QObject and emit signals from it. However, I can't find any documentation or examples about how to do that properly. Can someone please help with that?

Something like

import pya
class MyClass(pya.QObject):
  def __init__(self, parent = None):
    self.signal = ...Something...

  def doAction(self)
    self.signal.emit("Signal argument")

def receive(v):
    print(f"Received: {v}")

def main():
   c = MyClass()

if __name__=="__main__":

Hopefully to get "Signal argument" in console log.



  • edited August 3

    Hi Alex,

    signals and slots are concepts Qt introduced for supporting dynamic code paths in C++, which is a (extremely) static language.

    You do not need signals and slots and dynamic languages like Python. Just use instance method objects, lambdas or simply duck typing to achieve the same effect.

    Signals and slots are supported in KLayout, because they are needed for interfacing with the native Qt objects, that's all. There is no support for defining new signals. Slots for native signals are implemented by simply attaching an instance method to a native signal. So there is also no need for defining custom slots.


  • Thank you!

Sign In or Register to comment.