Package Gnumed :: Package timelinelib :: Package canvas :: Package data :: Module subevent |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.canvas.data.subevent

     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.event import Event
    20  from timelinelib.canvas.data.immutable import ImmutableEvent
    21  from timelinelib.features.experimental.experimentalfeatures import EXTENDED_CONTAINER_STRATEGY
    22
    23
    24 -class Subevent(Event):
    25
    26 -    def __init__(self, db=None, id_=None, immutable_value=ImmutableEvent()):
    27          Event.__init__(self, db=db, id_=id_, immutable_value=immutable_value)
    28          if not EXTENDED_CONTAINER_STRATEGY.enabled():
    29              self.locked = False
    30
    31 -    def save(self, save_all_subevents=True):
    32          with self._db.transaction("Save event"):
    33              if save_all_subevents and self.container is not None:
    34                  for subevent in self.container.subevents:
    35                      subevent.db = self.container.db
    36                      subevent.save(save_all_subevents=False)
    37              else:
    38                  Event.save(self)
    39          return self
    40
    41 -    def __eq__(self, other):
    42          return (isinstance(other, Subevent) and
    43                  super(Subevent, self).__eq__(other))
    44
    45 -    def __ne__(self, other):
    46          return not (self == other)
    47
    48 -    def __repr__(self):
    49          return "Subevent<id=%r, text=%r, ...>" % (
    50              self.get_id(), self.get_text())
    51
    52 -    def is_container(self):
    53          """Overrides parent method."""
    54          return False
    55
    56 -    def is_subevent(self):
    57          """Overrides parent method."""
    58          return True
    59
    60 -    def get_time_period(self):
    61          return self._immutable_value.time_period
    62
    63 -    def set_time_period(self, time_period):
    64          self._immutable_value = self._immutable_value.update(time_period=time_period)
    65          if self.container is not None:
    66              self.container.update_container(self)
    67          return self
    68
    69      time_period = property(get_time_period, set_time_period)
    70