PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Examples/python/class/runme.py

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