Package Gnumed :: Package timelinelib :: Package drawing :: Module viewproperties |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.drawing.viewproperties

      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 -class ViewProperties(object):
     20      """
     21      Store properties of a view.
     22
     23      Some timeline databases support storing some of these view properties
     24      together with the data.
     25      """
     26
     27 -    def __init__(self):
     28          self.sticky_balloon_event_ids = []
     29          self.hovered_event = None
     30          self.selected_event_ids = []
     31          self.hidden_categories = []
     32          self.period_selection = None
     33          self.show_legend = True
     34          self.divider_position = 0.5
     35          self.displayed_period = None
     36
     37 -    def clear_db_specific(self):
     38          self.sticky_balloon_event_ids = []
     39          self.hovered_event = None
     40          self.selected_event_ids = []
     41          self.hidden_categories = []
     42          self.period_selection = None
     43          self.displayed_period = None
     44
     45 -    def filter_events(self, events):
     46          def category_visible(e, cat):
     47              if cat is None:
     48                  return True
     49              elif e.is_subevent():
     50                  container_visible = category_visible(e.container,
     51                                                       e.container.category)
     52                  if container_visible:
     53                      if self.category_visible(cat) == True:
     54                          return category_visible(e, cat.parent)
     55                      else:
     56                          return False
     57                  else:
     58                      return False
     59              elif self.category_visible(cat) == True:
     60                  return category_visible(e, cat.parent)
     61              else:
     62                  return False
     63          return [e for e in events if category_visible(e, e.category)]
     64
     65 -    def is_selected(self, event):
     66          return event.id in self.selected_event_ids
     67
     68 -    def clear_selected(self):
     69          self.selected_event_ids = []
     70
     71 -    def event_is_hovered(self, event):
     72          return (self.hovered_event is not None and
     73                  event.id == self.hovered_event.id)
     74
     75 -    def event_has_sticky_balloon(self, event):
     76          return event.id in self.sticky_balloon_event_ids
     77
     78 -    def set_event_has_sticky_balloon(self, event, has_sticky=True):
     79          if has_sticky == True and not event.id in self.sticky_balloon_event_ids:
     80              self.sticky_balloon_event_ids.append(event.id)
     81          elif has_sticky == False and event.id in self.sticky_balloon_event_ids:
     82              self.sticky_balloon_event_ids.remove(event.id)
     83
     84 -    def set_selected(self, event, is_selected=True):
     85          if is_selected == True and not event.id in self.selected_event_ids:
     86              self.selected_event_ids.append(event.id)
     87          elif is_selected == False and event.id in self.selected_event_ids:
     88              self.selected_event_ids.remove(event.id)
     89
     90 -    def set_displayed_period(self, period):
     91          self.displayed_period = period
     92
     93 -    def get_selected_event_ids(self):
     94          return self.selected_event_ids[:]
     95
     96 -    def category_visible(self, category):
     97          return not category.id in self.hidden_categories
     98
     99 -    def set_category_visible(self, category, is_visible=True):
    100          if is_visible == True and category.id in self.hidden_categories:
    101              self.hidden_categories.remove(category.id)
    102          elif is_visible == False and not category.id in self.hidden_categories:
    103              self.hidden_categories.append(category.id)
    104