1 from __future__
import print_function
3 from gi
.repository
import GObject
6 class C(GObject
.GObject
):
7 @GObject.Signal(arg_types
=(int,))
8 def my_signal(self
, arg
):
9 """Decorator style signal which uses the method name as signal name and
10 the method as the closure.
12 Note that with python3 annotations can be used for argument types as follows:
14 def my_signal(self, arg:int):
17 print("C: class closure for `my_signal' called with argument", arg
)
20 def noarg_signal(self
):
21 """Decoration of a signal using all defaults and no arguments."""
22 print("C: class closure for `noarg_signal' called")
26 def do_my_signal(self
, arg
):
27 print("D: class closure for `my_signal' called. Chaining up to C")
28 C
.my_signal(self
, arg
)
31 def my_signal_handler(obj
, arg
, *extra
):
32 print("handler for `my_signal' called with argument", arg
, "and extra args", extra
)
38 inst
.connect("my_signal", my_signal_handler
, 1, 2, 3)
39 inst
.connect("noarg_signal", my_signal_handler
, 1, 2, 3)
40 inst
.emit("my_signal", 42)
41 inst
.emit("noarg_signal")
42 inst2
.emit("my_signal", 42)