1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """classic layout"""
19
20 from lib.xcairo import *
21 from lib.geom import *
22 import calendar
23 import sys
24 from datetime import date, timedelta
25
26 import _base
27
28 parser = _base.get_parser(__name__)
29
31 """returns the number of Monday-Sunday ranges (or subsets of) that a month contains, which are 4, 5 or 6
32
33 @rtype: int
34 """
35 day,span = calendar.monthrange(year, month)
36 if day == 0 and span == 28: return 4
37 if day == 5 and span == 31: return 6
38 if day == 6 and span >= 30: return 6
39 return 5
40
42 """classic tiles layout class"""
44 S,G,L = self.Theme
45 make_sloppy_rect(cr, rect, G.month.sloppy_dx, G.month.sloppy_dy, G.month.sloppy_rot)
46
47 day, span = calendar.monthrange(year, month)
48 weekrows = 6 if G.month.symmetric else _weekrows_of_month(year, month)
49 dom = -day + 1;
50 wmeasure = 'A'*max(map(len,L.day_name))
51 mmeasure = 'A'*max(map(len,L.month_name))
52 if self.options.month_with_year:
53 mmeasure += 'A'*(len(str(year))+1)
54
55 grid = GLayout(rect_from_origin(rect), 7, 7)
56
57 R_mb, R_db = rect_vsplit(grid.item_span(1, 7, 0, 0), 0.618)
58 R_dnc = HLayout(R_db, 7)
59 dom_grid = GLayout(grid.item_span(6, 7, 1, 0), weekrows, 7)
60
61
62 if S.month.box_shadow:
63 f = S.month.box_shadow_size
64 shad = (f,-f) if G.landscape else (f,f)
65 draw_shadow(cr, rect_from_origin(rect), shad)
66
67
68 for col in range(7):
69 R = R_dnc.item(col)
70 draw_box(cr, rect = R, stroke_rgba = S.dom.frame,
71 fill_rgba = S.dom.bg if col < 5 else S.dom_weekend.bg,
72 stroke_width = mm_to_dots(S.dow.frame_thickness))
73 R_text = rect_rel_scale(R, 1, 0.5)
74 draw_str(cr, text = L.day_name[col], rect = R_text, scaling = -1, stroke_rgba = S.dow.fg,
75 align = (2,0), font = S.dow.font, measure = wmeasure)
76
77
78 for row in range(weekrows):
79 for col in range(7):
80 R = dom_grid.item(row, col)
81 if dom > 0 and dom <= span:
82 holiday_tuple = self.holiday_provider(year, month, dom, col)
83 day_style = holiday_tuple[2]
84 dcell = _base.DayCell(day = (dom, col), header = holiday_tuple[0], footer = holiday_tuple[1],
85 theme = (day_style, G.dom, L), show_day_name = False)
86 dcell.draw(cr, R, self.options.short_daycell_ratio)
87 else:
88 day_style = S.dom_weekend if col >= 5 else S.dom
89 draw_box(cr, rect = R, stroke_rgba = day_style.frame, fill_rgba = day_style.bg,
90 stroke_width = mm_to_dots(day_style.frame_thickness))
91 dom += 1
92
93
94 mcolor = S.month.color_map_bg[year%2][month]
95 mcolor_fg = S.month.color_map_fg[year%2][month]
96 draw_box(cr, rect = R_mb, stroke_rgba = S.month.frame, fill_rgba = mcolor,
97 stroke_width = mm_to_dots(S.month.frame_thickness))
98 draw_box(cr, rect = rect_from_origin(rect), stroke_rgba = S.month.frame, fill_rgba = (),
99 stroke_width = mm_to_dots(S.month.frame_thickness))
100 R_text = rect_rel_scale(R_mb, 1, 0.5)
101 mshad = None
102 if S.month.text_shadow:
103 f = S.month.text_shadow_size
104 mshad = (f,-f) if G.landscape else (f,f)
105 title_str = L.month_name[month]
106 if self.options.month_with_year: title_str += ' ' + str(year)
107 draw_str(cr, text = title_str, rect = R_text, scaling = -1, stroke_rgba = mcolor_fg,
108 align = (2,0), font = S.month.font, measure = mmeasure, shadow = mshad)
109 cr.restore()
110