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

Source Code for Module Gnumed.timelinelib.canvas.drawing.drawers.minorstrip

 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 timelinelib.canvas.drawing.drawers.resources as resource 
20  import timelinelib.wxgui.components.font as font 
21   
22   
23 -class MinorStripDrawer:
24
25 - def __init__(self, drawer):
26 self._scene = drawer.scene 27 self._dc = drawer.dc 28 self._time_type = drawer.time_type 29 self._appearance = drawer.appearance 30 drawer.dc.SetPen(resource.get_pen('gray-dashed'))
31
32 - def draw(self, label, start_time, end_time):
33 self._draw_minor_strip_divider_line_at(end_time) 34 self._draw_minor_strip_label(label, start_time, end_time)
35
36 - def _draw_minor_strip_divider_line_at(self, end_time):
37 x = self._scene.x_pos_for_time(end_time) 38 self._dc.DrawLine(x, 0, x, self._scene.height)
39
40 - def _draw_minor_strip_label(self, label, start_time, end_time):
41 self._set_minor_strip_font(start_time) 42 x = self._calc_label_x_start_pos(label, start_time, end_time) 43 height = self._get_label_height(label) 44 {0: self._draw_at_top, 45 1: self._draw_at_divider, 46 2: self._draw_at_bottom}[self._appearance.get_time_scale_pos()](label, x, height)
47
48 - def _draw_at_divider(self, label, x, height):
49 self._dc.DrawText(label, x, self._scene.divider_y - height)
50
51 - def _draw_at_top(self, label, x, height):
52 self._dc.DrawText(label, x, height + 1)
53
54 - def _draw_at_bottom(self, label, x, height):
55 self._dc.DrawText(label, x, self._scene.height - 2 * height)
56
57 - def _calc_label_x_start_pos(self, label, start_time, end_time):
58 width = self._get_label_width(label) 59 start_x = self._scene.x_pos_for_time(start_time) 60 end_x = self._scene.x_pos_for_time(end_time) 61 return (start_x + end_x - width) / 2
62
63 - def _get_label_width(self, label):
64 return self._dc.GetTextExtent(label)[0]
65
66 - def _get_label_height(self, label):
67 return self._dc.GetTextExtent(label)[1]
68
69 - def _set_minor_strip_font(self, start_time):
70 if self._scene.minor_strip_is_day(): 71 bold = self._time_type.is_weekend_day(start_time) 72 italic = self._time_type.is_special_day(start_time) 73 font.set_minor_strip_text_font(self._appearance.get_minor_strip_font(), 74 self._dc, 75 force_bold=bold, 76 force_normal=not bold, 77 force_italic=italic, 78 force_upright=not italic) 79 else: 80 font.set_minor_strip_text_font(self._appearance.get_minor_strip_font(), self._dc)
81