runme.py 1003 B

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