Logger.SpingDemo

Package Logger :: Module SpingDemo |
[hide private]
[frames] | no frames]

# Source Code for Module Logger.SpingDemo

     1  # $Id: SpingDemo.py 2 2006-05-06 22:54:39Z glandrum $
     2  #
     3  #       Copyright (c) 2001-2006, Greg Landrum and Rational Discovery LLC,
     4  #
     5  #   @@ All Rights Reserved  @@
     6  #
     7  """ demo code for the Logger class
     8
     9  """
    10
    11  from sping.SVG import pidSVG
    12  from sping.PIL import pidPIL
    13  from sping import pid
    14  import Logger
    15
    16  # create a logged canvas and draw on it
    17  sz = (300,300)
    18  c1 = Logger.Logger(pidSVG.SVGCanvas,sz,'foo.svg',loggerFlushCommand='clear')
    19  c1.drawPolygon([(100,100),(100,200),(200,200),(200,100)],fillColor=pid.Color(0,0,1))
    20  c1.drawLines([(100,100,200,200),(100,200,200,100)],color=pid.Color(0,1,0),width=2)
    21
    22  # because the log has been instantiated with clear() as the loggerFlushCommand,
    23  # this will blow out the log as well as the contents of the canvas.
    24  c1.clear()
    25
    26  # draw some more stuff
    27  c1.drawPolygon([(100,100),(100,200),(200,200),(200,100)],fillColor=pid.Color(1,0,0))
    28  c1.drawLines([(100,100,200,200),(100,200,200,100)],color=pid.Color(0,0,0),width=2)
    29  # and write the resulting file.
    30  c1.save()
    31
    32  # save the log by pickling it.
    33  import cPickle
    34  cPickle.dump(c1._LoggerGetLog(),open('foo.pkl','wb+'))
    35
    36  # create a new canvas
    37  c2 = pidPIL.PILCanvas(sz,'foo.png')
    38  # read the pickled log back in
    39  t = cPickle.load(open('foo.pkl','rb'))
    40  # and play the log on the new canvas
    41  Logger.replay(t,c2)
    42  # there should now be a file 'foo.png' with the image
    43