release
[pygobject.git] / examples / signal.py
blob69c1d6248a379b4ed596976a524c106ee4aca1e4
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:
13 @GObject.Signal
14 def my_signal(self, arg:int):
15 pass
16 """
17 print("C: class closure for `my_signal' called with argument", arg)
19 @GObject.Signal
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")
25 class D(C):
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)
35 inst = C()
36 inst2 = D()
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)