Skip to content

Commit

Permalink
Select your own filename for output
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenroug committed Mar 15, 2009
1 parent 5cc2fa3 commit 3bee71c
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions examples/photoalbum.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#
# Contributor(s):
#
import os,sys,struct
import os,sys,getopt,struct
from cStringIO import StringIO
from odf.opendocument import OpenDocumentPresentation
from odf.style import Style, MasterPage, PageLayout, PageLayoutProperties, \
Expand Down Expand Up @@ -83,8 +83,22 @@ def getImageInfo(data):

return content_type, width, height

if __name__ == '__main__':
outfilename = "photoalbum.odp"
def usage():
sys.stderr.write("Usage: %s [-o outputfile] [input-directory]\n" % sys.argv[0])

if __name__ == "__main__":
try:
opts, args = getopt.getopt(sys.argv[1:], "o:", ["output="])
except getopt.GetoptError:
usage()
sys.exit(2)

outputfile = "photoalbum.odp"

for o, a in opts:
if o in ("-o", "--output"):
outputfile = a
if outputfile[-4:] != ".odp": outputfile += ".odp"

doc = OpenDocumentPresentation()

Expand Down Expand Up @@ -116,10 +130,10 @@ def getImageInfo(data):
masterpage = MasterPage(name="MyMaster", pagelayoutname=pagelayout)
doc.masterstyles.addElement(masterpage)

if len(sys.argv) == 1:
if len(args) == 0:
pict_dir = "."
else:
pict_dir = sys.argv[1]
pict_dir = args[0]
# Slides
for picture in os.listdir(pict_dir):
try:
Expand All @@ -144,9 +158,10 @@ def getImageInfo(data):
titleframe.addElement(textbox)
textbox.addElement(P(text=picture))

photoframe = Frame(stylename=photostyle, width="%fpt" % w, height="%fpt" % h, x="40pt", y="56pt")
offsetx = 400.0 - w/2.0
photoframe = Frame(stylename=photostyle, width="%fpt" % w, height="%fpt" % h, x="%fpt" % offsetx, y="56pt")
page.addElement(photoframe)
href = doc.addPicture(pict_dir + "/" + picture)
photoframe.addElement(Image(href=href))

doc.save(outfilename)
doc.save(outputfile)

0 comments on commit 3bee71c

Please sign in to comment.