Gnumed.timelinelib.canvas.backgrounddrawers.defaultbgdrawer

Package Gnumed :: Package timelinelib :: Package canvas :: Package backgrounddrawers :: Module defaultbgdrawer |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.canvas.backgrounddrawers.defaultbgdrawer

     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  import wx
    20
    21
    22 -class DefaultBackgroundDrawer(object):
    23
    24 -    def draw(self, drawer, dc, scene, timeline, colorize_weekends, weekend_colour, bg_colour):
    25          self.drawer = drawer
    26          self._erase_background(dc, bg_colour)
    27          self._draw_eras(dc, scene, timeline)
    28          self._draw_weekend_days(dc, drawer, scene, colorize_weekends, weekend_colour)
    29
    30 -    def _erase_background(self, dc, bg_colour):
    31          w, h = dc.GetSizeTuple()
    32          self._set_color(dc, bg_colour)
    33          dc.DrawRectangle(0, 0, w, h)
    34
    35 -    def _draw_weekend_days(self, dc, drawer, scene, colorize_weekends, weekend_colour):
    36          if colorize_weekends and scene.minor_strip_is_day():
    37              _, h = dc.GetSizeTuple()
    38              for strip_period in scene.minor_strip_data:
    39                  if scene.is_weekend_day(strip_period.start_time):
    40                      self._draw_weekend_rect(strip_period, h, weekend_colour)
    41
    42 -    def _draw_eras(self, dc, scene, timeline):
    43          _, h = dc.GetSizeTuple()
    44          for era in timeline.get_all_periods():
    45              if self.drawer.period_is_visible(era.get_time_period()):
    46                  self._draw_era(era, h)
    47
    48 -    def _draw_era(self, era, h):
    49          self._draw_era_rect(era, h)
    50          self._draw_era_name_in_center_of_visible_era(era, h)
    51
    52 -    def _draw_era_rect(self, era, h):
    53          self._draw_timeperiod_rect(era.get_time_period(), h, era.get_color(), 0)
    54
    55 -    def _draw_weekend_rect(self, timeperiod, h, weekend_colour):
    56          OFFSET = 15
    57          self._draw_timeperiod_rect(timeperiod, h, weekend_colour, OFFSET)
    58
    59 -    def _draw_timeperiod_rect(self, timeperiod, h, colour, Offset):
    60          x, width = self._get_timeperiod_measures(timeperiod)
    61          self._draw_backgound_rect(x, h, max(1, width), colour, Offset)
    62
    63 -    def _draw_backgound_rect(self, x, h, width, colour, Offset):
    64          self._set_color(self.drawer.dc, colour)
    65          self.drawer.dc.DrawRectangle(x, Offset, width, h - 2 * Offset)
    66
    67 -    def _draw_era_name_in_center_of_visible_era(self, era, h):
    68          x, width = self._get_timeperiod_measures(era.get_time_period())
    69          wt, ht = self.drawer.dc.GetTextExtent(era.get_name())
    70          self.drawer.dc.DrawText(era.get_name(), x + width / 2 - wt / 2, h - ht)
    71
    72 -    def _get_timeperiod_measures(self, time_period):
    73          x1, x2 = self.drawer.get_period_xpos(time_period)
    74          return x1, x2 - x1
    75
    76 -    def _set_color(self, dc, color):
    77          dc.SetPen(wx.Pen(color))
    78          dc.SetBrush(wx.Brush(color))
    79