runme.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # file: runme.py
  2. # This file illustrates the shadow-class C++ interface generated
  3. # by SWIG.
  4. from __future__ import print_function
  5. import new_example
  6. # ----- Object creation -----
  7. print ("Creating some objects:")
  8. c = new_example.Circle(10)
  9. print (" Created circle", c)
  10. s = new_example.Square(10)
  11. print (" Created square", s)
  12. # ----- Access a static member -----
  13. print ("\nA total of", new_example.cvar.Shape_nshapes,"shapes were created")
  14. # ----- Member data access -----
  15. # Set the location of the object
  16. c.x = 20
  17. c.y = 30
  18. s.x = -10
  19. s.y = 5
  20. print ("\nHere is their current position:")
  21. print (" Circle = (%f, %f)" % (c.x,c.y))
  22. print (" Square = (%f, %f)" % (s.x,s.y))
  23. # ----- Call some methods -----
  24. print ("\nHere are some properties of the shapes:")
  25. for o in [c,s]:
  26. print (" ", o)
  27. print (" area = ", o.area())
  28. print (" perimeter = ", o.perimeter())
  29. print ("\nGuess I'll clean up now")
  30. # Note: this invokes the virtual destructor
  31. del c
  32. del s
  33. s = 3
  34. print (new_example.cvar.Shape_nshapes,"shapes remain")
  35. print ("Goodbye")