I would like to know if it is possible to make a pyqtSignal() beeing a private signal of a class. The signal can be used inside the class but should not be visible outside of the class.
I tried to prefix my signal name with '_' like you can see in the code sample:
my signal name is _A_valueChanged
but it is still accessible by outside code of the Foo class.
import sys
from PyQt5 import QtCore
from PyQt5.QtCore import *
class Foo(QObject):
_A_valueChanged = pyqtSignal(int)
def __init__(self):
super().__init__()
self._A = 0
self.Linked_to_A = 0
self._A_valueChanged.connect( self.changeLinkedVar )
@property
def A(self):
return self._A
@A.setter
def A(self, value):
self._A = value
self._A_valueChanged.emit(value)
@QtCore.pyqtSlot(int)
def changeLinkedVar( self, value ):
print( "changeAttributeLinked " )
self.Linked_to_A= value
if __name__ == "__main__":
def MainNoticeThat_A_changed():
print( "Main : foo.A has changed ")
foo = Foo()
foo._A_valueChanged.connect( MainNoticeThat_A_changed )
foo.A = 5
print( "main : foo.A = %d , foo.Linked_to_A = %d " %( foo.A, foo.Linked_to_A) )
The signal _A_valueChanged is emitted in def A() of Foo class, and is well captured inside the class Foo and Foo method changeLinkedVar() is well called, updating the attribute self.Linked_to_A. That's wanted.
But in main, foo._A_valueChanged.connect( MainNoticeThat_A_changed )
is working, and MainNoticeThat_A_changed()
is called. That's not wanted.
I would like a python error like 'class Foo has no public signal _A_valueChanged'