PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/python/callback/runme.py

#
Python | 56 lines | 29 code | 18 blank | 9 comment | 0 complexity | deeb3da6ac2683766a966f86bc6b0023 MD5 | raw file
 1# file: runme.py
 2
 3# This file illustrates the cross language polymorphism using directors.
 4
 5import example 
 6
 7
 8class PyCallback(example.Callback):
 9	def __init__(self):
10		example.Callback.__init__(self)
11	def run(self):
12		print "PyCallback.run()"
13
14# Create an Caller instance
15
16caller = example.Caller()
17
18# Add a simple C++ callback (caller owns the callback, so
19# we disown it first by clearing the .thisown flag).
20
21print "Adding and calling a normal C++ callback"
22print "----------------------------------------"
23
24callback = example.Callback()
25callback.thisown = 0
26caller.setCallback(callback)
27caller.call()
28caller.delCallback();
29
30print
31print "Adding and calling a Python callback"
32print "------------------------------------"
33
34# Add a Python callback (caller owns the callback, so we
35# disown it first by calling __disown__).
36
37caller.setCallback(PyCallback().__disown__())
38caller.call()
39caller.delCallback()
40
41print
42print "Adding and calling another Python callback"
43print "------------------------------------------"
44
45# Lets do the same but use the weak reference this time.
46
47callback = PyCallback().__disown__()
48caller.setCallback(callback)
49caller.call()
50caller.delCallback()
51
52# All done.
53
54print
55print "python exit"
56