1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 from xml.sax.saxutils import escape as xmlescape
20 import base64
21 import StringIO
22
23 import wx
24
25 from timelinelib.db.utils import safe_write
26 from timelinelib.meta.version import get_full_version
27
28
29 ENCODING = "utf-8"
30 INDENT1 = " "
31 INDENT2 = " "
32 INDENT3 = " "
33
34
37
38
51 return wrapper
52
53
87 _write_categories = wrap_in_tag(_write_categories, "categories", INDENT1)
88
90 write_simple_tag(xmlfile, "name", cat.get_name(), INDENT3)
91 write_simple_tag(xmlfile, "color", color_string(cat.get_color()), INDENT3)
92 write_simple_tag(xmlfile, "progress_color", color_string(cat.get_progress_color()), INDENT3)
93 write_simple_tag(xmlfile, "done_color", color_string(cat.get_done_color()), INDENT3)
94 write_simple_tag(xmlfile, "font_color", color_string(cat.get_font_color()), INDENT3)
95 if cat._get_parent():
96 write_simple_tag(xmlfile, "parent", cat._get_parent().get_name(), INDENT3)
97 _write_category = wrap_in_tag(_write_category, "category", INDENT2)
98
105 _write_events = wrap_in_tag(_write_events, "events", INDENT1)
106
108 write_simple_tag(xmlfile, "start",
109 self._time_string(evt.get_time_period().start_time), INDENT3)
110 write_simple_tag(xmlfile, "end",
111 self._time_string(evt.get_time_period().end_time), INDENT3)
112 if evt.is_container():
113 write_simple_tag(xmlfile, "text", "[%d]%s" % (evt.id, evt.get_text()), INDENT3)
114 elif evt.is_subevent():
115 write_simple_tag(xmlfile, "text", "(%d)%s" % (evt.container.id, evt.get_text()), INDENT3)
116 else:
117 text = evt.get_text()
118 if self._text_starts_with_container_tag(evt.get_text()):
119 text = self._add_leading_space_to_text(evt.get_text())
120 write_simple_tag(xmlfile, "text", text, INDENT3)
121 if evt.get_data("progress") is not None:
122 write_simple_tag(xmlfile, "progress", "%s" % evt.get_data("progress"), INDENT3)
123 write_simple_tag(xmlfile, "fuzzy", "%s" % evt.get_fuzzy(), INDENT3)
124 write_simple_tag(xmlfile, "locked", "%s" % evt.get_locked(), INDENT3)
125 write_simple_tag(xmlfile, "ends_today", "%s" % evt.get_ends_today(), INDENT3)
126 if evt.get_category() is not None:
127 write_simple_tag(xmlfile, "category", evt.get_category().get_name(), INDENT3)
128 if evt.get_data("description") is not None:
129 write_simple_tag(xmlfile, "description", evt.get_data("description"), INDENT3)
130 alert = evt.get_data("alert")
131 if alert is not None:
132 write_simple_tag(xmlfile, "alert", alert_string(self.db.get_time_type(), alert),
133 INDENT3)
134 hyperlink = evt.get_data("hyperlink")
135 if hyperlink is not None:
136 write_simple_tag(xmlfile, "hyperlink", hyperlink, INDENT3)
137 if evt.get_data("icon") is not None:
138 icon_text = icon_string(evt.get_data("icon"))
139 write_simple_tag(xmlfile, "icon", icon_text, INDENT3)
140 default_color = evt.get_data("default_color")
141 if default_color is not None:
142 write_simple_tag(xmlfile, "default_color", color_string(default_color), INDENT3)
143 if evt.is_milestone():
144 write_simple_tag(xmlfile, "milestone", "True", INDENT3)
145 _write_event = wrap_in_tag(_write_event, "event", INDENT2)
146
150 _write_eras = wrap_in_tag(_write_eras, "eras", INDENT1)
151
153 write_simple_tag(xmlfile, "name", era.get_name(), INDENT3)
154 write_simple_tag(xmlfile, "start", self._time_string(era.get_time_period().start_time), INDENT3)
155 write_simple_tag(xmlfile, "end", self._time_string(era.get_time_period().end_time), INDENT3)
156 write_simple_tag(xmlfile, "color", color_string(era.get_color()), INDENT3)
157 write_simple_tag(xmlfile, "ends_today", "%s" % era.ends_today(), INDENT3)
158 _write_era = wrap_in_tag(_write_era, "era", INDENT2)
159
161 if len(text) > 0:
162 return text[0] in ('(', '[')
163 else:
164 return False
165
168
173 _write_view = wrap_in_tag(_write_view, "view", INDENT1)
174
175
182 _write_displayed_period = wrap_in_tag(_write_displayed_period,
183 "displayed_period", INDENT2)
184
188 _write_hidden_categories = wrap_in_tag(_write_hidden_categories,
189 "hidden_categories", INDENT2)
190
195
196
206
207
209 return "%i,%i,%i" % color
210
211
213 output = StringIO.StringIO()
214 image = wx.ImageFromBitmap(bitmap)
215 image.SaveStream(output, wx.BITMAP_TYPE_PNG)
216 return base64.b64encode(output.getvalue())
217
218
223