| 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._categories = []
38 self._container = None
39 self._milestone = False
40
42 duplicate = ItemBase.duplicate(self, target_db=target_db)
43 if duplicate.db is self.db:
44 duplicate.category = self.category
45 duplicate.sort_order = None
46 return duplicate
47
49 self._update_category_id()
50 self._update_category_ids()
51 self._update_container_id()
52 self._update_sort_order()
53 with self._db.transaction("Save event") as t:
54 t.save_event(self._immutable_value, self.ensure_id())
55 return self
56
59
61 if self.category is None:
62 self._immutable_value = self._immutable_value.update(
63 category_id=None
64 )
65 elif self.category.id is None:
66 raise Exception("Unknown category")
67 else:
68 self._immutable_value = self._immutable_value.update(
69 category_id=self.category.id
70 )
71
73 if self._categories == list():
74 self._immutable_value = self._immutable_value.update(
75 category_ids={}
76 )
77 else:
78 ids = [c.id for c in self._categories]
79 # Using a dictionary because we don't have any ImmutableList class
80 dic = {k: None for k in ids}
81 self._immutable_value = self._immutable_value.update(
82 category_ids=dic
83 )
84
86 if self.container is None:
87 self._immutable_value = self._immutable_value.update(
88 container_id=None
89 )
90 elif self.container.id is None:
91 raise Exception("Unknown container")
92 else:
93 self._immutable_value = self._immutable_value.update(
94 container_id=self.container.id
95 )
96
100
105
107 return (isinstance(other, Event) and
108 self.get_fuzzy() == other.get_fuzzy() and
109 self.get_locked() == other.get_locked() and
110 self.get_ends_today() == other.get_ends_today() and
111 self.get_id() == other.get_id() and
112 self.get_time_period().start_time == other.get_time_period().start_time and
113 (self.get_time_period().end_time == other.get_time_period().end_time or self.get_ends_today()) and
114 self.get_text() == other.get_text() and
115 self.get_category() == other.get_category() and
116 self.get_description() == other.get_description() and
117 self.get_hyperlink() == other.get_hyperlink() and
118 self.get_progress() == other.get_progress() and
119 self.get_alert() == other.get_alert() and
120 self.get_icon() == other.get_icon() and
121 self.get_default_color() == other.get_default_color())
122
125
128
131
134
137
139 return "%s<id=%r, text=%r, time_period=%r, ...>" % (
140 self.__class__.__name__,
141 self.get_id(),
142 self.get_text(),
143 self.get_time_period()
144 )
145
148
150 return self._immutable_value.text
151
155
156 text = property(get_text, set_text)
157
160
166
170
171 category = property(get_category, set_category)
172
175
177 if categories:
178 if self.category:
179 if self.category in categories:
180 categories.remove(self.category)
181 else:
182 self.category = categories[0]
183 categories = categories[1:]
184 self._categories = categories
185
188
190 if self._container is not None:
191 self._container.unregister_subevent(self)
192 self._container = container
193 if self._container is not None:
194 self._container.register_subevent(self)
195 return self
196
197 container = property(get_container, set_container)
198
200 return self._immutable_value.fuzzy
201
205
206 fuzzy = property(get_fuzzy, set_fuzzy)
207
209 return self._immutable_value.locked
210
214
215 locked = property(get_locked, set_locked)
216
218 return self._immutable_value.ends_today
219
221 if not self.locked:
222 self._immutable_value = self._immutable_value.update(ends_today=ends_today)
223 return self
224
225 ends_today = property(get_ends_today, set_ends_today)
226
228 return self._immutable_value.description
229
233
234 description = property(get_description, set_description)
235
237 return self._immutable_value.icon
238
242
243 icon = property(get_icon, set_icon)
244
246 return self._immutable_value.hyperlink
247
251
252 hyperlink = property(get_hyperlink, set_hyperlink)
253
255 return self._immutable_value.alert
256
260
261 alert = property(get_alert, set_alert)
262
264 return self._immutable_value.progress
265
269
270 progress = property(get_progress, set_progress)
271
273 return self._immutable_value.sort_order
274
278
279 sort_order = property(get_sort_order, set_sort_order)
280
282 color = self._immutable_value.default_color
283 if color is None:
284 color = DEFAULT_COLOR
285 return color
286
290
291 default_color = property(get_default_color, set_default_color)
292
294 if self.category:
295 return self.category.get_done_color()
296 else:
297 return get_progress_color(DEFAULT_COLOR)
298
300 category = self.category
301 if category:
302 if self.get_progress() == 100:
303 return category.get_done_color()
304 else:
305 return category.get_progress_color()
306 else:
307 return get_progress_color(DEFAULT_COLOR)
308
309 - def update(self, start_time, end_time, text, category=None, fuzzy=None,
310 locked=None, ends_today=None):
311 """Change the event data."""
312 self.update_period(start_time, end_time)
313 self.text = text.strip()
314 self.category = category
315 if ends_today is not None:
316 if not self.locked:
317 self.ends_today = ends_today
318 if fuzzy is not None:
319 self.fuzzy = fuzzy
320 if locked is not None:
321 self.locked = locked
322 return self
323
325 """
326 Return data with the given id or None if no data with that id exists.
327
328 See set_data for information how ids map to data.
329 """
330 if event_id == "description":
331 return self.description
332 elif event_id == "icon":
333 return self.icon
334 elif event_id == "hyperlink":
335 return self.hyperlink
336 elif event_id == "alert":
337 return self.alert
338 elif event_id == "progress":
339 return self.progress
340 elif event_id == "default_color":
341 if "default_color" in self._immutable_value:
342 return self._immutable_value.default_color
343 else:
344 return None
345 else:
346 raise Exception("should not happen")
347
349 """
350 Set data with the given id.
351
352 Here is how ids map to data:
353
354 description - string
355 icon - wx.Bitmap
356 """
357 if event_id == "description":
358 self.description = data
359 elif event_id == "icon":
360 self.icon = data
361 elif event_id == "hyperlink":
362 self.hyperlink = data
363 elif event_id == "alert":
364 self.alert = data
365 elif event_id == "progress":
366 self.progress = data
367 elif event_id == "default_color":
368 self.default_color = data
369 else:
370 raise Exception("should not happen")
371
373 data = {}
374 for event_id in DATA_FIELDS:
375 data[event_id] = self.get_data(event_id)
376 return data
377
381
382 data = property(get_whole_data, set_whole_data)
383
385 """Return True if the event has associated data, or False if not."""
386 for event_id in DATA_FIELDS:
387 if self.get_data(event_id) is not None:
388 return True
389 return False
390
392 """Return True if the event has associated data to be displayed in a balloon."""
393 return (self.get_data("description") is not None or
394 self.get_data("icon") is not None)
395
397 """Returns a unicode label describing the event."""
398 event_label = "%s (%s)" % (
399 self.text,
400 time_type.format_period(self.get_time_period()),
401 )
402 duration_label = self._get_duration_label(time_type)
403 if duration_label != "":
404 return "%s %s: %s" % (event_label, _("Duration"), duration_label)
405 else:
406 return event_label
407
409 label = time_type.format_delta(self.time_span())
410 if label == "0":
411 label = ""
412 return label
413
416
419
422
424 return EXPORTABLE_FIELDS
425
427 self._milestone = value
428
431
432
433 DATA_FIELDS = [
434 "description",
435 "icon",
436 "hyperlink",
437 "alert",
438 "progress",
439 "default_color",
440 ]
441
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Sat Feb 29 02:55:27 2020 | http://epydoc.sourceforge.net |