Update docstring with api keyword and ospworks url
[o_s.git] / liblove.py
blobd15eb4a03e5e1c8d4cc95aca3aac8d5748b3eb4e
1 #!/usr/bin/env python
3 """
4 A possible use of the odfpy api for the `Openbaar Schrijver' book.
5 Written by Open Source Publishing.
7 http://ospublish.constantvzw.org/works/valentine-scripting
8 http://ospublish.constantvzw.org/works/index.php?/project/publication-templates---openbaar-schrijver/
9 """
11 # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
13 import os
15 from odf.text import P
16 from odf.style import Style, TextProperties, ParagraphProperties
17 from odf.style import GraphicProperties
18 from odf.draw import Frame, TextBox
20 # general purpose
21 def directory_structure():
22 """Produces a directory hierarchy for the storage of the ODT's. From the
23 top-level directories and then down, the hierarchy looks like:
25 genre -- one of brief, gedicht, or verhaal
26 style -- relative to genre
27 spice -- one of character, dingbat, or image
29 Each ODT will live inside of a directory named after its spice. cf the
30 `myname' variable of the Spice classes.
32 """
33 genre = ["brief", "gedicht", "verhaal"]
34 spice = ["character", "dingbat", "image"]
35 style = {
36 "brief" : ["oesters", "nevels", "zon", "dromen", "rivieren", "toekan"],
37 "gedicht" : ["vulkanen", "souvenirs", "ster", "golven", "octopus", "rodepepers"],
38 "verhaal" : ["valleien", "ijs", "verlangens", "panter", "maan", "stormen"],
40 # genre = style.keys()
42 for mygenre in genre:
43 try:
44 os.mkdir(mygenre)
45 except:
46 pass
47 for mystyle in style[mygenre]:
48 try:
49 os.mkdir(mygenre + "/" + mystyle)
50 except:
51 pass
52 # myspace
53 for myspice in spice:
54 try:
55 os.mkdir(mygenre + "/" + mystyle + "/" + myspice)
56 except:
57 pass
59 def make_frame(odt, graphic_style, h, w, ax, ay, z):
60 """Creates an ODF frame, and places an ODF textbox inside of it. Returns
61 both the Frame and the TextBox instances. We will often use this function.
62 The arguments are:
64 odt -- an OpenDocumentText instance
65 graphic_style -- a GraphicProperties instance
66 h, w, ax, ay, z -- height, width, x-pos, y-pos and z-index, respectively
68 From the ODF spec: "within text documents, frames are also used to
69 position content outside of the default text flow of a document"
71 """
72 odt.styles.addElement(graphic_style)
73 myframe = Frame(stylename=graphic_style, height=h, width=w,
74 x=ax, y=ay, zindex=z)
75 mytextbox = TextBox()
76 myframe.addElement(mytextbox)
77 return {"frame" : myframe, "textbox" : mytextbox}
79 def kinda_p(paragraphic_style, text, textbox):
80 """Sets the given `text' string in a paragraph inside of `textbox' styled
81 according to `paragraphic_style'.
83 """
84 p = P(stylename=paragraphic_style, text=text)
85 textbox.addElement(p)
87 def frame_border(odt):
88 """Produces the frame around the contents of the ODT documents."""
89 ## graphic
90 graphic_style = Style(name="Border Frame", family="graphic")
91 graphic_properties = GraphicProperties(border="0.5mm double #000000")
92 graphic_style.addElement(graphic_properties)
93 frame = make_frame(odt, graphic_style, "273mm", "194mm", "-12mm", "-12mm", "1")
94 frameframe = frame["frame"]
95 textbox = frame["textbox"]
97 ## paragraphic
98 paragraphic_style = Style(name="Frame Border is Empty", family="paragraph")
99 text_props = TextProperties()
100 paragraphic_style.addElement(text_props)
101 paragraph_props = ParagraphProperties()
102 paragraphic_style.addElement(paragraph_props)
103 odt.styles.addElement(paragraphic_style)
104 kinda_p(paragraphic_style, u"", textbox)
106 odt.text.addElement(frameframe)
108 def header(odt):
109 """Produces the header frame of the `brief' ODT's."""
110 ## graphic
111 #FS ADDED ATLAS STYLE
112 header_graphic_style = Style(name="Header Frame", family="graphic")
113 header_graphic_properties = GraphicProperties(backgroundcolor="#ffffff", border="10mm double #ffffff")
114 header_graphic_style.addElement(header_graphic_properties)
115 frame = make_frame(odt, header_graphic_style, "20mm", "170mm", "0mm", "0mm", "2")
116 frameframe = frame["frame"]
117 textbox = frame["textbox"]
119 ## paragraphic
120 header_paragraphic_style = Style(name="Header - Date", family="paragraph")
121 atlas_paragraphic_style = Style(name="Header - Atlas", family="paragraph")
123 header_text_props = TextProperties(fontsize="12pt", fontfamily="DIN_OSP")
124 atlas_text_props = TextProperties(fontsize="16pt", fontfamily="OSP-Atlast")
126 header_paragraphic_style.addElement(header_text_props)
127 atlas_paragraphic_style.addElement(atlas_text_props)
129 header_paragraph_props = ParagraphProperties(textalign="right")
130 atlas_paragraph_props = ParagraphProperties(textalign="right")
131 header_paragraphic_style.addElement(header_paragraph_props)
132 atlas_paragraphic_style.addElement(atlas_paragraph_props)
133 odt.styles.addElement(header_paragraphic_style)
134 odt.styles.addElement(atlas_paragraphic_style)
136 kinda_p(header_paragraphic_style, u"Gaasbeek, 13 februari 2050", textbox)
138 kinda_p(atlas_paragraphic_style, u"Hello World", textbox)
140 odt.text.addElement(frameframe)