The way you do it is wonderful. If you had a lot of things, you could connect to a new function that handles everything for you.
I noticed that in your connected getValue
functions getValue
you get the value directly from the object; did you know that the value is passed as a parameter with the signal valueChanged(int)
? If you change your getValue
functions to accept an additional parameter, you will not need to get the value directly from the object. Of course, you can end the getValue
function all together and issue a print statement in a helper function.
self.connect(self.dial, SIGNAL("valueChanged(int)"), self.dial_value_changed) self.connect(self.spinbox, SIGNAL("valueChanged(int)"),self.spinbox_value_changed) def dial_value_changed(self, value): self.spinbox.setValue(value) self.getValue_dial(value) def spinbox_value_changed(self, value): self.dial.setValue(value) self.getValue_spinbox(value) def getValue_dial(self, value): print value def getValue_spinbox(self, value): print value
In addition, and it depends on preference, there is a new style for signals and slots that can make the code a little easier to read. It will change
self.connect(self.dial, SIGNAL("valueChanged(int)"), self.dial_value_changed) self.connect(self.spinbox, SIGNAL("valueChanged(int)"),self.spinbox_value_changed)
higher than
self.dial.valueChanged.connect(self.dial_value_changed) self.spinbox.valueChanged.connect(self.spinbox_value_changed)
But for the original question and for the two things you are doing, I just connected the signal twice, instead of having an auxiliary function.
source share