dinbat spices...
[o_s.git] / liblove.py
blob8fd9b9c8e085ae9bac64e6eb470dd91dc2a59889
1 # drawing hearts in the snow!
3 import os
5 from odf.text import P
6 from odf.style import Style, TextProperties, ParagraphProperties, BackgroundImage, GraphicProperties
7 from odf.draw import Frame, TextBox
9 from stylesheet import *
10 from texts import *
12 # general purpose
13 def directory_structure():
14 genre = ["brief", "gedicht", "verhaal"]
15 spice = ["character", "dingbat", "image"]
16 style = {
17 "brief" : ["oesters", "nevels", "zon", "dromen", "rivieren", "toekan"],
18 "gedicht" : ["vulkanen", "souvenirs", "ster", "golven", "octopus", "rodepepers"],
19 "verhaal" : ["valleien", "ijs", "verlangens", "panter", "maan", "stormen"],
21 # genre = style.keys()
23 for mygenre in genre:
24 try:
25 os.mkdir(mygenre)
26 except:
27 pass
28 for mystyle in style[mygenre]:
29 try:
30 os.mkdir(mygenre + "/" + mystyle)
31 except:
32 pass
33 # myspace
34 for myspice in spice:
35 try:
36 os.mkdir(mygenre + "/" + mystyle + "/" + myspice)
37 except:
38 pass
40 def make_frame(odt, graphic_style, h, w, ax, ay, z):
41 odt.styles.addElement(graphic_style)
42 myframe = Frame(stylename=graphic_style, height=h, width=w,
43 x=ax, y=ay, zindex=z)
44 mytextbox = TextBox()
45 myframe.addElement(mytextbox)
46 return {"frame" : myframe, "textbox" : mytextbox}
48 def kinda_p(paragraphic_style, text, textbox):
49 p = P(stylename=paragraphic_style, text=text)
50 textbox.addElement(p)
52 def frame_border(odt):
53 ## graphic
54 graphic_style = Style(name="Border Frame", family="graphic")
55 graphic_properties = GraphicProperties(border="0.5mm double #000000")
56 graphic_style.addElement(graphic_properties)
57 frame = make_frame(odt, graphic_style, "273mm", "194mm", "-12mm", "-12mm", "1")
58 frameframe = frame["frame"]
59 textbox = frame["textbox"]
61 ## paragraphic
62 paragraphic_style = Style(name="Frame Border is Empty", family="paragraph")
63 text_props = TextProperties()
64 paragraphic_style.addElement(text_props)
65 paragraph_props = ParagraphProperties()
66 paragraphic_style.addElement(paragraph_props)
67 odt.styles.addElement(paragraphic_style)
68 kinda_p(paragraphic_style, u"", textbox)
70 odt.text.addElement(frameframe)
72 def header(odt):
73 ## graphic
74 #FS ADDED ATLAS STYLE
75 header_graphic_style = Style(name="Header Frame", family="graphic")
76 header_graphic_properties = GraphicProperties(backgroundcolor="#ffffff", border="10mm double #ffffff")
77 header_graphic_style.addElement(header_graphic_properties)
78 frame = make_frame(odt, header_graphic_style, "20mm", "170mm", "0mm", "0mm", "2")
79 frameframe = frame["frame"]
80 textbox = frame["textbox"]
82 ## paragraphic
83 header_paragraphic_style = Style(name="Header - Date", family="paragraph")
84 atlas_paragraphic_style = Style(name="Header - Atlas", family="paragraph")
86 header_text_props = TextProperties(fontsize="12pt", fontfamily="DIN_OSP")
87 atlas_text_props = TextProperties(fontsize="16pt", fontfamily="OSP-Atlast")
89 header_paragraphic_style.addElement(header_text_props)
90 atlas_paragraphic_style.addElement(atlas_text_props)
92 header_paragraph_props = ParagraphProperties(textalign="right")
93 atlas_paragraph_props = ParagraphProperties(textalign="right")
94 header_paragraphic_style.addElement(header_paragraph_props)
95 atlas_paragraphic_style.addElement(atlas_paragraph_props)
96 odt.styles.addElement(header_paragraphic_style)
97 odt.styles.addElement(atlas_paragraphic_style)
99 kinda_p(header_paragraphic_style, u"Gaasbeek, 13 februari 2050", textbox)
101 kinda_p(atlas_paragraphic_style, u"Hello World", textbox)
103 odt.text.addElement(frameframe)
105 class Spice:
106 def __init__(self, genre, style):
107 self.genre = genre
108 self.style = style
110 def read_stylesheet(self):
111 myname = self.genre + "_" + self.style
112 # find text_template and paragraph_template dicts in stylesheet
113 text_template[self.genre].update(text_style[self.genre][self.style])
114 paragraph_template[self.genre].update(paragraph_style[self.genre][self.style])
115 oostyle = Style(name="Body Text", family="paragraph")
116 oostyle.addElement(TextProperties(attributes=text_template[self.genre]))
117 oostyle.addElement(ParagraphProperties(attributes=paragraph_template[self.genre]))
118 return oostyle
120 def text_frame(self, odt):
121 ### header frame (for letter)
122 if self.genre == "brief":
123 header(odt)
125 ### textframe
126 graphic_style = Style(name="Main Body Frame", family="graphic")
127 graphic_properties = GraphicProperties(backgroundcolor="#ffffff", border="10mm double #ffffff")
128 graphic_style.addElement(graphic_properties)
129 frame = make_frame(odt, graphic_style, "240mm", "170mm", "0mm", "0mm", "1")
130 frameframe = frame["frame"]
131 textbox = frame["textbox"]
133 for paragraph in txt[self.genre]:
134 kinda_p("Body Text", paragraph, textbox)
136 odt.text.addElement(frameframe)
138 def label(self, odt, spice):
139 ## graphic
140 graphic_style = Style(name="Label Frame", family="graphic")
141 graphic_properties = GraphicProperties()
142 graphic_style.addElement(graphic_properties)
143 frame = make_frame(odt, graphic_style, "5mm", "50mm", "60mm", "263mm", "1")
144 frameframe = frame["frame"]
145 textbox = frame["textbox"]
147 ## paragraphic
148 paragraphic_style = Style(name="Label Text", family="paragraph")
149 text_props = TextProperties(fontsize="11.1pt", fontfamily="Nimbus Sans L", color="#ffffff")
150 paragraphic_style.addElement(text_props)
151 paragraph_props = ParagraphProperties(backgroundcolor="#000000", textalign="center")
152 paragraphic_style.addElement(paragraph_props)
153 odt.styles.addElement(paragraphic_style)
154 kinda_p(paragraphic_style, spice + " " + self.style, textbox)
156 odt.text.addElement(frameframe)