PageRenderTime 42ms CodeModel.GetById 18ms 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
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. # file: runme.py
  2. # This file illustrates the cross language polymorphism using directors.
  3. import example
  4. class PyCallback(example.Callback):
  5. def __init__(self):
  6. example.Callback.__init__(self)
  7. def run(self):
  8. print "PyCallback.run()"
  9. # Create an Caller instance
  10. caller = example.Caller()
  11. # Add a simple C++ callback (caller owns the callback, so
  12. # we disown it first by clearing the .thisown flag).
  13. print "Adding and calling a normal C++ callback"
  14. print "----------------------------------------"
  15. callback = example.Callback()
  16. callback.thisown = 0
  17. caller.setCallback(callback)
  18. caller.call()
  19. caller.delCallback();
  20. print
  21. print "Adding and calling a Python callback"
  22. print "------------------------------------"
  23. # Add a Python callback (caller owns the callback, so we
  24. # disown it first by calling __disown__).
  25. caller.setCallback(PyCallback().__disown__())
  26. caller.call()
  27. caller.delCallback()
  28. print
  29. print "Adding and calling another Python callback"
  30. print "------------------------------------------"
  31. # Lets do the same but use the weak reference this time.
  32. callback = PyCallback().__disown__()
  33. caller.setCallback(callback)
  34. caller.call()
  35. caller.delCallback()
  36. # All done.
  37. print
  38. print "python exit"