Imported Upstream version 3.3.1
[platform/upstream/pygobject2.git] / examples / signal.py
1 from gi.repository import GObject
2
3
4 class C(GObject.GObject):
5     __gsignals__ = {
6         'my_signal': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE,
7                       (GObject.TYPE_INT,))
8     }
9
10     def do_my_signal(self, arg):
11         print "C: class closure for `my_signal' called with argument", arg
12
13
14 class D(C):
15     def do_my_signal(self, arg):
16         print "D: class closure for `my_signal' called.  Chaining up to C"
17         C.do_my_signal(self, arg)
18
19
20 def my_signal_handler(object, arg, *extra):
21     print "handler for `my_signal' called with argument", arg, \
22           "and extra args", extra
23
24 inst = C()
25 inst2 = D()
26
27 inst.connect("my_signal", my_signal_handler, 1, 2, 3)
28 inst.emit("my_signal", 42)
29 inst2.emit("my_signal", 42)