Gnumed.timelinelib.canvas.drawing.viewproperties

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

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

      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.general.observer import Observable
     20
     21
     22 -class ViewProperties(Observable):
     23      """
     24      Store properties of a view.
     25
     26      Some timeline databases support storing some of these view properties
     27      together with the data.
     28      """
     29
     30 -    def __init__(self):
     31          Observable.__init__(self)
     32          self.sticky_balloon_event_ids = []
     33          self.hovered_event = None
     34          self.selected_event_ids = []
     35          self._hidden_category_ids = []
     36          self.period_selection = None
     37          self.divider_position = 0.5
     38          self.displayed_period = None
     39          self.hscroll_amount = 0
     40          self.view_cats_individually = False
     41          self.fixed_event_vertical_pos = False
     42          self.fuzzy_icon = None
     43          self.locked_icon = None
     44          self.hyperlink_icon = None
     45          self.skip_s_in_decade_text = False
     46          self.display_checkmark_on_events_done = False
     47          self.legend_pos = 0
     48          self._hide_events_done = False
     49          self._all_events = []
     50          self._event_highlight_counters = {}
     51          self._selection_rect = None
     52
     53 -    def is_highlighted(self, event):
     54          return event.get_id() in self._event_highlight_counters
     55
     56 -    def has_higlights(self):
     57          return len(self._event_highlight_counters) > 0
     58
     59 -    def add_highlight(self, event, clear):
     60          if clear:
     61              self._event_highlight_counters.clear()
     62          self._event_highlight_counters[event.get_id()] = 0
     63
     64 -    def get_highlight_count(self, event):
     65          return self._event_highlight_counters[event.get_id()]
     66
     67 -    def tick_highlights(self, limit):
     68          self._event_highlight_counters = {
     69              event_id: count + 1
     70              for event_id, count in self._event_highlight_counters.iteritems()
     71              if count < limit
     72          }
     73
     74      @property
     75 -    def legend_pos(self):
     76          return self._legend_pos
     77
     78      @legend_pos.setter
     79 -    def legend_pos(self, pos):
     80          self._legend_pos = pos
     81
     82      @property
     83 -    def hide_events_done(self):
     84          return self._hide_events_done
     85
     86      @hide_events_done.setter
     87 -    def hide_events_done(self, value):
     88          self._hide_events_done = value
     89
     90 -    def get_fuzzy_icon(self):
     91          return self.fuzzy_icon
     92
     93 -    def set_fuzzy_icon(self, name):
     94          self.fuzzy_icon = name
     95
     96 -    def get_locked_icon(self):
     97          return self.locked_icon
     98
     99 -    def set_locked_icon(self, name):
    100          self.locked_icon = name
    101
    102 -    def get_hyperlink_icon(self):
    103          return self.hyperlink_icon
    104
    105 -    def set_hyperlink_icon(self, name):
    106          self.hyperlink_icon = name
    107
    108 -    def get_skip_s_in_decade_text(self):
    109          return self.skip_s_in_decade_text
    110
    111 -    def set_skip_s_in_decade_text(self, value):
    112          self.skip_s_in_decade_text = value
    113
    114 -    def get_display_checkmark_on_events_done(self):
    115          return self.display_checkmark_on_events_done
    116
    117 -    def set_display_checkmark_on_events_done(self, value):
    118          self.display_checkmark_on_events_done = value
    119
    120 -    def set_use_fixed_event_vertical_pos(self, value):
    121          self.fixed_event_vertical_pos = value
    122
    123 -    def use_fixed_event_vertical_pos(self):
    124          return self.fixed_event_vertical_pos
    125
    126 -    def clear_db_specific(self):
    127          self.sticky_balloon_event_ids = []
    128          self.hovered_event = None
    129          self.selected_event_ids = []
    130          self._hidden_category_ids = []
    131          self.period_selection = None
    132          self.displayed_period = None
    133          self._event_highlight_counters = {}
    134          self._notify()
    135
    136 -    def change_hovered_event(self, event):
    137          if self.hovered_event != event:
    138              self.hovered_event = event
    139              self._notify()
    140
    141 -    def set_selection_rect(self, rect):
    142          self._selection_rect = rect
    143
    144 -    def change_view_cats_individually(self, view_cats_individually):
    145          if self.view_cats_individually != view_cats_individually:
    146              self.view_cats_individually = view_cats_individually
    147              self._notify()
    148
    149 -    def get_displayed_period(self):
    150          return self.displayed_period
    151
    152 -    def filter_events(self, events):
    153          self._all_events = events
    154          return [event for event in events if self._is_event_visible(event)]
    155
    156 -    def _is_event_visible(self, event):
    157          if self._hide_events_done and event.get_progress() == 100:
    158              return False
    159          if event.is_subevent():
    160              return (self.is_event_with_category_visible(event.get_category()) and
    161                      self.is_event_with_category_visible(event.container.get_category()))
    162          else:
    163              return self.is_event_with_category_visible(event.get_category())
    164
    165 -    def is_selected(self, event):
    166          return event.get_id() in self.selected_event_ids
    167
    168 -    def clear_selected(self):
    169          if self.selected_event_ids:
    170              self.selected_event_ids = []
    171              self._notify()
    172
    173 -    def select_all_events(self):
    174          self.selected_event_ids = [event.get_id() for event in self._all_events
    175                                     if not event.is_container()]
    176          self._notify()
    177
    178 -    def event_is_hovered(self, event):
    179          return (self.hovered_event is not None and
    180                  event.id == self.hovered_event.id)
    181
    182 -    def event_has_sticky_balloon(self, event):
    183          return event.id in self.sticky_balloon_event_ids
    184
    185 -    def set_event_has_sticky_balloon(self, event, has_sticky=True):
    186          if has_sticky is True and event.id not in self.sticky_balloon_event_ids:
    187              self.sticky_balloon_event_ids.append(event.id)
    188          elif has_sticky is False and event.id in self.sticky_balloon_event_ids:
    189              self.sticky_balloon_event_ids.remove(event.id)
    190          self._notify()
    191
    192 -    def set_selected(self, event, is_selected=True):
    193          if is_selected is True and not event.get_id() in self.selected_event_ids:
    194              self.selected_event_ids.append(event.get_id())
    195              self._notify()
    196          elif is_selected is False and event.get_id() in self.selected_event_ids:
    197              self.selected_event_ids.remove(event.get_id())
    198              self._notify()
    199
    200 -    def set_all_selected(self, events):
    201          for event in events:
    202              if not event.get_id() in self.selected_event_ids:
    203                  self.selected_event_ids.append(event.get_id())
    204          self._notify()
    205
    206 -    def set_only_selected(self, event, is_selected):
    207          if is_selected:
    208              if self.selected_event_ids != [event.get_id()]:
    209                  self.selected_event_ids = [event.get_id()]
    210                  self._notify()
    211          else:
    212              self.clear_selected()
    213
    214 -    def set_displayed_period(self, period, notify=True):
    215          self.displayed_period = period
    216          if notify:
    217              self._notify()
    218
    219 -    def get_selected_event_ids(self):
    220          return self.selected_event_ids[:]
    221
    222 -    def toggle_category_visibility(self, category):
    223          self.set_category_visible(category,
    224                                    not self.is_category_visible(category))
    225
    226 -    def is_category_visible(self, category):
    227          return category.get_id() not in self._hidden_category_ids
    228
    229 -    def is_event_with_category_visible(self, category):
    230          if category is None:
    231              return True
    232          elif self.view_cats_individually:
    233              return self.is_category_visible(category)
    234          else:
    235              return self._is_category_recursively_visible(category)
    236
    237 -    def _is_category_recursively_visible(self, category):
    238          if self.is_category_visible(category):
    239              if category._get_parent() is None:
    240                  return True
    241              else:
    242                  return self._is_category_recursively_visible(category._get_parent())
    243          else:
    244              return False
    245
    246 -    def set_categories_visible(self, categories, is_visible=True):
    247          category_ids = [category.id for category in categories]
    248          self._set_categories_with_ids_visible(category_ids, is_visible)
    249
    250 -    def set_category_visible(self, category, is_visible=True):
    251          self._set_categories_with_ids_visible([category.get_id()], is_visible)
    252
    253 -    def _set_categories_with_ids_visible(self, category_ids, is_visible):
    254          need_notify = False
    255          for category_id in category_ids:
    256              if is_visible is True and category_id in self._hidden_category_ids:
    257                  self._hidden_category_ids.remove(category_id)
    258                  need_notify = True
    259              elif is_visible is False and category_id not in self._hidden_category_ids:
    260                  self._hidden_category_ids.append(category_id)
    261                  need_notify = True
    262          if need_notify:
    263              self._notify()
    264