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