Ejemplo n.º 1
0
 def _create_subevent(self):
     if self._is_new_container(self.view.GetContainer()):
         self._add_new_container()
     (start, end) = self._get_period_from_view()
     self.event = Subevent().update(start,
                                    end,
                                    self.view.GetName(),
                                    self.view.GetCategory(),
                                    ends_today=self.view.GetEndsToday())
     self.event.container = self.view.GetContainer()
Ejemplo n.º 2
0
 def _parse_event(self, text, tmp_dict):
     start = self._parse_time(tmp_dict.pop("tmp_start"))
     end = self._parse_time(tmp_dict.pop("tmp_end"))
     text = tmp_dict.pop("tmp_text")
     progress = self._parse_optional_int(tmp_dict, "tmp_progress")
     fuzzy = self._parse_optional_bool(tmp_dict, "tmp_fuzzy")
     locked = self._parse_optional_bool(tmp_dict, "tmp_locked")
     ends_today = self._parse_optional_bool(tmp_dict, "tmp_ends_today")
     category_text = tmp_dict.pop("tmp_category", None)
     if category_text is None:
         category = None
     else:
         category = tmp_dict["category_map"].get(category_text, None)
         if category is None:
             raise ParseException("Category '%s' not found." %
                                  category_text)
     description = tmp_dict.pop("tmp_description", None)
     alert_string = tmp_dict.pop("tmp_alert", None)
     alert = parse_alert_string(self.db.get_time_type(), alert_string)
     icon_text = tmp_dict.pop("tmp_icon", None)
     if icon_text is None:
         icon = None
     else:
         icon = parse_icon(icon_text)
     hyperlink = tmp_dict.pop("tmp_hyperlink", None)
     milestone = self._parse_optional_bool(tmp_dict, "tmp_milestone")
     if self._is_container_event(text):
         cid, text = self._extract_container_id(text)
         event = Container().update(start, end, text, category)
         self._containers_by_cid[cid] = event
     elif self._is_subevent(text):
         cid, text = self._extract_subid(text)
         event = Subevent().update(start,
                                   end,
                                   text,
                                   category,
                                   locked=locked,
                                   ends_today=ends_today)
         event.container = self._containers_by_cid[cid]
     elif milestone:
         event = Milestone().update(start, start, text)
         event.set_category(category)
     else:
         if self._text_starts_with_added_space(text):
             text = self._remove_added_space(text)
         event = Event().update(start, end, text, category, fuzzy, locked,
                                ends_today)
     default_color = tmp_dict.pop("tmp_default_color", "200,200,200")
     event.set_data("description", description)
     event.set_data("icon", icon)
     event.set_data("alert", alert)
     event.set_data("hyperlink", hyperlink)
     event.set_data("progress", int(progress))
     event.set_data("default_color", parse_color(default_color))
     self.db.save_event(event)
Ejemplo n.º 3
0
def a_subevent_with(start=None, end=None, time=ANY_TIME, text="sub", category=None, container=None):
    """Create a :doc:`Subevent <timelinelib_canvas_data_subevent>` object."""
    if start and end:
        start = human_time_to_gregorian(start)
        end = human_time_to_gregorian(end)
    else:
        start = human_time_to_gregorian(time)
        end = human_time_to_gregorian(time)
    event = Subevent().update(start, end, text, category=category)
    event.container = container
    return event
Ejemplo n.º 4
0
def a_container(name, category, sub_events):
    """Create a :doc:`Container <timelinelib_canvas_data_container>` object."""
    start = human_time_to_gregorian(ANY_TIME)
    end = human_time_to_gregorian(ANY_TIME)
    container = Container().update(start, end, name, category=category)
    all_events = []
    all_events.append(container)
    for (name, category) in sub_events:
        event = Subevent().update(start, end, name, category=category)
        event.container = container
        all_events.append(event)
    return all_events
Ejemplo n.º 5
0
 def _parse_event(self, text, tmp_dict):
     start = self._parse_time(tmp_dict.pop("tmp_start"))
     end = self._parse_time(tmp_dict.pop("tmp_end"))
     text = tmp_dict.pop("tmp_text")
     progress = self._parse_optional_int(tmp_dict, "tmp_progress")
     fuzzy = self._parse_optional_bool(tmp_dict, "tmp_fuzzy")
     locked = self._parse_optional_bool(tmp_dict, "tmp_locked")
     ends_today = self._parse_optional_bool(tmp_dict, "tmp_ends_today")
     category_text = tmp_dict.pop("tmp_category", None)
     if category_text is None:
         category = None
     else:
         category = self.get_category(tmp_dict, category_text)
     categories = []
     if "tmp_categories" in tmp_dict:
         # Remove duplicates but preserve order
         dic = {k: 0 for k in tmp_dict.pop("tmp_categories", None)}
         for category_text in dic:
             if category_text is not None:
                 cat = self.get_category(tmp_dict, category_text)
                 if category is None:
                     category = cat
                 else:
                     categories.append(cat)
     description = tmp_dict.pop("tmp_description", None)
     alert_string = tmp_dict.pop("tmp_alert", None)
     alert = parse_alert_string(self.db.get_time_type(), alert_string)
     icon_text = tmp_dict.pop("tmp_icon", None)
     if icon_text is None:
         icon = None
     else:
         icon = parse_icon(icon_text)
     hyperlink = tmp_dict.pop("tmp_hyperlink", None)
     milestone = self._parse_optional_bool(tmp_dict, "tmp_milestone")
     if self._is_container_event(text):
         cid, text = self._extract_container_id(text)
         event = Container().update(start, end, text, category)
         self._containers_by_cid[cid] = event
     elif self._is_subevent(text):
         cid, text = self._extract_subid(text)
         event = Subevent().update(start,
                                   end,
                                   text,
                                   category,
                                   locked=locked,
                                   ends_today=ends_today)
         event.container = self._containers_by_cid[cid]
     elif milestone:
         event = Milestone().update(start, start, text)
         event.set_category(category)
     else:
         if self._text_starts_with_added_space(text):
             text = self._remove_added_space(text)
         event = Event().update(start, end, text, category, fuzzy, locked,
                                ends_today)
     if categories:
         event.set_categories(categories)
     default_color = tmp_dict.pop("tmp_default_color", "200,200,200")
     event.set_data("description", description)
     event.set_data("icon", icon)
     event.set_data("alert", alert)
     event.set_data("hyperlink", hyperlink)
     event.set_data("progress", int(progress))
     event.set_data("default_color", parse_color(default_color))
     self.db.save_event(event)