Gnumed.timelinelib.db.objects.event

Package Gnumed :: Package timelinelib :: Package db :: Package objects :: Module event |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.db.objects.event

      1  # Copyright (C) 2009, 2010, 2011  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.db.objects.timeperiod import TimePeriod
     20
     21
     22 -class Event(object):
     23
     24 -    def __init__(self, time_type, start_time, end_time, text, category=None,
     25                   fuzzy=False, locked=False, ends_today=False):
     26          self.time_type = time_type
     27          self.fuzzy = fuzzy
     28          self.locked = locked
     29          self.ends_today = ends_today
     30          self.id = None
     31          self.selected = False
     32          self.draw_ballon = False
     33          self.update(start_time, end_time, text, category)
     34          self.data = {}
     35
     36 -    def has_id(self):
     37          return self.id is not None
     38
     39 -    def set_id(self, id):
     40          self.id = id
     41
     42 -    def update(self, start_time, end_time, text, category=None, fuzzy=None,
     43                 locked=None, ends_today=None):
     44          """Change the event data."""
     45          self.time_period = TimePeriod(self.time_type, start_time, end_time)
     46          self.text = text
     47          self.category = category
     48          if ends_today is not None:
     49              if not self.locked:
     50                  self.ends_today = ends_today
     51          if fuzzy is not None:
     52              self.fuzzy = fuzzy
     53          if locked is not None:
     54              self.locked = locked
     55
     56 -    def update_period(self, start_time, end_time):
     57          """Change the event period."""
     58          self.time_period = TimePeriod(self.time_type, start_time, end_time)
     59
     60 -    def update_period_o(self, new_period):
     61          self.update_period(new_period.start_time, new_period.end_time)
     62
     63 -    def update_start(self, start_time):
     64          """Change the event data."""
     65          if start_time <= self.time_period.end_time:
     66              self.time_period = TimePeriod(
     67                  self.time_type, start_time, self.time_period.end_time)
     68              return True
     69          return False
     70
     71 -    def update_end(self, end_time):
     72          """Change the event data."""
     73          if end_time >= self.time_period.start_time:
     74              self.time_period = TimePeriod(
     75                  self.time_type, self.time_period.start_time, end_time)
     76              return True
     77          return False
     78
     79 -    def inside_period(self, time_period):
     80          """Wrapper for time period method."""
     81          return self.time_period.overlap(time_period)
     82
     83 -    def is_period(self):
     84          """Wrapper for time period method."""
     85          return self.time_period.is_period()
     86
     87 -    def mean_time(self):
     88          """Wrapper for time period method."""
     89          return self.time_period.mean_time()
     90
     91 -    def get_data(self, id):
     92          """
     93          Return data with the given id or None if no data with that id exists.
     94
     95          See set_data for information how ids map to data.
     96          """
     97          return self.data.get(id, None)
     98
     99 -    def set_data(self, id, data):
    100          """
    101          Set data with the given id.
    102
    103          Here is how ids map to data:
    104
    105              description - string
    106              icon - wx.Bitmap
    107          """
    108          self.data[id] = data
    109
    110 -    def has_data(self):
    111          """Return True if the event has associated data, or False if not."""
    112          for id in self.data:
    113              if self.data[id] != None:
    114                  return True
    115          return False
    116
    117 -    def get_label(self):
    118          """Returns a unicode label describing the event."""
    119          return u"%s (%s)" % (self.text, self.time_period.get_label())
    120
    121 -    def clone(self):
    122          # Objects of type datetime are immutable.
    123          new_event = Event(self.time_type, self.time_period.start_time,
    124                            self.time_period.end_time, self.text, self.category)
    125          # Description is immutable
    126          new_event.set_data("description", self.get_data("description") )
    127          # Icon is immutable in the sense that it is never changed by our
    128          # application.
    129          new_event.set_data("icon", self.get_data("icon"))
    130          new_event.set_data("hyperlink", self.get_data("hyperlink"))
    131          return new_event
    132
    133 -    def is_container(self):
    134          return False
    135
    136 -    def is_subevent(self):
    137          return False
    138
    139 -    def time_span(self):
    140          return self.time_period.end_time - self.time_period.start_time
    141