summaryrefslogtreecommitdiff
path: root/examples/signal.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/signal.py')
-rw-r--r--examples/signal.py39
1 files changed, 28 insertions, 11 deletions
diff --git a/examples/signal.py b/examples/signal.py
index d1b7357..69c1d62 100644
--- a/examples/signal.py
+++ b/examples/signal.py
@@ -1,25 +1,42 @@
+from __future__ import print_function
+
from gi.repository import GObject
+
class C(GObject.GObject):
- __gsignals__ = {
- 'my_signal': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE,
- (GObject.TYPE_INT,))
- }
- def do_my_signal(self, arg):
- print "C: class closure for `my_signal' called with argument", arg
+ @GObject.Signal(arg_types=(int,))
+ def my_signal(self, arg):
+ """Decorator style signal which uses the method name as signal name and
+ the method as the closure.
+
+ Note that with python3 annotations can be used for argument types as follows:
+ @GObject.Signal
+ def my_signal(self, arg:int):
+ pass
+ """
+ print("C: class closure for `my_signal' called with argument", arg)
+
+ @GObject.Signal
+ def noarg_signal(self):
+ """Decoration of a signal using all defaults and no arguments."""
+ print("C: class closure for `noarg_signal' called")
+
class D(C):
def do_my_signal(self, arg):
- print "D: class closure for `my_signal' called. Chaining up to C"
- C.do_my_signal(self, arg)
+ print("D: class closure for `my_signal' called. Chaining up to C")
+ C.my_signal(self, arg)
+
+
+def my_signal_handler(obj, arg, *extra):
+ print("handler for `my_signal' called with argument", arg, "and extra args", extra)
-def my_signal_handler(object, arg, *extra):
- print "handler for `my_signal' called with argument", arg, \
- "and extra args", extra
inst = C()
inst2 = D()
inst.connect("my_signal", my_signal_handler, 1, 2, 3)
+inst.connect("noarg_signal", my_signal_handler, 1, 2, 3)
inst.emit("my_signal", 42)
+inst.emit("noarg_signal")
inst2.emit("my_signal", 42)