| Home | Trees | Indices | Help |
|
|---|
|
|
1 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Rickard Lindberg, Roger Lindberg
2 #
3 # This file is part of Timeline.
4 #
5 # Timeline is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Timeline is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Timeline. If not, see <http://www.gnu.org/licenses/>.
17
18
19 from timelinelib.canvas.data.base import ItemBase
20 from timelinelib.canvas.data.immutable import ImmutableEvent
21 from timelinelib.canvas.data.item import TimelineItem
22 from timelinelib.canvas.drawing.drawers import get_progress_color
23
24
25 DEFAULT_COLOR = (200, 200, 200)
26 EXPORTABLE_FIELDS = (_("Text"), _("Description"), _("Start"), _("End"), _("Category"),
27 _("Fuzzy"), _("Locked"), _("Ends Today"), _("Hyperlink"),
28 _("Progress"), _("Progress Color"), _("Done Color"), _("Alert"),
29 _("Is Container"), _("Is Subevent"))
30
31
33
35 ItemBase.__init__(self, db, id_, immutable_value)
36 self._category = None
37 self._container = None
38 self._milestone = False
39
41 duplicate = ItemBase.duplicate(self, target_db=target_db)
42 if duplicate.db is self.db:
43 duplicate.category = self.category
44 duplicate.sort_order = None
45 return duplicate
46
48 self._update_category_id()
49 self._update_container_id()
50 self._update_sort_order()
51 with self._db.transaction("Save event") as t:
52 t.save_event(self._immutable_value, self.ensure_id())
53 return self
54
57
59 if self.category is None:
60 self._immutable_value = self._immutable_value.update(
61 category_id=None
62 )
63 elif self.category.id is None:
64 raise Exception("Unknown category")
65 else:
66 self._immutable_value = self._immutable_value.update(
67 category_id=self.category.id
68 )
69
71 if self.container is None:
72 self._immutable_value = self._immutable_value.update(
73 container_id=None
74 )
75 elif self.container.id is None:
76 raise Exception("Unknown container")
77 else:
78 self._immutable_value = self._immutable_value.update(
79 container_id=self.container.id
80 )
81
85
90
92 return (isinstance(other, Event) and
93 self.get_fuzzy() == other.get_fuzzy() and
94 self.get_locked() == other.get_locked() and
95 self.get_ends_today() == other.get_ends_today() and
96 self.get_id() == other.get_id() and
97 self.get_time_period().start_time == other.get_time_period().start_time and
98 (self.get_time_period().end_time == other.get_time_period().end_time or self.get_ends_today()) and
99 self.get_text() == other.get_text() and
100 self.get_category() == other.get_category() and
101 self.get_description() == other.get_description() and
102 self.get_hyperlink() == other.get_hyperlink() and
103 self.get_progress() == other.get_progress() and
104 self.get_alert() == other.get_alert() and
105 self.get_icon() == other.get_icon() and
106 self.get_default_color() == other.get_default_color())
107
110
113
116
119
122
124 return "%s<id=%r, text=%r, time_period=%r, ...>" % (
125 self.__class__.__name__,
126 self.get_id(),
127 self.get_text(),
128 self.get_time_period()
129 )
130
133
135 return self._immutable_value.text
136
140
141 text = property(get_text, set_text)
142
145
151
155
156 category = property(get_category, set_category)
157
160
162 if self._container is not None:
163 self._container.unregister_subevent(self)
164 self._container = container
165 if self._container is not None:
166 self._container.register_subevent(self)
167 return self
168
169 container = property(get_container, set_container)
170
172 return self._immutable_value.fuzzy
173
177
178 fuzzy = property(get_fuzzy, set_fuzzy)
179
181 return self._immutable_value.locked
182
186
187 locked = property(get_locked, set_locked)
188
190 return self._immutable_value.ends_today
191
193 if not self.locked:
194 self._immutable_value = self._immutable_value.update(ends_today=ends_today)
195 return self
196
197 ends_today = property(get_ends_today, set_ends_today)
198
200 return self._immutable_value.description
201
205
206 description = property(get_description, set_description)
207
209 return self._immutable_value.icon
210
214
215 icon = property(get_icon, set_icon)
216
218 return self._immutable_value.hyperlink
219
223
224 hyperlink = property(get_hyperlink, set_hyperlink)
225
227 return self._immutable_value.alert
228
232
233 alert = property(get_alert, set_alert)
234
236 return self._immutable_value.progress
237
241
242 progress = property(get_progress, set_progress)
243
245 return self._immutable_value.sort_order
246
250
251 sort_order = property(get_sort_order, set_sort_order)
252
254 color = self._immutable_value.default_color
255 if color is None:
256 color = DEFAULT_COLOR
257 return color
258
262
263 default_color = property(get_default_color, set_default_color)
264
266 if self.category:
267 return self.category.get_done_color()
268 else:
269 return get_progress_color(DEFAULT_COLOR)
270
272 category = self.category
273 if category:
274 if self.get_progress() == 100:
275 return category.get_done_color()
276 else:
277 return category.get_progress_color()
278 else:
279 return get_progress_color(DEFAULT_COLOR)
280
281 - def update(self, start_time, end_time, text, category=None, fuzzy=None,
282 locked=None, ends_today=None):
283 """Change the event data."""
284 self.update_period(start_time, end_time)
285 self.text = text.strip()
286 self.category = category
287 if ends_today is not None:
288 if not self.locked:
289 self.ends_today = ends_today
290 if fuzzy is not None:
291 self.fuzzy = fuzzy
292 if locked is not None:
293 self.locked = locked
294 return self
295
297 """
298 Return data with the given id or None if no data with that id exists.
299
300 See set_data for information how ids map to data.
301 """
302 if event_id == "description":
303 return self.description
304 elif event_id == "icon":
305 return self.icon
306 elif event_id == "hyperlink":
307 return self.hyperlink
308 elif event_id == "alert":
309 return self.alert
310 elif event_id == "progress":
311 return self.progress
312 elif event_id == "default_color":
313 if "default_color" in self._immutable_value:
314 return self._immutable_value.default_color
315 else:
316 return None
317 else:
318 raise Exception("should not happen")
319
321 """
322 Set data with the given id.
323
324 Here is how ids map to data:
325
326 description - string
327 icon - wx.Bitmap
328 """
329 if event_id == "description":
330 self.description = data
331 elif event_id == "icon":
332 self.icon = data
333 elif event_id == "hyperlink":
334 self.hyperlink = data
335 elif event_id == "alert":
336 self.alert = data
337 elif event_id == "progress":
338 self.progress = data
339 elif event_id == "default_color":
340 self.default_color = data
341 else:
342 raise Exception("should not happen")
343
345 data = {}
346 for event_id in DATA_FIELDS:
347 data[event_id] = self.get_data(event_id)
348 return data
349
353
354 data = property(get_whole_data, set_whole_data)
355
357 """Return True if the event has associated data, or False if not."""
358 for event_id in DATA_FIELDS:
359 if self.get_data(event_id) is not None:
360 return True
361 return False
362
364 """Return True if the event has associated data to be displayed in a balloon."""
365 return (self.get_data("description") is not None or
366 self.get_data("icon") is not None)
367
369 """Returns a unicode label describing the event."""
370 event_label = u"%s (%s)" % (
371 self.text,
372 time_type.format_period(self.get_time_period()),
373 )
374 duration_label = self._get_duration_label(time_type)
375 if duration_label != "":
376 return u"%s %s: %s" % (event_label, _("Duration"), duration_label)
377 else:
378 return event_label
379
381 label = time_type.format_delta(self.time_span())
382 if label == "0":
383 label = ""
384 return label
385
388
391
394
396 return EXPORTABLE_FIELDS
397
399 self._milestone = value
400
403
404
405 DATA_FIELDS = [
406 "description",
407 "icon",
408 "hyperlink",
409 "alert",
410 "progress",
411 "default_color",
412 ]
413
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Fri Sep 13 01:55:28 2019 | http://epydoc.sourceforge.net |