Gnumed.timelinelib.canvas.data.era

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

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

      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 ImmutableEra
     21  from timelinelib.canvas.data.item import TimelineItem
     22
     23
     24  DEFAULT_ERA_COLOR = (200, 200, 200)
     25
     26
     27 -class Era(ItemBase, TimelineItem):
     28      """
     29      A clearly defined period of time of arbitrary but well-defined length.
     30      An Era is indicated in a timeline, by setting the background color
     31      to the Era color for the Era time period. The Era name is also
     32      drawn on the timeline within the Era time period.
     33      """
     34
     35 -    def __init__(self, db=None, id_=None, immutable_value=ImmutableEra()):
     36          ItemBase.__init__(self, db, id_, immutable_value)
     37
     38 -    def save(self):
     39          with self._db.transaction("Save era") as t:
     40              t.save_era(self._immutable_value, self.ensure_id())
     41          return self
     42
     43 -    def delete(self):
     44          with self._db.transaction("Delete era") as t:
     45              t.delete_era(self.id)
     46          self.id = None
     47
     48 -    def __eq__(self, other):
     49          return (isinstance(other, Era) and
     50                  self.get_id() == other.get_id() and
     51                  self.get_time_period() == other.get_time_period() and
     52                  self.get_name() == other.get_name() and
     53                  self.get_color() == other.get_color())
     54
     55 -    def __ne__(self, other):
     56          return not (self == other)
     57
     58 -    def __gt__(self, other):
     59          return self.get_start_time() > other.get_start_time()
     60
     61 -    def __lt__(self, other):
     62          return self.get_start_time() < other.get_start_time()
     63
     64 -    def ends_today(self):
     65          return self._immutable_value.ends_today
     66
     67 -    def set_ends_today(self, value):
     68          self._immutable_value = self._immutable_value.update(ends_today=value)
     69
     70      _ends_today = property(ends_today, set_ends_today)
     71
     72 -    def update(self, start_time, end_time, name, color=DEFAULT_ERA_COLOR):
     73          """ """
     74          self.update_period(start_time, end_time)
     75          self.name = name.strip()
     76          self.color = color
     77          return self
     78
     79 -    def set_name(self, name):
     80          self._immutable_value = self._immutable_value.update(name=name.strip())
     81          return self
     82
     83 -    def get_name(self):
     84          return self._immutable_value.name
     85
     86      name = property(get_name, set_name)
     87
     88 -    def set_color(self, color):
     89          self._immutable_value = self._immutable_value.update(color=color)
     90          return self
     91
     92 -    def get_color(self):
     93          return self._immutable_value.color
     94
     95      color = property(get_color, set_color)
     96
     97 -    def overlapping(self, era):
     98          """ """
     99          if era.get_start_time() >= self.get_end_time():
    100              return 0
    101          if era.get_start_time() == self.get_start_time():
    102              if era.get_end_time() == self.get_end_time():
    103                  return 4
    104              if era.get_end_time() > self.get_end_time():
    105                  return 2
    106              else:
    107                  return 3
    108          if era.get_end_time() == self.get_end_time():
    109              return 5
    110          if era.get_end_time() > self.get_end_time():
    111              return 1
    112          return 6
    113