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 io
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 = " " * 2
31 INDENT2 = " " * 4
32 INDENT3 = " " * 6
33 INDENT4 = " " * 8
34
35
38
39
52 return wrapper
53
54
88 _write_categories = wrap_in_tag(_write_categories, "categories", INDENT1)
89
91 write_simple_tag(xmlfile, "name", cat.get_name(), INDENT3)
92 write_simple_tag(xmlfile, "color", color_string(cat.get_color()), INDENT3)
93 write_simple_tag(xmlfile, "progress_color", color_string(cat.get_progress_color()), INDENT3)
94 write_simple_tag(xmlfile, "done_color", color_string(cat.get_done_color()), INDENT3)
95 write_simple_tag(xmlfile, "font_color", color_string(cat.get_font_color()), INDENT3)
96 if cat._get_parent():
97 write_simple_tag(xmlfile, "parent", cat._get_parent().get_name(), INDENT3)
98 _write_category = wrap_in_tag(_write_category, "category", INDENT2)
99
106 _write_events = wrap_in_tag(_write_events, "events", INDENT1)
107
109 write_simple_tag(xmlfile, "start",
110 self._time_string(evt.get_time_period().start_time), INDENT3)
111 write_simple_tag(xmlfile, "end",
112 self._time_string(evt.get_time_period().end_time), INDENT3)
113 if evt.is_container():
114 write_simple_tag(xmlfile, "text", "[%d]%s" % (evt.id, evt.get_text()), INDENT3)
115 elif evt.is_subevent():
116 write_simple_tag(xmlfile, "text", "(%d)%s" % (evt.container.id, evt.get_text()), INDENT3)
117 else:
118 text = evt.get_text()
119 if self._text_starts_with_container_tag(evt.get_text()):
120 text = self._add_leading_space_to_text(evt.get_text())
121 write_simple_tag(xmlfile, "text", text, INDENT3)
122 if evt.get_data("progress") is not None:
123 write_simple_tag(xmlfile, "progress", "%s" % evt.get_data("progress"), INDENT3)
124 write_simple_tag(xmlfile, "fuzzy", "%s" % evt.get_fuzzy(), INDENT3)
125 write_simple_tag(xmlfile, "locked", "%s" % evt.get_locked(), INDENT3)
126 write_simple_tag(xmlfile, "ends_today", "%s" % evt.get_ends_today(), INDENT3)
127 if evt.get_category() is not None:
128 write_simple_tag(xmlfile, "category", evt.get_category().get_name(), INDENT3)
129 if evt.get_categories():
130 self._write_event_categories(xmlfile, evt)
131 if evt.get_data("description") is not None:
132 write_simple_tag(xmlfile, "description", evt.get_data("description"), INDENT3)
133 alert = evt.get_data("alert")
134 if alert is not None:
135 write_simple_tag(xmlfile, "alert", alert_string(self.db.get_time_type(), alert),
136 INDENT3)
137 hyperlink = evt.get_data("hyperlink")
138 if hyperlink is not None:
139 write_simple_tag(xmlfile, "hyperlink", hyperlink, INDENT3)
140 if evt.get_data("icon") is not None:
141 icon_text = icon_string(evt.get_data("icon"))
142 write_simple_tag(xmlfile, "icon", icon_text, INDENT3)
143 default_color = evt.get_data("default_color")
144 if default_color is not None:
145 write_simple_tag(xmlfile, "default_color", color_string(default_color), INDENT3)
146 if evt.is_milestone():
147 write_simple_tag(xmlfile, "milestone", "True", INDENT3)
148 _write_event = wrap_in_tag(_write_event, "event", INDENT2)
149
153 _write_event_categories = wrap_in_tag(_write_event_categories, "categories", INDENT3)
154
158 _write_eras = wrap_in_tag(_write_eras, "eras", INDENT1)
159
161 write_simple_tag(xmlfile, "name", era.get_name(), INDENT3)
162 write_simple_tag(xmlfile, "start", self._time_string(era.get_time_period().start_time), INDENT3)
163 write_simple_tag(xmlfile, "end", self._time_string(era.get_time_period().end_time), INDENT3)
164 write_simple_tag(xmlfile, "color", color_string(era.get_color()), INDENT3)
165 write_simple_tag(xmlfile, "ends_today", "%s" % era.ends_today(), INDENT3)
166 _write_era = wrap_in_tag(_write_era, "era", INDENT2)
167
169 if len(text) > 0:
170 return text[0] in ('(', '[')
171 else:
172 return False
173
176
181 _write_view = wrap_in_tag(_write_view, "view", INDENT1)
182
183
190 _write_displayed_period = wrap_in_tag(_write_displayed_period,
191 "displayed_period", INDENT2)
192
196 _write_hidden_categories = wrap_in_tag(_write_hidden_categories,
197 "hidden_categories", INDENT2)
198
203
204
214
215
217 return "%i,%i,%i" % color[:3]
218
219
221 output = io.StringIO()
222 image = wx.ImageFromBitmap(bitmap)
223 image.SaveStream(output, wx.BITMAP_TYPE_PNG)
224 return base64.b64encode(output.getvalue())
225
226
231