Source

vanhoek / examples / hello_world.py

Full commit
import os
my_path =  os.path.dirname(__file__)

from vanhoek.api import \
    Slide, WhiteSlide, BlackSlide, Presentation, EnterKeyPresser
    
import vanhoek.primitives.api as primitives
import vanhoek.backends.api as backends

presentation = Presentation()

s1 = WhiteSlide([
    primitives.TextObject("Hello", (0, 100)),
    primitives.TextObject("world", (300, 300), (0.0, 1.0, 0.0, 1.0)),
    primitives.TextObject("!", (600, 500), (1.0, 0.0, 0.0, 1.0))
])

s2 = BlackSlide([
    primitives.TextObject("Hello", (0, 100), (1.0, 1.0, 1.0, 1.0)),
    primitives.TextObject("world", (300, 300), (0.0, 1.0, 0.0, 1.0)),
    primitives.TextObject("!", (600, 500), (1.0, 0.0, 0.0, 1.0))
])

presentation.append(s1)
presentation.append(s2)

if not os.path.isdir("output"): os.mkdir("output")

try:
    import matplotlib
    matplotlib.use("Agg")
    import pylab
    pylab.plot([1, 2, 3, 4, 5, 6], [0, 2, 4, 5, 7, 3], '-x')
    pylab.savefig("output/temp.png")
    s3 = WhiteSlide([
        primitives.ImageObject("output/temp.png", (0, 0)),
        primitives.TextObject("Overlaid!", (100, 100))
    ])
    os.unlink("output/temp.png")
    presentation.append(s3)
except ImportError:
    pass

if primitives.SVGObject._implemented == True:
    s4 = WhiteSlide([
        primitives.SVGObject(os.path.join(my_path, "drawing.svg"),
                             (0, 0))
        ])
    presentation.append(s4)

#output = backends.PNGWriter("output/slide_%04i.png")
output = backends.PDFWriter("output/output.pdf")
output.interactor = EnterKeyPresser()
presentation.display(output)