[Python-modules-commits] [python-odf] 52/118: Select your own filename for output
Wolfgang Borgert
debacle at moszumanska.debian.org
Fri Oct 3 21:27:21 UTC 2014
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to reference refs/remotes/upstream/master
in repository python-odf.
commit 3bee71cbd728192872743544457d032b3ee45697
Author: Søren Roug <soren.roug at eea.europa.eu>
Date: Sun Mar 15 17:52:30 2009 +0000
Select your own filename for output
---
examples/photoalbum.py | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)
diff --git a/examples/photoalbum.py b/examples/photoalbum.py
index 0acd258..923cb42 100644
--- a/examples/photoalbum.py
+++ b/examples/photoalbum.py
@@ -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, \
@@ -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()
@@ -116,10 +130,10 @@ if __name__ == '__main__':
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:
@@ -144,9 +158,10 @@ if __name__ == '__main__':
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)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-odf.git
More information about the Python-modules-commits
mailing list