Skip to content Skip to sidebar Skip to footer

Pyside Signal "duplicating" Behavior

from PySide.QtCore import * class Eggs(QObject): evt_spam = Signal() print 'Loaded' a = Eggs() b = Eggs() print a.evt_spam print b.evt_spam print a.evt_spam is b.evt_spam

Solution 1:

It's not being printed when you create a class instance, but rather when the class scope is executed. This code will print "Loaded", even though I never made an instance of "Test".

classTest:
    print"Loaded"

If you want to run code when the class is initialized, take a look at __init__(). This code will print "Loaded" when an instance is made, instead of when the class itself is defined.

classTest:
    def__init__(self):
        print"Loaded"

QT's QObject metaclass appears to be rewriting the class attributes to prevent duplicate signals when you initialize a new instance of the class. Perhaps you can assign the attribute like this:

classTest(QObject):def__init__(self, signal):
        self.evt_spam = signal

sig = Signal()
a = Test(sig)
b = Test(sig)

Or this:

classTest(QObject):defsignal(self, signal):
        self.evt_spam = evt_spam
        returnself

evt_spam = Signal()
a = Test().signal(evt_spam)
b = Test().signal(evt_spam)

Post a Comment for "Pyside Signal "duplicating" Behavior"