I gather that the way to create custom signals with Python in Gtk 3 is with the GObject.Signal decorator, not with
__gsignal__. Consider this simple test program:
import gi gi.require_version('Gtk', '3.0') from gi.repository import GObject class MyClass(GObject.Object): @GObject.Signal(flags=GObject.SignalFlags.RUN_FIRST) def my_signal(self): print('In my_signal') def do_my_signal(self): print("In do_my_signal") def on_my_signal(obj): print('In on_my_signal', obj) myclass = MyClass() myclass.connect('my_signal', on_my_signal) myclass.emit('my_signal')
When I run this program, I get a response from do_my_signal first and then from on_my_signal. I do not get any output from my_signal (although I do in my actual program). If I change to RUN_LAST then I get output from on_my_signal first and then from do_my_signal.
Does anyone have any general comments on:
When might I want a do_ method? If I need to do something before emitting the signal, could I not just put the necessary statements before the emit statement? The only useful application I can think of is related to handling of events, which do not emanate from a widget and so cannot be connected.
Why might I want to put any statements in a signal other than “pass”? Putting statements there seems equivalent to putting them in a do_ method.
Why is the print statement in my_signal not producing any output in this test program? Here’s the answer: I get output from my_signal only when do_my_signal is not present. Is there a rationale for this behavior?
When does it matter whether I choose RUN_FIRST or RUN_LAST?
Thanks for any comments on these general, philosophical questions.