2012-08-03 12:00:30 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# callirhoe - high quality calendar rendering
|
2014-03-10 00:29:49 +00:00
|
|
|
# Copyright (C) 2012-2014 George M. Tzoumas
|
2012-08-03 12:00:30 +00:00
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see http://www.gnu.org/licenses/
|
|
|
|
|
2014-09-03 12:56:19 +00:00
|
|
|
"""classic layout"""
|
2012-08-03 12:00:30 +00:00
|
|
|
|
|
|
|
from lib.xcairo import *
|
|
|
|
from lib.geom import *
|
|
|
|
import calendar
|
2012-08-06 10:50:18 +00:00
|
|
|
import sys
|
2013-12-29 20:56:48 +00:00
|
|
|
from datetime import date, timedelta
|
2012-08-03 12:00:30 +00:00
|
|
|
|
2014-03-10 00:29:49 +00:00
|
|
|
import _base
|
2012-08-03 12:00:30 +00:00
|
|
|
|
2014-05-09 14:01:28 +00:00
|
|
|
parser = _base.get_parser(__name__)
|
2012-08-03 12:00:30 +00:00
|
|
|
|
2014-02-04 00:10:19 +00:00
|
|
|
def _weekrows_of_month(year, month):
|
2014-10-21 16:45:52 +00:00
|
|
|
"""returns the number of Monday-Sunday ranges (or subsets of) that a month contains, which are 4, 5 or 6
|
|
|
|
|
|
|
|
@rtype: int
|
|
|
|
"""
|
2012-08-03 12:00:30 +00:00
|
|
|
day,span = calendar.monthrange(year, month)
|
|
|
|
if day == 0 and span == 28: return 4
|
|
|
|
if day == 5 and span == 31: return 6
|
|
|
|
if day == 6 and span >= 30: return 6
|
|
|
|
return 5
|
|
|
|
|
2014-05-09 14:01:28 +00:00
|
|
|
class CalendarRenderer(_base.CalendarRenderer):
|
2014-09-03 12:56:19 +00:00
|
|
|
"""classic tiles layout class"""
|
2014-09-03 21:18:16 +00:00
|
|
|
def _draw_month(self, cr, rect, month, year):
|
2014-05-09 14:01:28 +00:00
|
|
|
S,G,L = self.Theme
|
2014-09-03 12:56:19 +00:00
|
|
|
make_sloppy_rect(cr, rect, G.month.sloppy_dx, G.month.sloppy_dy, G.month.sloppy_rot)
|
2014-05-09 14:01:28 +00:00
|
|
|
|
|
|
|
day, span = calendar.monthrange(year, month)
|
|
|
|
weekrows = 6 if G.month.symmetric else _weekrows_of_month(year, month)
|
|
|
|
dom = -day + 1;
|
|
|
|
wmeasure = 'A'*max(map(len,L.day_name))
|
|
|
|
mmeasure = 'A'*max(map(len,L.month_name))
|
|
|
|
if self.options.month_with_year:
|
|
|
|
mmeasure += 'A'*(len(str(year))+1)
|
|
|
|
|
|
|
|
grid = GLayout(rect_from_origin(rect), 7, 7)
|
|
|
|
# 61.8% - 38.2% split (golden)
|
|
|
|
R_mb, R_db = rect_vsplit(grid.item_span(1, 7, 0, 0), 0.618) # month name bar, day name bar
|
|
|
|
R_dnc = HLayout(R_db, 7) # day name cells = 1/7-th of day name bar
|
|
|
|
dom_grid = GLayout(grid.item_span(6, 7, 1, 0), weekrows, 7)
|
2012-08-03 12:00:30 +00:00
|
|
|
|
2014-05-09 14:01:28 +00:00
|
|
|
# draw box shadow
|
|
|
|
if S.month.box_shadow:
|
|
|
|
f = S.month.box_shadow_size
|
|
|
|
shad = (f,-f) if G.landscape else (f,f)
|
|
|
|
draw_shadow(cr, rect_from_origin(rect), shad)
|
|
|
|
|
|
|
|
# draw day names
|
2012-08-03 12:00:30 +00:00
|
|
|
for col in range(7):
|
2014-05-09 14:01:28 +00:00
|
|
|
R = R_dnc.item(col)
|
|
|
|
draw_box(cr, rect = R, stroke_rgba = S.dom.frame,
|
|
|
|
fill_rgba = S.dom.bg if col < 5 else S.dom_weekend.bg,
|
|
|
|
stroke_width = mm_to_dots(S.dow.frame_thickness))
|
|
|
|
R_text = rect_rel_scale(R, 1, 0.5)
|
2014-09-03 12:56:19 +00:00
|
|
|
draw_str(cr, text = L.day_name[col], rect = R_text, scaling = -1, stroke_rgba = S.dow.fg,
|
2014-05-09 14:01:28 +00:00
|
|
|
align = (2,0), font = S.dow.font, measure = wmeasure)
|
2012-08-03 12:00:30 +00:00
|
|
|
|
2014-05-09 14:01:28 +00:00
|
|
|
# draw day cells
|
|
|
|
for row in range(weekrows):
|
|
|
|
for col in range(7):
|
|
|
|
R = dom_grid.item(row, col)
|
|
|
|
if dom > 0 and dom <= span:
|
|
|
|
holiday_tuple = self.holiday_provider(year, month, dom, col)
|
|
|
|
day_style = holiday_tuple[2]
|
|
|
|
dcell = _base.DayCell(day = (dom, col), header = holiday_tuple[0], footer = holiday_tuple[1],
|
|
|
|
theme = (day_style, G.dom, L), show_day_name = False)
|
2014-09-03 21:18:16 +00:00
|
|
|
dcell.draw(cr, R, self.options.short_daycell_ratio)
|
2014-05-09 14:01:28 +00:00
|
|
|
else:
|
|
|
|
day_style = S.dom_weekend if col >= 5 else S.dom
|
|
|
|
draw_box(cr, rect = R, stroke_rgba = day_style.frame, fill_rgba = day_style.bg,
|
|
|
|
stroke_width = mm_to_dots(day_style.frame_thickness))
|
|
|
|
dom += 1
|
|
|
|
|
|
|
|
# draw month title (name)
|
|
|
|
mcolor = S.month.color_map_bg[year%2][month]
|
|
|
|
mcolor_fg = S.month.color_map_fg[year%2][month]
|
|
|
|
draw_box(cr, rect = R_mb, stroke_rgba = S.month.frame, fill_rgba = mcolor,
|
|
|
|
stroke_width = mm_to_dots(S.month.frame_thickness)) # title box
|
|
|
|
draw_box(cr, rect = rect_from_origin(rect), stroke_rgba = S.month.frame, fill_rgba = (),
|
|
|
|
stroke_width = mm_to_dots(S.month.frame_thickness)) # full box
|
|
|
|
R_text = rect_rel_scale(R_mb, 1, 0.5)
|
|
|
|
mshad = None
|
|
|
|
if S.month.text_shadow:
|
|
|
|
f = S.month.text_shadow_size
|
|
|
|
mshad = (f,-f) if G.landscape else (f,f)
|
|
|
|
title_str = L.month_name[month]
|
|
|
|
if self.options.month_with_year: title_str += ' ' + str(year)
|
2014-09-03 12:56:19 +00:00
|
|
|
draw_str(cr, text = title_str, rect = R_text, scaling = -1, stroke_rgba = mcolor_fg,
|
2014-05-09 14:01:28 +00:00
|
|
|
align = (2,0), font = S.month.font, measure = mmeasure, shadow = mshad)
|
|
|
|
cr.restore()
|
2012-08-03 12:00:30 +00:00
|
|
|
|